Comparing version 1.0.3 to 2.0.0
62
index.js
'use strict'; | ||
// there's 3 implementations written in increasing order of efficiency | ||
// 1 - no Set type is defined | ||
function uniqNoSet(arr) { | ||
var ret = []; | ||
for (var i = 0; i < arr.length; i++) { | ||
if (ret.indexOf(arr[i]) === -1) { | ||
ret.push(arr[i]); | ||
} | ||
} | ||
return ret; | ||
} | ||
// 2 - a simple Set type is defined | ||
function uniqSet(arr) { | ||
var seen = new Set(); | ||
return arr.filter(function (el) { | ||
if (!seen.has(el)) { | ||
seen.add(el); | ||
return true; | ||
} | ||
return false; | ||
}); | ||
} | ||
// 3 - a standard Set type is defined and it has a forEach method | ||
function uniqSetWithForEach(arr) { | ||
var ret = []; | ||
(new Set(arr)).forEach(function (el) { | ||
ret.push(el); | ||
}); | ||
return ret; | ||
} | ||
// V8 currently has a broken implementation | ||
// https://github.com/joyent/node/issues/8449 | ||
function doesForEachActuallyWork() { | ||
var ret = false; | ||
(new Set([true])).forEach(function (el) { | ||
ret = el; | ||
}); | ||
return ret === true; | ||
} | ||
if ('Set' in global) { | ||
if (typeof Set.prototype.forEach === 'function' && doesForEachActuallyWork()) { | ||
module.exports = uniqSetWithForEach; | ||
} else { | ||
module.exports = uniqSet; | ||
} | ||
} else { | ||
module.exports = uniqNoSet; | ||
} | ||
module.exports = x => [...new Set(x)]; |
{ | ||
"name": "array-uniq", | ||
"version": "1.0.3", | ||
"description": "Create an array without duplicates", | ||
"license": "MIT", | ||
"repository": "sindresorhus/array-uniq", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"array", | ||
"arr", | ||
"set", | ||
"uniq", | ||
"unique", | ||
"es6", | ||
"duplicate", | ||
"remove" | ||
], | ||
"devDependencies": { | ||
"ava": "*", | ||
"es6-set": "^0.1.0", | ||
"require-uncached": "^1.0.2", | ||
"xo": "*" | ||
} | ||
"name": "array-uniq", | ||
"version": "2.0.0", | ||
"description": "Create an array without duplicates", | ||
"license": "MIT", | ||
"repository": "sindresorhus/array-uniq", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"array", | ||
"set", | ||
"uniq", | ||
"unique", | ||
"duplicate", | ||
"remove" | ||
], | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
} |
@@ -5,9 +5,7 @@ # array-uniq [![Build Status](https://travis-ci.org/sindresorhus/array-uniq.svg?branch=master)](https://travis-ci.org/sindresorhus/array-uniq) | ||
It's already pretty fast, but will be much faster when [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) becomes available in V8 (especially with large arrays). | ||
## Install | ||
``` | ||
$ npm install --save array-uniq | ||
$ npm install array-uniq | ||
``` | ||
@@ -14,0 +12,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
2135
2
29
1