@y13i/sort-keys
v0.4.0
Published
Sort keys of an object.
Downloads
36
Readme
sort-keys
Sort the keys of an object.
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.