Skip to content

Commit

Permalink
use default-compare lib
Browse files Browse the repository at this point in the history
  • Loading branch information
doowb committed Sep 11, 2017
1 parent cb459d9 commit 503e150
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
22 changes: 1 addition & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

'use strict';

var defaultCompare = require('default-compare');
var typeOf = require('kind-of');
var get = require('get-value');

Expand Down Expand Up @@ -89,27 +90,6 @@ function compare(prop, a, b) {
return defaultCompare(a, b);
}

/**
* Default compare function used as a fallback
* for sorting. Built-in array sorting pushes
* null and undefined values to the end of the array.
*/

function defaultCompare(a, b) {
var typeA = typeOf(a);
var typeB = typeOf(b);

if (typeA === 'null') {
return typeB === 'null' ? 0 : (typeB === 'undefined' ? -1 : 1);
} else if (typeA === 'undefined') {
return typeB === 'null' ? 1 : (typeB === 'undefined' ? 0 : 1);
} else if (typeB === 'null' || typeB === 'undefined') {
return -1;
} else {
return a < b ? -1 : (a > b ? 1 : 0);
}
}

/**
* Flatten the given array.
*/
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"test": "mocha"
},
"dependencies": {
"default-compare": "^1.0.0",
"get-value": "^2.0.5",
"kind-of": "^2.0.0"
},
Expand Down

0 comments on commit 503e150

Please sign in to comment.