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

Function safeStringify

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

Source from the content-addressed store, hash-verified

277 }
278
279 function safeStringify(obj, space) {
280 const tagged = JSON.stringify(
281 obj,
282 function (_key, value) {
283 if (typeof value === 'bigint') {
284 return `__FH_BIGINT__${value.toString()}`;
285 }
286 if (typeof value === 'number' && value.toString().includes('e')) {
287 return `__FH_NUMSTR__${value.toLocaleString('fullwide', { useGrouping: false })}`;
288 }
289 if (isBigNumberLike(value)) {
290 return `__FH_BIGNUM__${getBigNumberDisplayString(value)}`;
291 }
292 return value;
293 },
294 space,
295 );
296
297 return tagged
298 .replace(/"__FH_BIGINT__(-?\d+)"/g, '$1')
299 .replace(/"__FH_NUMSTR__(-?\d+)"/g, '$1')
300 .replace(/"__FH_BIGNUM__(-?\d+(?:\.\d+)?)"/g, '$1')
301 .replace(new RegExp('"' + PRESERVED_INTEGER_KEY_PREFIX + '(\\d+)":', 'g'), '"$1":');
302 }
303
304 function unwrapJSONLikeSource(source, options) {
305 options = options || {};

Callers 1

parseJSONLikeFunction · 0.70

Calls 2

isBigNumberLikeFunction · 0.70

Tested by

no test coverage detected