mostr / keyhole

Make projections on objects, as you'd look at them via keyhole.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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: '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

Build and test

$ npm run build
$ npm test

to run tests in "watch" mode issue npm run test-watch

License

MIT

About

Make projections on objects, as you'd look at them via keyhole.


Languages

Language:JavaScript 97.6%Language:Shell 2.4%