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

Function factOfHole

ark/type/runtime.ts:1240–1273  ·  view source on GitHub ↗
(
	hole: unknown,
	kind: HoleKind = "function",
	classes: Record<string, unknown> = {}
)

Source from the content-addressed store, hash-verified

1238type HoleFact = string | number
1239
1240export const factOfHole = (
1241 hole: unknown,
1242 kind: HoleKind = "function",
1243 classes: Record<string, unknown> = {}
1244): HoleFact => {
1245 if (kind === "symbol" || typeof hole !== "function" || isValidator(hole))
1246 return describeValue(hole)
1247 if (kind === "function") return Math.min(hole.length, 2)
1248 const builtinName = getBuiltinNameOfConstructor(hole)
1249 if (builtinName) return `the builtin ${builtinName}`
1250 const { prototype } = hole
1251 if (!hasDomain(prototype, "object")) return "a function without a prototype"
1252 // compared with the builtins and other classes the definition holds
1253 const ancestors: string[] = []
1254 for (
1255 let ancestor = prototypeOf(prototype);
1256 ancestor;
1257 ancestor = prototypeOf(ancestor)
1258 ) {
1259 const { constructor } = ancestor
1260 const ancestorName =
1261 typeof constructor === "function" &&
1262 constructor.prototype === ancestor &&
1263 getBuiltinNameOfConstructor(constructor)
1264 if (ancestorName) ancestors.push(ancestorName)
1265 for (const label in classes) {
1266 if ((classes[label] as Function).prototype === ancestor)
1267 ancestors.push(label)
1268 }
1269 }
1270 return ancestors.length ?
1271 `a class extending ${ancestors.join(", ")}`
1272 : "a class"
1273}
1274
1275export const describeShape = (value: unknown): string => {
1276 if (!hasDomain(value, "object")) return describeValue(value)

Callers

nothing calls this directly

Calls 6

hasDomainFunction · 0.90
prototypeOfFunction · 0.90
describeValueFunction · 0.85
isValidatorFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected