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

Function describeShape

ark/type/runtime.ts:1275–1288  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

1273}
1274
1275export const describeShape = (value: unknown): string => {
1276 if (!hasDomain(value, "object")) return describeValue(value)
1277 if (value instanceof Date) return `a Date at ${dateGetTime.call(value)}`
1278 if (value instanceof RegExp) return `the RegExp ${value}`
1279 if (Array.isArray(value)) return `an array of length ${value.length}`
1280 const prototype = prototypeOf(value)
1281 if (prototype !== Object.prototype && prototype !== null)
1282 return describeValue(value)
1283 const kind = prototype ? "object" : "null-prototype object"
1284 const keys = Reflect.ownKeys(value)
1285 return keys.length ?
1286 `${prototype ? "an" : "a"} ${kind} with keys ${keys.map(String).join(", ")}`
1287 : `an empty ${kind}`
1288}
1289
1290/**
1291 * What a plain object or array of primitives holds, as 53 bits: what kind it

Callers

nothing calls this directly

Calls 5

hasDomainFunction · 0.90
prototypeOfFunction · 0.90
describeValueFunction · 0.85
callMethod · 0.80
mapMethod · 0.65

Tested by

no test coverage detected