(source, options)
| 419 | } |
| 420 | |
| 421 | function parseJSONLike(source, options) { |
| 422 | options = options || {}; |
| 423 | const meta = unwrapJSONLikeSource(source, options); |
| 424 | const candidates = buildJSONLikeCandidates(meta.source, options); |
| 425 | |
| 426 | for (let i = 0; i < candidates.length; i++) { |
| 427 | const candidate = candidates[i]; |
| 428 | let jsonObj = null; |
| 429 | const startsAsContainer = /^[\{\[]/.test(candidate); |
| 430 | const startsAsEscapedContainer = options.nestedEscapeParse && /^["']/.test(candidate); |
| 431 | |
| 432 | if (!startsAsContainer && !startsAsEscapedContainer) { |
| 433 | continue; |
| 434 | } |
| 435 | |
| 436 | try { |
| 437 | jsonObj = parseWithBigInt(candidate); |
| 438 | } catch (_) { |
| 439 | try { |
| 440 | jsonObj = new Function('return ' + candidate)(); |
| 441 | } catch (exx) { |
| 442 | try { |
| 443 | jsonObj = new Function("return '" + candidate + "'")(); |
| 444 | if (typeof jsonObj === 'string') { |
| 445 | try { |
| 446 | jsonObj = parseWithBigInt(jsonObj); |
| 447 | } catch (_) { |
| 448 | jsonObj = new Function('return ' + jsonObj)(); |
| 449 | } |
| 450 | } |
| 451 | } catch (_) { |
| 452 | continue; |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | if (options.nestedEscapeParse && typeof jsonObj === 'string') { |
| 458 | jsonObj = unpackTopLevelEscapedJSON(jsonObj); |
| 459 | } |
| 460 | if (options.nestedEscapeParse && isJSONContainer(jsonObj)) { |
| 461 | jsonObj = deepParseJSONStrings(jsonObj); |
| 462 | } |
| 463 | if (!isJSONContainer(jsonObj)) { |
| 464 | continue; |
| 465 | } |
| 466 | |
| 467 | try { |
| 468 | meta.source = candidate; |
| 469 | meta.normalizedSource = safeStringify(jsonObj); |
| 470 | meta.value = jsonObj; |
| 471 | return meta; |
| 472 | } catch (_) { |
| 473 | return null; |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | return null; |
| 478 | } |
no test coverage detected