-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathbun.setup.ts
More file actions
36 lines (31 loc) · 933 Bytes
/
bun.setup.ts
File metadata and controls
36 lines (31 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
export {}
function cartesianProduct<T extends any[][]>(arrays: T) {
return arrays.reduce(
(acc, curr) => acc.flatMap((x) => curr.map((y) => [...x, y])),
[[]],
)
}
function createTestMatrix<T extends Record<string, any[]>>(
optionsMap: T,
): {
[K in keyof T]: T[K] extends (infer U)[] ? U : never
}[] {
const keys = Object.keys(optionsMap)
const values = Object.values(optionsMap)
return cartesianProduct(values).map<{
[K in keyof T]: T[K] extends (infer U)[] ? U : never
}>(
(combination) =>
Object.fromEntries(keys.map((key, i) => [key, combination[i]])) as {
[K in keyof T]: T[K] extends (infer U)[] ? U : never
},
)
}
globalThis.createTestMatrix = createTestMatrix
declare global {
function createTestMatrix<T extends Record<string, any[]>>(
optionsMap: T,
): {
[K in keyof T]: T[K] extends (infer U)[] ? U : never
}[]
}