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

Function staticTextOf

ark/schema/runtime.ts:121–162  ·  view source on GitHub ↗
(value: unknown, seen: unknown[])

Source from the content-addressed store, hash-verified

119}
120
121const staticTextOf = (value: unknown, seen: unknown[]): string => {
122 if (
123 value === null ||
124 (typeof value !== "object" && typeof value !== "function")
125 ) {
126 return (
127 typeof value === "string" ? JSON.stringify(value)
128 : typeof value === "bigint" ? `${value}n`
129 : Object.is(value, -0) ? "-0"
130 : String(value)
131 )
132 }
133 // a repeated object is named by its first visit
134 const index = seen.indexOf(value)
135 if (index !== -1) return `#${index}`
136 seen.push(value)
137 if (typeof value === "function") return "function"
138 const tag = Object.prototype.toString.call(value)
139 const builtins = [
140 null,
141 Object.prototype,
142 Array.prototype,
143 Date.prototype,
144 RegExp.prototype
145 ]
146 // inherited enumerable keys count too
147 const enumerable: PropertyKey[] = []
148 for (const k in value) enumerable.push(k)
149 let entries = ""
150 for (const k of new Set([...enumerable, ...Reflect.ownKeys(value)])) {
151 entries += `${enumerable.includes(k) ? "" : "~"}${JSON.stringify(
152 // a symbol key prints as its registered name
153 typeof k === "symbol" ? [Symbol.keyFor(k)] : k
154 )}:${staticTextOf((value as Record<PropertyKey, unknown>)[k], seen)},`
155 }
156 // the prototype, since Symbol.toStringTag can fake the tag
157 return `${tag}${builtins.indexOf(Object.getPrototypeOf(value))}${
158 tag === "[object Date]" ? Number(value)
159 : tag === "[object RegExp]" ? `${value}`
160 : ""
161 }{${entries}}`
162}
163
164// satisfies keeps the parens prettier would drop
165export const fixConfig = ((): void => {

Callers 1

fingerprintOfFunction · 0.85

Calls 4

StringInterface · 0.85
isMethod · 0.80
callMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected