diff --git a/.gitattributes b/.gitattributes index 391f0a4..6313b56 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1 @@ -* text=auto -*.js text eol=lf +* text=auto eol=lf diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..6221132 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,21 @@ +/** +Create an array without duplicates. + +@param array - The array to remove duplicates from. + +@example +``` +import arrayUniq = require('array-uniq'); + +arrayUniq([1, 1, 2, 3, 3]); +//=> [1, 2, 3] + +arrayUniq(['foo', 'foo', 'bar', 'foo']); +//=> ['foo', 'bar'] +``` +*/ +declare function arrayUniq( + array: ReadonlyArray +): ValueType[]; + +export = arrayUniq; diff --git a/index.js b/index.js index 3b29b27..82ea2b9 100644 --- a/index.js +++ b/index.js @@ -1,2 +1,5 @@ 'use strict'; -module.exports = x => [...new Set(x)]; + +const arrayUniq = array => [...new Set(array)]; + +module.exports = arrayUniq; diff --git a/index.test-d.ts b/index.test-d.ts new file mode 100644 index 0000000..8dc911b --- /dev/null +++ b/index.test-d.ts @@ -0,0 +1,4 @@ +import {expectType} from 'tsd'; +import arrayUniq = require('.'); + +expectType(arrayUniq([1, 2, 3])); diff --git a/package.json b/package.json index bc6e2d0..4c85c36 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "array-uniq", - "version": "2.0.0", + "version": "2.1.0", "description": "Create an array without duplicates", "license": "MIT", "repository": "sindresorhus/array-uniq", @@ -13,10 +13,11 @@ "node": ">=6" }, "scripts": { - "test": "xo && ava" + "test": "xo && ava && tsd" }, "files": [ - "index.js" + "index.js", + "index.d.ts" ], "keywords": [ "array", @@ -27,7 +28,8 @@ "remove" ], "devDependencies": { - "ava": "*", - "xo": "*" + "ava": "^1.4.1", + "tsd": "^0.7.2", + "xo": "^0.24.0" } } diff --git a/test.js b/test.js index 840baf8..309f637 100644 --- a/test.js +++ b/test.js @@ -1,7 +1,7 @@ import test from 'ava'; -import m from '.'; +import arrayUniq from '.'; test('main', t => { - t.deepEqual(m([1, 2, 2, 3, 1, 2, 4]), [1, 2, 3, 4]); - t.deepEqual(m(['a', 'a', 'b', 'a', 'c', 'a', 'd']), ['a', 'b', 'c', 'd']); + t.deepEqual(arrayUniq([1, 2, 2, 3, 1, 2, 4]), [1, 2, 3, 4]); + t.deepEqual(arrayUniq(['a', 'a', 'b', 'a', 'c', 'a', 'd']), ['a', 'b', 'c', 'd']); });