feat(js): m01 util and m02 model with tests, fixtures, purity audit

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
Lucas Winther
2026-10-28 23:38:29 +01:00
co-authored by Claude Sonnet 5.5
parent 5be3cebe71
commit 22c221a042
14 changed files with 508 additions and 4 deletions
+5 -4
View File
@@ -8,11 +8,12 @@ const here = dirname(fileURLToPath(import.meta.url))
export const loadFixture = (name) =>
JSON.parse(readFileSync(join(here, '..', '..', 'fixtures', `${name}.json`), 'utf8'))
/** Deep-freeze for tests (independent of the student's deepFreeze). */
export const freeze = (x) => {
if (x !== null && typeof x === 'object' && !Object.isFrozen(x)) {
/** Deep-freeze for tests (independent of the student's deepFreeze). Recurses into children even of already-frozen objects. */
export const freeze = (x, seen = new WeakSet()) => {
if (x !== null && typeof x === 'object' && !seen.has(x)) {
seen.add(x)
Object.freeze(x)
Object.values(x).forEach(freeze)
Object.values(x).forEach((v) => freeze(v, seen))
}
return x
}