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

@dldc/mappemonde

v3.0.9

Published

A multidimensional Map

Downloads

81

Readme

🗺 Mappemonde

A multidimensional (variadic keys) Map

This library expose a data structure similar to Map except it accept an arbitrary number of keys.

Gist

import { Mappemonde } from 'mappemonde';

const m = Mappemonde.byValue();
m.set(['foo', 42], 'bar');
m.get(['foo', 42]); // => 'bar'

Position vs Value

Mappemonde can work in two distinc modes: position or value. This define how items are identified:

  • in value mode the order of the keys does not matter and you can even pass a Set as a list of keys.
  • in position mode, the order does matter and you can't use a Set because Set are unordered.

You need to choose the mode you want to use when you create a Mappemonde:

const positionalMap = Mappemonde.byPosition();
const valueMap = Mappemonde.byValue();

API

Creating a Mappemonde

In both case you get back a Mappemonde instance

Mappemonde.byPosition();
// or
Mappemonde.byValue();
// or
Mappemonde.create('value');
Mappemonde.create('position');

Mappemonde instance

export interface Mappemonde<K extends Keys<any>, V> {
  get(keys: K): V | undefined;
  set(keys: K, value: V): void;
  has(keys: K): boolean;
  delete(keys: K): void;
  entries(): Array<[K, V]>;
  values(): Array<V>;
  keys(): Array<K>;
  cleanup(): void;
}

Typescript

This library is written in TypeScript and expose strict types !

import { Mappemonde } from 'mappemonde';

// keys should be number, value should be string
const m1 = Mappemonde.byValue<Array<number>, string>();

// keys should be of length 2 with first a string then a number
const m2 = Mappemonde.byPosition<[string, number], string>();

Cleanup

Internally this library uses a tree of Map. This mean that if you set, then delete an item you would end up with an empty Map, but Mappemonde prevent memory leaks by removing empty Map when they appear.

If this strategy doesn't work for you, you can change it using the cleanup option:

import { Mappemonde } from 'mappemonde';

// never cleanup
const m1 = Mappemonde.byValue({ cleanup: 'never' });
// you can call cleanup yourself
m1.cleanup();

// cleanup when you delete an item (default value)
const m2 = Mappemonde.byPosotion({ cleanup: 'onDelete' });

// cleanup every 10 delete
const m3 = Mappemonde.create('value', { cleanup: ['everyDelete', 10] });

// cleanup every 10 seconds
const m4 = Mappemonde.create('position', {
  cleanup: ['periodically', 10 * 1000],
});