You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

pmap

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pmap

Trie-based ES6 Map clone: keys=iterables, values=anything

2.0.0
latest
Source
npmnpm
Version published
Weekly downloads
83
-12.63%
Maintainers
1
Weekly downloads
 
Created
Source

Path Maps!

npm install pmap

A path map has the same API surface as an ES6 Map, except keys are arrays (or iterables) describing paths. Internally, a trie data structure is used to store entries. Here are some examples.

import PathMap from 'pmap';

const map = new PathMap();

map.set(['a','b','c'], 2);

// . (empty)
// └--a (empty)
//    └--b (empty)
//       └--c (2)

console.log(map.has(['a','b','c'])); // true
console.log(map.has(['a','b'])); // false
console.log(map.get(['a','b','c'])); // 2

map.set('ax', 3); // any iterable can be a path
                  // identical to map.set(['a', 'x'], 3)

// . (empty)
// └--a (empty)
//    |--b (empty)
//    |  └--c (2)
//    └--x (3)

map.set(['a'], 9);

// . (empty)
// └--a (9)
//    |--b (empty)
//    |  └--c (2)
//    └--x (3)

map.set([], null);

// . (null)
// └--a (9)
//    |--b (empty)
//    |  └--c (2)
//    └--x (3)

map.delete('abc');

// . (null)
// └--a (9)
//    └--x (3)

// there's also a find() method
// which ES6 `Map` doesn't have
map.clear();
map.set('my dog');
map.set('my dog has fleas');
map.set('my doug');
map.set('my doge');
map.set('my cat');
for (const [path] of map.find('my dog')) {
  console.log(path.join(''));
}

// 'my dog'
// 'my dog has fleas'
// 'my doge'

API documentation

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map

Caveats, change logs and notes:

  • Unlike ES6 maps, iteration order isn't guaranteed.
  • 1.x => 2.0 major version bump due to having removed es6 module syntax. No other changes.

Keywords

es6

FAQs

Package last updated on 25 Apr 2017

Did you know?

Socket

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.