Socket
Socket
Sign inDemoInstall

filter-obj

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    filter-obj

Filter object keys and values into a new object


Version published
Weekly downloads
6.4M
decreased by-16.34%
Maintainers
1
Install size
5.98 kB
Created
Weekly downloads
 

Readme

Source

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.

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

Keywords

FAQs

Last updated on 11 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc