-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Sindre Sorhus <[email protected]>
- Loading branch information
1 parent
b12cae3
commit aae7539
Showing
3 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters