sort-keys
- Version 5.1.0
- Published
- 5.46 kB
- 1 dependency
- MIT license
Install
npm i sort-keys
yarn add sort-keys
pnpm add sort-keys
Overview
Sort the keys of an object
Index
Functions
Type Aliases
Functions
function sortKeys
sortKeys: { <T extends Record<string, any>>(object: T, options?: Options): T; <T>(object: T[], options?: Options): T[];};
Sort the keys of an object.
Returns
A new object with sorted keys.
Example 1
import sortKeys from 'sort-keys';sortKeys({c: 0, a: 0, b: 0});//=> {a: 0, b: 0, c: 0}sortKeys({b: {b: 0, a: 0}, a: 0}, {deep: true});//=> {a: 0, b: {a: 0, b: 0}}sortKeys({b: [{b: 0, a: 0}], a: 0}, {deep: true});//=> {a: 0, b: [{a: 0, b: 0}]}sortKeys({c: 0, a: 0, b: 0}, {compare: (a, b) => -a.localeCompare(b)});//=> {c: 0, b: 0, a: 0}sortKeys([{b: 0, a:2}], {deep: true});//=> [{a: 2, b: 0}]
Type Aliases
type Options
type Options = { /** Recursively sort keys, including keys of objects inside arrays.
@default false */ readonly deep?: boolean;
/** [Compare function.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) */ readonly compare?: (left: string, right: string) => number;};
Package Files (1)
Dependencies (1)
Dev Dependencies (3)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/sort-keys
.
- Markdown[](https://www.jsdocs.io/package/sort-keys)
- HTML<a href="https://www.jsdocs.io/package/sort-keys"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3105 ms. - Missing or incorrect documentation? Open an issue for this package.