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 - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

12

index.js
'use strict'
const filter = require('filter-iterator')
const pf = require('possible-function')
const {entries, reconstruct} = require('m-o')
const filterIterable = require('filter-iter')
const isPlainObject = require('is-plain-object')
const PossibleFunction = require('possible-function')
module.exports = (map, test) => new (map.constructor)(filter(map.entries(), e => pf(test, (k, v) => !!v)(...e)))
module.exports = (map, test, options) => {
if (isPlainObject(test) && !isPlainObject(options)) options = test
test = PossibleFunction(test, (k, v) => !!v)
return reconstruct(map, filterIterable(entries(map), entry => test(...entry), options))
}
{
"name": "filter-map",
"version": "3.0.0",
"version": "3.1.0",
"description": "Returns a copy of a Map object containing only those entries which pass a test function.",

@@ -19,3 +19,5 @@ "keywords": [

"dependencies": {
"filter-iterator": "0.0.1",
"filter-iter": "^1.0.0",
"is-plain-object": "^2.0.4",
"m-o": "^2.1.0",
"possible-function": "^1.0.1"

@@ -22,0 +24,0 @@ },

# filter-map
Returns a copy of a [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) object containing only those entries which pass a test function.
Returns a copy of a [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/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

@@ -15,5 +17,10 @@

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}
```

@@ -25,4 +32,15 @@

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:
```javascript
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}
```
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