New:Socket for Asana Is Now Available.Learn more
Get Started

map-extras

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

map-extras

Utility functions for JavaScript Map — mapValues, filterEntries, merge, invert, and groupBy

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

map-extras

Utility functions for JavaScript Map — mapValues, filterEntries, merge, invert, and groupBy

Install

npm install map-extras

Usage

import {mapValues, filterEntries, mergeMap, invertMap, groupBy} from 'map-extras';

const prices = new Map([['apple', 1], ['banana', 2], ['cherry', 3]]);

mapValues(prices, value => value * 2);
//=> Map { 'apple' => 2, 'banana' => 4, 'cherry' => 6 }

filterEntries(prices, value => value > 1);
//=> Map { 'banana' => 2, 'cherry' => 3 }

mergeMap(prices, new Map([['date', 4]]));
//=> Map { 'apple' => 1, 'banana' => 2, 'cherry' => 3, 'date' => 4 }

invertMap(prices);
//=> Map { 1 => 'apple', 2 => 'banana', 3 => 'cherry' }

groupBy([1, 2, 3, 4], x => x % 2 === 0 ? 'even' : 'odd');
//=> Map { 'odd' => [1, 3], 'even' => [2, 4] }

API

mapValues(map, function_)

Returns a new Map with values transformed by function_(value, key).

filterEntries(map, function_)

Returns a new Map with entries where function_(value, key) is truthy.

mergeMap(...maps)

Returns a new Map merging all maps. Later maps override earlier ones.

invertMap(map)

Returns a new Map with keys and values swapped.

groupBy(iterable, function_)

Returns a Map where keys are function_(item) results and values are arrays of items.

  • set-extras - Set algebra operations
  • iterable-ops - Lazy utility functions for iterables

License

MIT

Keywords

map

FAQs

Package last updated on 16 Feb 2026

Related posts