char/avril
(wip) why'd you have to go and make things so complicaaaaated?
git clone https://git.t4t.associates/char/avril
eae10ac
main
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 } = { 11definitions :[], 12sealed :false , 13}; 14 15const arrayIncludes = uncurryThis ( Array . prototype . includes ); 16 17export function optionsOf ( value :unknown , allowed :string [], kind :string ) :Record < PropertyKey , unknown > { 18const options = dictionary ( value ); 19for ( const key of ReflectOwnKeys ( options )) { 20if ( ! arrayIncludes ( allowed , key )) { 21throw new TypeError ( `Unknown ${ kind } option: ${ String ( key )} ` ); 22} 23} 24return options ; 25} 26 27export function flag ( options :Record < PropertyKey , unknown >, name :string , Kind :string ) :boolean { 28const value = options [ name ]; 29if ( value === undefined ) return false ; 30if ( typeof value !== "boolean" ) { 31throw new TypeError ( ` ${ Kind } option ${ name } must be a boolean` ); 32} 33return value ; 34}