5.1.0 • Published 9 months ago

sort-keys v5.1.0

Weekly downloads
20,113,440
License
MIT
Repository
github
Last release
9 months ago

sort-keys

Sort the keys of an object

Useful to get a deterministically ordered object, as the order of keys can vary between engines.

Install

npm install sort-keys

Usage

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}]

API

sortKeys(object, options?)

Returns a new object with sorted keys.

object

Type: object | Array

options

Type: object

deep

Type: boolean\ Default: false

Recursively sort keys, including keys of objects inside arrays.

compare

Type: Function

Compare function.

sort-keys-lengthwrite-json-filewrite-pkgvuedragdropuploadimages@yannick243/rw-json-filejsn_web2cloud-archive-s3bb-chat@frxf/frxfwebchen-ddkygraphql-schema-flickrcogoportutilsdyx-reactlang-sync-clitalent-to-vite-clireact-native-slider-kfunblock-block-save-variablesldl_revopea-bootstraap@everything-registry/sub-chunk-2799node-common-sdk-discordp149-tablesz-gulp-revwinx-form-winxweb-elements-iconsvue-button-test1wp-salts-cliwrite-json5-filewrite-packagewrite-pkg-2xfx-gulp-revstatic-content-apistoppuhrswg-gulp-revvue-compment@doyokit/generator@ctfdio/picocss-themes@common-stack/client-react@common-stack/components-pro@potent/api@positionex/position-sdkcauseway-concrete-stylescbr-ratesjaid-corejaidbotjaidbot-desktopipfs-repoipfs-repo-ci-testjeuxuijest-snapshots-json-rest-apijesusdemojson-comb-corejohn-test-upgradejamuskalimkey-counterjsongokafirchain-tetrislazy-bee-ui3.0.0i18next-parser-async-translatesushi-sdk-ftmzzzxxxyyy321123spjsort-pkgsort-keys-clisort-keys-recursivesort-valuessunmi-cstock-ticker-react-widgettype-donetypes-localtingzi-vuepresstiledmap-loadertypewritertypings-coretovar.jstme-api-clienttrpc-selectionstrgraphtravis-watchut-apiut-runtweeter-client@artiso-solutions/vue-html-to-paper@appsemble/node-utils@angular-ru/ngx-i18n-combine@andrewflett/typewriter@adminide-stack/core@backtrack/core@best-shot/preset-env@best-shot/inspector@buganto/client@centeredgesoft/runtime-mock-routes@abhinavoneuipoc/stencil-test@codemayonnaise/extract-react-intl-messages@digidem/extract-react-intl-messages@contagt/metismenu@dapp.xyz/node-commonyeoman-generatorxys_cli
5.1.0

9 months ago

5.0.0

4 years ago

4.2.0

4 years ago

4.1.0

5 years ago

4.0.0

6 years ago

3.0.0

6 years ago

2.0.0

8 years ago

1.1.2

9 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.0

11 years ago

0.1.0

11 years ago