keyhole
v0.1.0
Published
Small utility for projecting only parts of objects, like via keyhole
Downloads
1
Readme
keyhole
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
).
Installation
$ npm install keyhole
Basic Usage
import keyhole from 'keyhole';
const source = {
name: 'john doe',
age: 29,
emails: {
work: '[email protected]',
priv: '[email protected]',
},
colors: ['red', 'green', 'blue']
};
const projection = keyhole(source, 'name', 'emails.work', 'colors');
projection
will be as follows:
{
name: 'john doe',
emails: {
work: '[email protected]'
},
colors: ['red', 'green', 'blue']
}
For more examples see tests directory
Build and test
$ npm run build
$ npm test
to run tests in "watch" mode issue npm run test-watch