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

dry-4-js

v0.1.0-alpha.1

Published

Structural duplicate detector for JavaScript/ES6 code

Readme

dryjs

Structural duplicate detector for JavaScript/ES6 code.

dryjs finds code with the same shape even when names, literals, and minor details differ. Inspired by dry4clj by Robert C. Martin.

How It Works

scanFiles → parseFile → normalise → fingerprint → compare → report
  1. Scan – discovers all JS/MJS/JSX/TS/TSX files under the given paths
  2. Parse – uses @babel/parser to extract top-level forms
  3. Normalise – converts each form's AST into a minimal, deterministic NormNode tree where all identifiers → :symbol and all literals → :literal
  4. Fingerprint – walks every sub-tree and collects a Set<string> of serialised sub-trees
  5. Compare – computes Jaccard similarity over fingerprint sets for every pair
  6. Report – outputs matches above the threshold

Why Structural?

Two functions with different names and different variable names but the same shape will score 1.0:

// alpha.js
function alpha(xs) {
  const ys = xs.filter(isOdd);
  return ys.map(increment);
}

// beta.js
function beta(items) {
  const kept = items.filter(isEven);
  return kept.map(decrement);
}
DUPLICATE score=1.00
  alpha.js:2-5
  beta.js:2-5

Functions that share most of their structure score below 1.0 (e.g. 0.89) — still worth reviewing.

Installation

npm install

Usage

node src/cli.mjs [options] [paths...]

Options

| Flag | Description | Default | | ----------------------- | --------------------------------------- | -------- | | -t, --threshold <n> | Minimum similarity score | 0.82 | | --min-lines <n> | Minimum source lines per candidate form | 4 | | --min-nodes <n> | Minimum normalised node count | 20 | | -f, --format <fmt> | Output format:text or json | text | | --json | Shorthand for --format json | | | -V, --version | Show version | | | -h, --help | Show help | |

Examples

# Scan src/ directory (default)
node src/cli.mjs

# Scan multiple paths
node src/cli.mjs src lib

# Higher threshold — only near-perfect structural matches
node src/cli.mjs --threshold 0.9 src

# Lower threshold — catch more partial matches
node src/cli.mjs --threshold 0.7 src

# JSON output for tooling / CI
node src/cli.mjs --json src

# Tune sensitivity (skip short forms)
node src/cli.mjs --min-lines 6 --min-nodes 30 src

Sample Text Output

DUPLICATE score=0.89
  src/billing/invoice.js:12-25
  src/billing/receipt.js:30-44

DUPLICATE score=1.00
  src/utils/alpha.js:1-6
  src/utils/beta.js:1-6

Sample JSON Output

{
  "candidates": [
    {
      "score": 0.89,
      "left": { "file": "src/billing/invoice.js", "startLine": 12, "endLine": 25 },
      "right": { "file": "src/billing/receipt.js", "startLine": 30, "endLine": 44 },
      "leftNodes": 88,
      "rightNodes": 91
    }
  ]
}

Architecture

src/
  scanner.mjs      – File discovery (glob, recursive)
  parser.mjs       – @babel/parser + top-level form extraction
  normaliser.mjs   – AST → deterministic NormNode { type, children }
  fingerprinter.mjs – NormNode → Set<string> fingerprints
  comparator.mjs   – Jaccard similarity over fingerprint sets
  reporter.mjs     – Output formatting (text / JSON)
  cli.mjs          – Orchestration + CLI (commander)
  utils.mjs        – Shared helpers

Development

npm install
npm test              # run all tests (Vitest)
npm run test:watch    # watch mode
npm run test:coverage # tests + coverage report

Testing

107 tests across 6 test files covering:

  • Scanner file discovery
  • Parser form extraction and error resilience
  • Normaliser determinism and structural invariants
  • Fingerprinter sub-tree collection and MIN_NODES filter
  • Comparator Jaccard similarity and duplicate finding
  • Reporter text + JSON formatting
  • Full end-to-end pipeline scenarios

License

CC-BY-NC-4.0