filter-obj
Filter object keys and values into a new object
Last updated 10 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm
$ 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

  • 5.1.0                                ...           latest (3 years ago)

5 Versions

  • 5.1.0                                ...           3 years ago
  • 3.0.0                                ...           4 years ago
  • 2.0.2                                ...           4 years ago
  • 2.0.1                                ...           6 years ago
  • 1.1.0                                ...           10 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org