npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

extra-map

v3.2.0

Published

A group of functions for working with Maps.

Downloads

713

Readme

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

| Property | Description | | ---- | ---- | | is | Check if value is a map. | | keys | List all keys. | | values | List all values. | | entries | List all key-value pairs. | | | | | from | Convert entries to map. | | from$ | Convert entries to map. | | fromLists | Convert lists to map. | | fromKeys | Create a map from keys. | | fromValues | Create a map from values. | | | | | compare | Compare two maps. | | isEqual | Check if two maps are equal. | | | | | size | Find the size of a map. | | isEmpty | Check if a map is empty. | | | | | get | Get value at key. | | getAll | Get values at keys. | | getPath | Get value at path in a nested map. | | hasPath | Check if nested map has a path. | | set | Set value at key. | | set$ | Set value at key. | | setPath$ | Set value at path in a nested map. | | swap | Exchange two values. | | swap$ | Exchange two values. | | remove | Remove value at key. | | remove$ | Remove value at key. | | removePath$ | Remove value at path in a nested map. | | | | | count | Count values which satisfy a test. | | countAs | Count occurrences of values. | | min | Find smallest value. | | minEntry | Find smallest entry. | | max | Find largest value. | | maxEntry | Find largest entry. | | range | Find smallest and largest values. | | rangeEntries | Find smallest and largest entries. | | | | | head | Get first entry from map (default order). | | tail | Get a map without its first entry (default order). | | take | Keep first n entries only (default order). | | take$ | Keep first n entries only (default order). | | drop | Remove first n entries (default order). | | drop$ | Remove first n entries (default order). | | | | | subsets | List all possible subsets. | | randomKey | Pick an arbitrary key. | | randomEntry | Pick an arbitrary entry. | | randomSubset | Pick an arbitrary subset. | | | | | has | Check if map has a key. | | hasValue | Check if map has a value. | | hasEntry | Check if map has an entry. | | hasSubset | Check if map has a subset. | | find | Find first value passing a test (default order). | | findAll | Find values passing a test. | | search | Find key of an entry passing a test. | | searchAll | Find keys of entries passing a test. | | searchValue | Find a key with given value. | | searchValueAll | Find keys with given value. | | | | | forEach | Call a function for each value. | | some | Check if any value satisfies a test. | | every | Check if all values satisfy a test. | | map | Transform values of a map. | | map$ | Transform values of a map. | | reduce | Reduce values of set to a single value. | | filter | Keep entries which pass a test. | | filter$ | Keep entries which pass a test. | | filterAt | Keep values at given keys. | | filterAt$ | Keep values at given keys. | | reject | Discard entries which pass a test. | | reject$ | Discard entries which pass a test. | | rejectAt | Discard values at given keys. | | rejectAt$ | Discard values at given keys. | | flat | Flatten nested map to given depth. | | flatMap | Flatten nested map, based on map function. | | zip | Combine matching entries from maps. | | | | | partition | Segregate entries by test result. | | partitionAs | Segregate entries by similarity. | | chunk | Break map into chunks of given size. | | | | | concat | Append entries from maps, preferring last. | | concat$ | Append entries from maps, preferring last. | | join | Join entries together into a string. | | | | | isDisjoint | Check if maps have no common keys. | | unionKeys | Obtain keys present in any map. | | union | Obtain entries present in any map. | | union$ | Obtain entries present in any map. | | intersectionKeys | Obtain keys present in all maps. | | intersection | Obtain entries present in both maps. | | intersection$ | Obtain entries present in both maps. | | difference | Obtain entries not present in another map. | | difference$ | Obtain entries not present in another map. | | symmetricDifference | Obtain entries not present in both maps. | | symmetricDifference$ | Obtain entries not present in both maps. | | cartesianProduct | List cartesian product of maps. |

ORG DOI Coverage Status Test Coverage Maintainability