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
Install size
5.08 kB
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 filterObject from 'filter-obj';

const object = {
	foo: true,
	bar: false
};

const newObject = filterObject(object, (key, value) => value === true);
//=> {foo: true}

const newObject2 = filterObject(object, ['bar']);
//=> {bar: false}

API

filterObject(source, filter)

filterObject(source, includeKeys)

source

Type: object

The source object to filter properties from.

filter

Type: (sourceKey, sourceValue, source) => boolean

A predicate function that detemines whether a property should be assigned to the new object.

includeKeys

Type: string[]

An array of property names that should be assigned to the new object.

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

Keywords

FAQs

Last updated on 26 Aug 2021

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