A transform stream used to censor data from objects before passing them down the pipeline.
white-out 2.x mutates the target object passed (unless immutable option is enabled), which may lead to undesirable results such as keys being undefined, changed, etc.
Creates a new WhiteOut transform stream with the following arguments.
filter- a key value pair wherekeyis the property value to censor on the object payload and thevalueis the censor type.- Valid options for
valueare "censor", "remove" and a RegExp.- "censor" - replaces the value with a string of "X"s.
- "remove" - completely removes the key from object
- Anything else will be treated as a
RegExpdefinition and will be passed intonew RegExp.
- Valid options for
[options]- Additional constructor options. Defaults to{}.[root]- an object string path (ex'response.payload') that will be used when the censor algorithm starts. Useful for censoring only a subsection of the entiredataobject. Defaults toundefinedwhich means the entiredataobject will be traversed. For performance reasons, it is recodmended to setrootto only the specific segment ofdatayou wish to filter.[stream]- additional options to pass into the transform stream constructor.objectModeis alwaystrue.[immutable]- change processing mode to immutable, so source object want be modified. Default to false.
const wo = new WhiteOut({ password: 'remove' });
wo.write({
name: 'John Smith',
age: 55,
values: [1,2,3],
password: 'hunter1',
foo: {
password: 'hunter1',
value: 10
}
});
/* results in
{
name: 'John Smith',
age: 55,
values: [1,2,3],
foo: {
value: 10
}
}
*/const wo = new WhiteOut({ password: 'remove', { root: 'foo' } });
wo.write({
name: 'John Smith',
age: 55,
values: [1,2,3],
password: 'hunter1',
foo: {
password: 'hunter1',
value: 10
}
});
/* results in
{
name: 'John Smith',
age: 55,
values: [1,2,3],
password: 'hunter1',
foo: {
value: 10
}
}
*/const wo = new WhiteOut({ ssn: 'remove', age: 'censor' });
wo.write([{
name: 'Moe',
age: 44,
ssn: 123
}, {
name: 'Larry',
age: 41,
ssn: 34343
}, {
name: 'Shemp',
age: 38,
ssn: 9923
}]);
/* results in
[{ name: 'Moe', age: 'XX' }, { name: 'Larry', age: 'XX' }, { name: 'Shemp', age: 'XX' }]
*/const wo = new WhiteOut({ password: '^.{3}' });
wo.write({
values: [{
name: 'Moe',
password: 'password1'
}, {
name: 'Larry',
password: 'password2'
}, {
name: 'Shemp',
password: 'password3'
}]
});
/*
results in
{
values: [{
name: 'Moe',
password: 'XXXsword1'
}, {
name: 'Larry',
password: 'XXXsword2'
}, {
name: 'Shemp',
password: 'XXXsword3'
}]
}
*/