white-out
v2.1.0
Published
Transform stream to censor object data.
Downloads
1,220
Readme
white-out
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.
new WhiteOut (filter, [options])
Creates a new WhiteOut
transform stream with the following arguments.
filter
- a key value pair wherekey
is the property value to censor on the object payload and thevalue
is the censor type.- Valid options for
value
are "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
RegExp
definition 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 entiredata
object. Defaults toundefined
which means the entiredata
object will be traversed. For performance reasons, it is recodmended to setroot
to only the specific segment ofdata
you wish to filter.[stream]
- additional options to pass into the transform stream constructor.objectMode
is alwaystrue
.[immutable]
- change processing mode to immutable, so source object want be modified. Default to false.
Examples
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'
}]
}
*/