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

filter-obj

Filter object keys and values into a new object

Install

npm install filter-obj

Usage

import {includeKeys, excludeKeys} from 'filter-obj';

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

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

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

const newObject = excludeKeys(object, (key, value) => value === true);
//=> {bar: false}

const newObject3 = excludeKeys(object, ['bar']);
//=> {foo: true}

API

includeKeys(source, filter)

includeKeys(source, keys)

excludeKeys(source, filter)

excludeKeys(source, keys)

source

Type: object

The source object to filter properties from.

filter

Type: (sourceKey: string | symbol, sourceValue: unknown, source: object) => boolean

A predicate function that determines whether a property should be filtered.

keys

Type: Array<string | symbol>

An array of property keys to be filtered.

Related

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

Current Tags

  • 5.1.0                                ...           latest (2 years ago)

9 Versions

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

Copyright 2013 - present © cnpmjs.org | Home |