New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

filter-map

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filter-map

Returns a copy of a Map object containing only those entries which pass a test function.

  • 3.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

filter-map

Returns a copy of a Map or Object containing only those entries which pass a test function.

Supports a numeric limit on the number of entries in the resulting Map or Object.

Installation

npm install filter-map --save

Usage

const filterMap = require('filter-map')

const map = new Map([['a', 1], ['b', 2], ['c', 3]])
const filteredMap = filterMap(map, (key, value) => value > 1)
filteredMap.size // 2

// Works on objects too
const obj = {a: 1, b: 2, c: 3}
filterMap(obj, (key, value) => value > 1) // {b: 2, c: 3}

If no test function is provided, values are filtered by truthiness:

const filterMap = require('filter-map')

const map = new Map([[1, true], [2, false], [3, true]])
filterMap(map).size // 2

filterMap({1: true, 2: false, 3: true}) // {1: true, 3: true}

If you only want a certain number of entries in the filtered Map or Object, you can specify a numeric limit parameter:

const obj = {a: 0, b: 1, c: 2, d: 3}
filterMap(obj, (k, v) => v > 1, {limit: 1}) // {c: 2}
filterMap(obj, {limit: 1}) // {b: 1}

Keywords

FAQs

Package last updated on 14 Dec 2017

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc