MCPcopy Create free account
hub / github.com/zxlie/FeHelper / safeStringify

Function safeStringify

apps/json-format/json-utils.js:333–355  ·  view source on GitHub ↗
(obj, space)

Source from the content-addressed store, hash-verified

331
332// ─── 安全的 safeStringify(保留 BigInt 精度)──────────────
333export 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 的纯函数版本)──
358export function formatDate(date, pattern) {

Callers

nothing calls this directly

Calls 2

isBigNumberLikeFunction · 0.70

Tested by

no test coverage detected