UNPKG

data-guardian

Version:

Tiny, zero-dependencies, package which tries to mask sensitive data in arbitrary collections, errors, objects and strings.

79 lines (78 loc) 3.34 kB
export type SensitiveContentKey = keyof typeof sensitiveContentRegExp; type MaskingChar = 'X' | 'x' | '$' | '/' | '.' | '*' | '#' | '+' | '@' | '-' | '_' | ' '; interface IMaskDataOptions { keyCheck: (key: string) => boolean; immutable: boolean; customPatterns: Record<string, RegExp>; maskingChar: MaskingChar; maskLength: number; types: SensitiveContentKey[]; customSensitiveContentRegExp: Record<string, RegExp>; /** * When enabled, masks the sensitive content with a fixed number of characters, * irrespective of the original content's length. This prevents inferring the * length of the original content from the masked output. * Default is 'false', which means the mask will reflect the original content's length. */ fixedMaskLength: boolean; excludeMatchers?: SensitiveContentKey[]; convertNumbersToStringWhenFieldMatch?: boolean; } declare const sensitiveContentRegExp: { readonly uuid: RegExp; readonly creditCard: RegExp; readonly ssn: RegExp; readonly url: RegExp; readonly ipv4: RegExp; readonly email: RegExp; readonly passwordSubstring: RegExp; readonly password: RegExp; readonly passwordInUri: RegExp; readonly passwordMention: RegExp; }; /** * Masks sensitive parts of a string based on predefined and custom patterns. * * @param {string} value - The string to mask. * @returns {string} The masked string. */ export declare function maskString(value: string): string; /** * Masks sensitive parts of a string based on provided options. * * @param {string} value - The string to mask. * @param {Partial<IMaskDataOptions>} options - The options to customize the masking process. * @returns {string} The masked string. */ export declare function maskString(value: string, options: Partial<IMaskDataOptions>): string; /** * Masks sensitive parts of a string based on specified types and optionally custom patterns and options. * * @param {string} value - The string to mask. * @param {SensitiveContentKey[]} types - The types of sensitive content to mask. * @param {Record<string, RegExp>} [customSensitiveContentRegExp] - Custom regular expressions for detecting sensitive content. * @param {Partial<IMaskDataOptions>} [options] - The options to customize the masking process. * @returns {string} The masked string. */ export declare function maskString(value: string, types: SensitiveContentKey[], // This remains non-optional customSensitiveContentRegExp?: Record<string, RegExp>, options?: Partial<IMaskDataOptions>): string; /** * Masks data based on the type and the provided masking options. * This function is recursively called for nested objects. * * @template T * @param {T} item - The original data to mask. * @param {Partial<IMaskDataOptions>} [options={}] - Optional masking options. * @returns {T} The masked data. */ export declare function maskData<T>(item: T, options?: Partial<IMaskDataOptions>): T; /** * Masks arguments of a function call, based on the provided masking options. * * @template T * @param {unknown[]} args - The original arguments to mask. * @param {IMaskDataOptions} [options] - Optional masking options. * @returns {T[]} The masked arguments. */ export declare function maskArguments<T>(args: unknown[], options?: IMaskDataOptions): T[]; export {};