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

schlibs

v0.1.0

Published

BDD-driven dual-language library for JSON-Path and JSON-Pointer conversion

Downloads

6

Readme

@schlibs/pathlib

TypeScript library for bidirectional conversion between JSON-Path and JSON-Pointer formats.

Part of the schlibs dual-language library project - identical implementations in Python and TypeScript.

Installation

npm install @schlibs/pathlib

Usage

import {
  pointerToPath,
  pathToPointer,
  pathToPointers,
  PathNotFoundError,
  AmbiguousPathError,
} from '@schlibs/pathlib';

// JSON-Pointer → JSON-Path (no document required)
const path = pointerToPath('/store/book/0/title');
// Returns: "$.store.book[0].title"

// JSON-Path → JSON-Pointer (requires document)
const doc = {
  store: {
    book: [
      { title: 'Book 1', price: 8.95 },
      { title: 'Book 2', price: 12.99 }
    ]
  }
};

const pointer = pathToPointer('$.store.book[0].title', doc);
// Returns: "/store/book/0/title"

// With filter expressions
const pointer2 = pathToPointer('$.store.book[?(@.price > 10)].title', doc);
// Returns: "/store/book/1/title"

// Multiple results
const pointers = pathToPointers('$.store.book[*].title', doc);
// Returns: ["/store/book/0/title", "/store/book/1/title"]

Error Handling

import { PathNotFoundError, AmbiguousPathError } from '@schlibs/pathlib';

try {
  pathToPointer('$.nonexistent', doc);
} catch (error) {
  if (error instanceof PathNotFoundError) {
    console.log('Path not found in document');
  }
}

try {
  pathToPointer('$.store.book[*].title', doc);  // Multiple results
} catch (error) {
  if (error instanceof AmbiguousPathError) {
    console.log('Path resolves to multiple locations');
    // Use pathToPointers() instead
  }
}

API

pointerToPath(pointer: string): string

Convert a JSON-Pointer to a JSON-Path. This is a straightforward syntactic transformation that does not require a document.

Parameters:

  • pointer: JSON-Pointer string (e.g., "/store/book/0/title")

Returns: JSON-Path string (e.g., "$.store.book[0].title")

pathToPointer(jsonpath: string, document: any): string

Convert a JSON-Path to a JSON-Pointer by resolving it against a document. Throws an error if the path resolves to zero or multiple results.

Parameters:

  • jsonpath: JSON-Path string (e.g., "$.store.book[0].title")
  • document: Document to resolve the path against

Returns: JSON-Pointer string (e.g., "/store/book/0/title")

Throws:

  • PathNotFoundError: If the path resolves to zero results
  • AmbiguousPathError: If the path resolves to multiple results

pathToPointers(jsonpath: string, document: any): string[]

Convert a JSON-Path to a list of JSON-Pointers. Handles paths that resolve to multiple results.

Parameters:

  • jsonpath: JSON-Path string (e.g., "$.store.book[*].title")
  • document: Document to resolve the path against

Returns: Array of JSON-Pointer strings

Why the Asymmetry?

JSON-Pointer → JSON-Path conversion is straightforward because JSON-Pointers are concrete paths that always point to exactly one location.

JSON-Path → JSON-Pointer conversion requires a document because:

  • JSON-Paths can be queries (filters, wildcards) that need evaluation against actual data
  • Without a document, we cannot determine which elements match a query
  • Requiring a document ensures consistent behavior and validates path existence

Development

This package is BDD-tested with Cucumber to ensure identical behavior with the Python implementation.

# Run BDD tests
npm test

# Build
npm run build

# Test deployment
./test_deployment.sh

License

MIT