filter-obj

Filter object keys and values into a new object

MIT 11 个版本
安装
npm install filter-obj
yarn add filter-obj
pnpm add filter-obj
bun add filter-obj
README

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> | Set<string | symbol>

An array or Set of property keys to be filtered.

  • map-obj - Map object keys and values into a new object
版本列表
6.1.0 2024-05-27
6.0.0 2024-03-11
5.1.0 2022-07-30
5.0.0 2022-07-26
4.0.0 2022-07-23
3.0.0 2021-08-26
2.0.2 2021-04-06
2.0.1 2019-10-04
2.0.0 2019-04-22
1.1.0 2015-08-12
1.0.0 2015-08-10