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

@metagov/path

v0.4.0

Published

A utility class for dynamic construction of paths to access object properties

Readme

@metagov/path

A TypeScript utility class for dynamic construction of paths to access object properties using dotted and indexed notation. Key features:

  • Value Equality: $.a.b.c === $.a.b.c
  • Iteration: [...$.a.b.c] // ['a', 'b', 'c']
  • Callable Paths: $.a.b.c({a:{b:{c: 42}}}) // 42
  • Type Safety: Fully typed for robust development

Installation

npm install @metagov/path

Usage

import { Path } from '@metagov/path'

// Define a root path
const $ = new Path()

// Grow new paths from the root
const a = $.a
const ab = $.a.b
const abc = ab.c
const abc2 = $.a.b.c[2]

// Equality (identity)
abc === $.a.b.c // true

// Iteration
[...$] // []
[...abc] // ['a', 'b', 'c']
for (const key of $.a[2]) {
  console.log(key)
} // outputs 'a' and '2'

// Calling paths to dig into objects and arrays
const data = {a: {b: {c: [0, 1, 42]}}}
$(data) === data // true
abc(data) === data.a.b.c // true
abc2(data) === 42 // true
[{a:1}, {a:2}, {a:3}].map($.a) // [1, 2, 3]

// Edge cases
abc({}) // undefined (path not found)
$.a['b.c']({a: {'b.c': 42}}) // 42 (special characters in keys)

// Path methods
Path.isPath($.a) // true
Path.concat(abc, ['d', 'e'], $.f) // $.a.b.c.d.e.f
Path.array(ab) // ['a', 'b']
Path.callable(abc2)(data) // 42 (typesafe call)

API

Path Class

A utility class for dynamic path construction and property access.

  • constructor(path: Key[] = []): Creates a new Path instance.

    • path: Optional array of keys (strings or numbers) to initialize the path.
    • Example: new Path(['a', 'b']) // $.a.b
  • [key: Key]: Path: Dynamically creates a new Path by appending a key.

    • Example: $.a.b // Path for $.a.b
  • [Symbol.iterator](): IterableIterator<Key>: Enables iteration over path keys.

    • Example: [...$.a.b] // ['a', 'b']
  • [Symbol.toPrimitive](): string: Returns the string representation of the path.

    • Example: String($.a.b) // '$.a.b'
  • (obj: any): any: Resolves the path against an object, returning the value or undefined if not found.

    • Example: $.a.b({a: {b: 42}}) // 42

Static Methods

  • Path.callable(path: Path): CallablePath: Converts a Path to a callable function.

    • path: The Path instance to convert.
    • Returns: A callable Path that resolves values.
    • Example: Path.callable($.a.b)({a: {b: 42}}) // 42
  • Path.isPath(x: any): x is Path: Checks if a value is a Path instance.

    • x: The value to check.
    • Returns: true if x is a Path, false otherwise.
    • Example: Path.isPath($.a) // true
  • Path.array(path: Path): Key[]: Returns the underlying path as an array of keys.

    • path: The Path instance.
    • Returns: Array of keys.
    • Example: Path.array($.a.b) // ['a', 'b']
  • Path.concat(path: Path, ...paths: (Path | Key[])[]): Path: Concatenates paths or key arrays to create a new Path.

    • path: The base Path.
    • paths: Additional Path instances or key arrays to concatenate.
    • Returns: A new Path with combined keys.
    • Example: Path.concat($.a, ['b', 'c']) // $.a.b.c

Building

pnpm run clean # optional
pnpm install
pnpm run build

Testing

pnpm run test
pnpm run test --coverage

License

ISC