Socket
Book a DemoInstallSign in
Socket

trim-keys

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trim-keys

Keep or remove certain keys from an object.

latest
Source
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

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

// CommonJS
var trim = require('trim-keys');
// AMD
require(['trim-keys'], function(trim) { ... });
// Script Tag
var trim = window.trim;

API

trim(obj, keyMap)

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 or true to include the field.
  • 0 or false 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 = require('trim-keys');

var person = { name: 'John Doe', age: 40, height: { ft: 5, in: 10 } };

trim(person, { name: 1 })
// person === { name: 'John Doe' }
var trim = require('trim-keys');

var person = { name: 'John Doe', age: 40, height: { ft: 5, in: 10 } };

trim(person, { age: 0, height: { in: 0 } });
// person === { name: 'John Doe', height: { ft: 5 } }

Keywords

object

FAQs

Package last updated on 21 Feb 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts