You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

filter-obj

Package Overview
Dependencies
0
Maintainers
1
Versions
11
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
Maintainers
1
Created

Package description

What is filter-obj?

The filter-obj npm package allows users to filter the properties of an object based on specific criteria. This can be useful for creating subsets of an object, removing unwanted properties, or selectively copying properties based on dynamic conditions.

What are filter-obj's main functionalities?

Filtering based on property names

This feature allows you to filter an object by specifying which property names to keep. It is useful for extracting specific properties from an object.

const filterObj = require('filter-obj');
const obj = { a: 1, b: '2', c: 3 };
const filtered = filterObj(obj, ['a', 'c']);
console.log(filtered); // Output: { a: 1, c: 3 }

Filtering using a function

This feature enables filtering based on a function that takes key and value as arguments. It allows for more dynamic and condition-based filtering, such as filtering out properties based on their types or values.

const filterObj = require('filter-obj');
const obj = { a: 1, b: '2', c: 3 };
const filtered = filterObj(obj, (key, value) => typeof value === 'number');
console.log(filtered); // Output: { a: 1, c: 3 }

Other packages similar to filter-obj

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

An array or Set of property keys to be filtered.

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

Keywords

FAQs

Package last updated on 27 May 2024

Did you know?

Socket

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
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc