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

Function valueFacts

ark/type/deferred.ts:772–814  ·  view source on GitHub ↗
(
	v: unknown,
	into: Facts
)

Source from the content-addressed store, hash-verified

770
771// what a prop's value says, if it's one a literal can hold without throwing
772const valueFacts = (
773 v: unknown,
774 into: Facts
775): [facts: Facts, held: unknown] | undefined => {
776 if (typeof v === "string") {
777 const facts = scanLeaf(v)
778 return facts && [facts, v]
779 }
780 if (Array.isArray(v)) {
781 const element = v.length === 2 && v[1] === "[]" && valueFacts(v[0], into)
782 return element && !element[0].defaults ?
783 [arrayFacts(element[0]), [element[1], "[]"]]
784 : undefined
785 }
786 if (v instanceof RegExp) {
787 const facts = regexFacts(v)
788 return facts && [facts, v]
789 }
790 if (typeof v !== "object" && typeof v !== "function") return
791 if (!v) return
792 const d = deferred.get(v)
793 if (d) return [d.facts, d.target ?? v]
794 if (isNode(v)) {
795 const of = isInstanceOf(v, BaseRoot) && v.isRoot() && nodeFacts(v)
796 return of ? [of, v] : undefined
797 }
798 if (typeof v === "function" || !isPlainObject(v)) return
799 const nested: Facts = { key: "", domains: objectBits, pure: true }
800 const held = walkLiteral(v as Dict, nested, into)
801 return (
802 held && [
803 {
804 key: nested.key,
805 domains: objectBits,
806 pure: into.pure,
807 narrowedWithin: nested.narrowedWithin,
808 unitsWithin: nested.unitsWithin,
809 ends: nested.ends
810 },
811 held
812 ]
813 )
814}
815
816const walkLiteral = (
817 def: Dict,

Callers 3

walkLiteralFunction · 0.85
deferUnionFunction · 0.85
instantiateFunction · 0.85

Calls 9

isNodeFunction · 0.90
isInstanceOfFunction · 0.90
scanLeafFunction · 0.85
arrayFactsFunction · 0.85
regexFactsFunction · 0.85
nodeFactsFunction · 0.85
isPlainObjectFunction · 0.85
walkLiteralFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected