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

@ossl-dev/differens-core

v0.2.0

Published

Semantic diff core: GumTree-lineage tree matching over postorder arrays, emitting typed edit scripts

Readme

@ossl-dev/differens-core

The matching engine behind differens: give it two trees, get back what changed as typed actions rather than as lines.

No dependencies, no parser, no opinion about where the trees came from. If you can shape your data into a Node, you can diff it.

npm install @ossl-dev/differens-core

Diffing a value

import { diffTrees, treeFromValue } from "@ossl-dev/differens-core";

const before = treeFromValue({ retries: 3, host: "a.example" });
const after = treeFromValue({ retries: 5, host: "a.example" });

diffTrees(before, after).changes;
// [{ type: "Update",
//    node: { kind: "leaf", label: "retries", ... },
//    detail: { kind: "ValueChanged", from: "3", to: "5" } }]

host is untouched, so it produces nothing. That is the whole point: the output is proportional to what changed, not to how much text moved.

Diffing your own tree

Build nodes with createNode and the matcher takes it from there.

import { createNode, diffTrees } from "@ossl-dev/differens-core";

const fn = (name: string, body: string) =>
  createNode({
    kind: "Function",
    label: name,
    children: [createNode({ kind: "Body", value: body, byteRange: [0, body.length] })],
    byteRange: [0, 0],
  });

const before = createNode({ kind: "file", children: [fn("parse", "…")], byteRange: [0, 0] });
const after = createNode({ kind: "file", children: [fn("load", "…")], byteRange: [0, 0] });

diffTrees(before, after).changes;
// [{ type: "Update", detail: { kind: "Renamed", from: "parse", to: "load" } }]

kind groups nodes that are allowed to match each other. label is the name a human would use. value is leaf content. Anything with the same kind and identical children is recognised as unchanged wherever it ends up in the tree, which is what turns a relocation into one Move instead of a delete and an add.

What comes back

interface DiffResult {
  changes: EditAction[];
  /** Set when the trees were too large to match and the caller should line-diff */
  fallback?: "lines";
  nodeCount: number;
}

EditAction is a discriminated union on type:

| Type | Carries | |---|---| | Insert | the node, its parent, its position | | Delete | the node | | Update | the node and a detail of Renamed or ValueChanged | | Move | the node, fromParent, toParent, toPosition |

Every action also carries context, the chain of enclosing named nodes, so a change can be reported as "in class RetryPolicy" without a second traversal.

fallback: "lines" only appears when the caller sets maxNodes and one of the trees exceeds it. The default is Infinity: every tree size is matched for real. Treat an explicit fallback as "diff this some other way" rather than as "no changes" -- an empty changes array means both things otherwise.

diffTrees(before, after, { minHeight: 2, bottomUpRatio: 0.5 });

How it matches

Two passes, in the GumTree lineage (Falleri et al., ASE 2014):

  1. Top-down. Identical subtrees are found by content hash, tallest first, and matched whole. A function that moved to another file is the same subtree, so it matches before anything else gets a chance to guess.
  2. Bottom-up. Remaining containers match when enough of their descendants already did, by Dice coefficient. This is what survives a body edit: the function still matches even though its insides changed.

The tree is indexed in postorder, so a subtree is a contiguous id range and "is X inside Y" is an integer comparison. Matching state lives in flat Int32Arrays rather than maps. Moves are reduced to a minimum by taking the longest increasing subsequence of matched positions -- reordering three items out of fifty reports three moves, not fifty.

Deterministic throughout: same inputs, same output, no model anywhere.

Related

MIT. Source.