From 021ea5535890fc99eac169c1053486f48431bb01 Mon Sep 17 00:00:00 2001 From: Sam Verschueren Date: Tue, 19 Apr 2016 17:35:43 +0200 Subject: [PATCH 1/6] tweaks (#3) es2015ify (#4) --- .editorconfig | 4 ---- .jshintrc | 13 ------------- .travis.yml | 4 +--- index.js | 8 +++----- package.json | 10 +++++++--- readme.md | 6 +++--- test.js | 10 +++++----- 7 files changed, 19 insertions(+), 36 deletions(-) delete mode 100644 .jshintrc diff --git a/.editorconfig b/.editorconfig index 8311fe1..173fe04 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,4 +1,3 @@ -# editorconfig.org root = true [*] @@ -11,6 +10,3 @@ insert_final_newline = true [package.json] indent_style = space indent_size = 2 - -[*.md] -trim_trailing_whitespace = false diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 804f8af..0000000 --- a/.jshintrc +++ /dev/null @@ -1,13 +0,0 @@ -{ - "node": true, - "esnext": true, - "bitwise": true, - "camelcase": true, - "curly": true, - "immed": true, - "newcap": true, - "noarg": true, - "undef": true, - "unused": "vars", - "strict": true -} diff --git a/.travis.yml b/.travis.yml index dedfc07..c9c9848 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,4 @@ sudo: false language: node_js node_js: - - 'iojs' - - '0.12' - - '0.10' + - '6' diff --git a/index.js b/index.js index fbe2ed2..85e0737 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,5 @@ 'use strict'; -module.exports = function (arr) { - var rest = [].concat.apply([], [].slice.call(arguments, 1)); - return arr.filter(function (el) { - return rest.indexOf(el) === -1; - }); +module.exports = (arr, ...values) => { + const rest = new Set([].concat(...values)); + return arr.filter(x => !rest.has(x)); }; diff --git a/package.json b/package.json index a8c4683..ae20874 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,10 @@ "url": "http://sindresorhus.com" }, "engines": { - "node": ">=0.10.0" + "node": ">=6" }, "scripts": { - "test": "mocha" + "test": "xo && ava" }, "files": [ "index.js" @@ -27,6 +27,10 @@ "exclude" ], "devDependencies": { - "mocha": "*" + "ava": "*", + "xo": "*" + }, + "xo": { + "esnext": true } } diff --git a/readme.md b/readme.md index 68f5d36..eac13aa 100644 --- a/readme.md +++ b/readme.md @@ -5,7 +5,7 @@ ## Install -```sh +``` $ npm install --save array-differ ``` @@ -13,7 +13,7 @@ $ npm install --save array-differ ## Usage ```js -var arrayDiffer = require('array-differ'); +const arrayDiffer = require('array-differ'); arrayDiffer([2, 3, 4], [3, 50]); //=> [2, 4] @@ -38,4 +38,4 @@ Arrays of values to exclude. ## License -MIT © [Sindre Sorhus](http://sindresorhus.com) +MIT © [Sindre Sorhus](https://sindresorhus.com) diff --git a/test.js b/test.js index d3f3858..5fbfc98 100644 --- a/test.js +++ b/test.js @@ -1,7 +1,7 @@ -'use strict'; -var assert = require('assert'); -var arrayDifference = require('./'); +import test from 'ava'; +import m from './'; -it('should filter out the difference', function () { - assert.deepEqual(arrayDifference([2, 3, 4], [3, 50, 60]), [2, 4]); +test(t => { + t.deepEqual(m([2, 3, 4], [3, 50, 60]), [2, 4]); + t.deepEqual(m([2, 3, 4], [3, 50], [2, 60]), [4]); }); From dc64ec370eea09c152edd3f942db37b0b4b56629 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 27 Apr 2016 15:13:10 +0700 Subject: [PATCH 2/6] meta tweaks --- .editorconfig | 2 +- package.json | 2 +- readme.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.editorconfig b/.editorconfig index 173fe04..98a761d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,6 +7,6 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[package.json] +[{package.json,*.yml}] indent_style = space indent_size = 2 diff --git a/package.json b/package.json index ae20874..996dc8c 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", - "url": "http://sindresorhus.com" + "url": "sindresorhus.com" }, "engines": { "node": ">=6" diff --git a/readme.md b/readme.md index eac13aa..f05131b 100644 --- a/readme.md +++ b/readme.md @@ -23,7 +23,7 @@ arrayDiffer([2, 3, 4], [3, 50]); ### arrayDiffer(input, values, [values, ...]) -Returns the new array. +Returns a new array. #### input From 2698f88f4e9e1c45f7b0375236bb923696b8ecdb Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 27 Apr 2016 15:13:21 +0700 Subject: [PATCH 3/6] 2.0.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 996dc8c..e898381 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "array-differ", - "version": "1.0.0", + "version": "2.0.3", "description": "Create an array with values that are present in the first input array but not additional ones", "license": "MIT", "repository": "sindresorhus/array-differ", From 4615e4d9f8fd6eab1abd4165580ba1fe95e7d9ef Mon Sep 17 00:00:00 2001 From: Satya Rohith Date: Sun, 3 Mar 2019 00:17:37 +0530 Subject: [PATCH 4/6] Add Typescript definition (#7) Co-authored-by: Sindre Sorhus --- index.d.ts | 15 +++++++++++++++ index.js | 5 ++++- index.test-d.ts | 5 +++++ package.json | 6 ++++-- test.js | 4 ++-- 5 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 index.d.ts create mode 100644 index.test-d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..12a94e1 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,15 @@ +/** + * Create an array with values that are present in the first array but not additional ones. + * + * @param array - The array to compare against. + * @param values - The arrays with values to be excluded. + * @returns A new array of filtered values. + * + * @example + * + * import arrayDiffer from 'array-differ'; + * + * arrayDiffer([2, 3, 4], [3, 50]); + * //=> [2, 4] + */ +export default function arrayDiffer(array: ArrayLike, ...values: ArrayLike[]): T[]; diff --git a/index.js b/index.js index 85e0737..2c655db 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,8 @@ 'use strict'; -module.exports = (arr, ...values) => { +const arrayDiffer = (arr, ...values) => { const rest = new Set([].concat(...values)); return arr.filter(x => !rest.has(x)); }; + +module.exports = arrayDiffer; +module.exports.default = arrayDiffer; diff --git a/index.test-d.ts b/index.test-d.ts new file mode 100644 index 0000000..6ad424e --- /dev/null +++ b/index.test-d.ts @@ -0,0 +1,5 @@ +import {expectType} from 'tsd-check'; +import arrayDiffer from '.'; + +expectType(arrayDiffer(['a', 'b', 'c'], ['b'], ['c'])); +expectType(arrayDiffer([1, 2, 3], [2], [3])); diff --git a/package.json b/package.json index e898381..effe8cb 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,11 @@ "node": ">=6" }, "scripts": { - "test": "xo && ava" + "test": "xo && ava && tsd-check" }, "files": [ - "index.js" + "index.js", + "index.d.ts" ], "keywords": [ "array", @@ -28,6 +29,7 @@ ], "devDependencies": { "ava": "*", + "tsd-check": "^0.3.0", "xo": "*" }, "xo": { diff --git a/test.js b/test.js index 5fbfc98..9677f72 100644 --- a/test.js +++ b/test.js @@ -1,7 +1,7 @@ import test from 'ava'; -import m from './'; +import m from '.'; -test(t => { +test('main', t => { t.deepEqual(m([2, 3, 4], [3, 50, 60]), [2, 4]); t.deepEqual(m([2, 3, 4], [3, 50], [2, 60]), [4]); }); From 3996ab258f0058a2704145a6a1dd989358de5082 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 3 Mar 2019 01:52:49 +0700 Subject: [PATCH 5/6] Meta tweaks --- .npmrc | 1 + index.js | 5 ++-- package.json | 69 +++++++++++++++++++++++++--------------------------- readme.md | 8 +++--- test.js | 6 ++--- 5 files changed, 44 insertions(+), 45 deletions(-) create mode 100644 .npmrc diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/index.js b/index.js index 2c655db..1ef9418 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,8 @@ 'use strict'; -const arrayDiffer = (arr, ...values) => { + +const arrayDiffer = (array, ...values) => { const rest = new Set([].concat(...values)); - return arr.filter(x => !rest.has(x)); + return array.filter(x => !rest.has(x)); }; module.exports = arrayDiffer; diff --git a/package.json b/package.json index effe8cb..55ad09e 100644 --- a/package.json +++ b/package.json @@ -1,38 +1,35 @@ { - "name": "array-differ", - "version": "2.0.3", - "description": "Create an array with values that are present in the first input array but not additional ones", - "license": "MIT", - "repository": "sindresorhus/array-differ", - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" - }, - "engines": { - "node": ">=6" - }, - "scripts": { - "test": "xo && ava && tsd-check" - }, - "files": [ - "index.js", - "index.d.ts" - ], - "keywords": [ - "array", - "difference", - "diff", - "differ", - "filter", - "exclude" - ], - "devDependencies": { - "ava": "*", - "tsd-check": "^0.3.0", - "xo": "*" - }, - "xo": { - "esnext": true - } + "name": "array-differ", + "version": "2.0.3", + "description": "Create an array with values that are present in the first input array but not additional ones", + "license": "MIT", + "repository": "sindresorhus/array-differ", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "sindresorhus.com" + }, + "engines": { + "node": ">=6" + }, + "scripts": { + "test": "xo && ava && tsd-check" + }, + "files": [ + "index.js", + "index.d.ts" + ], + "keywords": [ + "array", + "difference", + "diff", + "differ", + "filter", + "exclude" + ], + "devDependencies": { + "ava": "^1.2.1", + "tsd-check": "^0.3.0", + "xo": "^0.24.0" + } } diff --git a/readme.md b/readme.md index f05131b..b98cc06 100644 --- a/readme.md +++ b/readme.md @@ -6,7 +6,7 @@ ## Install ``` -$ npm install --save array-differ +$ npm install array-differ ``` @@ -21,17 +21,17 @@ arrayDiffer([2, 3, 4], [3, 50]); ## API -### arrayDiffer(input, values, [values, ...]) +### arrayDiffer(input, ...values) Returns a new array. #### input -Type: `array` +Type: `unknown[]` #### values -Type: `array` +Type: `unknown[]` Arrays of values to exclude. diff --git a/test.js b/test.js index 9677f72..5375bbf 100644 --- a/test.js +++ b/test.js @@ -1,7 +1,7 @@ import test from 'ava'; -import m from '.'; +import arrayDiffer from '.'; test('main', t => { - t.deepEqual(m([2, 3, 4], [3, 50, 60]), [2, 4]); - t.deepEqual(m([2, 3, 4], [3, 50], [2, 60]), [4]); + t.deepEqual(arrayDiffer([2, 3, 4], [3, 50, 60]), [2, 4]); + t.deepEqual(arrayDiffer([2, 3, 4], [3, 50], [2, 60]), [4]); }); From 0f1f2857375dd65cc0df0096076e8869a7325ba9 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 3 Mar 2019 01:55:19 +0700 Subject: [PATCH 6/6] 2.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 55ad09e..371229e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "array-differ", - "version": "2.0.3", + "version": "2.1.0", "description": "Create an array with values that are present in the first input array but not additional ones", "license": "MIT", "repository": "sindresorhus/array-differ",