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

@yarn-tool/sort-package-json-exports

v1.0.6

Published

Sort package.json exports field with consistent key ordering / 排序 package.json exports 欄位,確保鍵值順序一致

Readme

@yarn-tool/sort-package-json-exports

Sort package.json exports field with consistent key ordering 排序 package.json exports 欄位,確保鍵值順序一致

NPM version License

Description / 描述

This module provides utilities for sorting the exports field in package.json. It ensures consistent key ordering for better readability and version control.

此模組提供排序 package.json 中 exports 欄位的工具函式。 確保鍵值順序一致,提高可讀性和版本控制友好性。

Installation / 安裝

# Using yarn
yarn add @yarn-tool/sort-package-json-exports

# Using yarn-tool
yarn-tool add @yarn-tool/sort-package-json-exports

# Using yt (yarn-tool alias)
yt add @yarn-tool/sort-package-json-exports

# Using npm
npm install @yarn-tool/sort-package-json-exports

Usage / 使用方式

sortPackageJsonExports(exports, options?)

Sort the exports field in package.json.

排序 package.json 中的 exports 欄位。

import sortPackageJsonExports from '@yarn-tool/sort-package-json-exports';

const exports = {
  '.': {
    import: './dist/index.esm.mjs',
    require: './dist/index.cjs',
    types: './dist/index.d.ts',
  },
  './sub': {
    default: './dist/sub.js',
    types: './dist/sub.d.ts',
  },
};

const sorted = sortPackageJsonExports(exports);
// Returns:
// {
//   '.': { types: './dist/index.d.ts', require: './dist/index.cjs', import: './dist/index.esm.mjs' },
//   './sub': { types: './dist/sub.d.ts', default: './dist/sub.js' }
// }

Custom Ordering / 自定義順序

import sortPackageJsonExports from '@yarn-tool/sort-package-json-exports';

const sorted = sortPackageJsonExports(exports, {
  rootOrder: ['browser', 'module'],  // Prepend to default order
  entryOrder: ['worker'],             // Prepend to default order
});

isPackageJsonExportsEntryObject(exports)

Check if the exports value is an entry object (not a string).

檢查 exports 值是否為項物件(非字串)。

import { isPackageJsonExportsEntryObject } from '@yarn-tool/sort-package-json-exports';

isPackageJsonExportsEntryObject({ import: './dist/index.js' });  // true
isPackageJsonExportsEntryObject('./dist/index.js');              // false

Key Ordering / 鍵值順序

Root-level keys / 根層級鍵

  1. types
  2. require
  3. import
  4. node
  5. node-addons

Entry-level keys / 項層級鍵

  1. types
  2. require
  3. import
  4. node
  5. node-addons
  6. default
  7. .
  8. ./
  9. ./package.json

API Reference / API 參考

| Function | Description | |----------|-------------| | sortPackageJsonExports(exports, options?) | Sort the exports field in package.json | | isPackageJsonExportsEntryObject(exports) | Check if exports is an entry object |

IOptions

| Property | Type | Description | |----------|------|-------------| | rootOrder | readonly string[] | Custom order for root-level exports keys | | entryOrder | readonly string[] | Custom order for nested exports entry keys |

Related / 相關套件

License / 授權

ISC © bluelovers