{
  "_id": "default-compare",
  "maintainers": [
    {
      "name": "doowb",
      "email": "brian.woodward@gmail.com"
    }
  ],
  "keywords": [
    "compare",
    "default"
  ],
  "dist-tags": {
    "latest": "1.0.0"
  },
  "author": {
    "name": "Brian Woodward",
    "url": "https://doowb.com"
  },
  "_rev": "1-5aca40ba2a1b5d22d3f61ea5aa935a89",
  "description": "Basic sort algorithm that has similar behavior to Array.prototype.sort for null and undefined, but also allows sorting by an object property.",
  "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._",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/doowb/default-compare.git"
  },
  "bugs": {
    "url": "https://github.com/doowb/default-compare/issues"
  },
  "license": "MIT",
  "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": {
        "integrity": "sha512-QWfXlM0EkAbqOCbD/6HjdwT19j7WCkMyiRhWilc4H9/5h/RzTF9gv5LYh1+CmDV5d1rki6KAWLtQale0xt20eQ==",
        "shasum": "cb61131844ad84d84788fb68fd01681ca7781a2f",
        "tarball": "https://archive.ito.gov.ir/npm/_packages/default-compare/-/default-compare-1.0.0.tgz",
        "signatures": [
          {
            "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
            "sig": "MEUCIG4uMbGiSblskXnFjfsJGofYDqxR3dYjkvB5LR9RpOPUAiEA50Tie8fa3t9c8WWoTYef+vw3BobM7t7ctliqm5txihM="
          }
        ]
      },
      "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"
      }
    }
  },
  "name": "default-compare",
  "time": {
    "modified": "2026-05-20T15:56:33.213Z",
    "created": "2017-09-11T16:37:48.264Z",
    "1.0.0": "2017-09-11T16:37:48.264Z"
  },
  "readmeFilename": "README.md",
  "homepage": "https://github.com/doowb/default-compare"
}