(obj, space)
| 331 | |
| 332 | // ─── 安全的 safeStringify(保留 BigInt 精度)────────────── |
| 333 | export function safeStringify(obj, space) { |
| 334 | const tagged = JSON.stringify( |
| 335 | obj, |
| 336 | function (_key, value) { |
| 337 | if (typeof value === 'bigint') { |
| 338 | return `__FH_BIGINT__${value.toString()}`; |
| 339 | } |
| 340 | if (typeof value === 'number' && value.toString().includes('e')) { |
| 341 | return `__FH_NUMSTR__${value.toLocaleString('fullwide', { useGrouping: false })}`; |
| 342 | } |
| 343 | if (isBigNumberLike(value)) { |
| 344 | return `__FH_BIGNUM__${getBigNumberDisplayString(value)}`; |
| 345 | } |
| 346 | return value; |
| 347 | }, |
| 348 | space, |
| 349 | ); |
| 350 | return tagged |
| 351 | .replace(/"__FH_BIGINT__(-?\d+)"/g, '$1') |
| 352 | .replace(/"__FH_NUMSTR__(-?\d+)"/g, '$1') |
| 353 | .replace(/"__FH_BIGNUM__(-?\d+(?:\.\d+)?)"/g, '$1') |
| 354 | .replace(new RegExp('"' + PRESERVED_INTEGER_KEY_PREFIX + '(\\d+)":', 'g'), '"$1":'); |
| 355 | } |
| 356 | |
| 357 | // ─── 日期格式化(替代 Date.prototype.format 的纯函数版本)── |
| 358 | export function formatDate(date, pattern) { |
nothing calls this directly
no test coverage detected