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

Answer stability round 1: accept a plain object from another realm

This commit is contained in:
2026-10-05 01:03:17 +02:00
committed by Lillem4n
parent 02204b3b48
commit 0cdc56a56f
2 changed files with 4 additions and 2 deletions
+2 -2
View File
@@ -19,11 +19,11 @@ export function isJsonValue(value: unknown): value is JsonValue {
return true
}
// A Date, Map or class instance passes typeof but JSON writes it as {} or a key per element.
// Any realm's Object.prototype has a null prototype; a Date, Map or typed array would serialize 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
return prototype === null || (typeof prototype === 'object' && Object.getPrototypeOf(prototype) === null)
}
export function nestingDepth(value: unknown): number {