-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
98 lines (94 loc) · 2.82 KB
/
index.d.ts
File metadata and controls
98 lines (94 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
export interface ObscureStringOptions {
/** Character to use for masking (default: '*') */
maskChar?: string;
/** Number of characters to show at the beginning (default: 3) */
prefixLength?: number;
/** Number of characters to show at the end (default: 3) */
suffixLength?: number;
/** Minimum number of mask characters required (default: 0) */
minMaskLength?: number;
/** Mask the entire string (default: false) */
fullMask?: boolean;
/** Show middle, hide edges (default: false) */
reverseMask?: boolean;
/** Mask a percentage of the string (0-100) */
percentage?: number;
/** Maximum string length to process (default: 1000000) */
maxLength?: number;
/** Use a preset pattern: 'email', 'creditCard', 'phone' */
preset?: 'email' | 'creditCard' | 'phone';
}
export interface MaskInfo {
/** Whether the string will be masked */
willBeMasked: boolean;
/** Reason if not masked */
reason?: string;
/** Original string length */
originalLength?: number;
/** Number of characters that will be masked */
maskedLength?: number;
/** Number of visible characters */
visibleChars?: number;
/** Number of masked characters */
maskedChars?: number;
/** Prefix length */
prefixLength?: number;
/** Suffix length */
suffixLength?: number;
/** Minimum mask length */
minMaskLength?: number;
/** Actual mask length */
maskLength?: number;
}
/**
* Obscures a portion of a string by replacing characters with a mask character.
*
* @param str - The string to obscure
* @param options - Configuration options
* @returns The masked string
*
* @example
* ```ts
* obscureString('mysecretkey') // 'mys*****key'
* obscureString('john@example.com', { preset: 'email' }) // 'jo**@example.com'
* obscureString('4111111111111111', { preset: 'creditCard' }) // '************1111'
* ```
*/
export function obscureString(
str: string | null | undefined,
options?: ObscureStringOptions
): string;
/**
* Batch obscure multiple strings with the same options.
*
* @param strings - Array of strings to obscure
* @param options - Configuration options
* @returns Array of masked strings
*
* @example
* ```ts
* obscureStringBatch(['secret1', 'secret2'], { prefixLength: 2 })
* // ['se****1', 'se****2']
* ```
*/
export function obscureStringBatch(
strings: string[],
options?: ObscureStringOptions
): string[];
/**
* Get information about how a string would be masked without actually masking it.
*
* @param str - The string to analyze
* @param options - Configuration options
* @returns Information about the masking
*
* @example
* ```ts
* getMaskInfo('mysecret', { prefixLength: 3, suffixLength: 3 })
* // { willBeMasked: true, originalLength: 8, maskedLength: 2, ... }
* ```
*/
export function getMaskInfo(
str: string | null | undefined,
options?: ObscureStringOptions
): MaskInfo;