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

Function parseWithBigInt

apps/json-format/json-utils.js:213–236  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

211
212// ─── BigInt 安全解析(统一实现,替代 format-lib 和 json-worker 各自的版本)──
213export 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 字符串 ──────────────────────────────
239export function deepParseJSONStrings(obj) {

Callers 1

Calls 4

normalizeLooseJSONSourceFunction · 0.70
markIntegerIndexKeysFunction · 0.70
isInsideQuotedSegmentFunction · 0.70
parseMethod · 0.45

Tested by

no test coverage detected