redact-it 0.2.5 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -47,15 +47,15 @@ For the following examples, we are going to use this main object as reference:
47
47
 
48
48
  ```typescript
49
49
  const userInfoToBeLogged = {
50
- password: "123",
51
- name: "foo",
52
- TOKEN: "my-secret-access-token",
50
+ password: '123',
51
+ name: 'foo',
52
+ TOKEN: 'my-secret-access-token',
53
53
  card: {
54
- number: "1234567887654321",
55
- cvv: "123",
56
- expirationDate: "2020-12-20",
54
+ number: '1234567887654321',
55
+ cvv: '123',
56
+ expirationDate: '2020-12-20',
57
57
  },
58
- authorization: "Bearer token",
58
+ authorization: 'Bearer token',
59
59
  };
60
60
  ```
61
61
 
@@ -66,7 +66,7 @@ The default `Mask` is the `replace` with the fixed string `[redacted]`:
66
66
 
67
67
  ```typescript
68
68
  const redactItConfig: RedactItConfig = {
69
- fields: ["password", "cvv", "TOKEN", "authorization"],
69
+ fields: ['password', 'cvv', 'TOKEN', 'authorization'],
70
70
  };
71
71
 
72
72
  const replacerFunction: ReplacerFunction = redactIt(redactItConfig);
@@ -94,31 +94,31 @@ const parsedResult = JSON.parse(stringResult);
94
94
  ```typescript
95
95
  const redactItConfig: RedactItConfig = [
96
96
  {
97
- fields: ["password"], // which fields to redact
97
+ fields: ['password'], // which fields to redact
98
98
  mask: {
99
99
  // How to redact the fields
100
- type: "undefine", // the undefine mask removes the fields
100
+ type: 'undefine', // the undefine mask removes the fields
101
101
  },
102
102
  },
103
103
  {
104
104
  fields: [/token/i], // Will match the regex against all fields
105
105
  },
106
106
  {
107
- fields: ["expirationDate", "number"],
107
+ fields: ['expirationDate', 'number'],
108
108
  mask: {
109
- type: "percentage", // Percentage masks redact data partially
110
- redactWith: "•", // Redacted characters replaced by •
109
+ type: 'percentage', // Percentage masks redact data partially
110
+ redactWith: '•', // Redacted characters replaced by •
111
111
  percentage: 75, // 75% of the value should be redacted
112
112
  },
113
113
  },
114
114
  {
115
- fields: ["authorization"],
115
+ fields: ['authorization'],
116
116
  mask: {
117
- type: "replace", // Replaces the whole value with the `redactWith` string
118
- redactWith: "[REDACTED FOR COMPLIANCE REASONS]",
117
+ type: 'replace', // Replaces the whole value with the `redactWith` string
118
+ redactWith: '[REDACTED FOR COMPLIANCE REASONS]',
119
119
  },
120
120
  },
121
- { fields: ["cvv"] }, // if no mask is passed, fields values are redacted as [redacted]
121
+ { fields: ['cvv'] }, // if no mask is passed, fields values are redacted as [redacted]
122
122
  ];
123
123
 
124
124
  const replacerFunction: ReplacerFunction = redactIt(redactItConfig);
package/dist/index.cjs.js CHANGED
@@ -1,13 +1,10 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  const percentageValueMasker = (value, mask) => {
6
- var _a, _b, _c, _d;
7
- const redactor = (_a = mask.redactWith) !== null && _a !== void 0 ? _a : "•";
8
- const percentage = (_b = mask.percentage) !== null && _b !== void 0 ? _b : 100;
9
- const complementary = (_c = mask.position === "center" && mask.complementary) !== null && _c !== void 0 ? _c : false;
10
- const position = (_d = mask.position) !== null && _d !== void 0 ? _d : "left";
4
+ const redactor = mask.redactWith ?? '•';
5
+ const percentage = mask.percentage ?? 100;
6
+ const complementary = (mask.position === 'center' && mask.complementary) ?? false;
7
+ const position = mask.position ?? 'left';
11
8
  const finalRedactor = p1 => redactor.length > 1 ? redactor : p1.replace(/./g, redactor);
12
9
  if (percentage === 100) return finalRedactor(value);
13
10
  const stringValue = String(value);
@@ -15,10 +12,10 @@ const percentageValueMasker = (value, mask) => {
15
12
  const maskedLength = Math.ceil(stringLength * percentage / 100);
16
13
  const unmaskedLength = stringLength - maskedLength;
17
14
  const regexString = () => {
18
- if (position === "center") {
15
+ if (position === 'center') {
19
16
  return `(.{${unmaskedLength / 2}})(.{${maskedLength}})(.+)`;
20
17
  }
21
- if (position === "right") {
18
+ if (position === 'right') {
22
19
  return `(.{${unmaskedLength}})(.{${maskedLength}})`;
23
20
  }
24
21
  return `(.{${maskedLength}})(.{${unmaskedLength}})`;
@@ -33,7 +30,7 @@ const percentageValueMasker = (value, mask) => {
33
30
  // Center
34
31
  return `${p1}${finalRedactor(p2)}${p3}`;
35
32
  }
36
- if (position === "right") {
33
+ if (position === 'right') {
37
34
  // Right
38
35
  return `${p1}${finalRedactor(p2)}`;
39
36
  }
@@ -45,19 +42,18 @@ const percentageValueMasker = (value, mask) => {
45
42
  };
46
43
  const redactIt = configs => {
47
44
  const defaultMask = {
48
- type: "replace",
49
- redactWith: "[redacted]"
45
+ type: 'replace',
46
+ redactWith: '[redacted]'
50
47
  };
51
48
  const defaultOptions = {
52
- fields: ["password"],
49
+ fields: ['password'],
53
50
  mask: defaultMask
54
51
  };
55
52
  const mappedFields = new Map();
56
- const optionsArray = Array.isArray(configs) ? configs : [configs !== null && configs !== void 0 ? configs : defaultOptions];
53
+ const optionsArray = Array.isArray(configs) ? configs : [configs ?? defaultOptions];
57
54
  optionsArray.forEach(option => {
58
55
  option.fields.forEach(field => {
59
- var _a;
60
- mappedFields.set(field, (_a = option.mask) !== null && _a !== void 0 ? _a : defaultMask);
56
+ mappedFields.set(field, option.mask ?? defaultMask);
61
57
  });
62
58
  });
63
59
  const getMaskForKey = key => {
@@ -79,10 +75,10 @@ const redactIt = configs => {
79
75
  const replacer = (key, value) => {
80
76
  const mask = getMaskForKey(key);
81
77
  if (mask) {
82
- if (mask.type === "replace") {
78
+ if (mask.type === 'replace') {
83
79
  return mask.redactWith;
84
80
  }
85
- if (mask.type === "undefine") {
81
+ if (mask.type === 'undefine') {
86
82
  return undefined;
87
83
  }
88
84
  return percentageValueMasker(value, mask);
@@ -93,3 +89,4 @@ const redactIt = configs => {
93
89
  };
94
90
 
95
91
  exports.redactIt = redactIt;
92
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/redact-it.ts"],"sourcesContent":["import type {\n Mask,\n RedactIt,\n RedactItConfig,\n ReplacerFunction,\n PercentageMask,\n CenterPercentageMask,\n} from '../typings';\n\nconst percentageValueMasker = (\n value: any,\n mask: PercentageMask | CenterPercentageMask,\n): string | undefined => {\n const redactor = mask.redactWith ?? '•';\n const percentage = mask.percentage ?? 100;\n const complementary = (mask.position === 'center' && mask.complementary) ?? false;\n const position = mask.position ?? 'left';\n\n const finalRedactor = (p1: string): string =>\n redactor.length > 1 ? redactor : p1.replace(/./g, redactor);\n\n if (percentage === 100) return finalRedactor(value);\n\n const stringValue = String(value);\n const stringLength = stringValue.length;\n const maskedLength = Math.ceil((stringLength * percentage) / 100);\n const unmaskedLength = stringLength - maskedLength;\n\n const regexString = (): string => {\n if (position === 'center') {\n return `(.{${unmaskedLength / 2}})(.{${maskedLength}})(.+)`;\n }\n if (position === 'right') {\n return `(.{${unmaskedLength}})(.{${maskedLength}})`;\n }\n return `(.{${maskedLength}})(.{${unmaskedLength}})`;\n };\n\n const regex = new RegExp(regexString());\n\n const masoq = (_match: any, p1: string, p2: string, p3?: string): string => {\n if (p3 && complementary) {\n // Center + complementary\n return `${finalRedactor(p1)}${p2}${finalRedactor(p3)}`;\n }\n if (p3) {\n // Center\n return `${p1}${finalRedactor(p2)}${p3}`;\n }\n if (position === 'right') {\n // Right\n return `${p1}${finalRedactor(p2)}`;\n }\n // Left\n return `${finalRedactor(p1)}${p2}`;\n };\n\n stringValue.replace(regex, (_match, p1, p2) => `${p1}${finalRedactor(p2)}`);\n\n return stringValue.replace(regex, masoq);\n};\n\nexport const redactIt: RedactIt = (\n configs?: RedactItConfig | RedactItConfig[],\n): ReplacerFunction => {\n const defaultMask: Mask = {\n type: 'replace',\n redactWith: '[redacted]',\n };\n\n const defaultOptions: RedactItConfig = {\n fields: ['password'],\n mask: defaultMask,\n };\n\n const mappedFields: Map<string | RegExp, Mask> = new Map();\n\n const optionsArray: RedactItConfig[] = Array.isArray(configs)\n ? configs\n : [configs ?? defaultOptions];\n\n optionsArray.forEach((option: RedactItConfig) => {\n option.fields.forEach((field) => {\n mappedFields.set(field, option.mask ?? defaultMask);\n });\n });\n\n const getMaskForKey = (key: any): Mask | null => {\n const mask = mappedFields.get(key);\n if (mask) {\n return mask;\n }\n\n for (const [matcher, mask] of mappedFields.entries()) {\n if (matcher instanceof RegExp) {\n if (matcher.test(key)) {\n return mask;\n }\n } else if (matcher === key) {\n return mask;\n }\n }\n return null;\n };\n\n const replacer = (key: any, value: any): any => {\n const mask = getMaskForKey(key);\n if (mask) {\n if (mask.type === 'replace') {\n return mask.redactWith;\n }\n if (mask.type === 'undefine') {\n return undefined;\n }\n return percentageValueMasker(value, mask);\n }\n return value;\n };\n return replacer;\n};\n"],"names":[],"mappings":";;AASA,MAAM,qBAAqB,GAAG,CAC5B,KAAU,EACV,IAA2C,KACpB;AACvB,EAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,IAAI,GAAG;AACvC,EAAA,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,GAAG;AACzC,EAAA,MAAM,aAAa,GAAG,CAAC,IAAI,CAAC,QAAQ,KAAK,QAAQ,IAAI,IAAI,CAAC,aAAa,KAAK,KAAK;AACjF,EAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,MAAM;AAExC,EAAA,MAAM,aAAa,GAAI,EAAU,IAC/B,QAAQ,CAAC,MAAM,GAAG,CAAC,GAAG,QAAQ,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;EAE7D,IAAI,UAAU,KAAK,GAAG,EAAE,OAAO,aAAa,CAAC,KAAK,CAAC;AAEnD,EAAA,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC;AACjC,EAAA,MAAM,YAAY,GAAG,WAAW,CAAC,MAAM;EACvC,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAE,YAAY,GAAG,UAAU,GAAI,GAAG,CAAC;AACjE,EAAA,MAAM,cAAc,GAAG,YAAY,GAA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AC;AAED,EAAA,MAAM,QAAQ,GAAG,CAAC,GAAQ,EAAE,KAAU,KAAU;AAC9C,IAAA,MAAM,IAAI,GAAG,aAAa,CAAC,GAAG,CAAC;AAC/B,IAAA,IAAI,IAAI,EAAE;AACR,MAAA,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE;QAC3B,OAAO,IAAI,CAAC,UAAU;AACxB,MAAA;AACA,MAAA,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE;AAC5B,QAAA,OAAO,SAAS;AAClB,MAAA;AACA,MAAA,OAAO,qBAAqB,CAAC,KAAK,EAAE,IAAI,CAAC;AAC3C,IAAA;AACA,IAAA,OAAO,KAAK;EACd,CAAC;AACD,EAAA,OAAO,QAAQ;AACjB;;"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { redactIt } from "./src/redact-it";
2
- export * from "./typings";
1
+ export { redactIt } from './src/redact-it';
2
+ export type * from './typings';
package/dist/index.esm.js CHANGED
@@ -1,9 +1,8 @@
1
1
  const percentageValueMasker = (value, mask) => {
2
- var _a, _b, _c, _d;
3
- const redactor = (_a = mask.redactWith) !== null && _a !== void 0 ? _a : "•";
4
- const percentage = (_b = mask.percentage) !== null && _b !== void 0 ? _b : 100;
5
- const complementary = (_c = mask.position === "center" && mask.complementary) !== null && _c !== void 0 ? _c : false;
6
- const position = (_d = mask.position) !== null && _d !== void 0 ? _d : "left";
2
+ const redactor = mask.redactWith ?? '•';
3
+ const percentage = mask.percentage ?? 100;
4
+ const complementary = (mask.position === 'center' && mask.complementary) ?? false;
5
+ const position = mask.position ?? 'left';
7
6
  const finalRedactor = p1 => redactor.length > 1 ? redactor : p1.replace(/./g, redactor);
8
7
  if (percentage === 100) return finalRedactor(value);
9
8
  const stringValue = String(value);
@@ -11,10 +10,10 @@ const percentageValueMasker = (value, mask) => {
11
10
  const maskedLength = Math.ceil(stringLength * percentage / 100);
12
11
  const unmaskedLength = stringLength - maskedLength;
13
12
  const regexString = () => {
14
- if (position === "center") {
13
+ if (position === 'center') {
15
14
  return `(.{${unmaskedLength / 2}})(.{${maskedLength}})(.+)`;
16
15
  }
17
- if (position === "right") {
16
+ if (position === 'right') {
18
17
  return `(.{${unmaskedLength}})(.{${maskedLength}})`;
19
18
  }
20
19
  return `(.{${maskedLength}})(.{${unmaskedLength}})`;
@@ -29,7 +28,7 @@ const percentageValueMasker = (value, mask) => {
29
28
  // Center
30
29
  return `${p1}${finalRedactor(p2)}${p3}`;
31
30
  }
32
- if (position === "right") {
31
+ if (position === 'right') {
33
32
  // Right
34
33
  return `${p1}${finalRedactor(p2)}`;
35
34
  }
@@ -41,19 +40,18 @@ const percentageValueMasker = (value, mask) => {
41
40
  };
42
41
  const redactIt = configs => {
43
42
  const defaultMask = {
44
- type: "replace",
45
- redactWith: "[redacted]"
43
+ type: 'replace',
44
+ redactWith: '[redacted]'
46
45
  };
47
46
  const defaultOptions = {
48
- fields: ["password"],
47
+ fields: ['password'],
49
48
  mask: defaultMask
50
49
  };
51
50
  const mappedFields = new Map();
52
- const optionsArray = Array.isArray(configs) ? configs : [configs !== null && configs !== void 0 ? configs : defaultOptions];
51
+ const optionsArray = Array.isArray(configs) ? configs : [configs ?? defaultOptions];
53
52
  optionsArray.forEach(option => {
54
53
  option.fields.forEach(field => {
55
- var _a;
56
- mappedFields.set(field, (_a = option.mask) !== null && _a !== void 0 ? _a : defaultMask);
54
+ mappedFields.set(field, option.mask ?? defaultMask);
57
55
  });
58
56
  });
59
57
  const getMaskForKey = key => {
@@ -75,10 +73,10 @@ const redactIt = configs => {
75
73
  const replacer = (key, value) => {
76
74
  const mask = getMaskForKey(key);
77
75
  if (mask) {
78
- if (mask.type === "replace") {
76
+ if (mask.type === 'replace') {
79
77
  return mask.redactWith;
80
78
  }
81
- if (mask.type === "undefine") {
79
+ if (mask.type === 'undefine') {
82
80
  return undefined;
83
81
  }
84
82
  return percentageValueMasker(value, mask);
@@ -89,3 +87,4 @@ const redactIt = configs => {
89
87
  };
90
88
 
91
89
  export { redactIt };
90
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":["../src/redact-it.ts"],"sourcesContent":["import type {\n Mask,\n RedactIt,\n RedactItConfig,\n ReplacerFunction,\n PercentageMask,\n CenterPercentageMask,\n} from '../typings';\n\nconst percentageValueMasker = (\n value: any,\n mask: PercentageMask | CenterPercentageMask,\n): string | undefined => {\n const redactor = mask.redactWith ?? '•';\n const percentage = mask.percentage ?? 100;\n const complementary = (mask.position === 'center' && mask.complementary) ?? false;\n const position = mask.position ?? 'left';\n\n const finalRedactor = (p1: string): string =>\n redactor.length > 1 ? redactor : p1.replace(/./g, redactor);\n\n if (percentage === 100) return finalRedactor(value);\n\n const stringValue = String(value);\n const stringLength = stringValue.length;\n const maskedLength = Math.ceil((stringLength * percentage) / 100);\n const unmaskedLength = stringLength - maskedLength;\n\n const regexString = (): string => {\n if (position === 'center') {\n return `(.{${unmaskedLength / 2}})(.{${maskedLength}})(.+)`;\n }\n if (position === 'right') {\n return `(.{${unmaskedLength}})(.{${maskedLength}})`;\n }\n return `(.{${maskedLength}})(.{${unmaskedLength}})`;\n };\n\n const regex = new RegExp(regexString());\n\n const masoq = (_match: any, p1: string, p2: string, p3?: string): string => {\n if (p3 && complementary) {\n // Center + complementary\n return `${finalRedactor(p1)}${p2}${finalRedactor(p3)}`;\n }\n if (p3) {\n // Center\n return `${p1}${finalRedactor(p2)}${p3}`;\n }\n if (position === 'right') {\n // Right\n return `${p1}${finalRedactor(p2)}`;\n }\n // Left\n return `${finalRedactor(p1)}${p2}`;\n };\n\n stringValue.replace(regex, (_match, p1, p2) => `${p1}${finalRedactor(p2)}`);\n\n return stringValue.replace(regex, masoq);\n};\n\nexport const redactIt: RedactIt = (\n configs?: RedactItConfig | RedactItConfig[],\n): ReplacerFunction => {\n const defaultMask: Mask = {\n type: 'replace',\n redactWith: '[redacted]',\n };\n\n const defaultOptions: RedactItConfig = {\n fields: ['password'],\n mask: defaultMask,\n };\n\n const mappedFields: Map<string | RegExp, Mask> = new Map();\n\n const optionsArray: RedactItConfig[] = Array.isArray(configs)\n ? configs\n : [configs ?? defaultOptions];\n\n optionsArray.forEach((option: RedactItConfig) => {\n option.fields.forEach((field) => {\n mappedFields.set(field, option.mask ?? defaultMask);\n });\n });\n\n const getMaskForKey = (key: any): Mask | null => {\n const mask = mappedFields.get(key);\n if (mask) {\n return mask;\n }\n\n for (const [matcher, mask] of mappedFields.entries()) {\n if (matcher instanceof RegExp) {\n if (matcher.test(key)) {\n return mask;\n }\n } else if (matcher === key) {\n return mask;\n }\n }\n return null;\n };\n\n const replacer = (key: any, value: any): any => {\n const mask = getMaskForKey(key);\n if (mask) {\n if (mask.type === 'replace') {\n return mask.redactWith;\n }\n if (mask.type === 'undefine') {\n return undefined;\n }\n return percentageValueMasker(value, mask);\n }\n return value;\n };\n return replacer;\n};\n"],"names":[],"mappings":"AASA,MAAM,qBAAqB,GAAG,CAC5B,KAAU,EACV,IAA2C,KACpB;AACvB,EAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,IAAI,GAAG;AACvC,EAAA,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,GAAG;AACzC,EAAA,MAAM,aAAa,GAAG,CAAC,IAAI,CAAC,QAAQ,KAAK,QAAQ,IAAI,IAAI,CAAC,aAAa,KAAK,KAAK;AACjF,EAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,MAAM;AAExC,EAAA,MAAM,aAAa,GAAI,EAAU,IAC/B,QAAQ,CAAC,MAAM,GAAG,CAAC,GAAG,QAAQ,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;EAE7D,IAAI,UAAU,KAAK,GAAG,EAAE,OAAO,aAAa,CAAC,KAAK,CAAC;AAEnD,EAAA,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC;AACjC,EAAA,MAAM,YAAY,GAAG,WAAW,CAAC,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AACF,MAAA,CAAC,MAAM,IAAI,OAAO,KAAK,GAAG,EAAE;AAC1B,QAAA,OAAO,IAAI;AACb,MAAA;AACF,IAAA;AACA,IAAA,OAAO,IAAI;EACb,CAAC;AAED,EAAA,MAAM,QAAQ,GAAG,CAAC,GAAQ,EAAE,KAAU,KAAU;AAC9C,IAAA,MAAM,IAAI,GAAG,aAAa,CAAC,GAAG,CAAC;AAC/B,IAAA,IAAI,IAAI,EAAE;AACR,MAAA,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE;QAC3B,OAAO,IAAI,CAAC,UAAU;AACxB,MAAA;AACA,MAAA,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE;AAC5B,QAAA,OAAO,SAAS;AAClB,MAAA;AACA,MAAA,OAAO,qBAAqB,CAAC,KAAK,EAAE,IAAI,CAAC;AAC3C,IAAA;AACA,IAAA,OAAO,KAAK;EACd,CAAC;AACD,EAAA,OAAO,QAAQ;AACjB;;"}
@@ -1,2 +1,2 @@
1
- import { RedactIt } from "../typings";
1
+ import type { RedactIt } from '../typings';
2
2
  export declare const redactIt: RedactIt;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,11 +1,11 @@
1
1
  export type Mask = PercentageMask | CenterPercentageMask | UndefineMask | ReplaceMask;
2
2
  export interface PercentageMask {
3
- type: "percentage";
3
+ type: 'percentage';
4
4
  /**
5
5
  * Character to be used as the redacted part
6
6
  * @default "•"
7
7
  */
8
- redactWith?: "*" | "•" | string;
8
+ redactWith?: '*' | '•' | string;
9
9
  /**
10
10
  * Percentage of the value to apply the mask on
11
11
  * @default 100
@@ -15,16 +15,16 @@ export interface PercentageMask {
15
15
  * Which part of the value to redact
16
16
  * @default "left"
17
17
  */
18
- position?: "left" | "right";
18
+ position?: 'left' | 'right';
19
19
  }
20
20
  export interface CenterPercentageMask {
21
- type: "percentage";
22
- position: "center";
21
+ type: 'percentage';
22
+ position: 'center';
23
23
  /**
24
24
  * Character to be used as the redacted part
25
25
  * @default "•"
26
26
  */
27
- redactWith?: "*" | "•" | string;
27
+ redactWith?: '*' | '•' | string;
28
28
  /**
29
29
  * Percentage of the value to apply the mask on
30
30
  * @default 100
@@ -37,15 +37,15 @@ export interface CenterPercentageMask {
37
37
  complementary?: boolean;
38
38
  }
39
39
  export interface UndefineMask {
40
- type: "undefine";
40
+ type: 'undefine';
41
41
  }
42
42
  export interface ReplaceMask {
43
- type: "replace";
43
+ type: 'replace';
44
44
  /**
45
45
  * Replace the value entirely with this string
46
46
  * @default "[redacted]"
47
47
  */
48
- redactWith: "[redacted]" | string;
48
+ redactWith: '[redacted]' | string;
49
49
  }
50
50
  /** Redact-it configs to customize how and which fields are going to be redacted */
51
51
  export interface RedactItConfig {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redact-it",
3
- "version": "0.2.5",
3
+ "version": "0.2.8",
4
4
  "description": "A flexible tool to redact JS objects' data",
5
5
  "author": "AlanPCS <alanpcsilva+npm@gmail.com>",
6
6
  "license": "MIT",
@@ -10,47 +10,48 @@
10
10
  "files": [
11
11
  "dist"
12
12
  ],
13
- "devDependencies": {
14
- "@babel/core": "^7.14.6",
15
- "@babel/plugin-transform-runtime": "^7.14.5",
16
- "@babel/preset-typescript": "^7.14.5",
17
- "@babel/runtime": "^7.14.6",
18
- "@rollup/plugin-babel": "^5.3.0",
19
- "@rollup/plugin-node-resolve": "^13.0.0",
20
- "@types/chai": "^4.2.19",
21
- "@types/mocha": "^8.2.2",
22
- "@types/node": "^15.12.5",
23
- "@types/node-fetch": "^2.5.10",
24
- "@typescript-eslint/eslint-plugin": "^4.28.1",
25
- "@typescript-eslint/parser": "^4.28.1",
26
- "chai": "^4.3.4",
27
- "eslint": "^7.29.0",
28
- "karma-nyan-reporter": "^0.2.5",
29
- "mocha": "^10.2.0",
30
- "npm-run-all": "^4.1.5",
31
- "nyc": "^15.0.1",
32
- "prettier": "^2.3.2",
33
- "rollup": "^2.52.4",
34
- "rollup-plugin-typescript2": "^0.36.0",
35
- "ts-mocha": "^10.0.0",
36
- "ts-node": "^10.0.0",
37
- "tslint": "^6.1.3",
38
- "typescript": "^4.3.4"
39
- },
13
+ "packageManager": "pnpm@12.16.1",
40
14
  "scripts": {
41
- "test": "run-p lint test:compile test:mocha",
42
- "test:ci": "run-p lint test:compile test:coverage",
43
- "test:compile": "tsc",
44
- "test:mocha": "ts-mocha --config test/.mocharc.json",
45
- "test:watch": "yarn test:mocha --watch -R min",
46
- "test:coverage": "nyc --reporter=text yarn test:mocha -R spec",
47
- "lint": "eslint 'src/**/*.ts' 'test/**/*.ts'",
48
- "lint:fix": "eslint 'src/**/*.ts' 'test/**/*.ts' --fix",
49
- "build": "rm -rf dist && rollup -c rollup.config.ts && tsc --emitDeclarationOnly",
50
- "deploy": "yarn build && npm publish"
15
+ "test": "jest",
16
+ "test:ci": "pnpm lint && pnpm test:compile && pnpm test:coverage",
17
+ "test:compile": "tsc --noEmit",
18
+ "test:watch": "pnpm test --watch -R min",
19
+ "test:coverage": "jest --coverage",
20
+ "lint": "eslint .",
21
+ "lint:fix": "pnpm lint --fix",
22
+ "format": "prettier --write .",
23
+ "format:check": "prettier --check .",
24
+ "build": "rm -rf dist && rollup -c rollup.config.ts --bundleConfigAsCjs && tsc --emitDeclarationOnly",
25
+ "deploy": "pnpm build && npm publish",
26
+ "bless": "pnpm peers check && pnpm format:check && pnpm lint && pnpm test:compile && pnpm test:coverage && pnpm knip && pnpm build && pnpm audit",
27
+ "knip": "knip"
28
+ },
29
+ "devDependencies": {
30
+ "@babel/core": "^8.1.4",
31
+ "@babel/preset-env": "^8.1.4",
32
+ "@babel/preset-typescript": "^8.0.7",
33
+ "@eslint/js": "^10.0.1",
34
+ "@rollup/plugin-babel": "^7.2.0",
35
+ "@rollup/plugin-node-resolve": "^16.0.3",
36
+ "@types/jest": "^30.0.0",
37
+ "@types/node": "^26.6.11",
38
+ "@typescript-eslint/eslint-plugin": "^8.74.0",
39
+ "@typescript-eslint/parser": "^8.74.0",
40
+ "@typescript/native": "npm:typescript@^7.0.2",
41
+ "eslint": "^10.16.0",
42
+ "eslint-plugin-jest": "^29.17.2",
43
+ "jest": "^30.5.2",
44
+ "jiti": "^2.7.0",
45
+ "knip": "^6.49.0",
46
+ "prettier": "^3.10.1",
47
+ "rollup": "^4.69.2",
48
+ "typescript": "npm:@typescript/typescript6@^6.0.2"
51
49
  },
52
50
  "repository": {
53
51
  "type": "git",
54
- "url": "ssh://git@github.com/alanpcs/redact-it.git"
52
+ "url": "git+https://github.com/alanpcs/redact-it.git"
53
+ },
54
+ "engines": {
55
+ "node": "26"
55
56
  }
56
57
  }