(json: unknown, max: number)
| 357 | v === undefined || typeof v === "function" || typeof v === "symbol" |
| 358 | |
| 359 | const jsonPrefixOf = (json: unknown, max: number): string => { |
| 360 | if (max <= 0) return "" |
| 361 | if (typeof json !== "object" || json === null) |
| 362 | return JSON.stringify(json).slice(0, max) |
| 363 | const array = isArray(json) |
| 364 | let prefix = array ? "[" : "{" |
| 365 | for (const k of Object.keys(json)) { |
| 366 | if (prefix.length >= max) return prefix.slice(0, max) |
| 367 | const v = (json as Dict)[k] |
| 368 | if (!array && isUnwritten(v)) continue |
| 369 | if (prefix.length > 1) prefix += "," |
| 370 | if (!array) prefix += `${JSON.stringify(k)}:` |
| 371 | prefix += isUnwritten(v) ? "null" : jsonPrefixOf(v, max - prefix.length) |
| 372 | } |
| 373 | return `${prefix}${array ? "]" : "}"}`.slice(0, max) |
| 374 | } |
| 375 | |
| 376 | const digests = new WeakMap<object, string>() |
| 377 |
no test coverage detected