This is supposed to be served next to a fonts.css file defining one or more font-families, ex:
@font-face {
font-family: "American Captain";
src: url("./American-Captain.woff") format("woff");
}
// array of [outcome, weight] | |
export function weightedRandom(arr) { | |
const outcomeCuts = []; | |
let accum = 0; | |
for (const [out, weight] of arr) { | |
accum += weight; | |
outcomeCuts.push([out, accum]); | |
} | |
const r = accum * Math.random(); | |
let best; |
// import { webcrypto as crypto } from 'node:crypto'; // NODE | |
// eslint-disable-next-line no-undef | |
const crypto = globalThis.crypto; // BROWSER | |
const subtle = crypto.subtle; | |
const ALGO = 'AES-CBC'; | |
// HELPER FUNCTIONS |
function defer<T>(): { | |
promise: Promise<T>; | |
resolve: (resp: T) => void; | |
reject: (err: any) => void; | |
} { | |
const answer: any = {}; | |
answer.promise = new Promise((resolve, reject) => { | |
answer.resolve = resolve; | |
answer.reject = reject; | |
}); |
import { test } from 'node:test'; | |
import { strictEqual, deepEqual } from 'node:assert'; | |
/* | |
inspired by https://www.youtube.com/watch?v=umSuLpjFUf8 | |
3 3 * 4 4 * + sqrt | |
equivalent to | |
Math.sqrt(3*3 + 4*4) | |
*/ |
import { createReadStream } from 'fs'; | |
export function streamSplitBy(file, onMatch, splitBy='\n') { | |
return new Promise((resolve) => { | |
const stream = createReadStream(file); | |
let ongoing = ''; | |
stream.on('data', buff => { | |
const chunk = buff.toString(); |
export function spy(fn: Function, prot = fn.prototype) { | |
function proxyFn() { | |
const args = Array.prototype.slice.call(arguments); | |
const call = { args, result: undefined, error: undefined, real: true }; | |
proxyFn.calls.push(call); | |
let responded = false; | |
// check if preparedCalls can answer |
type SortableType = number | string | boolean; | |
type SortFn<T> = (el: T) => SortableType; | |
interface SortHelperApi<T> { | |
sortBy(fn: SortFn<T>, decrescent?: boolean): SortHelperApi<T>; | |
execute(): T[]; | |
} | |
/** |
This is supposed to be served next to a fonts.css file defining one or more font-families, ex:
@font-face {
font-family: "American Captain";
src: url("./American-Captain.woff") format("woff");
}
const ignoreKeys = new Set([ | |
'parent', | |
'transform', | |
]); | |
const numberKeyRgx = /^[0-9]+$/; | |
const simpleKeyRgx = /^[a-zA-Z_\$][a-zA-Z0-9_\$]*$/; | |
const getExpr = function (key: string) { | |
if (numberKeyRgx.test(key)) return `[${key}]`; | |
return (simpleKeyRgx.test(key)) ? `.${key}` : `['${key}']`; |