slice-keys

0.0.0 • Public • Published

slice-keys

Returns a subset of the given object with only the requested attributes.

sliceKeys({x:1, y:2, z:3}, ['x','z']) //=> {x:1, z:3}
sliceKeys({x:1, y:2, z:3}, 'x', 'z')  //=> {x:1, z:3}

This is particularly useful when filtering user input:

params = {name: "Monty Pontihew", admin: true};
allow  = ['name', 'age'];

user.update(sliceKeys(params, allow)); // Only name will be passed in

Installation

Install with npm:

npm install slice-keys

Tests

Test with mocha:

mocha

Enjoy.


Adam Sanderson

Readme

Keywords

none

Package Sidebar

Install

npm i slice-keys

Weekly Downloads

0

Version

0.0.0

License

BSD

Last publish

Collaborators

  • adamsanderson