Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email
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.

70 lines
1.9 KiB

  1. # [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status][coveralls-image]][coveralls-url]
  2. > Get a compare function for array to sort
  3. ## Install
  4. ```sh
  5. $ npm install --save compare-func
  6. ```
  7. ## Usage
  8. ```js
  9. var compareFunc = require('compare-func');
  10. // sort by an object property
  11. [{x: 'b'}, {x: 'a'}, {x: 'c'}].sort(compareFunc('x'));
  12. //=> [{x: 'a'}, {x: 'b'}, {x: 'c'}]
  13. // sort by a nested object property
  14. [{x: {y: 'b'}}, {x: {y: 'a'}}].sort(compareFunc('x.y'));
  15. //=> [{x: {y: 'a'}}, {x: {y: 'b'}}]
  16. // sort by the `x` propery, then `y`
  17. [{x: 'c', y: 'c'}, {x: 'b', y: 'a'}, {x: 'b', y: 'b'}].sort(compareFunc(['x', 'y']));
  18. //=> [{x: 'b', y: 'a'}, {x: 'b', y: 'b'}, {x: 'c', y: 'c'}]
  19. // sort by the returned value
  20. [{x: 'b'}, {x: 'a'}, {x: 'c'}].sort(compareFunc(function(el) {
  21. return el.x;
  22. }));
  23. //=> [{x: 'a'}, {x: 'b'}, {x: 'c'}]
  24. ```
  25. ## API
  26. ### compareFunc([property])
  27. Returns a compare function for array to sort
  28. #### property
  29. Type: `string`, `function` or `array` of either
  30. If missing it sorts on itself.
  31. The string can be a [dot path](https://github.com/sindresorhus/dot-prop) to a nested object property.
  32. ## Related
  33. - [sort-on](https://github.com/sindresorhus/sort-on) - Sort an array on an object property
  34. ## License
  35. MIT © [Steve Mao](https://github.com/stevemao)
  36. [npm-image]: https://badge.fury.io/js/compare-func.svg
  37. [npm-url]: https://npmjs.org/package/compare-func
  38. [travis-image]: https://travis-ci.org/stevemao/compare-func.svg?branch=master
  39. [travis-url]: https://travis-ci.org/stevemao/compare-func
  40. [daviddm-image]: https://david-dm.org/stevemao/compare-func.svg?theme=shields.io
  41. [daviddm-url]: https://david-dm.org/stevemao/compare-func
  42. [coveralls-image]: https://coveralls.io/repos/stevemao/compare-func/badge.svg
  43. [coveralls-url]: https://coveralls.io/r/stevemao/compare-func