0.2.2 • Published 1 year ago

@y13i/sort-keys v0.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago