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:
co-authored by
Claude Sonnet 5.5
parent
5be3cebe71
commit
22c221a042
+5
-4
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user