extra-map 3.0.70
Install from the command line:
Learn more about npm packages
$ npm install @nodef/extra-map@3.0.70
Install via package.json:
"@nodef/extra-map": "3.0.70"
About this version
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/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 }
// ]
Method | Action |
---|---|
is | Checks if value is map. |
get | Gets value at key. |
set | Sets value at key. |
remove | Deletes an entry. |
swap | Exchanges two values. |
size | Gets size of map. |
head | Gets first entry. |
take | Keeps first n entries only. |
shift | Removes first entry. |
from | Creates map from entries. |
concat | Appends entries from maps, preferring last. |
flat | Flattens nested map to given depth. |
chunk | Breaks map into chunks of given size. |
filterAt | Gets map with given keys. |
map | Updates values based on map function. |
filter | Keeps entries which pass a test. |
reduce | Reduces values to a single value. |
range | Finds smallest and largest entries. |
count | Counts values which satisfy a test. |
partition | Segregates values by test result. |
cartesianProduct | Lists cartesian product of maps. |
some | Checks if any value satisfies a test. |
zip | Combines matching entries from maps. |
union | Gives entries present in any map. |
intersection | Gives entries present in both maps. |
difference | Gives entries of map not present in another. |
symmetricDifference | Gives entries not present in both maps. |
isDisjoint | Checks if maps have no common keys. |
key | Picks an arbitrary key. |
value | Picks an arbitrary value. |
entry | Picks an arbitrary entry. |
subset | Picks an arbitrary subset. |
isEmpty | Checks if map is empty. |
isEqual | Checks if two maps are equal. |
compare | Compares two maps. |
find | Finds a value passing a test. |
search | Finds key of an entry passing a test. |
scanWhile | Finds key of first entry not passing a test. |