{"_id":"default-compare","_rev":"77014","name":"default-compare","description":"Basic sort algorithm that has similar behavior to Array.prototype.sort for null and undefined, but also allows sorting by an object property.","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"doowb","email":"brian.woodward@gmail.com"}],"time":{"modified":"2021-06-03T10:24:47.000Z","created":"2017-09-11T16:37:48.264Z","1.0.0":"2017-09-11T16:37:48.264Z"},"users":{},"author":{"name":"Brian Woodward","url":"https://doowb.com"},"repository":{"type":"git","url":"git+https://github.com/doowb/default-compare.git"},"versions":{"1.0.0":{"name":"default-compare","description":"Basic sort algorithm that has similar behavior to Array.prototype.sort for null and undefined, but also allows sorting by an object property.","version":"1.0.0","homepage":"https://github.com/doowb/default-compare","author":{"name":"Brian Woodward","url":"https://doowb.com"},"repository":{"type":"git","url":"git+https://github.com/doowb/default-compare.git"},"bugs":{"url":"https://github.com/doowb/default-compare/issues"},"license":"MIT","files":["index.js"],"main":"index.js","engines":{"node":">=0.10.0"},"scripts":{"test":"mocha"},"dependencies":{"kind-of":"^5.0.2"},"devDependencies":{"gulp-format-md":"^1.0.0","mocha":"^3.5.2"},"keywords":["compare","default"],"verb":{"toc":false,"layout":"default","tasks":["readme"],"plugins":["gulp-format-md"],"lint":{"reflinks":true}},"gitHead":"2f56e4346d80672cf92aa724fee8307aa22f8b5f","_id":"default-compare@1.0.0","_npmVersion":"5.3.0","_nodeVersion":"8.4.0","_npmUser":{"name":"doowb","email":"brian.woodward@gmail.com"},"dist":{"shasum":"cb61131844ad84d84788fb68fd01681ca7781a2f","size":2880,"noattachment":false,"key":"/default-compare/-/default-compare-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/default-compare/download/default-compare-1.0.0.tgz"},"maintainers":[{"name":"doowb","email":"brian.woodward@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/default-compare-1.0.0.tgz_1505147867961_0.4462420700583607"},"directories":{},"publish_time":1505147868264,"_cnpm_publish_time":1505147868264,"_hasShrinkwrap":false}},"readme":"# default-compare [![NPM version](https://img.shields.io/npm/v/default-compare.svg?style=flat)](https://www.npmjs.com/package/default-compare) [![NPM monthly downloads](https://img.shields.io/npm/dm/default-compare.svg?style=flat)](https://npmjs.org/package/default-compare)  [![NPM total downloads](https://img.shields.io/npm/dt/default-compare.svg?style=flat)](https://npmjs.org/package/default-compare) [![Linux Build Status](https://img.shields.io/travis/doowb/default-compare.svg?style=flat&label=Travis)](https://travis-ci.org/doowb/default-compare) [![Windows Build Status](https://img.shields.io/appveyor/ci/doowb/default-compare.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/doowb/default-compare)\n\n> Basic sort algorithm that has similar behavior to Array.prototype.sort for null and undefined, but also allows sorting by an object property.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save default-compare\n```\n\nInstall with [yarn](https://yarnpkg.com):\n\n```sh\n$ yarn add default-compare\n```\n\n## Usage\n\n```js\nvar defaultCompare = require('default-compare');\n```\n\n**basic array**\n\n```js\nvar arr = ['c', 'a', undefined, 'b', 'd', null, 'e'];\nconsole.log(arr.sort(defaultCompare));\n//=> ['a', 'b', 'c', 'd', 'e', null, undefined]\n```\n\n**objects sorted by their \"name\" property**\n\n```js\nvar arr = [\n  {name: 'c', title: 'C'},\n  {name: 'a', title: 'A'},\n  {title: 'G'},\n  {name: 'b', title: 'B'},\n  {name: 'd', title: 'D'},\n  {name: null, title: 'F'},\n  {name: 'e', title: 'E'}\n];\n\narr.sort(function(a, b) {\n  return defaultCompare(a, b, 'name');\n});\n\nconsole.log(arr);\n//=> [\n//=>   {name: 'a', title: 'A'},\n//=>   {name: 'b', title: 'B'},\n//=>   {name: 'c', title: 'C'},\n//=>   {name: 'd', title: 'D'},\n//=>   {name: 'e', title: 'E'},\n//=>   {name: null, title: 'F'},\n//=>   {title: 'G'}\n//=> ];\n```\n\n## API\n\n### [defaultCompare](index.js#L16)\n\nBasic sort algorithm that has similar behavior to `Array.prototype.sort`\nfor null and undefined, but also allows sorting by an object property.\n\n**Params**\n\n* `a` **{Mixed}**: First value to compare.\n* `b` **{Mixed}**: Second value to compare.\n* `prop` **{String}**: Optional property to use when comparing objects. If specified must be a string.\n* `returns` **{Number}**: Returns 1 when `a` should come after `b`, -1 when `a` should come before `b`, and 0 when `a` and `b` are equal.\n\n## About\n\n### Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\nPlease read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.\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**Brian Woodward**\n\n* [github/doowb](https://github.com/doowb)\n* [twitter/doowb](https://twitter.com/doowb)\n\n### License\n\nCopyright © 2017, [Brian Woodward](https://doowb.com).\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._","_attachments":{},"homepage":"https://github.com/doowb/default-compare","bugs":{"url":"https://github.com/doowb/default-compare/issues"},"license":"MIT"}