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

Method jsElemTfs

ark/schema/structure/sequence.ts:446–462  ·  view source on GitHub ↗

writes the transforms of data's elements, into `copy` before the first change or, without one, in place

(js: NodeCompiler, copy: string | undefined)

Source from the content-addressed store, hash-verified

444
445 /** writes the transforms of data's elements, into `copy` before the first change or, without one, in place */
446 jsElemTfs(js: NodeCompiler, copy: string | undefined): NodeCompiler {
447 let i = 0
448 this.jsElements(js, (keyExpr, node) => {
449 const element = `element${i}`
450 const transformed = `elementTf${i++}`
451 return js
452 .const(element, `data[${keyExpr}]`)
453 .tfKey(transformed, element, [{ node }], {
454 keyExpr,
455 onChange: () =>
456 (copy ? js.if("out === data", () => js.set("out", copy)) : js).line(
457 `out[${keyExpr}] = ${transformed}`
458 )
459 })
460 })
461 return js
462 }
463
464 /** writes the checks of data's elements */
465 private jsElements(

Callers 2

jsTfMethod · 0.95
jsTfMethod · 0.80

Calls 6

jsElementsMethod · 0.95
tfKeyMethod · 0.80
constMethod · 0.80
lineMethod · 0.80
ifMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected