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

@console-one/walker

v0.1.2

Published

Path-based tree walker framework with a JSONPath walker implementation. Register handlers against dotted paths, walk a value, and receive per-path callbacks.

Downloads

407

Readme

@console-one/walker

Path-based tree walker framework with a JSONPath walker implementation. Register handlers against dotted paths (@.user.name, @.tags.0), then walk a value and receive per-path callbacks when each registered path is found.

Use this when:

  • You need to extract values from a nested structure by path.
  • You want to react to multiple paths in a single pass (O(n) over the tree, not O(n × paths)).
  • You want to plug in your own walker for non-JSON structures (extend Walker).

Install

npm install @console-one/walker

Usage

loadAll — synchronous bulk extraction

Quickest way to pull several paths out of an object in one pass:

import { JSONPathWalker } from '@console-one/walker'

const walker = new JSONPathWalker(false)
const results = walker.loadAll(
  ['@.apple', '@.carrot.count', '@.mango.color'],
  {
    apple:  { color: 'red' },
    carrot: { color: 'orange' },
    mango:  { color: 'orange' },
  }
)
// results[0] → { color: 'red' }
// results[1] → undefined (carrot.count doesn't exist)
// results[2] → 'orange'

walk + Handler — callback-per-match

For reactive/evaluative patterns where you want to be notified on each match:

import { JSONPathWalker, Handler } from '@console-one/walker'

const walker = new JSONPathWalker(false)  // errorOnUnfound = false

walker.addHandler('@.user.name', new Handler(
  (value) => console.log('name is', value),
  (err)   => console.error('name lookup failed', err),
))

walker.addHandler('@.user.roles.0', new Handler(
  (value) => console.log('primary role', value),
  (err)   => {}
))

walker.walk({
  user: {
    name: 'Andrew',
    roles: ['admin', 'editor']
  }
})
// → name is Andrew
// → primary role admin

Multiple handlers can be registered against the same path and all fire in order of registration.

errorOnUnfound

const strict  = new JSONPathWalker(true)   // missing paths → error handler
const lenient = new JSONPathWalker(false)  // missing paths → complete() only

Integration with @console-one/subscription

addHandler also accepts a Subscription<any> in place of a Handler. When the path resolves, the subscription receives the value via resolve(); when it's unfound, it receives resolve(null) or reject(error) depending on errorOnUnfound.

import { Subscription } from '@console-one/subscription'

const sub = new Subscription<any>()
walker.addHandler('@.item', sub)
sub.subscribe((value) => { /* ... */ })
walker.walk({ item: 'hello' })

WalkerFactory

Lookup by type name:

import { WalkerFactory } from '@console-one/walker'
const walker = WalkerFactory.create('json')

Currently 'json' is the only supported type. To add a new walker type, extend the Walker interface and register it via the factory (PR welcome).

API

JSONPathWalker(errorOnUnfound?: boolean)

| Method | Description | |---|---| | loadAll(paths, item) | One-shot: resolve several paths into an array of values in parallel. Returns undefined for missing paths. | | addHandler(path, handler) | Register a Handler or Subscription<any> for a path. Returns this. | | walk(item, unfound?, currentpath?) | Walk a value, firing handlers as paths resolve. unfound and currentpath are used internally during recursion; omit them for top-level calls. | | type | 'json' |

Handler

new Handler(success, error, complete?)

A plain value container — no magic. Passed into walker.addHandler(path, handler).

PipedHandler<K, V, Version>

A richer handler shape used by consumers that need to key items by id and track per-version state. Stores success, error, complete, and unsubscribe callbacks. cancel() invokes unsubscribe. Not used by the built-in JSONPathWalker; exported for external walkers.

Walker interface

interface Walker {
  type: string
  addHandler(path: string, handler: Handler | Subscription<any>): Walker
  walk(item: any, unfound?: Set<string>, currentpath?: string): void
}

Implement this if you want to write a walker for a structure other than JSON (XML, YAML AST, Protobuf, etc.).

WalkerFactory

WalkerFactory.create(type: 'json'): Walker

Dependencies

Notes on behavior

  • complete callbacks are dispatched via typeof === 'function', not hasOwnProperty('complete'). Handler's constructor assigns the property even when no callback is passed (it's just undefined), so a hasOwnProperty check would fire for every handler and crash on invocation.

Tests

npm test

15 tests covering loadAll, single-pass walks, multiple handlers per path, nested + array traversal, error vs. lenient unfound handling, and factory construction.