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

nub

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

nub - npm Package Compare versions

Comparing version 0.0.0 to 1.0.0

LICENSE

4

index.js

@@ -20,4 +20,4 @@ var nub = module.exports = function (xs, cmp) {

var recs = x === '__proto__'
? keys.objects
: keys[typeof x] || keys.objects
? keys.object
: keys[typeof x] || keys.object
;

@@ -24,0 +24,0 @@

{
"name" : "nub",
"version" : "0.0.0",
"description" : "Uniqueness functions",
"main" : "index.js",
"directories" : {
"lib" : ".",
"example" : "example",
"test" : "test"
},
"dependencies" : {
},
"devDependencies" : {
"expresso" : "0.7.x"
},
"scripts" : {
"test" : "expresso"
},
"repository" : {
"type" : "git",
"url" : "http://github.com/substack/node-nub.git"
},
"keywords" : [
"unique",
"uniq",
"uniqBy",
"nub",
"nubBy"
],
"author" : {
"name" : "James Halliday",
"email" : "mail@substack.net",
"url" : "http://substack.net"
},
"license" : "MIT/X11",
"engine" : { "node" : ">=0.4" }
"name": "nub",
"version": "1.0.0",
"description": "Uniqueness functions",
"main": "index.js",
"devDependencies": {
"tape": "^2.14.0"
},
"scripts": {
"test": "tape test/*.js"
},
"repository": {
"type": "git",
"url": "http://github.com/substack/node-nub.git"
},
"keywords": [
"unique",
"uniq",
"uniqBy",
"nub",
"nubBy"
],
"author": {
"name": "James Halliday",
"email": "mail@substack.net",
"url": "http://substack.net"
},
"license": "MIT"
}

@@ -1,51 +0,35 @@

var assert = require('assert');
'use strict';
var test = require('tape');
var nub = require('../');
exports.false = function () {
var xs = [ 3, 3, 1, 1, 2, 1, 2, 1 ];
assert.deepEqual(
nub.by(xs, function () { return false }),
xs
);
};
test('nub.by', function(t) {
var xs = [ 3, 3, 1, 1, 2, 1, 2, 1 ];
var ys = { a : 1, b : 2 };
var zs = { a : 1, b : 2 };
exports.true = function () {
var xs = [ 3, 3, 1, 1, 2, 1, 2, 1 ];
assert.deepEqual(
nub.by(xs, function () { return true }),
[3]
);
};
t.deepEqual(nub.by(xs, function() { return false; }), xs, 'comparator finds all elements unique');
t.deepEqual(nub.by(xs, function() { return true; }), [3], 'comparator finds all elements the same');
exports.stringify = function () {
var xs = { a : 1, b : 2 };
var ys = { a : 1, b : 2 };
assert.deepEqual(
nub.by([ 3, 4, xs, ys, 5, 6 ], function (x, y) {
return JSON.stringify(x) === JSON.stringify(y)
}),
[ 3, 4, xs, 5, 6 ]
);
};
t.deepEqual(
nub.by([ 3, 4, ys, zs, 5, 6 ], function (x, y) {
return JSON.stringify(x) === JSON.stringify(y);
}),
[ 3, 4, ys, 5, 6 ],
'comparator composed of JSON.stringify'
);
t.deepEqual(
nub.by([ 1, 6, 3, 4, 5, 2, 7, 8 ], function (x, y) {
return x % 4 === y % 4;
}),
[ 1, 6, 3, 4 ],
'comparator composed of mod'
);
t.end();
});
exports.mod = function () {
var xs = { a : 1, b : 2 };
var ys = { a : 1, b : 2 };
assert.deepEqual(
nub.by([ 1, 6, 3, 4, 5, 2, 7, 8 ], function (x, y) {
return x % 4 === y % 4
}),
[ 1, 6, 3, 4 ]
);
};
exports.dispatchMod = function () {
var xs = { a : 1, b : 2 };
var ys = { a : 1, b : 2 };
assert.deepEqual(
nub([ 1, 6, 3, 4, 5, 2, 7, 8 ], function (x, y) {
return x % 4 === y % 4
}),
[ 1, 6, 3, 4 ]
);
};
test('nub.by sugar', function(t) {
var xs = [ 3, 3, 1, 1, 2, 1, 2, 1 ];
t.deepEqual(nub(xs, function() { return true; }), [3], 'nub should forward to nub.by if function is included');
t.deepEqual(nub.by(function() { return true; }, xs), [3], 'arguments can be reversed');
t.end();
});

@@ -0,46 +1,59 @@

'use strict';
var test = require('tape');
var nub = require('../');
var assert = require('assert');
exports.empty = function () {
assert.deepEqual(nub([]), []);
};
test('nub', function(t) {
var f = function () {};
var g = function () {};
var re = /meow/;
var xs = { a : 4, b : 5 };
var ys = { c : 6 };
var zs = [
1, 2, '3', 3, 2, '2', f, f, g, re, false, false, true, false, re,
undefined, null, undefined, 1, null, null, undefined
];
exports.already = function () {
assert.deepEqual(nub([ 1, 2, 3 ]), [ 1, 2, 3 ]);
};
t.deepEqual(nub([]), [], 'empty array should return an empty array');
t.deepEqual(nub([ 1, 2, 3 ]), [ 1, 2, 3], 'unique array should return the same array');
t.deepEqual(nub([ 1, 1, 2, 1, 3, 2 ]), [ 1, 2, 3 ], 'non-unique arrays should drop duplicate elements');
exports.dups = function () {
assert.deepEqual(nub([ 1, 1, 2, 1, 3, 2 ]), [ 1, 2, 3 ]);
};
t.deepEqual(
nub([ 1, 1, 2, 3, xs, xs, ys, xs, 2, 7, 7, 3, 1, 5 ]),
[ 1, 2, 3, xs, ys, 7, 5 ],
'should support objects'
);
exports.objects = function () {
var xs = { a : 4, b : 5 };
var ys = { c : 6 };
assert.deepEqual(
nub([ 1, 1, 2, 3, xs, xs, ys, xs, 2, 7, 7, 3, 1, 5 ]),
[ 1, 2, 3, xs, ys, 7, 5 ]
t.deepEqual(
nub(zs),
[ 1, 2, '3', 3, '2', f, g, re, false, true, undefined, null ],
'should support arrays of mixed types'
);
t.deepEqual(
nub(zs).map(function (r) { return typeof r; }),
[
'number', 'number', 'string', 'number', 'string', 'function',
'function', typeof re, 'boolean', 'boolean', 'undefined', 'object'
],
'arrays of mixed types should return an array of element of the correct type'
);
t.deepEqual(
nub([0, 1, 2, 3, '__proto__']),
[0, 1, 2, 3, '__proto__'],
'this special case should work'
);
if (global.Symbol && (typeof new Symbol() === 'symbol')) {
var xsym = new Symbol('x');
var ysym = new Symbol('y');
t.deepEqual(
nub(xsym, ysym, xsym),
[xsym, ysym],
'should support Symbols'
);
};
}
exports.mixed = function () {
var f = function () {};
var g = function () {};
var re = /meow/;
var xs = [
1, 2, '3', 3, 2, '2', f, f, g, re, false, false, true, false, re,
undefined, null, undefined, 1, null, null, undefined
];
var res = nub(xs);
assert.deepEqual(res, [
1, 2, '3', 3, '2', f, g, re, false, true, undefined, null
]);
assert.deepEqual(
res.map(function (r) { return typeof r }),
[
'number', 'number', 'string', 'number', 'string', 'function',
'function', 'function', 'boolean', 'boolean', 'undefined', 'object'
]
);
};
t.throws(nub.bind(null, undefined));
t.end();
});
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