JSPM

sort-object-keys

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2036006
  • Score
    100M100P100Q207583F
  • License MIT

Sort an object's keys, including an optional key list

Package Exports

  • sort-object-keys

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sort-object-keys) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Sort Object

Returns a copy of an object with all keys sorted.

You can pass an array of keys, which it will use for ordering - to provide custom sorts.

const assert = require('assert');
const sortObject = require('sort-object-keys');

assert.equal(JSON.stringify({
  c: 1,
  b: 1,
  d: 1,
  a: 1,
}), JSON.stringify({
  a: 1,
  b: 1,
  c: 1,
  d: 1,
}));

assert.equal(JSON.stringify(sortObject({
  c: 1,
  b: 1,
  d: 1,
  a: 1,
}, ['b', 'a', 'd', 'c'])), JSON.stringify({
  b: 1,
  a: 1,
  d: 1,
  c: 1,
}));