Make projections on your objects, as you'd look at them via keyhole. Define which object properties you want to see and resulting object will have exactly these properties, nothing more (also supports nested properties via dot notation e.g. foo.bar.baz
).
$ npm install keyhole
import keyhole from 'keyhole';
const source = {
name: 'john doe',
age: 29,
emails: {
work: 'john@work.com',
priv: 'john@priv.com',
},
colors: ['red', 'green', 'blue']
};
const projection = keyhole(source, 'name', 'emails.work', 'colors');
projection
will be as follows:
{
name: 'john doe',
emails: {
work: 'john@work.com'
},
colors: ['red', 'green', 'blue']
}
For more examples see tests directory
$ npm run build
$ npm test
to run tests in "watch" mode issue npm run test-watch