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

sort-package-json3

v3.0.9

Published

Enhanced sort-package-json with scripts and exports sorting / 增強版 sort-package-json,支援 scripts 和 exports 排序

Downloads

789

Readme

sort-package-json3

Enhanced sort-package-json with scripts and exports sorting 增強版 sort-package-json,支援 scripts 和 exports 排序

NPM version License

Description / 描述

This module provides an enhanced sort-package-json function that:

  • Sorts package.json keys in a predefined order
  • Sorts scripts following npm lifecycle order
  • Sorts exports field with consistent key ordering

此模組提供增強的 sort-package-json 函式:

  • 按預定義順序排序 package.json 鍵
  • 按 npm 生命週期順序排序 scripts
  • 按一致的鍵值順序排序 exports 欄位

Installation / 安裝

# Using yarn
yarn add sort-package-json3

# Using yarn-tool
yarn-tool add sort-package-json3

# Using yt (yarn-tool alias)
yt add sort-package-json3

# Using npm
npm install sort-package-json3

Usage / 使用方式

import sortPackageJson from 'sort-package-json3';

const pkg = {
  version: '1.0.0',
  name: 'my-package',
  scripts: {
    test: 'jest',
    pretest: 'npm run lint',
    posttest: 'echo done',
  },
  exports: {
    '.': {
      import: './dist/index.esm.mjs',
      require: './dist/index.cjs',
      types: './dist/index.d.ts',
    },
  },
  dependencies: {
    lodash: '^4.17.21',
  },
};

const sorted = sortPackageJson(pkg);
// Returns:
// {
//   name: 'my-package',
//   version: '1.0.0',
//   exports: { '.': { types: '...', require: '...', import: '...' } },
//   scripts: { pretest: '...', test: '...', posttest: '...' },
//   dependencies: { lodash: '^4.17.21' }
// }

Features / 功能

  • Top-level Key Sorting: Sorts package.json keys in a logical order

  • Scripts Sorting: Sorts scripts following npm lifecycle order (pre, main, post)

  • betterScripts Sorting: Also sorts betterScripts field

  • Exports Sorting: Sorts exports field with consistent key ordering

  • 頂層鍵排序:按邏輯順序排序 package.json 鍵

  • Scripts 排序:按 npm 生命週期順序排序 scripts(pre、main、post)

  • betterScripts 排序:也排序 betterScripts 欄位

  • Exports 排序:按一致的鍵值順序排序 exports 欄位

Related Packages / 相關套件

License / 授權

ISC © bluelovers