trim-keys
Keep or remove certain keys from an object.
Installation
npm install trim-keys
Environment Support
trim-keys has been tested in Node, IE9+, Chrome, Firefox, and Opera.
Usage
// CommonJSvar trim = ;
// AMD;
// Script Tagvar trim = windowtrim;
API
obj
type: Object
The object to trim. This object will be modified, so if you want to retain your original object, you'll need to pass in a copy of that object.
keyMap
type: Object
This object defines what properties to keep, or what properties to remove. It takes the following form:
field1: <boolean> field2: <boolean> ...
The <boolean>
value can be any of the following:
1
ortrue
to include the field.0
orfalse
to exclude the field.
A keyMap
cannot contain both include and exclude specifications. An error will be thrown if all of the keys are not the same value.
Example
var trim = ; var person = name: 'John Doe' age: 40 height: ft: 5 in: 10 ; // person === { name: 'John Doe' }
var trim = ; var person = name: 'John Doe' age: 40 height: ft: 5 in: 10 ; ;// person === { name: 'John Doe', height: { ft: 5 } }