Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

uniqs

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uniqs - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

14

index.js

@@ -1,12 +0,6 @@

var filter = Array.prototype.filter;
var indexOf = Array.prototype.indexOf;
/**
* Returns a de-duplicated version of the given list.
*/
module.exports = function uniqs(list) {
if (!list) return [];
return filter.call(list, function(item, i) {
return i == indexOf.call(list, item);
module.exports = function uniqs() {
var list = Array.prototype.concat.apply([], arguments);
return list.filter(function(item, i) {
return i == list.indexOf(item);
});
};
{
"name": "uniqs",
"version": "1.0.0",
"description": "Creates a de-duplicated version of a given list",
"keywords": [ "unique", "uniq", "dedupe" ],
"version": "2.0.0",
"description": "Tiny utility to create unions and de-duplicated lists",
"keywords": [
"unique",
"uniq",
"dedupe",
"union"
],
"repository": {

@@ -7,0 +12,0 @@ "type": "git",

[![Build Status](https://travis-ci.org/fgnass/uniqs.svg?branch=master)](https://travis-ci.org/fgnass/uniqs)
### Tiny utility to de-duplicate lists.
### Tiny utility to create unions and de-duplicated lists.

@@ -11,18 +11,26 @@ Example:

var foo = { foo: 23 };
var list = [ 3, 2, 2, 1, foo, foo ];
var list = [3, 2, 2, 1, foo, foo];
console.log(uniqs(list));
uniqs(list);
// => [3, 2, 1, { foo: 23 }]
```
Output:
You can pass multiple lists to create a union:
```js
[ 3, 2, 1, { foo: 23 } ]
uniqs([2, 1, 1], [2, 3, 3, 4], [4, 3, 2]);
// => [2, 1, 3, 4]
```
Passing individual items works too:
```js
uniqs(3, 2, 2, [1, 1, 2]);
// => [3, 2, 1]
```
### Summary
* Uniqueness is defined based on strict object equality.
* The list does not need to be sorted.
* The original list is not modified.
* If the given argument is not _array-like_, an empty array is returned.
* The lists do not need to be sorted.
* The resulting array contains the items in the order of their first appearance.

@@ -39,9 +47,6 @@ ### About

```js
var filter = Array.prototype.filter;
var indexOf = Array.prototype.indexOf;
module.exports = function uniqs(list) {
if (!list) return [];
return filter.call(list, function(item, i) {
return i == indexOf.call(list, item);
module.exports = function uniqs() {
var list = Array.prototype.concat.apply([], arguments);
return list.filter(function(item, i) {
return i == list.indexOf(item);
});

@@ -48,0 +53,0 @@ };

@@ -8,12 +8,16 @@ var uniqs = require('./');

[
[ [2, 2, 3, "a", 3, 1, foo, foo, "a" ], [ 2, 3, "a", 1, foo ] ],
[ [[2, 1, 1], [2, 3, 3, 4], [4, 3, 2]], [2, 1, 3, 4] ],
[ [3, 2, 2, [1, 1, 2]], [3, 2, 1] ],
[ [[2, 2, 3, "a", 3, 1, foo, foo, "a" ]], [ 2, 3, "a", 1, foo ] ],
[ [23], [23] ],
[ [], [] ],
[ undefined, [] ],
[ 23, [] ]
[ [[]], [] ],
[ [[null], null], [null] ]
]
.forEach(function(t) {
assert.deepEqual(uniqs(t[0]), t[1],
util.format('✘ uniqs(%j) !== %j', t[0], t[1])
var args = t[0].map(JSON.stringify);
assert.deepEqual(uniqs.apply(this, t[0]), t[1],
util.format('✘ uniqs(%s) !== %j', args, t[1])
);
console.log('✔ uniqs(%j) == %j', t[0], t[1]);
console.log('✔ uniqs(%s) == %j', args, t[1]);
});
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc