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

Function attachBoundUnits

ark/schema/parse.ts:214–235  ·  view source on GitHub ↗
(inner: dict)

Source from the content-addressed store, hash-verified

212
213// bounds inside an intersection inherit their basis's unit (e.g. "character" for string, "item" for Array)
214const attachBoundUnits = (inner: dict): void => {
215 const basis = (inner.proto ?? inner.domain) as
216 | nodeOfKind<Intersection.BasisKind>
217 | undefined
218 const unit = basis?.boundUnit
219 if (!unit) return
220 for (const k in inner) {
221 if (!isKeyOf(k, boundUnitKeys)) continue
222 const v = inner[k] as listable<BaseNode>
223 if (isArray(v)) {
224 let updated: BaseNode[] | undefined
225 for (let i = 0; i < v.length; i++) {
226 const node = v[i]
227 if ((node.inner as { unit?: BoundUnit }).unit !== undefined) continue
228 updated ??= v.slice()
229 updated[i] = withBoundUnit(node, unit)
230 }
231 if (updated) inner[k] = updated
232 } else if ((v.inner as { unit?: BoundUnit }).unit === undefined)
233 inner[k] = withBoundUnit(v, unit)
234 }
235}
236
237const withBoundUnit = (node: BaseNode, unit: BoundUnit): BaseNode =>
238 node.$.node(node.kind, { ...node.inner, unit, meta: node.meta } as never, {

Callers 1

parseNodeFunction · 0.85

Calls 2

isKeyOfFunction · 0.90
withBoundUnitFunction · 0.85

Tested by

no test coverage detected