diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/webgpu/tests/cts/checkout/src/common/util/data_tables.ts | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dom/webgpu/tests/cts/checkout/src/common/util/data_tables.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/dom/webgpu/tests/cts/checkout/src/common/util/data_tables.ts b/dom/webgpu/tests/cts/checkout/src/common/util/data_tables.ts new file mode 100644 index 0000000000..7f1be2f701 --- /dev/null +++ b/dom/webgpu/tests/cts/checkout/src/common/util/data_tables.ts @@ -0,0 +1,39 @@ +import { ResolveType, ZipKeysWithValues } from './types.js'; + +export type valueof<K> = K[keyof K]; + +export function keysOf<T extends string>(obj: { [k in T]: unknown }): readonly T[] { + return (Object.keys(obj) as unknown[]) as T[]; +} + +export function numericKeysOf<T>(obj: object): readonly T[] { + return (Object.keys(obj).map(n => Number(n)) as unknown[]) as T[]; +} + +/** + * Creates an info lookup object from a more nicely-formatted table. See below for examples. + * + * Note: Using `as const` on the arguments to this function is necessary to infer the correct type. + */ +export function makeTable< + Members extends readonly string[], + Defaults extends readonly unknown[], + Table extends { readonly [k: string]: readonly unknown[] } +>( + members: Members, + defaults: Defaults, + table: Table +): { + readonly [k in keyof Table]: ResolveType<ZipKeysWithValues<Members, Table[k], Defaults>>; +} { + const result: { [k: string]: { [m: string]: unknown } } = {}; + for (const [k, v] of Object.entries<readonly unknown[]>(table)) { + const item: { [m: string]: unknown } = {}; + for (let i = 0; i < members.length; ++i) { + item[members[i]] = v[i] ?? defaults[i]; + } + result[k] = item; + } + /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ + return result as any; +} |