diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..cb4933e --- /dev/null +++ b/index.d.ts @@ -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( + value: T | ((index: number, count: number, currentArray: T[]) => T), + count: number +): T[]; diff --git a/index.test-d.ts b/index.test-d.ts new file mode 100644 index 0000000..1394f06 --- /dev/null +++ b/index.test-d.ts @@ -0,0 +1,6 @@ +import {expectType} from 'tsd'; +import filledArray from './index.js'; + +expectType(filledArray('x', 3)); +expectType(filledArray(0, 3)); +expectType(filledArray(index => `Hey ${index}`, 3)); diff --git a/package.json b/package.json index 5b45fb3..1001cdc 100644 --- a/package.json +++ b/package.json @@ -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", @@ -33,6 +34,7 @@ ], "devDependencies": { "ava": "^4.0.0", + "tsd": "^0.19.1", "xo": "^0.47.0" } }