You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 1002B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # sort-keys [![Build Status](https://travis-ci.org/sindresorhus/sort-keys.svg?branch=master)](https://travis-ci.org/sindresorhus/sort-keys)
  2. > Sort the keys of an object
  3. Useful to get a deterministically ordered object, as the order of keys can vary between engines.
  4. ## Install
  5. ```
  6. $ npm install --save sort-keys
  7. ```
  8. ## Usage
  9. ```js
  10. const sortKeys = require('sort-keys');
  11. sortKeys({c: 0, a: 0, b: 0});
  12. //=> {a: 0, b: 0, c: 0}
  13. sortKeys({b: {b: 0, a: 0}, a: 0}, {deep: true});
  14. //=> {a: 0, b: {a: 0, b: 0}}
  15. sortKeys({c: 0, a: 0, b: 0}, {
  16. compare: (a, b) => -a.localeCompare(b)
  17. });
  18. //=> {c: 0, b: 0, a: 0}
  19. ```
  20. ## API
  21. ### sortKeys(input, [options])
  22. Returns a new object with sorted keys.
  23. #### input
  24. Type: `Object`
  25. #### options
  26. ##### deep
  27. Type: `boolean`
  28. Recursively sort keys.
  29. ##### compare
  30. Type: `Function`
  31. [Compare function.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
  32. ## License
  33. MIT © [Sindre Sorhus](https://sindresorhus.com)