0.0.0 • Published 12 years ago
slice-keys v0.0.0
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 inInstallation
Install with npm:
npm install slice-keysTests
Test with mocha:
mochaEnjoy.
0.0.0
12 years ago