-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
77 lines (71 loc) · 1.92 KB
/
index.ts
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
export type Mask =
| PercentageMask
| CenterPercentageMask
| UndefineMask
| ReplaceMask;
export interface PercentageMask {
type: "percentage";
/**
* Character to be used as the redacted part
* @default "•"
*/
redactWith?: "*" | "•" | string;
/**
* Percentage of the value to apply the mask on
* @default 100
*/
percentage?: number;
/**
* Which part of the value to redact
* @default "left"
*/
position?: "left" | "right";
}
export interface CenterPercentageMask {
type: "percentage";
position: "center";
/**
* Character to be used as the redacted part
* @default "•"
*/
redactWith?: "*" | "•" | string;
/**
* Percentage of the value to apply the mask on
* @default 100
*/
percentage?: number;
/**
* Whether the complementary part of the percentage should be masked
* @default false
*/
complementary?: boolean;
}
export interface UndefineMask {
type: "undefine";
}
export interface ReplaceMask {
type: "replace";
/**
* Replace the value entirely with this string
* @default "[redacted]"
*/
redactWith: "[redacted]" | string;
}
/** Redact-it configs to customize how and which fields are going to be redacted */
export interface RedactItConfig {
/** Field names to redact */
fields: (string | RegExp)[];
/** Which mask to apply */
mask?: Mask;
}
/** A replacer function compatible with JSON.stringify */
export type ReplacerFunction = (key: any, value: any) => any;
/**
* A function that takes the argument and creates a replacer function
* The argument may be a single object of the RedactItConfig type or an array of these objects
* @param {RedactItConfig | RedactItConfig[]} configs - RedactItConfig to customize the redact function
* @return {ReplacerFunction} replacer - A replacer function compatible with JSON.stringify
*/
export type RedactIt = (
configs?: RedactItConfig | RedactItConfig[]
) => ReplacerFunction;