(text)
| 132 | } |
| 133 | |
| 134 | function normalizeLooseJSONSource(text) { |
| 135 | let fixed = String(text).trim(); |
| 136 | |
| 137 | fixed = replaceOutsideQuotedSegments(fixed, /([\{,]\s*)'([^'\\]*?)'(\s*:)/g, function (match, prefix, key, suffix) { |
| 138 | return prefix + '"' + key + '"' + suffix; |
| 139 | }); |
| 140 | fixed = replaceOutsideQuotedSegments(fixed, /([\{,]\s*)(\w+)(\s*:)/g, function (match, prefix, key, suffix) { |
| 141 | return prefix + '"' + key + '"' + suffix; |
| 142 | }); |
| 143 | fixed = replaceOutsideQuotedSegments(fixed, /(:\s*)'([^'\\]*?)'/g, function (match, prefix, value) { |
| 144 | return prefix + '"' + value + '"'; |
| 145 | }); |
| 146 | |
| 147 | return fixed; |
| 148 | } |
| 149 | |
| 150 | export function isIntegerIndexKey(key) { |
| 151 | if (typeof key !== 'string' || !/^(0|[1-9]\d*)$/.test(key)) return false; |
no test coverage detected