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

path-map-ts

v0.1.1

Published

A Map that uses an array of keys (path) to map to a value. A generic prefix tree map.

Readme

path-map

A Map that uses an array of keys (a path) to map to a value. Think of it as a nested Map with a flat API.

Installation

npm i path-map

Usage

import { PathMap } from 'path-map';

const map = new PathMap<string[], number>();

// Set values using an array of keys
map.set(['a', 'b', 'c'], 42);

// Get values
map.get(['a', 'b', 'c']); // 42
map.get(['a', 'b']);      // undefined — intermediate nodes are internal

// Check if a path exists
map.has(['a', 'b', 'c']); // true

// Delete a path
map.delete(['a', 'b', 'c']);

// Iteration
map.set(['x', 'y'], 1);
map.set(['x', 'z'], 2);

for (const [keys, value] of map) {
  console.log(keys, value);
}
// ['x', 'y'] 1
// ['x', 'z'] 2

// All entries
map.entries(); // [[['x', 'y'], 1], [['x', 'z'], 2]]
map.keys();    // [['x', 'y'], ['x', 'z']]
map.values();  // [1, 2]

// forEach — third argument is the PathMap instance itself
map.forEach((value, keys, pathMap) => {
  console.log(keys, value, pathMap === map); // true
});

const m = new PathMap<string[], string>();
m.set(['a'], 'hello');

const v1 = m.get(['a']);     // 'hello'
const v2 = m.get(['b']);     // undefined (not found)
const v3 = m.get(['a', 'b']); // undefined (intermediate node, no value stored)

// Clear everything
map.clear();

API

new PathMap<K extends any[], V>(entries?)

Creates a new PathMap instance.

  • entries — optional Iterable<[K, V]> to populate the map on construction.

.get(keys: K): V | undefined

Returns the value at the given key path, or undefined if:

  • the path does not exist, or
  • an intermediate node along the path does not exist.

.set(keys: K, value: V): this

Sets the value at the given key path. Intermediate Map nodes are created automatically. If an existing value sits on an intermediate key, it is overwritten by a new Map node.

.has(keys: K): boolean

Returns true if a value exists at the given key path.

.delete(keys: K): void

Deletes the value at the given key path.

.clear(): this

Removes all entries.

.entries(): [K, V][]

Returns an array of [keys, value] pairs.

.keys(): K[]

Returns an array of all key paths.

.values(): V[]

Returns an array of all values.

.forEach(callbackfn, thisArg?): this

Invokes callbackfn for each entry. The callback receives:

(value: V, keys: K, pathMap: PathMap<K, V>) => void

The third argument is the PathMap instance itself (consistent with Map.prototype.forEach).

[Symbol.iterator](): IterableIterator<[K, V]>

Makes the map iterable. Yields [keys, value] tuples. Enables for...of and spread.

[Symbol.toStringTag]

Returns 'PathMap'.

Differences from native Map

| Feature | Map | PathMap | | ------------------ | -------------- | --------------------------------------- | | Key type | single value | array of values (a path) | | Intermediate nodes | — | auto-created, hidden | | forEach 3rd arg | Map instance | PathMap instance | | .size | O(1) | not provided (O(n) would be misleading) |

License

MIT