Socket
Socket
Sign inDemoInstall

extra-map

Package Overview
Dependencies
0
Maintainers
1
Versions
307
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    extra-map

A group of functions for working with Maps.


Version published
Maintainers
1
Install size
74.7 kB
Created

Readme

Source

A group of functions for working with Maps.
📦 Node.js, 🌐 Web, 📜 Files, 📰 Docs, 📘 Wiki.

A Map is a collection of key-value pairs, with unique keys. This package includes common set functions related to querying about map, generating them, comparing one with another, finding their size, adding and removing entries, obtaining its properties, getting a part of it, getting a subset entries in it, finding an entry in it, performing functional operations, manipulating it in various ways, combining together maps or its entries, of performing set operations upon it.

All functions except from*() take set as 1st parameter. Some names are borrowed from Haskell, Python, Java, Processing. Methods like swap() are pure and do not modify the map itself, while methods like swap$() do modify (update) the map itself.

This package is available in Node.js and Web formats. The web format is exposed as extra_set standalone variable and can be loaded from jsDelivr CDN.

Stability: Experimental.


const map = require('extra-map');
// import * as map from "extra-map";
// import * as map from "https://unpkg.com/extra-map@2.1.0/index.mjs"; (deno)

var x = new Map([["a", 1], ["b", 2], ["c", 3], ["d", 4]]);
map.swap(x, "a", "b");
// Map(4) { "a" => 2, "b" => 1, "c" => 3, "d" => 4 }

var x = new Map([["a", 1], ["b", 2], ["c", 3], ["d", 4]]);
var y = new Map([["b", 20], ["c", 30], ["e", 50]]);
map.intersection(x, y);
// Map(2) { "b" => 2, "c" => 3 }

var x = new Map([["a", 1], ["b", 2], ["c", 3], ["d", -2]]);
map.searchAll(x, v => Math.abs(v) === 2);
// [ "b", "d" ]              ^                   ^

var x = new Map([["a", 1], ["b", 2], ["c", 3]]);
[...map.subsets(x)];
// [
//   Map(0) {},
//   Map(1) { "a" => 1 },
//   Map(1) { "b" => 2 },
//   Map(2) { "a" => 1, "b" => 2 },
//   Map(1) { "c" => 3 },
//   Map(2) { "a" => 1, "c" => 3 },
//   Map(2) { "b" => 2, "c" => 3 },
//   Map(3) { "a" => 1, "b" => 2, "c" => 3 }
// ]


Index

MethodAction
isChecks if value is map.
getGets value at key.
setSets value at key.
removeDeletes an entry.
swapExchanges two values.
sizeGets size of map.
headGets first entry.
takeKeeps first n entries only.
shiftRemoves first entry.
fromCreates map from entries.
concatAppends entries from maps, preferring last.
flatFlattens nested map to given depth.
chunkBreaks map into chunks of given size.
filterAtGets map with given keys.
mapUpdates values based on map function.
filterKeeps entries which pass a test.
reduceReduces values to a single value.
rangeFinds smallest and largest entries.
countCounts values which satisfy a test.
partitionSegregates values by test result.
cartesianProductLists cartesian product of maps.
someChecks if any value satisfies a test.
zipCombines matching entries from maps.
unionGives entries present in any map.
intersectionGives entries present in both maps.
differenceGives entries of map not present in another.
symmetricDifferenceGives entries not present in both maps.
isDisjointChecks if maps have no common keys.
keyPicks an arbitrary key.
valuePicks an arbitrary value.
entryPicks an arbitrary entry.
subsetPicks an arbitrary subset.
isEmptyChecks if map is empty.
isEqualChecks if two maps are equal.
compareCompares two maps.
findFinds a value passing a test.
searchFinds key of an entry passing a test.
scanWhileFinds key of first entry not passing a test.


Keywords

FAQs

Last updated on 05 Dec 2022

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