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 🙏

© 2026 – Pkg Stats / Ryan Hefner

map-extensions

v1.1.0

Published

Extensions to help when working with Map objects

Readme

Run Tests

Map Extensions

This is a small, single purpose package to assist in working with JavaScript / TypeScript Maps.

Installation

npm i map-extensions

Added Functionality

This package provides a MapWrapper object which, exactly as it sounds, wraps current Map functionality while providing a few other useful methods. Those methods currently are:

  • find
  • filter
  • map
  • some
  • tuples

The added methods perform similarly to their Array counterparters but instead work on the wrapped Map object.

MapWrapper Examples

Find
const map = new Map([
  ["first", "first value"],
  ["second", "second value"],
  ["third", "third value"],
]);
const wrapper = new MapWrapper(map);

const actual = wrapper.find((value) => value === "second value");

// actual will be the second tuple from the Map
// Special note that find returns an object named Tuple created in this package. It is a wrapper for the native tuple to make its use more clear.

const key = actual.key; // Would be "second"
const value = actual.value; // Would be "second value"
const nativeTuple = actual.toNativeTuple(); // Would be ["second", "second value"]
const newMap = actual.toMap(); // Would be a new Map instance with the tuple included within it
const newWrappedMap = actual.toMapWrapper(); // Would be a new MapWrapper instance with the tuple included within it
Filter
const map = new Map<string, number>([
  ["uno", 1],
  ["dos", 2],
  ["tres", 3],
  ["quatro", 4],
  ["cinco", 5],
  ["seis", 6],
  ["siete", 7],
  ["ocho", 8],
  ["nueve", 9],
]);
const wrapper = new MapWrapper(map);

const actual = wrapper.filter((value, _key) => value > 6);

// actual will be a Map only containing the tuples 7, 8, and 9
console.log(actual);
/*
Will output:
Map {
  'siete' => 7,
  'ocho' => 8,
  'nueve' => 9 }
*/
Map
const map = new Map<string, number>([
  ["uno", 1],
  ["dos", 2],
  ["tres", 3],
  ["quatro", 4],
  ["cinco", 5],
  ["seis", 6],
  ["siete", 7],
  ["ocho", 8],
  ["nueve", 9],
]);
const wrapper = new MapWrapper(map);

const actual = wrapper.map((value) => Math.pow(value, value));

// actual will be an array of the original numbers to their own power
// output would be [ 1, 4, 27, 256, 3125, 46656, 823543, 16777216, 387420489 ]
Some
const map = new Map<string, number>([
  ["uno", 1],
  ["dos", 2],
  ["tres", 3],
  ["quatro", 4],
  ["cinco", 5],
  ["seis", 6],
  ["siete", 7],
  ["ocho", 8],
  ["nueve", 9],
]);
const wrapper = new MapWrapper(map);

let actual = wrapper.some((value, key) => key === 'ocho' || value === 8); // Returns true

let actual2 = wrapper.some(value => value > 100); // Returns false
Tuples

This is a method similar to the entries method on a Map. The difference is that tuples will return a collection of Tuple objects instead of the native iterator containing key, value pairs.

const map = new Map<string, number>([
    ['first', 1],
    ['second', 2],
    ['third', 3],
]);
const wrapper = new MapWrapper(map);

let actual = wrapper.tuples();

console.log(actual[0].key); // 'first'
console.log(actual[2].value); // 3

console.log(actual);
/*
Will output:
[
  Tuple { key: 'first', value: 1 },
  Tuple { key: 'second', value: 2 },
  Tuple { key: 'third', value: 3 }
]
*/

Custom Tuple Object Examples

This package includes a custom Tuple object to make it easier working with Map entries.

key
const map = new Map<string, number>([
    ['first', 1],
    ['second', 2],
    ['third', 3],
]);
const wrapper = new MapWrapper(map);

const actual = wrapper.tuples();
const myTuple = actual[0];

console.log(myTuple.key) // 'first';
value
const map = new Map<string, number>([
    ['first', 1],
    ['second', 2],
    ['third', 3],
]);
const wrapper = new MapWrapper(map);

const actual = wrapper.tuples();
const myTuple = actual[0];

console.log(myTuple.value) // 1;
toNativeTuple
const map = new Map<string, number>([
    ['first', 1],
    ['second', 2],
    ['third', 3],
]);
const wrapper = new MapWrapper(map);

const actual = wrapper.tuples();
const myTuple = actual[0];

console.log(myTuple.toNativeTuple()); // ['first', 1]
toMap
const map = new Map<string, number>([
    ['first', 1],
    ['second', 2],
    ['third', 3],
]);
const wrapper = new MapWrapper(map);

const actual = wrapper.tuples();
const myTuple = actual[1];

console.log(myTuple.toMap()); 
/*
Returns a new Map object containing only myTuple as an entry:

Map {
  'second' => 2
  }
*/
toMapWrapper
const map = new Map<string, number>([
    ['first', 1],
    ['second', 2],
    ['third', 3],
]);
const wrapper = new MapWrapper(map);

const actual = wrapper.tuples();
const myTuple = actual[2];

console.log(myTuple.toMapWrapper()); 
/*
Returns a new MapWrapper object containing only myTuple as an entry.
*/