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

Function jsonLengthOf

ark/schema/node.ts:333–347  ·  view source on GitHub ↗
(json: unknown)

Source from the content-addressed store, hash-verified

331
332// approximate, memoized per object
333export const jsonLengthOf = (json: unknown): number => {
334 if (typeof json !== "object" || json === null)
335 return typeof json === "string" ? json.length + 2 : 5
336 let length = jsonLengths.get(json)
337 if (length !== undefined) return length
338 length = 2
339 let nests = false
340 for (const k in json) {
341 const v = (json as Dict)[k]
342 if (typeof v === "object" && v !== null) nests = true
343 length += k.length + 4 + jsonLengthOf(v)
344 }
345 if (nests) jsonLengths.set(json, length)
346 return length
347}
348
349export const holdsSameChildren = (l: BaseNode, r: BaseNode): boolean => {
350 if (l.children.length !== r.children.length) return false

Callers 3

instantiateMethod · 0.90
hashJsonOfFunction · 0.85
digestOfFunction · 0.85

Calls 2

getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected