@y13i/sort-keys
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

sort-keys

npm version

Sort the keys of an object.

Live Demo

Installation

npm install @y13i/sort-keys

Usage

import { sortKeys } from "@y13i/sort-keys";

sortKeys(object, option?)

Returns a new object with sorted keys.

object

Type: object

The object to sort keys of.

option

Type: object

option.depth

Type: number (1 or greater integer)

Default: Infinity

Defines how many times to recursively sort keys in a nested object or an array.

option.prioritize.keys

Type: string[]

If specified, keys in this array will be put at the first.

option.prioritize.primitives

Type: boolean

If true, primitive values (number, string, boolean, null, undefined) will be put at the first.

option.compare

Type: Function, (object) => (leftKey: string, rightKey: string) => number

A higher-order function that returns a comparator function.

Examples

See test code for examples.

CLI

See y13i/sort-keys-cli.

Prior art

Readme

Keywords

Package Sidebar

Install

npm i @y13i/sort-keys

Weekly Downloads

3

Version

0.4.0

License

MIT

Unpacked Size

9.74 kB

Total Files

7

Last publish

Collaborators

  • y13i