default-compare

WebJar for default-compare

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

default-compare
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

default-compare
WebJar for default-compare
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/doowb/default-compare

Download default-compare

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/default-compare/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>default-compare</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/default-compare/
implementation 'org.webjars.npm:default-compare:1.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/default-compare/
implementation ("org.webjars.npm:default-compare:1.0.0")
'org.webjars.npm:default-compare:jar:1.0.0'
<dependency org="org.webjars.npm" name="default-compare" rev="1.0.0">
  <artifact name="default-compare" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='default-compare', version='1.0.0')
)
libraryDependencies += "org.webjars.npm" % "default-compare" % "1.0.0"
[org.webjars.npm/default-compare "1.0.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.npm : kind-of jar [5.0.2,6)

Project Modules

There are no modules declared in this project.

default-compare NPM version NPM monthly downloads NPM total downloads Linux Build Status Windows Build Status

Basic sort algorithm that has similar behavior to Array.prototype.sort for null and undefined, but also allows sorting by an object property.

Install

Install with npm:

$ npm install --save default-compare

Install with yarn:

$ yarn add default-compare

Usage

var defaultCompare = require('default-compare');

basic array

var arr = ['c', 'a', undefined, 'b', 'd', null, 'e'];
console.log(arr.sort(defaultCompare));
//=> ['a', 'b', 'c', 'd', 'e', null, undefined]

objects sorted by their "name" property

var arr = [
  {name: 'c', title: 'C'},
  {name: 'a', title: 'A'},
  {title: 'G'},
  {name: 'b', title: 'B'},
  {name: 'd', title: 'D'},
  {name: null, title: 'F'},
  {name: 'e', title: 'E'}
];

arr.sort(function(a, b) {
  return defaultCompare(a, b, 'name');
});

console.log(arr);
//=> [
//=>   {name: 'a', title: 'A'},
//=>   {name: 'b', title: 'B'},
//=>   {name: 'c', title: 'C'},
//=>   {name: 'd', title: 'D'},
//=>   {name: 'e', title: 'E'},
//=>   {name: null, title: 'F'},
//=>   {title: 'G'}
//=> ];

API

defaultCompare

Basic sort algorithm that has similar behavior to Array.prototype.sort for null and undefined, but also allows sorting by an object property.

Params

  • a {Mixed}: First value to compare.
  • b {Mixed}: Second value to compare.
  • prop {String}: Optional property to use when comparing objects. If specified must be a string.
  • 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.

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Please read the contributing guide for advice on opening issues, pull requests, and coding standards.

Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

Running 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:

$ npm install && npm test

Author

Brian Woodward

License

Copyright © 2017, Brian Woodward. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on September 11, 2017.

Versions

Version
1.0.0