@handy-common-utils/misc-utils
Version:
Miscellaneous utilities
66 lines • 4.01 kB
TypeScript
/**
* Mask the content of a string
* @param input The input which could also be null or undefined
* @param keepLeft Number of characters on the left to be kept in the output without masking.
* Default value is 1.
* @param keepRight Number of characters on the right to be kept in the output without masking.
* Default value is 0.
* @param minLength Minimal length of the string for keepLeft and keepRight to be effective.
* If the input string is shorter than this length, the whole string would be masked.
* Default value is 3.
* @param maskLengthOrMaskString The string to be used for replacing the part in the input that needs to be masked,
* or the length of the mask string if a fixed length is desired,
* or null/undefined if the mask string should have the same length as the part to be masked.
* Default value is null.
* @param maskPattern The pattern to be repeated as the mask.
* Default value is '*'.
* @returns String with masked content
*/
export declare function mask<T extends string | undefined | null>(input: T, keepLeft?: number, keepRight?: number, minLength?: number, maskLengthOrMaskString?: number | string | undefined | null, maskPattern?: string): T;
/**
* Create a mask function with pre-set parameters.
* @example
* const maskApiKey = masker(2, 2, 10);
* const maskedString = maskApiKey(myApiKey);
*
* @param keepLeft Number of characters on the left to be kept in the output without masking.
* Default value is 1.
* @param keepRight Number of characters on the right to be kept in the output without masking.
* Default value is 0.
* @param minLength Minimal length of the string for keepLeft and keepRight to be effective.
* If the input string is shorter than this length, the whole string would be masked.
* Default value is 3.
* @param maskLengthOrMaskString The string to be used for replacing the part in the input that needs to be masked,
* or the length of the mask string if a fixed length is desired,
* or null/undefined if the mask string should have the same length as the part to be masked.
* Default value is null.
* @param maskPattern The pattern to be repeated as the mask.
* Default value is '*'.
* @returns A mask function that has specified parameters as pre-set
*/
export declare function masker<T extends string | undefined | null = string>(keepLeft?: number, keepRight?: number, minLength?: number, maskLengthOrMaskString?: number | string | undefined | null, maskPattern?: string): (input: T) => T;
/**
* Mask sensitive information in an email address while keeping some information for troubleshooting
* @param email the email address which could also be null or undefined
* @returns masked email address
*/
export declare function maskEmail<T extends string | undefined | null>(email: T): T;
/**
* Mask sensitive information in the full name while keeping useful information for troubleshooting
* @param name the full name which could also be null or undefined
* @returns masked full name
*/
export declare function maskFullName<T extends string | undefined | null>(name: T): T;
/**
* Replace each character of the input with '*'
* @param input a string or null or undefined
* @returns masked string or null or undefined
*/
export declare function maskAll<T extends string | undefined | null>(input: T): T;
/**
* Mask credit card number string
* @param input credit card number string which could also be null or undefined
* @returns Something like ****-****-****-1234, or null/undefined if the input is null/undefined
*/
export declare function maskCreditCard<T extends string | undefined | null>(input: T): T;
//# sourceMappingURL=mask.d.ts.map