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:
+8
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user