3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-19 06:35:44 +01:00

4b - the walk reports its headroom, so a list falling back to the directive form refuses at zero and the list limit stays 500

This commit is contained in:
2026-09-18 00:34:52 +02:00
parent bd14b25b20
commit 9c0daa18d5
9 changed files with 94 additions and 64 deletions
+9 -4
View File
@@ -19,15 +19,20 @@ export function isJsonValue(value: unknown): value is JsonValue {
return true
}
export function overNested(value: JsonValue, levels: number = largestNesting): boolean {
const pending: { depth: number; item: JsonValue }[] = [{ depth: 0, item: value }]
export function nestingDepth(value: unknown): number {
const pending: { depth: number; item: unknown }[] = [{ depth: 0, item: value }]
let deepest = 0
while (pending.length > 0) {
const entry = pending.pop()
if (entry === undefined) continue
const { depth, item } = entry
if (depth > levels) return true
deepest = Math.max(deepest, depth)
if (Array.isArray(item)) for (const child of item) pending.push({ depth: depth + 1, item: child })
else if (item !== null && typeof item === 'object') for (const child of Object.values(item)) pending.push({ depth: depth + 1, item: child })
}
return false
return deepest
}
export function overNested(value: unknown, levels: number = largestNesting): boolean {
return nestingDepth(value) > levels
}