filter-obj
TypeScript icon, indicating that this package has built-in type declarations

6.0.0 • Public • Published

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

Package Sidebar

Install

npm i filter-obj

Weekly Downloads

7,455,659

Version

6.0.0

License

MIT

Unpacked Size

6.12 kB

Total Files

5

Last publish

Collaborators

  • sindresorhus