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

Method jsDefaults

ark/schema/structure/structure.ts:1288–1305  ·  view source on GitHub ↗

writes the defaults of its missing keys

(js: NodeCompiler, options?: CopyOptions)

Source from the content-addressed store, hash-verified

1286
1287 /** writes the defaults of its missing keys */
1288 private jsDefaults(js: NodeCompiler, options?: CopyOptions): NodeCompiler {
1289 // a default can fail, but where none is written, the check before stands
1290 if (!this.defaultable.length && !this.sequence?.defaultables) return js
1291 let first = options?.first === true
1292 for (const node of this.defaultable) {
1293 js.if(`!(${node.jsHoldsValue(js, "data")})`, () =>
1294 compileDefault(
1295 this.jsCopy(js, { first }),
1296 node,
1297 "out",
1298 !node.defaultsUndefined
1299 )
1300 )
1301 first = false
1302 }
1303 this.jsSequenceDefaults(js)
1304 return js.retIfFailed()
1305 }
1306
1307 /** writes `out`, which a transform writes into: data at the first site and where it writes in place */
1308 private jsCopy(js: NodeCompiler, options?: CopyOptions): NodeCompiler {

Callers 2

jsTfMethod · 0.95
jsDeleteFromCopyMethod · 0.95

Calls 5

jsCopyMethod · 0.95
jsSequenceDefaultsMethod · 0.95
compileDefaultFunction · 0.85
ifMethod · 0.80
jsHoldsValueMethod · 0.80

Tested by

no test coverage detected