Socket
Socket
Sign inDemoInstall

array-uniq

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

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)];

66

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc