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
Weekly downloads
29
decreased by-39.58%

Weekly downloads

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/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

PropertyDescription
isCheck if value is a map.
keysList all keys.
valuesList all values.
entriesList all key-value pairs.
fromConvert entries to map.
from$Convert entries to map.
fromListsConvert lists to map.
fromKeysCreate a map from keys.
fromValuesCreate a map from values.
compareCompare two maps.
isEqualCheck if two maps are equal.
sizeFind the size of a map.
isEmptyCheck if a map is empty.
getGet value at key.
getAllGet values at keys.
getPathGet value at path in a nested map.
hasPathCheck if nested map has a path.
setSet value at key.
set$Set value at key.
setPath$Set value at path in a nested map.
swapExchange two values.
swap$Exchange two values.
removeRemove value at key.
remove$Remove value at key.
removePath$Remove value at path in a nested map.
countCount values which satisfy a test.
countAsCount occurrences of values.
minFind smallest value.
minEntryFind smallest entry.
maxFind largest value.
maxEntryFind largest entry.
rangeFind smallest and largest values.
rangeEntriesFind smallest and largest entries.
headGet first entry from map (default order).
tailGet a map without its first entry (default order).
takeKeep first n entries only (default order).
take$Keep first n entries only (default order).
dropRemove first n entries (default order).
drop$Remove first n entries (default order).
subsetsList all possible subsets.
randomKeyPick an arbitrary key.
randomEntryPick an arbitrary entry.
randomSubsetPick an arbitrary subset.
hasCheck if map has a key.
hasValueCheck if map has a value.
hasEntryCheck if map has an entry.
hasSubsetCheck if map has a subset.
findFind first value passing a test (default order).
findAllFind values passing a test.
searchFind key of an entry passing a test.
searchAllFind keys of entries passing a test.
searchValueFind a key with given value.
searchValueAllFind keys with given value.
forEachCall a function for each value.
someCheck if any value satisfies a test.
everyCheck if all values satisfy a test.
mapTransform values of a map.
map$Transform values of a map.
reduceReduce values of set to a single value.
filterKeep entries which pass a test.
filter$Keep entries which pass a test.
filterAtKeep values at given keys.
filterAt$Keep values at given keys.
rejectDiscard entries which pass a test.
reject$Discard entries which pass a test.
rejectAtDiscard values at given keys.
rejectAt$Discard values at given keys.
flatFlatten nested map to given depth.
flatMapFlatten nested map, based on map function.
zipCombine matching entries from maps.
partitionSegregate entries by test result.
partitionAsSegregate entries by similarity.
chunkBreak map into chunks of given size.
concatAppend entries from maps, preferring last.
concat$Append entries from maps, preferring last.
joinJoin entries together into a string.
isDisjointCheck if maps have no common keys.
unionKeysObtain keys present in any map.
unionObtain entries present in any map.
union$Obtain entries present in any map.
intersectionKeysObtain keys present in all maps.
intersectionObtain entries present in both maps.
intersection$Obtain entries present in both maps.
differenceObtain entries not present in another map.
difference$Obtain entries not present in another map.
symmetricDifferenceObtain entries not present in both maps.
symmetricDifference$Obtain entries not present in both maps.
cartesianProductList cartesian product of maps.


ORG DOI Coverage Status Test Coverage Maintainability

Keywords

FAQs

Last updated on 19 Oct 2023

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