3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-17 05:40:26 +01:00

Refuse an attribute value JSON does not hold, and push a folded callout's title leaves one at a time

This commit is contained in:
2026-10-05 00:59:46 +02:00
committed by Lillem4n
parent 59ea87f6aa
commit 7da3c1fbbe
7 changed files with 30 additions and 20 deletions
+8 -1
View File
@@ -13,12 +13,19 @@ export function isJsonValue(value: unknown): value is JsonValue {
}
// A hole is not a JSON value, and Array.prototype methods skip holes — spreading materialises them.
if (Array.isArray(item)) for (const child of [...item]) pending.push(child)
else if (typeof item === 'object') for (const child of Object.values(item)) pending.push(child)
else if (isPlainObject(item)) for (const child of Object.values(item)) pending.push(child)
else return false
}
return true
}
// A Date, Map or class instance passes typeof but JSON writes it as {} or a key per element.
function isPlainObject(value: unknown): value is object {
if (typeof value !== 'object' || value === null) return false
const prototype: unknown = Object.getPrototypeOf(value)
return prototype === Object.prototype || prototype === null
}
export function nestingDepth(value: unknown): number {
const pending: { depth: number; item: unknown }[] = [{ depth: 0, item: value }]
let deepest = 0