We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a9ae7be commit 22a8a7dCopy full SHA for 22a8a7d
src/helpers.ts
@@ -0,0 +1,25 @@
1
+export interface WeaveOptions<TInput> {
2
+ amount: number;
3
+ customizer: (input: TInput, index: number) => TInput;
4
+}
5
+
6
+const DEFAULT_WEAVE_OPTIONS: WeaveOptions<any> = {
7
+ amount: 10,
8
+ customizer: (input) => input,
9
+};
10
11
+export function weave<TInput>(input: TInput | TInput[], opts?: WeaveOptions<TInput>): TInput[] {
12
+ const { amount, customizer } = opts ?? DEFAULT_WEAVE_OPTIONS;
13
14
+ // convert single input to array
15
+ const inputs = Array.isArray(input) ? input : [input];
16
+ const result: TInput[] = [];
17
18
+ for (let i = 0; i < amount; i++) {
19
+ for (const item of inputs) {
20
+ result.push(customizer(item, i));
21
+ }
22
23
24
+ return result;
25
0 commit comments