Skip to content

Commit 35c640c

Browse files
BendingBendersindresorhus
authored andcommitted
Add TypeScript definition (#2)
1 parent 8cee9d2 commit 35c640c

File tree

7 files changed

+37
-11
lines changed

7 files changed

+37
-11
lines changed

.gitattributes

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
* text=auto
2-
*.js text eol=lf
1+
* text=auto eol=lf

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: node_js
22
node_js:
3+
- '10'
34
- '8'
45
- '6'

index.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
Get consecutively unique elements from an array.
3+
4+
@returns A function that when called will return a random element that's never the same as the previous.
5+
6+
@example
7+
```
8+
import uniqueRandomArray = require('unique-random-array');
9+
const random = uniqueRandomArray([1, 2, 3, 4]);
10+
11+
console.log(random(), random(), random(), random());
12+
//=> 4 2 1 4
13+
```
14+
*/
15+
declare function uniqueRandomArray<ValueType>(
16+
array: readonly ValueType[]
17+
): () => ValueType;
18+
19+
export = uniqueRandomArray;

index.test-d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {expectType} from 'tsd';
2+
import uniqueRandomArray = require('.');
3+
4+
expectType<() => number>(uniqueRandomArray([1, 2, 3, 4]));
5+
expectType<() => string | number>(uniqueRandomArray(['1', 2, 3, 4]));

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
"node": ">=6"
1414
},
1515
"scripts": {
16-
"test": "xo && ava"
16+
"test": "xo && ava && tsd"
1717
},
1818
"files": [
19-
"index.js"
19+
"index.js",
20+
"index.d.ts"
2021
],
2122
"keywords": [
2223
"unique",
@@ -36,7 +37,8 @@
3637
"unique-random": "^2.0.0"
3738
},
3839
"devDependencies": {
39-
"ava": "*",
40-
"xo": "*"
40+
"ava": "^1.4.1",
41+
"tsd": "^0.7.2",
42+
"xo": "^0.24.0"
4143
}
4244
}

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ console.log(random(), random(), random(), random());
2525

2626
## API
2727

28-
### uniqueRandomArray(input)
28+
### uniqueRandomArray(array)
2929

3030
Returns a function that when called will return a random element that's never the same as the previous.
3131

32-
#### input
32+
#### array
3333

34-
Type: `Array`
34+
Type: `Array<unknown>`
3535

3636

3737
## Related

test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import test from 'ava';
2-
import m from '.';
2+
import uniqueRandomArray from '.';
33

44
test('main', t => {
5-
const random = m([1, 2, 3, 4]);
5+
const random = uniqueRandomArray([1, 2, 3, 4]);
66

77
let current;
88
let previous;

0 commit comments

Comments
 (0)