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

@exadev/json-compose

v1.0.0

Published

Composes a JSON document from files it extends, with parameters, replace markers and the origin of every node

Readme

@exadev/json-compose

Composes one JSON document from a file and the files it extends, and remembers which file and pointer every node of the result was authored at, so a validation error on the merged value can be reported against the source that caused it.

It does no validation of its own and has no runtime dependencies. File access is injected, so it runs wherever you can supply a read(path) function.

Usage

import { readFile } from "node:fs/promises";
import { composeJson } from "@exadev/json-compose";

const composed = await composeJson(
  "ci/main.json",
  { read: (path) => readFile(path, "utf8") },
  { concatenate: ["steps"] },
);

composed.value; // the merged JSON
composed.files; // every file read, entry first
composed.originOf("/jobs/lint/timeout"); // { file: "ci/base.json", pointer: "/jobs/lint/timeout" }
{
  "extends": ["./base.json", { "path": "./node-job.json", "with": { "version": 22 } }],
  "env": { "CI": "true" }
}

API

composeJson(entry, reader, options?) resolves to a ComposedJson, or rejects with a CompositionError.

  • entry is the path of the root document. Paths are POSIX, and extends paths resolve relative to the file that names them (resolveRelative(from, relative) is exported). Whatever root they are relative to is the reader's business.
  • reader is { read(path: string): Promise<string> }.
  • options.concatenate is a set or array of property names whose array values concatenate across extends. The default is none.
  • options.onDocument(json, file) runs on every document as authored, the entry and each fragment, before its extends and parameters are read. It returns issues; any returned are raised together. Use it for checks this package should not know about, such as requiring a $schema member.

ComposedJson has:

  • value, the merged document with extends, parameters, $param and $replace consumed.
  • files, every file read in the order first reached.
  • originOf(pointer), the { file, pointer } a node was authored at. A pointer that does not exist in value resolves to its nearest enclosing node, so a path from a validator's error always has an answer. A string that is not an RFC 6901 pointer throws RangeError.

Composition rules

A document is a JSON object. Two members are reserved and removed from the result.

extends is a path, an object { "path": "...", "with": { ... } }, or an array of either. Parents are merged in order, then the document's own members are applied last.

Merging, where over is applied on top of base:

  • Objects deep-merge, key by key.
  • Arrays under a key listed in concatenate are base followed by over.
  • Every other array, and every scalar, is replaced by over.
  • { "$replace": value } replaces whatever was inherited with value outright, whatever the types. Where there is nothing to replace it unwraps to value.

parameters declares values a file expects its extender to supply:

{
  "parameters": {
    "version": { "type": "number" },
    "runner": { "type": "string", "default": "ubuntu-latest", "description": "Where it runs" }
  },
  "runsOn": { "$param": "runner" },
  "node": { "$param": "version" }
}

A declaration has a type (string, number or boolean), an optional default and an optional description. The extending file supplies values through with. A parameter needs a value or a default, the value must have the declared type, and a supplied name must be declared. A { "$param": "name" } object is replaced by the value, wherever it appears in the declaring file. Parameters are scoped to the file that declares them: they are not inherited by, or visible to, files further up or down the chain.

A __proto__ key in a document is an ordinary data property, in the input and in the result.

Errors

Every defect raises CompositionError: unreadable or unparseable files, a document that is not an object, a malformed extends or parameters member, an extends cycle, a missing, mistyped or undeclared parameter, and anything onDocument returns.

error.issues is a list of { message, file, pointer }, located at the node as authored, including inside fragments reached through extends. error.message joins them one per line as file#pointer: message:

ci/fragment.json#/parameters/minutes: parameter "minutes" has no value and no default

A file that cannot be read is reported against the file that extends it, at /extends. A cycle is reported against the file that closes it, with the whole chain in the message.

Validating the result

Validate value with whatever schema library you use, then map each issue path back through originOf:

const result = schema.safeParse(composed.value);
if (!result.success) {
  for (const issue of result.error.issues) {
    const pointer = issue.path.map((segment) => `/${String(segment)}`).join("");
    console.error(composed.originOf(pointer), issue.message);
  }
}

Escape ~ as ~0 and / as ~1 in segments if your keys can contain them.

Development

Node 22 or later, pnpm. ESM only.

| Script | | | --- | --- | | pnpm lint / pnpm lint:check | ESLint, fixing / check only | | pnpm typecheck | tsc | | pnpm test | Vitest, tests colocated as *.unit.test.ts | | pnpm build | tsdown into dist |

Commits follow Conventional Commits and are checked by commitlint. Releases are cut by semantic-release from main in CI, published to npm with provenance.

CLAUDE.md and AGENTS.md are symlinks to this file.