1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-29 15:50:28 +01:00
metamask-extension/shared/modules/string-utils.ts

30 lines
793 B
TypeScript
Raw Normal View History

/**
* Compare 2 given strings and return boolean
* eg: "foo" and "FOO" => true
* eg: "foo" and "bar" => false
* eg: "foo" and 123 => false
*
* @param value1 - first string to compare
* @param value2 - first string to compare
* @returns true if 2 strings are identical when they are lowercase
*/
export function isEqualCaseInsensitive(
value1: string,
value2: string,
): boolean {
if (typeof value1 !== 'string' || typeof value2 !== 'string') {
return false;
}
return value1.toLowerCase() === value2.toLowerCase();
}
/**
* Takes a number with max length until the resulting string reaches the given length
*
* @param num
* @param maxLength
*/
export function prependZero(num: number, maxLength: number): string {
return num.toString().padStart(maxLength, '0');
}