[Pkg-javascript-commits] [node-array-unique] 02/06: New upstream version 0.3.2

Julien Puydt julien.puydt at laposte.net
Fri Nov 24 23:04:18 UTC 2017


This is an automated email from the git hooks/post-receive script.

jpuydt-guest pushed a commit to branch master
in repository node-array-unique.

commit 77a6ca39a3f66291ab361056a1f9df10db47c1cc
Author: Julien Puydt <julien.puydt at laposte.net>
Date:   Fri Nov 24 23:56:44 2017 +0100

    New upstream version 0.3.2
---
 .editorconfig                      |  13 ++++
 .eslintrc.json                     | 122 ++++++++++++++++++++++++++++++
 .gitattributes                     |  10 +++
 .gitignore                         |  11 +++
 .travis.yml                        |  10 +++
 .verb.md                           |  16 ++++
 LICENSE                            |   2 +-
 README.md                          |  82 +++++++++++++-------
 benchmark/code/filter.js           |  12 +++
 benchmark/code/for-in.js           |  17 +++++
 benchmark/code/linear-search-01.js |  19 +++++
 benchmark/code/set-immutable.js    |   3 +
 benchmark/code/set.js              |   3 +
 benchmark/code/while-hash.js       |  16 ++++
 benchmark/code/while.js            |  14 ++++
 benchmark/fixtures/long.js         |   2 +
 benchmark/fixtures/med.js          |   2 +
 benchmark/fixtures/short.js        |   2 +
 benchmark/index.js                 |  10 +++
 benchmark/randomize.js             |  28 +++++++
 index.js                           |  15 ++++
 package.json                       |  59 ++++++++++-----
 test.js                            | 151 +++++++++++++++++++++++++++++++++++++
 23 files changed, 573 insertions(+), 46 deletions(-)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..818e072
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,13 @@
+root = true
+
+[*]
+indent_style = space
+end_of_line = lf
+charset = utf-8
+indent_size = 2
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[{**/{actual,fixtures,expected,templates}/**,*.md}]
+trim_trailing_whitespace = false
+insert_final_newline = false
\ No newline at end of file
diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 0000000..948dbdb
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,122 @@
+{
+  "ecmaFeatures": {
+    "modules": true,
+    "experimentalObjectRestSpread": true
+  },
+
+  "env": {
+    "browser": false,
+    "es6": true,
+    "node": true,
+    "mocha": true
+  },
+
+  "globals": {
+    "document": false,
+    "navigator": false,
+    "window": false
+  },
+
+  "rules": {
+    "accessor-pairs": 2,
+    "arrow-spacing": [2, { "before": true, "after": true }],
+    "block-spacing": [2, "always"],
+    "brace-style": [2, "1tbs", { "allowSingleLine": true }],
+    "comma-dangle": [2, "never"],
+    "comma-spacing": [2, { "before": false, "after": true }],
+    "comma-style": [2, "last"],
+    "constructor-super": 2,
+    "curly": [2, "multi-line"],
+    "dot-location": [2, "property"],
+    "eol-last": 2,
+    "eqeqeq": [2, "allow-null"],
+    "generator-star-spacing": [2, { "before": true, "after": true }],
+    "handle-callback-err": [2, "^(err|error)$" ],
+    "indent": [2, 2, { "SwitchCase": 1 }],
+    "key-spacing": [2, { "beforeColon": false, "afterColon": true }],
+    "keyword-spacing": [2, { "before": true, "after": true }],
+    "new-cap": [2, { "newIsCap": true, "capIsNew": false }],
+    "new-parens": 2,
+    "no-array-constructor": 2,
+    "no-caller": 2,
+    "no-class-assign": 2,
+    "no-cond-assign": 2,
+    "no-const-assign": 2,
+    "no-control-regex": 2,
+    "no-debugger": 2,
+    "no-delete-var": 2,
+    "no-dupe-args": 2,
+    "no-dupe-class-members": 2,
+    "no-dupe-keys": 2,
+    "no-duplicate-case": 2,
+    "no-empty-character-class": 2,
+    "no-eval": 2,
+    "no-ex-assign": 2,
+    "no-extend-native": 2,
+    "no-extra-bind": 2,
+    "no-extra-boolean-cast": 2,
+    "no-extra-parens": [2, "functions"],
+    "no-fallthrough": 2,
+    "no-floating-decimal": 2,
+    "no-func-assign": 2,
+    "no-implied-eval": 2,
+    "no-inner-declarations": [2, "functions"],
+    "no-invalid-regexp": 2,
+    "no-irregular-whitespace": 2,
+    "no-iterator": 2,
+    "no-label-var": 2,
+    "no-labels": 2,
+    "no-lone-blocks": 2,
+    "no-mixed-spaces-and-tabs": 2,
+    "no-multi-spaces": 2,
+    "no-multi-str": 2,
+    "no-multiple-empty-lines": [2, { "max": 1 }],
+    "no-native-reassign": 0,
+    "no-negated-in-lhs": 2,
+    "no-new": 2,
+    "no-new-func": 2,
+    "no-new-object": 2,
+    "no-new-require": 2,
+    "no-new-wrappers": 2,
+    "no-obj-calls": 2,
+    "no-octal": 2,
+    "no-octal-escape": 2,
+    "no-proto": 0,
+    "no-redeclare": 2,
+    "no-regex-spaces": 2,
+    "no-return-assign": 2,
+    "no-self-compare": 2,
+    "no-sequences": 2,
+    "no-shadow-restricted-names": 2,
+    "no-spaced-func": 2,
+    "no-sparse-arrays": 2,
+    "no-this-before-super": 2,
+    "no-throw-literal": 2,
+    "no-trailing-spaces": 0,
+    "no-undef": 2,
+    "no-undef-init": 2,
+    "no-unexpected-multiline": 2,
+    "no-unneeded-ternary": [2, { "defaultAssignment": false }],
+    "no-unreachable": 2,
+    "no-unused-vars": [2, { "vars": "all", "args": "none" }],
+    "no-useless-call": 0,
+    "no-with": 2,
+    "one-var": [0, { "initialized": "never" }],
+    "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }],
+    "padded-blocks": [0, "never"],
+    "quotes": [2, "single", "avoid-escape"],
+    "radix": 2,
+    "semi": [2, "always"],
+    "semi-spacing": [2, { "before": false, "after": true }],
+    "space-before-blocks": [2, "always"],
+    "space-before-function-paren": [2, "never"],
+    "space-in-parens": [2, "never"],
+    "space-infix-ops": 2,
+    "space-unary-ops": [2, { "words": true, "nonwords": false }],
+    "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
+    "use-isnan": 2,
+    "valid-typeof": 2,
+    "wrap-iife": [2, "any"],
+    "yoda": [2, "never"]
+  }
+}
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..4a3f1d3
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,10 @@
+# Enforce Unix newlines
+* text eol=lf
+
+# binaries
+*.ai binary
+*.psd binary
+*.jpg binary
+*.gif binary
+*.png binary
+*.jpeg binary
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9e685a4
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,11 @@
+*.DS_Store
+*.sublime-*
+_gh_pages
+bower_components
+node_modules
+npm-debug.log
+temp
+test/actual
+tmp
+TODO.md
+vendor
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..ab7d381
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,10 @@
+sudo: false
+language: node_js
+node_js:
+  - '6'
+  - '5'
+  - '4'
+  - '0.12'
+  - '0.10'
+matrix:
+  fast_finish: true
diff --git a/.verb.md b/.verb.md
new file mode 100644
index 0000000..636052d
--- /dev/null
+++ b/.verb.md
@@ -0,0 +1,16 @@
+## Usage
+
+```js
+var unique = require('{%= name %}');
+
+var arr = ['a', 'b', 'c', 'c'];
+console.log(unique(arr)) //=> ['a', 'b', 'c']
+console.log(arr)         //=> ['a', 'b', 'c']
+
+/* The above modifies the input array. To prevent that at a slight performance cost: */
+var unique = require("array-unique").immutable;
+
+var arr = ['a', 'b', 'c', 'c'];
+console.log(unique(arr)) //=> ['a', 'b', 'c']
+console.log(arr)         //=> ['a', 'b', 'c', 'c']
+```
diff --git a/LICENSE b/LICENSE
old mode 100755
new mode 100644
index fa30c4c..842218c
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
 The MIT License (MIT)
 
-Copyright (c) 2014-2015, Jon Schlinkert.
+Copyright (c) 2014-2016, Jon Schlinkert
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
old mode 100755
new mode 100644
index 2e28774..41c8c90
--- a/README.md
+++ b/README.md
@@ -1,11 +1,13 @@
-# array-unique [![NPM version](https://badge.fury.io/js/array-unique.svg)](http://badge.fury.io/js/array-unique)  [![Build Status](https://travis-ci.org/jonschlinkert/array-unique.svg)](https://travis-ci.org/jonschlinkert/array-unique) 
+# array-unique [![NPM version](https://img.shields.io/npm/v/array-unique.svg?style=flat)](https://www.npmjs.com/package/array-unique) [![NPM downloads](https://img.shields.io/npm/dm/array-unique.svg?style=flat)](https://npmjs.org/package/array-unique) [![Build Status](https://img.shields.io/travis/jonschlinkert/array-unique.svg?style=flat)](https://travis-ci.org/jonschlinkert/array-unique)
 
-> Return an array free of duplicate values. Fastest ES5 implementation.
+Remove duplicate values from an array. Fastest ES5 implementation.
 
-## Install with [npm](npmjs.org)
+## Install
 
-```bash
-npm i array-unique --save
+Install with [npm](https://www.npmjs.com/):
+
+```sh
+$ npm install --save array-unique
 ```
 
 ## Usage
@@ -13,39 +15,63 @@ npm i array-unique --save
 ```js
 var unique = require('array-unique');
 
-unique(['a', 'b', 'c', 'c']);
-//=> ['a', 'b', 'c']
+var arr = ['a', 'b', 'c', 'c'];
+console.log(unique(arr)) //=> ['a', 'b', 'c']
+console.log(arr)         //=> ['a', 'b', 'c']
+
+/* The above modifies the input array. To prevent that at a slight performance cost: */
+var unique = require("array-unique").immutable;
+
+var arr = ['a', 'b', 'c', 'c'];
+console.log(unique(arr)) //=> ['a', 'b', 'c']
+console.log(arr)         //=> ['a', 'b', 'c', 'c']
 ```
 
-## Related
-* [arr-diff](https://github.com/jonschlinkert/arr-diff): Returns an array with only the unique values from the first array, by excluding all values from additional arrays using strict equality for comparisons.
-* [arr-union](https://github.com/jonschlinkert/arr-union): Returns an array of unique values using strict equality for comparisons.
-* [arr-flatten](https://github.com/jonschlinkert/arr-flatten): Recursively flatten an array or arrays. This is the fastest implementation of array flatten.
-* [arr-reduce](https://github.com/jonschlinkert/arr-reduce): Fast array reduce that also loops over sparse elements.
-* [arr-map](https://github.com/jonschlinkert/arr-map): Faster, node.js focused alternative to JavaScript's native array map.
-* [arr-pluck](https://github.com/jonschlinkert/arr-pluck): Retrieves the value of a specified property from all elements in the collection.
+## About
+
+### Related projects
+
+* [arr-diff](https://www.npmjs.com/package/arr-diff): Returns an array with only the unique values from the first array, by excluding all… [more](https://github.com/jonschlinkert/arr-diff) | [homepage](https://github.com/jonschlinkert/arr-diff "Returns an array with only the unique values from the first array, by excluding all values from additional arrays using strict equality for comparisons.")
+* [arr-flatten](https://www.npmjs.com/package/arr-flatten): Recursively flatten an array or arrays. This is the fastest implementation of array flatten. | [homepage](https://github.com/jonschlinkert/arr-flatten "Recursively flatten an array or arrays. This is the fastest implementation of array flatten.")
+* [arr-map](https://www.npmjs.com/package/arr-map): Faster, node.js focused alternative to JavaScript's native array map. | [homepage](https://github.com/jonschlinkert/arr-map "Faster, node.js focused alternative to JavaScript's native array map.")
+* [arr-pluck](https://www.npmjs.com/package/arr-pluck): Retrieves the value of a specified property from all elements in the collection. | [homepage](https://github.com/jonschlinkert/arr-pluck "Retrieves the value of a specified property from all elements in the collection.")
+* [arr-reduce](https://www.npmjs.com/package/arr-reduce): Fast array reduce that also loops over sparse elements. | [homepage](https://github.com/jonschlinkert/arr-reduce "Fast array reduce that also loops over sparse elements.")
+* [arr-union](https://www.npmjs.com/package/arr-union): Combines a list of arrays, returning a single array with unique values, using strict equality… [more](https://github.com/jonschlinkert/arr-union) | [homepage](https://github.com/jonschlinkert/arr-union "Combines a list of arrays, returning a single array with unique values, using strict equality for comparisons.")
+
+### Contributing
+
+Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
 
-## Run tests
-Install dev dependencies.
+### Building docs
 
-```bash
-npm i -d && npm test
+_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_
+
+To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
+
+```sh
+$ npm install -g verb verb-generate-readme && verb
 ```
 
-## Contributing
-Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/array-unique/issues)
+### Running tests
 
-## Author
+Install dev dependencies:
+
+```sh
+$ npm install -d && npm test
+```
+
+### Author
 
 **Jon Schlinkert**
- 
-+ [github/jonschlinkert](https://github.com/jonschlinkert)
-+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) 
 
-## License
-Copyright (c) 2015 Jon Schlinkert  
-Released under the MIT license
+* [github/jonschlinkert](https://github.com/jonschlinkert)
+* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
+
+### License
+
+Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
+Released under the [MIT license](https://github.com/jonschlinkert/array-unique/blob/master/LICENSE).
 
 ***
 
-_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 24, 2015._
\ No newline at end of file
+_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.1.28, on July 31, 2016._
\ No newline at end of file
diff --git a/benchmark/code/filter.js b/benchmark/code/filter.js
new file mode 100644
index 0000000..b8eda9a
--- /dev/null
+++ b/benchmark/code/filter.js
@@ -0,0 +1,12 @@
+'use strict';
+
+module.exports = function (arr) {
+  var stack = [];
+  return arr.filter(function (ele) {
+    if (stack.indexOf(ele) > -1) {
+      return false;
+    }
+    stack.push(ele);
+    return true;
+  });
+};
diff --git a/benchmark/code/for-in.js b/benchmark/code/for-in.js
new file mode 100644
index 0000000..ab56fac
--- /dev/null
+++ b/benchmark/code/for-in.js
@@ -0,0 +1,17 @@
+'use strict';
+
+module.exports = function(arr) {
+  var len = arr.length;
+  var res = [];
+  var o = {};
+  var i;
+
+  for (i = 0; i < len; i += 1) {
+    o[arr[i]] = arr[i];
+  }
+
+  for (i in o) {
+    res.push(o[i]);
+  }
+  return res;
+};
diff --git a/benchmark/code/linear-search-01.js b/benchmark/code/linear-search-01.js
new file mode 100644
index 0000000..5778b89
--- /dev/null
+++ b/benchmark/code/linear-search-01.js
@@ -0,0 +1,19 @@
+'use strict';
+
+module.exports = function(arr) {
+  var set = [];
+
+  for (var i = 0, len = arr.length; i < len; i++) {
+    var value = arr[i];
+    for (var j = len; --j > i;) {
+      if (value === arr[j]) {
+        break;
+      }
+    }
+
+    if (j == i) {
+      set.push(value);
+    }
+  }
+  return set;
+};
diff --git a/benchmark/code/set-immutable.js b/benchmark/code/set-immutable.js
new file mode 100644
index 0000000..7c5afca
--- /dev/null
+++ b/benchmark/code/set-immutable.js
@@ -0,0 +1,3 @@
+'use strict';
+
+module.exports = require('array-uniq').immutable;
diff --git a/benchmark/code/set.js b/benchmark/code/set.js
new file mode 100644
index 0000000..a55f89b
--- /dev/null
+++ b/benchmark/code/set.js
@@ -0,0 +1,3 @@
+'use strict';
+
+module.exports = require('array-uniq');
diff --git a/benchmark/code/while-hash.js b/benchmark/code/while-hash.js
new file mode 100644
index 0000000..0435efa
--- /dev/null
+++ b/benchmark/code/while-hash.js
@@ -0,0 +1,16 @@
+'use strict';
+
+module.exports = function(arr) {
+  var i = arr.length;
+
+  var hash = Object.create(null);
+  var res = [];
+
+  while (i--) {
+    if (!hash[arr[i]]) {
+      hash[arr[i]] = true;
+      res.push(arr[i]);
+    }
+  }
+  return res;
+};
diff --git a/benchmark/code/while.js b/benchmark/code/while.js
new file mode 100644
index 0000000..a5c34a0
--- /dev/null
+++ b/benchmark/code/while.js
@@ -0,0 +1,14 @@
+'use strict';
+
+module.exports = function(arr) {
+  var len = arr.length;
+  var res = [];
+
+  while (len--) {
+    var curr = arr[len];
+    if (res.indexOf(curr) === -1) {
+      res.push(curr);
+    }
+  }
+  return res;
+};
diff --git a/benchmark/fixtures/long.js b/benchmark/fixtures/long.js
new file mode 100644
index 0000000..766deea
--- /dev/null
+++ b/benchmark/fixtures/long.js
@@ -0,0 +1,2 @@
+var randomize = require('../randomize');
+module.exports = randomize(10000);
diff --git a/benchmark/fixtures/med.js b/benchmark/fixtures/med.js
new file mode 100644
index 0000000..e932cd9
--- /dev/null
+++ b/benchmark/fixtures/med.js
@@ -0,0 +1,2 @@
+var randomize = require('../randomize');
+module.exports = randomize(500);
diff --git a/benchmark/fixtures/short.js b/benchmark/fixtures/short.js
new file mode 100644
index 0000000..248acaa
--- /dev/null
+++ b/benchmark/fixtures/short.js
@@ -0,0 +1,2 @@
+var randomize = require('../randomize');
+module.exports = randomize(10);
diff --git a/benchmark/index.js b/benchmark/index.js
new file mode 100644
index 0000000..bbcac44
--- /dev/null
+++ b/benchmark/index.js
@@ -0,0 +1,10 @@
+'use';
+
+var Suite = require('benchmarked');
+var suite = new Suite({
+  add: 'code/*.js',
+  fixtures: 'fixtures/*.js',
+  cwd: __dirname
+});
+
+suite.run();
diff --git a/benchmark/randomize.js b/benchmark/randomize.js
new file mode 100644
index 0000000..0927c97
--- /dev/null
+++ b/benchmark/randomize.js
@@ -0,0 +1,28 @@
+/**
+ * Source: http://jsperf.com/array-unique2/15
+ */
+
+module.exports = function randomize(n) {
+  var values = [];
+  var rand;
+  while (n--) {
+    rand = Math.random() * n * 2 | 0;
+    if (rand < values.length) {
+      values.push(values[rand]);
+    }
+    else {
+      switch (Math.random() * 3 | 0) {
+      case 0:
+        values.push(Math.random() * 1e10 | 0);
+        break;
+      case 1:
+        values.push((Math.random() * 1e32).toString(36));
+        break;
+      case 2:
+        values.push({});
+        break;
+      }
+    }
+  }
+  return values;
+};
diff --git a/index.js b/index.js
old mode 100755
new mode 100644
index 7fa75af..7e481e0
--- a/index.js
+++ b/index.js
@@ -26,3 +26,18 @@ module.exports = function unique(arr) {
   }
   return arr;
 };
+
+module.exports.immutable = function uniqueImmutable(arr) {
+  if (!Array.isArray(arr)) {
+    throw new TypeError('array-unique expects an array.');
+  }
+
+  var arrLen = arr.length;
+  var newArr = new Array(arrLen);
+
+  for (var i = 0; i < arrLen; i++) {
+    newArr[i] = arr[i];
+  }
+
+  return module.exports(newArr);
+};
diff --git a/package.json b/package.json
old mode 100755
new mode 100644
index a493f69..d87640a
--- a/package.json
+++ b/package.json
@@ -1,25 +1,18 @@
 {
   "name": "array-unique",
-  "description": "Return an array free of duplicate values. Fastest ES5 implementation.",
-  "version": "0.2.1",
+  "description": "Remove duplicate values from an array. Fastest ES5 implementation.",
+  "version": "0.3.2",
   "homepage": "https://github.com/jonschlinkert/array-unique",
-  "author": {
-    "name": "Jon Schlinkert",
-    "url": "https://github.com/jonschlinkert"
-  },
-  "repository": {
-    "type": "git",
-    "url": "git://github.com/jonschlinkert/array-unique.git"
-  },
+  "author": "Jon Schlinkert (https://github.com/jonschlinkert)",
+  "repository": "jonschlinkert/array-unique",
   "bugs": {
     "url": "https://github.com/jonschlinkert/array-unique/issues"
   },
-  "license": {
-    "type": "MIT",
-    "url": "https://github.com/jonschlinkert/array-unique/blob/master/LICENSE"
-  },
+  "license": "MIT",
   "files": [
-    "index.js"
+    "index.js",
+    "LICENSE",
+    "README.md"
   ],
   "main": "index.js",
   "engines": {
@@ -31,7 +24,39 @@
   "devDependencies": {
     "array-uniq": "^1.0.2",
     "benchmarked": "^0.1.3",
-    "mocha": "*",
-    "should": "*"
+    "gulp-format-md": "^0.1.9",
+    "mocha": "^2.5.3",
+    "should": "^10.0.0"
+  },
+  "keywords": [
+    "array",
+    "unique"
+  ],
+  "verb": {
+    "toc": false,
+    "layout": "default",
+    "tasks": [
+      "readme"
+    ],
+    "plugins": [
+      "gulp-format-md"
+    ],
+    "related": {
+      "list": [
+        "arr-diff",
+        "arr-union",
+        "arr-flatten",
+        "arr-reduce",
+        "arr-map",
+        "arr-pluck"
+      ]
+    },
+    "reflinks": [
+      "verb",
+      "verb-generate-readme"
+    ],
+    "lint": {
+      "reflinks": true
+    }
   }
 }
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..2a326bd
--- /dev/null
+++ b/test.js
@@ -0,0 +1,151 @@
+/*!
+ * array-unique <https://github.com/jonschlinkert/array-unique>
+ *
+ * Copyright (c) 2014-2015, Jon Schlinkert.
+ * Licensed under the MIT License.
+ */
+
+'use strict';
+
+require('mocha');
+var assert = require('assert');
+var should = require('should');
+var unique = require('./');
+
+describe('unique', function() {
+  it('should throw an error if the value passed is not an array:', function() {
+    (function() {
+      unique('a', 'b', 'c');
+    }).should.throw('array-unique expects an array.');
+  });
+
+  it('should return an array with unique values:', function() {
+    unique(['a', 'b', 'c', 'a', 'b', 'd']).should.eql(['a', 'b', 'c', 'd']);
+    unique(['a', 'b', 'c', 'a', 'b', 'a', 'b', 'c', 'b', 'f', 'a', 'b']).should.eql(['a', 'b', 'c', 'f']);
+    unique(['a', 'b', 'c', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b', 'a', 'b',  [...]
+    unique(['foo/bar/baz/quux/fez/test/fixtures', 'foo/bar/baz/quux/fez/test/fixtures', 'foo/bar/baz/quux/fez/test/fixtures/a.js', 'foo/bar/baz/quux/fez/test/fixtures', 'foo/bar/baz/quux/fez/test/fixtures', 'foo/bar/baz/quux/fez/test/fixtures/b.js', 'foo/bar/baz/quux/fez/test/fixtures/b.js', 'foo/bar/baz/quux/fez/test/fixtures', 'foo/bar/baz/quux/fez/test/fixtures', 'foo/bar/baz/quux/fez/test/fixtures/a.js', 'foo/bar/baz/quux/fez/test/fixtures/j.js', 'foo/bar/baz/quux/fez/test/fixtures/z [...]
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures/a.js',
+        'foo/bar/baz/quux/fez/test/fixtures/b.js',
+        'foo/bar/baz/quux/fez/test/fixtures/j.js',
+        'foo/bar/baz/quux/fez/test/fixtures/z.js',
+        'foo/bar/baz/quux/fez/test/fixtures/c.js',
+        'foo/bar/baz/quux/fez/test/fixtures/d.js',
+        'foo/bar/baz/quux/fez/test/fixtures/h.js',
+        'foo/bar/baz/quux/fez/test/fixtures/i.js',
+        'foo/bar/baz/quux/fez/test/fixtures/k.js',
+        'foo/bar/baz/quux/fez/test/fixtures/l.js',
+        'foo/bar/baz/quux/fez/test/fixtures/m.js'
+      ]);
+  });
+});
+
+describe('unique.immutable', function() {
+  it('should throw an error if the value passed is not an array:', function() {
+    (function() {
+      unique.immutable('a', 'b', 'c');
+    }).should.throw('array-unique expects an array.');
+  });
+
+  it('should return an array with unique values without modifying the input:', function() {
+    (function() {
+      var original = ['a', 'b', 'c', 'a', 'b', 'd'];
+      var before =   ['a', 'b', 'c', 'a', 'b', 'd'];
+      var expected = ['a', 'b', 'c', 'd'];
+
+      unique.immutable(before).should.eql(expected);
+      before.should.eql(original);
+    })();
+
+    (function() {
+      var original = ['a', 'b', 'c', 'a', 'b', 'a', 'b', 'c', 'b', 'f', 'a', 'b'];
+      var before   = ['a', 'b', 'c', 'a', 'b', 'a', 'b', 'c', 'b', 'f', 'a', 'b'];
+      var expected = ['a', 'b', 'c', 'f'];
+
+      unique.immutable(before).should.eql(expected);
+      before.should.eql(original);
+    })();
+
+    (function() {
+      var original = ['a', 'b', 'c', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b',  [...]
+      var before   = ['a', 'b', 'c', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b', 'a', 'b', 'a', 'b', 'b', 'f', 'a', 'b', 'x', 'y', 'z', 'a', 'b',  [...]
+      var expected = ['a', 'b', 'c', 'f', 'x', 'y', 'z'];
+      unique.immutable(before).should.eql(expected);
+      before.should.eql(original);
+    })();
+
+    (function() {
+      var original = [
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures/a.js',
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures/b.js',
+        'foo/bar/baz/quux/fez/test/fixtures/b.js',
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures/a.js',
+        'foo/bar/baz/quux/fez/test/fixtures/j.js',
+        'foo/bar/baz/quux/fez/test/fixtures/z.js',
+        'foo/bar/baz/quux/fez/test/fixtures/c.js',
+        'foo/bar/baz/quux/fez/test/fixtures/d.js',
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures/a.js',
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures/h.js',
+        'foo/bar/baz/quux/fez/test/fixtures/i.js',
+        'foo/bar/baz/quux/fez/test/fixtures/j.js',
+        'foo/bar/baz/quux/fez/test/fixtures/k.js',
+        'foo/bar/baz/quux/fez/test/fixtures/l.js',
+        'foo/bar/baz/quux/fez/test/fixtures/m.js',
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures/a.js'
+      ];
+      var before = [
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures/a.js',
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures/b.js',
+        'foo/bar/baz/quux/fez/test/fixtures/b.js',
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures/a.js',
+        'foo/bar/baz/quux/fez/test/fixtures/j.js',
+        'foo/bar/baz/quux/fez/test/fixtures/z.js',
+        'foo/bar/baz/quux/fez/test/fixtures/c.js',
+        'foo/bar/baz/quux/fez/test/fixtures/d.js',
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures/a.js',
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures/h.js',
+        'foo/bar/baz/quux/fez/test/fixtures/i.js',
+        'foo/bar/baz/quux/fez/test/fixtures/j.js',
+        'foo/bar/baz/quux/fez/test/fixtures/k.js',
+        'foo/bar/baz/quux/fez/test/fixtures/l.js',
+        'foo/bar/baz/quux/fez/test/fixtures/m.js',
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures/a.js'
+      ];
+      var expected = [
+        'foo/bar/baz/quux/fez/test/fixtures',
+        'foo/bar/baz/quux/fez/test/fixtures/a.js',
+        'foo/bar/baz/quux/fez/test/fixtures/b.js',
+        'foo/bar/baz/quux/fez/test/fixtures/j.js',
+        'foo/bar/baz/quux/fez/test/fixtures/z.js',
+        'foo/bar/baz/quux/fez/test/fixtures/c.js',
+        'foo/bar/baz/quux/fez/test/fixtures/d.js',
+        'foo/bar/baz/quux/fez/test/fixtures/h.js',
+        'foo/bar/baz/quux/fez/test/fixtures/i.js',
+        'foo/bar/baz/quux/fez/test/fixtures/k.js',
+        'foo/bar/baz/quux/fez/test/fixtures/l.js',
+        'foo/bar/baz/quux/fez/test/fixtures/m.js'
+      ];
+
+      unique.immutable(before).should.eql(expected);
+      before.should.eql(original);
+    })();
+  });
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-array-unique.git



More information about the Pkg-javascript-commits mailing list