$ gnpm install filter-obj
Filter object keys and values into a new object
npm install filter-obj
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}
Type: object
The source object to filter properties from.
Type: (sourceKey: string | symbol, sourceValue: unknown, source: object) => boolean
A predicate function that determines whether a property should be filtered.
Type: Array<string | symbol>
An array of property keys to be filtered.
Copyright 2013 - present © cnpmjs.org | Home |