char/avril

(wip) why'd you have to go and make things so complicaaaaated?

git clone https://git.t4t.associates/char/avril

Charlotte Somgenerate test typedefs from typescript impleae10ac

main
1.2 KiB34 linesraw
1import { ReflectOwnKeys, String, TypeError, uncurryThis } from "ext:core/primordials";
2import type { TestContext } from "./main.js";
3import { dictionary } from "ext:web/idl.js";
4
5export type ParsedStep = { name: string } & (
6  { ignore: true; fn: ((context: TestContext) => unknown) | undefined } |
7  { ignore: false; fn: (context: TestContext) => unknown }
8);
9export type Definition = ParsedStep & { only: boolean; timeout: number };
10export const registry: { definitions: Definition[]; sealed: boolean } = {
11  definitions: [],
12  sealed: false,
13};
14
15const arrayIncludes = uncurryThis(Array.prototype.includes);
16
17export function optionsOf(value: unknown, allowed: string[], kind: string): Record<PropertyKey, unknown> {
18  const options = dictionary(value);
19  for (const key of ReflectOwnKeys(options)) {
20    if (!arrayIncludes(allowed, key)) {
21      throw new TypeError(`Unknown ${kind} option: ${String(key)}`);
22    }
23  }
24  return options;
25}
26
27export function flag(options: Record<PropertyKey, unknown>, name: string, Kind: string): boolean {
28  const value = options[name];
29  if (value === undefined) return false;
30  if (typeof value !== "boolean") {
31    throw new TypeError(`${Kind} option ${name} must be a boolean`);
32  }
33  return value;
34}