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

Function scanUnion

ark/type/deferred.ts:493–525  ·  view source on GitHub ↗
(def: string)

Source from the content-addressed store, hash-verified

491 f.terms ? f.terms.every(t => insert(terms, t)) : insert(terms, f.key)
492
493const scanUnion = (def: string): Facts | undefined => {
494 const parts = splitTop(def, " | ")
495 if (parts.length === 1) return scanTerm(def)
496 let domains = 0
497 let open = 0
498 let values: unknown[] | undefined = []
499 let units: boolean | undefined
500 let unitsWithin: boolean | undefined
501 let ends: Ends | undefined
502 const terms: string[] = []
503 for (let i = 0; i < parts.length; i++) {
504 const term = scanTerm(parts[i])
505 // a value in what another allows isn't a branch of what it reduces to
506 if (!term || term.domains & (term.values ? open : domains)) return
507 domains |= term.domains
508 if (!term.values) open |= term.domains
509 values = term.values && values?.concat(term.values)
510 units ||= term.units
511 unitsWithin ||= term.unitsWithin
512 ends = joinEnds(ends, term.ends)
513 if (!insertAll(terms, term)) return
514 }
515 return {
516 key: terms.join("|"),
517 terms,
518 domains,
519 pure: true,
520 values,
521 units,
522 unitsWithin,
523 ends
524 }
525}
526
527const refinesString = (f: Facts | undefined): f is Facts =>
528 !!f && f.pure && f.domains === stringBits && !f.values && !f.defaults

Callers 4

scanTermFunction · 0.85
scanAndFunction · 0.85
scanUncachedFunction · 0.85
instantiateFunction · 0.85

Calls 4

splitTopFunction · 0.85
scanTermFunction · 0.85
joinEndsFunction · 0.85
insertAllFunction · 0.85

Tested by

no test coverage detected