Skip to content

Transform stream to censor object data.

License

Notifications You must be signed in to change notification settings

krystianolech/white-out

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

white-out

Current Version Travis CI belly-button-style

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 where key is the property value to censor on the object payload and the value 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 into new RegExp.
  • [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 entire data object. Defaults to undefined which means the entire data object will be traversed. For performance reasons, it is recodmended to set root to only the specific segment of data you wish to filter.
    • [stream] - additional options to pass into the transform stream constructor. objectMode is always true.
    • [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'
  }]
}
*/

About

Transform stream to censor object data.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%