MCPcopy Create free account
hub / github.com/arktypeio/arktype / writeDefault

Method writeDefault

ark/schema/structure/structure.ts:1376–1389  ·  view source on GitHub ↗
(i: number)

Source from the content-addressed store, hash-verified

1374 if (!sequence?.defaultables) return
1375 const defaultables = sequence.defaultables
1376 const writeDefault = (i: number) => {
1377 const [node, defaultValue] = defaultables[i]
1378 const morph = sequence.defMorphs[i]
1379 return typeof defaultValue !== "function" && !node.tfs ?
1380 js.line(
1381 `out[${sequence.preLen + i}] = ${serializeDefault(js, defaultValue)}`
1382 )
1383 : compileDefaultMorph(
1384 js,
1385 sequence,
1386 `${js.ref(morph)}(out${morph.length === 2 ? ", ctx" : ""})`,
1387 "out"
1388 )
1389 }
1390 // an undefined element is replaced too, so each is checked on its own
1391 if (sequence.defaultsUndefined) {
1392 for (let i = 0; i < defaultables.length; i++) {

Callers

nothing calls this directly

Calls 4

serializeDefaultFunction · 0.85
compileDefaultMorphFunction · 0.85
lineMethod · 0.80
refMethod · 0.45

Tested by

no test coverage detected