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

Function parseWithBigInt

apps/json-format/json-auto-utils.js:201–223  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

199 }
200
201 function parseWithBigInt(text) {
202 const fixed = normalizeLooseJSONSource(text);
203 const ordered = markIntegerIndexKeys(fixed);
204
205 const marked = ordered.replace(
206 /([:,\[]\s*)(-?\d{16,})(\s*)(?=(?:,|\]|\}|$))/g,
207 function (match, prefix, number, spaces, offset) {
208 if (isInsideQuotedSegment(ordered, offset)) return match;
209 return prefix + '"__BigInt__' + number + '"' + spaces;
210 },
211 );
212
213 return JSON.parse(marked, function (_key, value) {
214 if (typeof value === 'string' && value.startsWith('__BigInt__')) {
215 try {
216 return BigInt(value.slice(10));
217 } catch (_) {
218 return value.slice(10);
219 }
220 }
221 return value;
222 });
223 }
224
225 function isJSONContainer(value) {
226 if (typeof value !== 'object' || value === null) return false;

Callers 3

deepParseJSONStringsFunction · 0.70
parseJSONLikeFunction · 0.70

Calls 4

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

Tested by

no test coverage detected