{"name":"array-sort","description":"Fast and powerful array sorting. Sort an array of objects by one or more properties. Any number of nested properties or custom comparison functions may be used.","version":"0.1.0","homepage":"https://github.com/jonschlinkert/array-sort","author":{"name":"Jon Schlinkert","url":"https://github.com/jonschlinkert"},"repository":{"type":"git","url":"git+https://github.com/jonschlinkert/array-sort.git"},"bugs":{"url":"https://github.com/jonschlinkert/array-sort/issues"},"license":"MIT","files":["index.js"],"main":"index.js","engines":{"node":">=0.10.0"},"scripts":{"test":"mocha"},"dependencies":{"get-value":"^1.1.5","kind-of":"^2.0.0"},"devDependencies":{"mocha":"*","should":"*"},"keywords":["arr","array","asc","ascend","ascending","desc","descend","descending","dot","element","elements","get","multiple","nested","obj","object","order","ordered","path","prop","properties","property","sort","sorted","sorting"],"verb":{"related":{"list":["sort-asc","sort-desc","get-value","set-value","sort-object"]}},"gitHead":"8d160bb7ab415f3b0868e795f3bd4cb1596802fa","_id":"array-sort@0.1.0","_shasum":"b71ff5542d6abe4eb1ec03149d3db30aacccd9b8","_from":".","_npmVersion":"2.10.1","_nodeVersion":"0.12.4","_npmUser":{"name":"jonschlinkert","email":"github@sellside.com"},"maintainers":[{"name":"jonschlinkert","email":"github@sellside.com"}],"dist":{"shasum":"b71ff5542d6abe4eb1ec03149d3db30aacccd9b8","tarball":"http://registry-npm.ywwl.com/array-sort/download/array-sort-0.1.0.tgz","integrity":"sha512-ImnW0py5K/1T3przH5uvWdI/p6cip50G/ev5PO6+0dkD1jCg08voQrp/xo9ypYrE1fQf16ZhMLImX6CtvCRZKw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD+A/JvcDsWPe/FkTnLdMzLkVdPZcMR0vv48R1kI9gT5gIgLGJDEjuCPyJX2xpGwtoAESxon0cdmoIFlfbfKiSGizA="}],"size":4031,"noattachment":false,"key":"/array-sort/-/array-sort-0.1.0.tgz"},"directories":{},"readme":"# array-sort [![NPM version](https://img.shields.io/npm/v/array-sort.svg?style=flat)](https://www.npmjs.com/package/array-sort) [![NPM monthly downloads](https://img.shields.io/npm/dm/array-sort.svg?style=flat)](https://npmjs.org/package/array-sort)  [![NPM total downloads](https://img.shields.io/npm/dt/array-sort.svg?style=flat)](https://npmjs.org/package/array-sort) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/array-sort.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/array-sort) [![Windows Build Status](https://img.shields.io/appveyor/ci/jonschlinkert/array-sort.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/jonschlinkert/array-sort)\n\n> Fast and powerful array sorting. Sort an array of objects by one or more properties. Any number of nested properties or custom comparison functions may be used.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save array-sort\n```\n\nInstall with [yarn](https://yarnpkg.com):\n\n```sh\n$ yarn add array-sort\n```\n\n## Usage\n\nSort an array by the given object property:\n\n```js\nvar arraySort = require('array-sort');\n\narraySort([{foo: 'y'}, {foo: 'z'}, {foo: 'x'}], 'foo');\n//=> [{foo: 'x'}, {foo: 'y'}, {foo: 'z'}]\n```\n\n**Reverse order**\n\n```js\narraySort([{foo: 'y'}, {foo: 'z'}, {foo: 'x'}], 'foo', {reverse: true});\n//=> [{foo: 'z'}, {foo: 'y'}, {foo: 'x'}]\n```\n\n## Params\n\n```js\narraySort(array, comparisonArgs);\n```\n\n* `array`: **{Array}** The array to sort\n* `comparisonArgs`: **{Function|String|Array}**: One or more functions or object paths to use for sorting.\n\n## Examples\n\n**[Sort blog posts](examples/blog-posts.js)**\n\n```js\nvar arraySort = require('array-sort');\n\nvar posts = [\n  { path: 'c.md', locals: { date: '2014-01-09' } },\n  { path: 'a.md', locals: { date: '2014-01-02' } },\n  { path: 'b.md', locals: { date: '2013-05-06' } },\n];\n\n// sort by `locals.date`\nconsole.log(arraySort(posts, 'locals.date'));\n\n// sort by `path`\nconsole.log(arraySort(posts, 'path'));\n```\n\n**[Sort by multiple properties](examples/multiple-props.js)**\n\n```js\nvar arraySort = require('array-sort');\n\nvar posts = [\n  { locals: { foo: 'bbb', date: '2013-05-06' }},\n  { locals: { foo: 'aaa', date: '2012-01-02' }},\n  { locals: { foo: 'ccc', date: '2014-01-02' }},\n  { locals: { foo: 'ccc', date: '2015-01-02' }},\n  { locals: { foo: 'bbb', date: '2014-06-01' }},\n  { locals: { foo: 'aaa', date: '2014-02-02' }},\n];\n\n// sort by `locals.foo`, then `locals.date`\nvar result = arraySort(posts, ['locals.foo', 'locals.date']);\n\nconsole.log(result);\n// [ { locals: { foo: 'aaa', date: '2012-01-02' } },\n//   { locals: { foo: 'aaa', date: '2014-02-02' } },\n//   { locals: { foo: 'bbb', date: '2013-05-06' } },\n//   { locals: { foo: 'bbb', date: '2014-06-01' } },\n//   { locals: { foo: 'ccc', date: '2014-01-02' } },\n//   { locals: { foo: 'ccc', date: '2015-01-02' } } ]\n```\n\n**[Custom function](examples/custom-function.js)**\n\nIf custom functions are supplied, array elements are sorted according to the return value of the compare function. See the [docs for ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)`Array.sort()` for more details.\n\n```js\nvar arr = [\n  {one: 'w', two: 'b'},\n  {one: 'z', two: 'a'},\n  {one: 'x', two: 'c'},\n  {one: 'y', two: 'd'},\n];\n\nfunction compare(prop) {\n  return function (a, b) {\n    return a[prop].localeCompare(b[prop]);\n  };\n}\n\nvar result = arraySort(arr, function (a, b) {\n  return a.two.localeCompare(b.two);\n});\n\nconsole.log(result);\n// [ { one: 'z', two: 'a' },\n//   { one: 'w', two: 'b' },\n//   { one: 'x', two: 'c' },\n//   { one: 'y', two: 'd' } ]\n```\n\n**[Multiple custom functions](examples/custom-functions.js)**\n\n```js\nvar arr = [\n  {foo: 'w', bar: 'y', baz: 'w'},\n  {foo: 'x', bar: 'y', baz: 'w'},\n  {foo: 'x', bar: 'y', baz: 'z'},\n  {foo: 'x', bar: 'x', baz: 'w'},\n];\n\n// reusable compare function\nfunction compare(prop) {\n  return function (a, b) {\n    return a[prop].localeCompare(b[prop]);\n  };\n}\n\n// the `compare` functions can be a list or array\nvar result = arraySort(arr, compare('foo'), compare('bar'), compare('baz'));\n\nconsole.log(result);\n// [ { foo: 'w', bar: 'y', baz: 'w' },\n//   { foo: 'x', bar: 'x', baz: 'w' },\n//   { foo: 'x', bar: 'y', baz: 'w' },\n//   { foo: 'x', bar: 'y', baz: 'z' } ]\n```\n\n## About\n\n### Related projects\n\n* [get-value](https://www.npmjs.com/package/get-value): Use property paths (`a.b.c`) to get a nested value from an object. | [homepage](https://github.com/jonschlinkert/get-value \"Use property paths (`a.b.c`) to get a nested value from an object.\")\n* [set-value](https://www.npmjs.com/package/set-value): Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths. | [homepage](https://github.com/jonschlinkert/set-value \"Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.\")\n* [sort-asc](https://www.npmjs.com/package/sort-asc): Sort array elements in ascending order. | [homepage](https://github.com/jonschlinkert/sort-asc \"Sort array elements in ascending order.\")\n* [sort-desc](https://www.npmjs.com/package/sort-desc): Sort array elements in descending order. | [homepage](https://github.com/jonschlinkert/sort-desc \"Sort array elements in descending order.\")\n* [sort-object](https://www.npmjs.com/package/sort-object): Sort the keys in an object. | [homepage](https://github.com/doowb/sort-object \"Sort the keys in an object.\")\n\n### Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n### Contributors\n\n| **Commits** | **Contributor** |  \n| --- | --- |  \n| 10 | [jonschlinkert](https://github.com/jonschlinkert) |  \n| 4  | [doowb](https://github.com/doowb) |  \n| 1  | [iamstolis](https://github.com/iamstolis) |  \n| 1  | [wkevina](https://github.com/wkevina) |  \n\n### Building docs\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme && verb\n```\n\n### Running tests\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install && npm test\n```\n\n### Author\n\n**Jon Schlinkert**\n\n* [github/jonschlinkert](https://github.com/jonschlinkert)\n* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)\n\n### License\n\nCopyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on September 11, 2017._","publish_time":1437201149758,"_cnpm_publish_time":1437201149758,"dist-tags":{"latest":"1.0.0"}}