compare
Advanced tools
Comparing version 0.0.1 to 2.0.0
16
index.js
@@ -1,15 +0,3 @@ | ||
module.exports = compare | ||
function compare(array, comparator) { | ||
var l = array.length | ||
var a | ||
for (var i = 0; i < l; i += 1) { | ||
a = array[i] | ||
for (var j = 0; j < l; j += 1) { | ||
if (i === j) continue | ||
if (!comparator(a, array[j], i, j)) return false | ||
} | ||
} | ||
return true | ||
module.exports = function (a, b) { | ||
return a < b ? -1 : a > b ? 1 : 0 | ||
} |
{ | ||
"name": "compare", | ||
"version": "0.0.1", | ||
"description": "ERROR: No README.md file found!", | ||
"version": "2.0.0", | ||
"description": "Compare primitives the right way (using `<`, `>` and `==`)", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node test.js" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": {}, | ||
"scripts": {}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/hughsk/compare.git" | ||
"url": "git+https://github.com/emilbayes/compare.git" | ||
}, | ||
"author": "Hugh Kennedy <hughskennedy@gmail.com> (http://hughskennedy.com/)", | ||
"license": "MIT", | ||
"keywords": [ | ||
"compare", | ||
"all", | ||
"elements", | ||
"array", | ||
"comparison" | ||
"cmpstr", | ||
"string", | ||
"number", | ||
"numeric", | ||
"sort", | ||
"stable", | ||
"ascii" | ||
], | ||
"devDependencies": { | ||
"tape": "~1.0.4" | ||
} | ||
"author": "Emil Bay <github@tixz.dk>", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/emilbayes/compare/issues" | ||
}, | ||
"homepage": "https://github.com/emilbayes/compare#readme" | ||
} |
@@ -1,19 +0,50 @@ | ||
# compare # | ||
# `compare` | ||
Compare each element in an array with every other element in the array. | ||
![100-correct](https://img.shields.io/badge/Correct%20-100%25-brightgreen.svg?style=flat) | ||
## Installation ## | ||
> Compare primitives the right way (using `<`, `>` and `==`) | ||
``` bash | ||
npm install compare | ||
This module does the right thing with numbers and ascii strings. | ||
Normally `String.prototype.localeCompare` is recommended for strings, | ||
but that can have nasty side effects on some machines, eg. | ||
```js | ||
'cu'.localeCompare('cs', 'hu') | ||
``` | ||
## Usage ## | ||
Compare the above in stock node (which doesn't come with `Intl`) and | ||
a browser of your choice (which most likely has `Intl` support). | ||
``` javascript | ||
## Usage | ||
```js | ||
var compare = require('compare') | ||
[1, 2, 10].sort() // [1, 10, 2] | ||
[1, 2, 10].sort(compare) // [1, 2, 10] | ||
compare([1, 1, 1, 1], function(a, b) { return a === b }) // true | ||
compare([1, 2, 3, 4], function(a, b) { return a !== b }) // true | ||
compare([1, 2, 3, 3], function(a, b) { return a !== b }) // false | ||
// Below is sorted correctly according to Hungarian, but runtimes without Intl | ||
// support will reorder them | ||
['cu', 'cs'].sort((a, b) => a.localeCompare(b, 'hu')) | ||
['cu', 'cs'].sort(compare) // This will always sort the same | ||
``` | ||
## API | ||
### `compare(a, b)` | ||
Standard `Array.prototype.sort(cmp)` function signature. If `a > b` return `1`, | ||
if `a < b` return `-1`, otherwise return `0` | ||
## Credit | ||
Thanks to [`hughsk`](https://github.com/hughsk) for the npm name! | ||
## Install | ||
```sh | ||
npm install compare | ||
``` | ||
## License | ||
[ISC](LICENSE) |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
0
1
0
51
2682
4
3
2