(text)
| 211 | |
| 212 | // ─── BigInt 安全解析(统一实现,替代 format-lib 和 json-worker 各自的版本)── |
| 213 | export function parseWithBigInt(text) { |
| 214 | let fixed = normalizeLooseJSONSource(text); |
| 215 | const ordered = markIntegerIndexKeys(fixed); |
| 216 | |
| 217 | // 3) 标记 16 位及以上的整数,确保不在字符串内部 |
| 218 | const marked = ordered.replace( |
| 219 | /([:,\[]\s*)(-?\d{16,})(\s*)(?=[,\]\}])/g, |
| 220 | function (match, prefix, number, spaces, offset) { |
| 221 | if (isInsideQuotedSegment(ordered, offset)) return match; |
| 222 | return prefix + '"__BigInt__' + number + '"' + spaces; |
| 223 | }, |
| 224 | ); |
| 225 | |
| 226 | return JSON.parse(marked, function (_key, value) { |
| 227 | if (typeof value === 'string' && value.startsWith('__BigInt__')) { |
| 228 | try { |
| 229 | return BigInt(value.slice(10)); |
| 230 | } catch (_) { |
| 231 | return value.slice(10); |
| 232 | } |
| 233 | } |
| 234 | return value; |
| 235 | }); |
| 236 | } |
| 237 | |
| 238 | // ─── 深度解包嵌套 JSON 字符串 ────────────────────────────── |
| 239 | export function deepParseJSONStrings(obj) { |
no test coverage detected