Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
Returns an array filled with the specified input.

@param value - The value to fill the array with.
@param count - The number of items to fill the array with.

@example
```
import filledArray from 'filled-array';

filledArray('x', 3);
//=> ['x', 'x', 'x']

filledArray(0, 3);
//=> [0, 0, 0]

filledArray(index => {
return (++index % 3 ? '' : 'Fizz') + (index % 5 ? '' : 'Buzz') || index;
}, 15);
//=> [1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'FizzBuzz']
```
*/
export default function filledArray<T>(
value: T | ((index: number, count: number, currentArray: T[]) => T),
count: number
): T[];
6 changes: 6 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {expectType} from 'tsd';
import filledArray from './index.js';

expectType<string[]>(filledArray('x', 3));
expectType<number[]>(filledArray(0, 3));
expectType<string[]>(filledArray(index => `Hey ${index}`, 3));
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
"node": ">=12"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd"
},
"files": [
"index.js"
],
"index.js",
"index.d.ts"
],
"keywords": [
"array",
"elements",
Expand All @@ -33,6 +34,7 @@
],
"devDependencies": {
"ava": "^4.0.0",
"tsd": "^0.19.1",
"xo": "^0.47.0"
}
}