filter-obj
Filter object keys and values into a new object
Last updated a year ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install filter-obj 
SYNC missed versions from official npm registry.

filter-obj Build Status

Filter object keys and values into a new object

Install

$ npm install filter-obj

Usage

const filterObject = require('filter-obj');

const object = {
	foo: true,
	bar: false
};

const newObject = filterObject(object, (key, value) => value === true);
//=> {foo: true}

const newObject2 = filterObject(object, ['bar']);
//=> {bar: false}

API

filterObject(source, filter)

filterObject(source, includeKeys)

source

Type: object

Source object to filter properties from.

filter

Type: Function

A predicate function that detemines whether a property should be assigned to the new object. The function has the signature filterFunction(sourceKey, sourceValue, source).

includeKeys

Type: string[]

Array of property names that should be assigned to the new object.

Related

  • map-obj - Map object keys and values into a new object

Current Tags

  • 2.0.1                                ...           latest (a year ago)

4 Versions

  • 2.0.1                                ...           a year ago
  • 2.0.0                                ...           2 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.0                                ...           5 years ago

Copyright 2014 - 2016 © taobao.org |