
Security News
pnpm 11.5 Adds Support for Recognizing npm Staged Publishes
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.
@y13i/sort-keys
Advanced tools
Sort the keys of an object.
npm install @y13i/sort-keys
import { sortKeys } from "@y13i/sort-keys";
sortKeys(object, option?)Returns a new object with sorted keys.
sortKeys({ name: "Alice", age: 30, city: "Tokyo" });
// => { age: 30, city: "Tokyo", name: "Alice" }
objectType: object
The object to sort keys of.
optionType: object
option.depthType: number (1 or greater integer)
Default: Infinity
Limits how many levels deep to recursively sort. 1 sorts only the top-level object; the default Infinity sorts all nested objects and arrays.
sortKeys(
{ version: 1, author: { name: "Alice", email: "alice@example.com" } },
{ depth: 1 }
);
// => { author: { name: "Alice", email: "alice@example.com" }, version: 1 }
// (nested object left unsorted)
option.prioritize.keysType: string[]
Keys listed here are moved to the front, in the order given, before the remaining keys are sorted alphabetically.
sortKeys(
{ spec: {}, kind: "Deployment", metadata: {}, apiVersion: "apps/v1" },
{ prioritize: { keys: ["apiVersion", "kind", "metadata"] } }
);
// => { apiVersion: "apps/v1", kind: "Deployment", metadata: {}, spec: {} }
option.prioritize.primitivesType: boolean
When true, keys with primitive values (numbers, strings, booleans, null, undefined) are sorted before keys with object or array values.
sortKeys(
{ scripts: { build: "tsc" }, name: "my-app", version: "1.0.0", dependencies: { react: "^18.0.0" } },
{ prioritize: { primitives: true } }
);
// => { name: "my-app", version: "1.0.0", dependencies: { react: "^18.0.0" }, scripts: { build: "tsc" } }
option.compareType: Function, (object) => (leftKey: string, rightKey: string) => number
Custom sort logic. The outer function receives the object being sorted; the inner comparator receives two key names and returns a number, following the same convention as Array.prototype.sort. When provided, prioritize options are ignored.
sortKeys(
{ createdAt: "2024-01-01", id: 1, title: "Hello" },
{
compare: () => (left, right) => left.length - right.length || left.localeCompare(right),
}
);
// => { id: 1, title: "Hello", createdAt: "2024-01-01" } (sorted by key length)
See y13i/sort-keys-cli.
FAQs
Sort keys of an object.
We found that @y13i/sort-keys demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.

Security News
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.

Research
/Security News
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.