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

Function objectKindOf

ark/util/objectKinds.ts:203–225  ·  view source on GitHub ↗
(
	data: data
)

Source from the content-addressed store, hash-verified

201>
202
203export const objectKindOf = <data extends object>(
204 data: data
205): objectKindOf<data> | undefined => {
206 // Realm-safe: cross-window/vm arrays fail `instanceof Array` but pass
207 // Array.isArray (https://github.com/arktypeio/arktype/issues/1597).
208 if (Array.isArray(data)) return "Array" as never
209
210 let prototype: Partial<Object> | null = prototypeOf(data)
211 if (prototype === Object.prototype) return undefined
212 const constructors = builtinsOf()
213 while (
214 prototype?.constructor &&
215 (!hasOwn(constructors, prototype.constructor.name) ||
216 constructors[prototype.constructor.name as BuiltinObjectKind]
217 ?.prototype !== prototype)
218 )
219 prototype = Object.getPrototypeOf(prototype)
220
221 const name = prototype?.constructor?.name
222 if (name === undefined || name === "Object") return undefined
223
224 return name as never
225}
226
227export const objectKindOrDomainOf = <data>(
228 data: data

Callers 5

parseObjectFunction · 0.90
canFillFunction · 0.90
baseNameOfFunction · 0.90
objectKindOrDomainOfFunction · 0.85
hasObjectKindFunction · 0.85

Calls 3

prototypeOfFunction · 0.90
hasOwnFunction · 0.90
builtinsOfFunction · 0.85

Tested by

no test coverage detected