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

Method tfElems

ark/schema/structure/sequence.ts:399–422  ·  view source on GitHub ↗

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

(
		data: array,
		ctx: InternalTraversal,
		copy: ((data: array) => object) | undefined
	)

Source from the content-addressed store, hash-verified

397
398 /** transforms data's elements, into the copy before the first change or, without one, in place */
399 tfElems(
400 data: array,
401 ctx: InternalTraversal,
402 copy: ((data: array) => object) | undefined
403 ): array {
404 let out = data as unknown[]
405 for (let i = 0; i < data.length; i++) {
406 const node = this.atIndex(data, i).node
407 if (!node.tfs) continue
408 // an undefined a default replaces isn't transformed first
409 if (
410 i >= this.preLen &&
411 i < this.preLen + this.defLen &&
412 !this.holdsElement(data, i)
413 )
414 continue
415 const element = data[i]
416 const transformed = travKey(i, () => transform(ctx, node, element), ctx)
417 if (Object.is(transformed, element)) continue
418 if (out === data && copy) out = copy(data) as unknown[]
419 out[i] = transformed
420 }
421 return out
422 }
423
424 // minLength/maxLength compilation should be handled by Intersection
425 compile(js: NodeCompiler): void {

Callers 2

tTransformMethod · 0.95
tTransformMethod · 0.80

Calls 6

atIndexMethod · 0.95
holdsElementMethod · 0.95
travKeyFunction · 0.90
transformFunction · 0.90
isMethod · 0.80
copyFunction · 0.50

Tested by

no test coverage detected