import { ScramjetConfig, ScramjetFlags } from "../types"; export let codecEncode: (input: string) => string; export let codecDecode: (input: string) => string; const nativeFunction = Function; export function loadCodecs() { codecEncode = nativeFunction(`return ${config.codec.encode}`)() as any; codecDecode = nativeFunction(`return ${config.codec.decode}`)() as any; } export function flagEnabled(flag: keyof ScramjetFlags, url: URL): boolean { const value = config.flags[flag]; for (const regex in config.siteFlags) { const partialflags = config.siteFlags[regex]; if (new RegExp(regex).test(url.href) && flag in partialflags) { return partialflags[flag]; } } return value; } export let config: ScramjetConfig; export function setConfig(newConfig: ScramjetConfig) { config = newConfig; loadCodecs(); }