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

keytidy

v0.1.0

Published

Tidy JSON key order — and sort package.json the conventional way (canonical field order, sorted dependencies, untouched scripts). Zero dependencies.

Readme

keytidy

Tidy JSON key order — and sort package.json the way it's actually meant to look. Inconsistent key order is pure diff noise: one teammate's editor writes name first, another's tool writes it last, and every PR churns lines that didn't really change. keytidy gives every JSON file one deterministic order. Zero dependencies.

npx keytidy                 # sort ./package.json in place
npx keytidy --check         # CI gate: exit 1 if anything isn't sorted

It's not just "sort all the keys"

Sorting package.json alphabetically would be wrongname belongs at the top, not wedged between module and optionalDependencies. So keytidy treats package.json specially:

  • Top-level fields follow the conventional order (name, version, description, …, scripts, dependencies, devDependencies, …). Unknown fields (your jest, prettier, etc.) sort alphabetically after the known ones.
  • Dependency blocks (dependencies, devDependencies, peerDependencies, …) are sorted A→Z — the part you actually want sorted.
  • scripts is left in your order, because script order is frequently meaningful (pretesttestposttest, ordered build steps). Opt in with --sort-scripts if you disagree.

Every other .json file just gets a clean recursive alphabetical sort, with arrays left in their original order (an array is data, not config).

Example

// before
{ "version": "1.0.0", "scripts": { "test": "…", "build": "…" },
  "name": "demo", "dependencies": { "zod": "…", "axios": "…" } }

// after  →  npx keytidy
{
  "name": "demo",
  "version": "1.0.0",
  "scripts": { "test": "…", "build": "…" },        // order preserved
  "dependencies": { "axios": "…", "zod": "…" }      // sorted A→Z
}

Usage

keytidy                    # sort ./package.json in place
keytidy package.json tsconfig.json
keytidy *.json             # your shell expands the glob
keytidy --check            # don't write; exit 1 if any file isn't sorted
keytidy --stdout pkg.json  # print the sorted result instead of writing
keytidy --indent 4         # force 4-space indent (default: detected, else 2)
keytidy --sort-scripts     # also sort the package.json scripts block
keytidy --all-keys         # ignore the conventional order, sort A→Z

Indentation is detected from the file and preserved, so keytidy doesn't fight your existing 2-space / 4-space / tab style. The trailing newline is kept as-is.

As a CI / pre-commit gate

- run: npx keytidy --check        # fails the build if package.json drifted

Exit codes

| Code | Meaning | |------|---------| | 0 | sorted (write mode) or everything already sorted (--check) | | 1 | a file needs sorting (--check only) | | 2 | invalid JSON, or a file couldn't be read/written |

Notes

  • It rewrites by parsing and re-serializing, so it normalizes JSON formatting (whitespace, number representation). It does not support comments or trailing commas (JSONC / tsconfig.json with comments will report invalid JSON rather than mangle them).
  • The sort itself is pure and deterministic, shared by the Node and Python ports.

Also available for Python

Same behavior, same flags: pip install keytidy (source: keytidy-py).

License

MIT