@hackylabs/deep-redact 3.0.0 → 3.0.1
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 +11 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ objRedaction.redact(obj)
|
|
|
60
60
|
// }
|
|
61
61
|
|
|
62
62
|
const strRedaction = new DeepRedact({
|
|
63
|
-
|
|
63
|
+
stringTests: [
|
|
64
64
|
{
|
|
65
65
|
pattern: /<(email|password)>([^<]+)<\/\1>/gi,
|
|
66
66
|
replacer: (value: string, pattern: RegExp) => value.replace(pattern, '<$1>[REDACTED]</$1>'),
|
|
@@ -73,25 +73,19 @@ strRedaction.redact('<email>someone@somewhere.com</email><keepThis>This is fine<
|
|
|
73
73
|
// '<email>[REDACTED]</email><keepThis>This is fine</keepThis><password>[REDACTED]</password>'
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
// Override the `
|
|
76
|
+
// Override the `transformers` property to handle unsupported values in your own way
|
|
77
|
+
// WARNING: You are responsible for ensuring all used transformers safely and reliably transform unsupported values
|
|
77
78
|
|
|
78
79
|
```typescript
|
|
79
|
-
|
|
80
|
-
constructor(options) {
|
|
81
|
-
super(options)
|
|
82
|
-
this.rewriteUnsupported = (value) => {
|
|
83
|
-
if (value instanceof BigInt) return value.toString()
|
|
84
|
-
|
|
85
|
-
// Add more conditional statements for unsupported value types here (e.g. Error, Date, Map, Set, etc.)
|
|
86
|
-
|
|
87
|
-
// If the value is supported, return it
|
|
88
|
-
return value
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const customRedaction = new CustomRedaction({
|
|
80
|
+
const customRedaction = new DeepRedact({
|
|
94
81
|
blacklistedKeys: ['sensitive', 'password', /name/i],
|
|
82
|
+
transformers: [
|
|
83
|
+
(value: unknown) => {
|
|
84
|
+
if (typeof value !== 'bigint') return value
|
|
85
|
+
return value.toString(10)
|
|
86
|
+
},
|
|
87
|
+
...
|
|
88
|
+
]
|
|
95
89
|
})
|
|
96
90
|
|
|
97
91
|
customRedaction.redact({ a: BigInt(1) })
|
package/package.json
CHANGED