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.
; const map = ; map; // . (empty)// └--a (empty)// └--b (empty)// └--c (2) console; // trueconsole; // falseconsole; // 2 map; // any iterable can be a path // identical to map.set(['a', 'x'], 3) // . (empty)// └--a (empty)// |--b (empty)// | └--c (2)// └--x (3) map; // . (empty)// └--a (9)// |--b (empty)// | └--c (2)// └--x (3) map; // . (null)// └--a (9)// |--b (empty)// | └--c (2)// └--x (3) map; // . (null)// └--a (9)// └--x (3) // there's also a find() method// which ES6 `Map` doesn't havemapclear;map;map;map;map;map;for const path of map console; // '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.