blue-pencil
Mask your JSON values as of a given array of not allowed fields.
Usage
The main export of this library is BluePencil
, a utility
that receives a JSON and an array of elements and returns the same JSON with the given elements
with asterisks.
Install
You can install blue-pencil using npm.
npm install --save blue-pencil
API
Exported symbols:
Kind: global class
-
BluePencil
- new BluePencil(options)
-
.censor(objectToCensor, valuesToHide) ⇒
Object
|Array
new BluePencil(options)
Create an BluePencils that hide the give keys in a given object.
Param | Type | Description |
---|---|---|
options | object | |
options.wildcard | string | Wildcard we would like to use for the mask (e.g.: |
Example
const bluePencil = require('blue-pencil');
let myBluePencil = new BluePencil({escapeWildcard: '#####'});
Object
| Array
blue-pencil.censor(objectToCensor, valuesToHide) ⇒ Returns the given object but with the given values masked.
Type: static method of blue-pencil
Returns: Object
The new object with the values masked.
Param | Type | Description |
---|---|---|
objectToCensor |
Object | Array
|
Input data to be filtered |
valuesToHide | Array |
Elements to mask in the given object |
Example
const bluePencil = require('blue-pencil');
let myBluePencil = new BluePencil({escapeWildcard: '#####'});
const nestedObj = {
root: [{
foo: 'bar',
}],
};
const valuesToHide = ['foo'];
// censor
const filteredObject = myBluePencil.censor(nestedObj, valuesToHide)
License
MIT @ Angel Muelas Martinez