jsonrepair
Advanced tools
Comparing version 3.6.1 to 3.7.0
@@ -465,5 +465,10 @@ "use strict"; | ||
i++; | ||
if (expectDigitOrRepair(start)) { | ||
if (atEndOfNumber()) { | ||
repairNumberEndingWithNumericSymbol(start); | ||
return true; | ||
} | ||
if (!(0, _stringUtils.isDigit)(text.charCodeAt(i))) { | ||
i = start; | ||
return false; | ||
} | ||
} | ||
@@ -480,5 +485,10 @@ | ||
i++; | ||
if (expectDigitOrRepair(start)) { | ||
if (atEndOfNumber()) { | ||
repairNumberEndingWithNumericSymbol(start); | ||
return true; | ||
} | ||
if (!(0, _stringUtils.isDigit)(text.charCodeAt(i))) { | ||
i = start; | ||
return false; | ||
} | ||
while ((0, _stringUtils.isDigit)(text.charCodeAt(i))) { | ||
@@ -493,5 +503,10 @@ i++; | ||
} | ||
if (expectDigitOrRepair(start)) { | ||
if (atEndOfNumber()) { | ||
repairNumberEndingWithNumericSymbol(start); | ||
return true; | ||
} | ||
if (!(0, _stringUtils.isDigit)(text.charCodeAt(i))) { | ||
i = start; | ||
return false; | ||
} | ||
while ((0, _stringUtils.isDigit)(text.charCodeAt(i))) { | ||
@@ -501,2 +516,8 @@ i++; | ||
} | ||
// if we're not at the end of the number by this point, allow this to be parsed as another type | ||
if (!atEndOfNumber()) { | ||
i = start; | ||
return false; | ||
} | ||
if (i > start) { | ||
@@ -531,3 +552,3 @@ // repair a number with leading zeros like "00789" | ||
/** | ||
* Repair and unquoted string by adding quotes around it | ||
* Repair an unquoted string by adding quotes around it | ||
* Repair a MongoDB function call like NumberLong("2") | ||
@@ -538,4 +559,5 @@ * Repair a JSONP function call like callback({...}); | ||
// note that the symbol can end with whitespaces: we stop at the next delimiter | ||
// also, note that we allow strings to contain a slash / in order to support repairing regular expressions | ||
const start = i; | ||
while (i < text.length && !(0, _stringUtils.isDelimiter)(text[i]) && !(0, _stringUtils.isQuote)(text.charCodeAt(i))) { | ||
while (i < text.length && !(0, _stringUtils.isDelimiterExceptSlash)(text[i]) && !(0, _stringUtils.isQuote)(text.charCodeAt(i))) { | ||
i++; | ||
@@ -583,19 +605,10 @@ } | ||
} | ||
function expectDigit(start) { | ||
if (!(0, _stringUtils.isDigit)(text.charCodeAt(i))) { | ||
const numSoFar = text.slice(start, i); | ||
throw new _JSONRepairError.JSONRepairError("Invalid number '".concat(numSoFar, "', expecting a digit ").concat(got()), i); | ||
} | ||
function atEndOfNumber() { | ||
return i >= text.length || (0, _stringUtils.isDelimiter)(text[i]) || (0, _stringUtils.isWhitespace)(text.charCodeAt(i)); | ||
} | ||
function expectDigitOrRepair(start) { | ||
if (i >= text.length) { | ||
// repair numbers cut off at the end | ||
// this will only be called when we end after a '.', '-', or 'e' and does not | ||
// change the number more than it needs to make it valid JSON | ||
output += text.slice(start, i) + '0'; | ||
return true; | ||
} else { | ||
expectDigit(start); | ||
return false; | ||
} | ||
function repairNumberEndingWithNumericSymbol(start) { | ||
// repair numbers cut off at the end | ||
// this will only be called when we end after a '.', '-', or 'e' and does not | ||
// change the number more than it needs to make it valid JSON | ||
output += text.slice(start, i) + '0'; | ||
} | ||
@@ -621,5 +634,2 @@ function throwInvalidCharacter(char) { | ||
} | ||
function got() { | ||
return text[i] ? "but got '".concat(text[i], "'") : 'but reached end of input'; | ||
} | ||
} | ||
@@ -626,0 +636,0 @@ function atEndOfBlockComment(text, i) { |
@@ -561,5 +561,10 @@ "use strict"; | ||
i++; | ||
if (expectDigitOrRepair(start)) { | ||
if (atEndOfNumber()) { | ||
repairNumberEndingWithNumericSymbol(start); | ||
return stack.update(_stack.Caret.afterValue); | ||
} | ||
if (!(0, _stringUtils.isDigit)(input.charCodeAt(i))) { | ||
i = start; | ||
return false; | ||
} | ||
} | ||
@@ -576,5 +581,10 @@ | ||
i++; | ||
if (expectDigitOrRepair(start)) { | ||
if (atEndOfNumber()) { | ||
repairNumberEndingWithNumericSymbol(start); | ||
return stack.update(_stack.Caret.afterValue); | ||
} | ||
if (!(0, _stringUtils.isDigit)(input.charCodeAt(i))) { | ||
i = start; | ||
return false; | ||
} | ||
while ((0, _stringUtils.isDigit)(input.charCodeAt(i))) { | ||
@@ -589,5 +599,10 @@ i++; | ||
} | ||
if (expectDigitOrRepair(start)) { | ||
if (atEndOfNumber()) { | ||
repairNumberEndingWithNumericSymbol(start); | ||
return stack.update(_stack.Caret.afterValue); | ||
} | ||
if (!(0, _stringUtils.isDigit)(input.charCodeAt(i))) { | ||
i = start; | ||
return false; | ||
} | ||
while ((0, _stringUtils.isDigit)(input.charCodeAt(i))) { | ||
@@ -597,2 +612,8 @@ i++; | ||
} | ||
// if we're not at the end of the number by this point, allow this to be parsed as another type | ||
if (!atEndOfNumber()) { | ||
i = start; | ||
return false; | ||
} | ||
if (i > start) { | ||
@@ -645,4 +666,5 @@ // repair a number with leading zeros like "00789" | ||
// note that the symbol can end with whitespaces: we stop at the next delimiter | ||
// also, note that we allow strings to contain a slash / in order to support repairing regular expressions | ||
let j = i; | ||
while (!input.isEnd(j) && !(0, _stringUtils.isDelimiter)(input.charAt(j)) && !(0, _stringUtils.isQuote)(input.charCodeAt(j))) { | ||
while (!input.isEnd(j) && !(0, _stringUtils.isDelimiterExceptSlash)(input.charAt(j)) && !(0, _stringUtils.isQuote)(input.charCodeAt(j))) { | ||
j++; | ||
@@ -659,19 +681,10 @@ } | ||
} | ||
function expectDigit(start) { | ||
if (!(0, _stringUtils.isDigit)(input.charCodeAt(i))) { | ||
const numSoFar = input.substring(start, i); | ||
throw new _JSONRepairError.JSONRepairError("Invalid number '".concat(numSoFar, "', expecting a digit ").concat(got()), i); | ||
} | ||
function atEndOfNumber() { | ||
return input.isEnd(i) || (0, _stringUtils.isDelimiter)(input.charAt(i)) || (0, _stringUtils.isWhitespace)(input.charCodeAt(i)); | ||
} | ||
function expectDigitOrRepair(start) { | ||
if (input.isEnd(i)) { | ||
// repair numbers cut off at the end | ||
// this will only be called when we end after a '.', '-', or 'e' and does not | ||
// change the number more than it needs to make it valid JSON | ||
output.push(input.substring(start, i) + '0'); | ||
return true; | ||
} else { | ||
expectDigit(start); | ||
return false; | ||
} | ||
function repairNumberEndingWithNumericSymbol(start) { | ||
// repair numbers cut off at the end | ||
// this will only be called when we end after a '.', '-', or 'e' and does not | ||
// change the number more than it needs to make it valid JSON | ||
output.push(input.substring(start, i) + '0'); | ||
} | ||
@@ -697,6 +710,2 @@ function throwInvalidCharacter(char) { | ||
} | ||
function got() { | ||
const char = input.charAt(i); | ||
return char ? "but got '".concat(char, "'") : 'but reached end of input'; | ||
} | ||
function atEndOfBlockComment(i) { | ||
@@ -703,0 +712,0 @@ return input.charAt(i) === '*' && input.charAt(i + 1) === '/'; |
@@ -11,2 +11,3 @@ "use strict"; | ||
exports.isDelimiter = isDelimiter; | ||
exports.isDelimiterExceptSlash = isDelimiterExceptSlash; | ||
exports.isDigit = isDigit; | ||
@@ -82,2 +83,5 @@ exports.isDoubleQuote = isDoubleQuote; | ||
const regexDelimiter = /^[,:[\]/{}()\n+]$/; | ||
function isDelimiterExceptSlash(char) { | ||
return isDelimiter(char) && char !== '/'; | ||
} | ||
function isStartOfValue(char) { | ||
@@ -84,0 +88,0 @@ return regexStartOfValue.test(char) || char && isQuote(char.charCodeAt(0)); |
import { JSONRepairError } from '../utils/JSONRepairError.js'; | ||
import { codeAsterisk, codeBackslash, codeCloseParenthesis, codeClosingBrace, codeClosingBracket, codeColon, codeComma, codeDot, codeDoubleQuote, codeLowercaseE, codeMinus, codeNewline, codeOpeningBrace, codeOpeningBracket, codeOpenParenthesis, codePlus, codeSemicolon, codeSlash, codeUppercaseE, endsWithCommaOrNewline, insertBeforeLastWhitespace, isControlCharacter, isDelimiter, isDigit, isDoubleQuote, isDoubleQuoteLike, isHex, isQuote, isSingleQuote, isSingleQuoteLike, isSpecialWhitespace, isStartOfValue, isValidStringCharacter, isWhitespace, removeAtIndex, stripLastOccurrence } from '../utils/stringUtils.js'; | ||
import { codeAsterisk, codeBackslash, codeCloseParenthesis, codeClosingBrace, codeClosingBracket, codeColon, codeComma, codeDot, codeDoubleQuote, codeLowercaseE, codeMinus, codeNewline, codeOpeningBrace, codeOpeningBracket, codeOpenParenthesis, codePlus, codeSemicolon, codeSlash, codeUppercaseE, endsWithCommaOrNewline, insertBeforeLastWhitespace, isControlCharacter, isDelimiter, isDelimiterExceptSlash, isDigit, isDoubleQuote, isDoubleQuoteLike, isHex, isQuote, isSingleQuote, isSingleQuoteLike, isSpecialWhitespace, isStartOfValue, isValidStringCharacter, isWhitespace, removeAtIndex, stripLastOccurrence } from '../utils/stringUtils.js'; | ||
const controlCharacters = { | ||
@@ -459,5 +459,10 @@ '\b': '\\b', | ||
i++; | ||
if (expectDigitOrRepair(start)) { | ||
if (atEndOfNumber()) { | ||
repairNumberEndingWithNumericSymbol(start); | ||
return true; | ||
} | ||
if (!isDigit(text.charCodeAt(i))) { | ||
i = start; | ||
return false; | ||
} | ||
} | ||
@@ -474,5 +479,10 @@ | ||
i++; | ||
if (expectDigitOrRepair(start)) { | ||
if (atEndOfNumber()) { | ||
repairNumberEndingWithNumericSymbol(start); | ||
return true; | ||
} | ||
if (!isDigit(text.charCodeAt(i))) { | ||
i = start; | ||
return false; | ||
} | ||
while (isDigit(text.charCodeAt(i))) { | ||
@@ -487,5 +497,10 @@ i++; | ||
} | ||
if (expectDigitOrRepair(start)) { | ||
if (atEndOfNumber()) { | ||
repairNumberEndingWithNumericSymbol(start); | ||
return true; | ||
} | ||
if (!isDigit(text.charCodeAt(i))) { | ||
i = start; | ||
return false; | ||
} | ||
while (isDigit(text.charCodeAt(i))) { | ||
@@ -495,2 +510,8 @@ i++; | ||
} | ||
// if we're not at the end of the number by this point, allow this to be parsed as another type | ||
if (!atEndOfNumber()) { | ||
i = start; | ||
return false; | ||
} | ||
if (i > start) { | ||
@@ -525,3 +546,3 @@ // repair a number with leading zeros like "00789" | ||
/** | ||
* Repair and unquoted string by adding quotes around it | ||
* Repair an unquoted string by adding quotes around it | ||
* Repair a MongoDB function call like NumberLong("2") | ||
@@ -532,4 +553,5 @@ * Repair a JSONP function call like callback({...}); | ||
// note that the symbol can end with whitespaces: we stop at the next delimiter | ||
// also, note that we allow strings to contain a slash / in order to support repairing regular expressions | ||
const start = i; | ||
while (i < text.length && !isDelimiter(text[i]) && !isQuote(text.charCodeAt(i))) { | ||
while (i < text.length && !isDelimiterExceptSlash(text[i]) && !isQuote(text.charCodeAt(i))) { | ||
i++; | ||
@@ -577,19 +599,10 @@ } | ||
} | ||
function expectDigit(start) { | ||
if (!isDigit(text.charCodeAt(i))) { | ||
const numSoFar = text.slice(start, i); | ||
throw new JSONRepairError("Invalid number '".concat(numSoFar, "', expecting a digit ").concat(got()), i); | ||
} | ||
function atEndOfNumber() { | ||
return i >= text.length || isDelimiter(text[i]) || isWhitespace(text.charCodeAt(i)); | ||
} | ||
function expectDigitOrRepair(start) { | ||
if (i >= text.length) { | ||
// repair numbers cut off at the end | ||
// this will only be called when we end after a '.', '-', or 'e' and does not | ||
// change the number more than it needs to make it valid JSON | ||
output += text.slice(start, i) + '0'; | ||
return true; | ||
} else { | ||
expectDigit(start); | ||
return false; | ||
} | ||
function repairNumberEndingWithNumericSymbol(start) { | ||
// repair numbers cut off at the end | ||
// this will only be called when we end after a '.', '-', or 'e' and does not | ||
// change the number more than it needs to make it valid JSON | ||
output += text.slice(start, i) + '0'; | ||
} | ||
@@ -615,5 +628,2 @@ function throwInvalidCharacter(char) { | ||
} | ||
function got() { | ||
return text[i] ? "but got '".concat(text[i], "'") : 'but reached end of input'; | ||
} | ||
} | ||
@@ -620,0 +630,0 @@ function atEndOfBlockComment(text, i) { |
@@ -5,3 +5,3 @@ import { createInputBuffer } from './buffer/InputBuffer.js'; | ||
import { Caret, createStack, StackType } from './stack.js'; | ||
import { codeAsterisk, codeBackslash, codeCloseParenthesis, codeClosingBrace, codeClosingBracket, codeColon, codeComma, codeDot, codeDoubleQuote, codeLowercaseE, codeMinus, codeNewline, codeOpeningBrace, codeOpeningBracket, codeOpenParenthesis, codePlus, codeSemicolon, codeSlash, codeUppercaseE, isControlCharacter, isDelimiter, isDigit, isDoubleQuote, isDoubleQuoteLike, isHex, isQuote, isSingleQuote, isSingleQuoteLike, isSpecialWhitespace, isStartOfValue, isValidStringCharacter, isWhitespace } from '../utils/stringUtils.js'; | ||
import { codeAsterisk, codeBackslash, codeCloseParenthesis, codeClosingBrace, codeClosingBracket, codeColon, codeComma, codeDot, codeDoubleQuote, codeLowercaseE, codeMinus, codeNewline, codeOpeningBrace, codeOpeningBracket, codeOpenParenthesis, codePlus, codeSemicolon, codeSlash, codeUppercaseE, isControlCharacter, isDelimiter, isDelimiterExceptSlash, isDigit, isDoubleQuote, isDoubleQuoteLike, isHex, isQuote, isSingleQuote, isSingleQuoteLike, isSpecialWhitespace, isStartOfValue, isValidStringCharacter, isWhitespace } from '../utils/stringUtils.js'; | ||
const controlCharacters = { | ||
@@ -556,5 +556,10 @@ '\b': '\\b', | ||
i++; | ||
if (expectDigitOrRepair(start)) { | ||
if (atEndOfNumber()) { | ||
repairNumberEndingWithNumericSymbol(start); | ||
return stack.update(Caret.afterValue); | ||
} | ||
if (!isDigit(input.charCodeAt(i))) { | ||
i = start; | ||
return false; | ||
} | ||
} | ||
@@ -571,5 +576,10 @@ | ||
i++; | ||
if (expectDigitOrRepair(start)) { | ||
if (atEndOfNumber()) { | ||
repairNumberEndingWithNumericSymbol(start); | ||
return stack.update(Caret.afterValue); | ||
} | ||
if (!isDigit(input.charCodeAt(i))) { | ||
i = start; | ||
return false; | ||
} | ||
while (isDigit(input.charCodeAt(i))) { | ||
@@ -584,5 +594,10 @@ i++; | ||
} | ||
if (expectDigitOrRepair(start)) { | ||
if (atEndOfNumber()) { | ||
repairNumberEndingWithNumericSymbol(start); | ||
return stack.update(Caret.afterValue); | ||
} | ||
if (!isDigit(input.charCodeAt(i))) { | ||
i = start; | ||
return false; | ||
} | ||
while (isDigit(input.charCodeAt(i))) { | ||
@@ -592,2 +607,8 @@ i++; | ||
} | ||
// if we're not at the end of the number by this point, allow this to be parsed as another type | ||
if (!atEndOfNumber()) { | ||
i = start; | ||
return false; | ||
} | ||
if (i > start) { | ||
@@ -640,4 +661,5 @@ // repair a number with leading zeros like "00789" | ||
// note that the symbol can end with whitespaces: we stop at the next delimiter | ||
// also, note that we allow strings to contain a slash / in order to support repairing regular expressions | ||
let j = i; | ||
while (!input.isEnd(j) && !isDelimiter(input.charAt(j)) && !isQuote(input.charCodeAt(j))) { | ||
while (!input.isEnd(j) && !isDelimiterExceptSlash(input.charAt(j)) && !isQuote(input.charCodeAt(j))) { | ||
j++; | ||
@@ -654,19 +676,10 @@ } | ||
} | ||
function expectDigit(start) { | ||
if (!isDigit(input.charCodeAt(i))) { | ||
const numSoFar = input.substring(start, i); | ||
throw new JSONRepairError("Invalid number '".concat(numSoFar, "', expecting a digit ").concat(got()), i); | ||
} | ||
function atEndOfNumber() { | ||
return input.isEnd(i) || isDelimiter(input.charAt(i)) || isWhitespace(input.charCodeAt(i)); | ||
} | ||
function expectDigitOrRepair(start) { | ||
if (input.isEnd(i)) { | ||
// repair numbers cut off at the end | ||
// this will only be called when we end after a '.', '-', or 'e' and does not | ||
// change the number more than it needs to make it valid JSON | ||
output.push(input.substring(start, i) + '0'); | ||
return true; | ||
} else { | ||
expectDigit(start); | ||
return false; | ||
} | ||
function repairNumberEndingWithNumericSymbol(start) { | ||
// repair numbers cut off at the end | ||
// this will only be called when we end after a '.', '-', or 'e' and does not | ||
// change the number more than it needs to make it valid JSON | ||
output.push(input.substring(start, i) + '0'); | ||
} | ||
@@ -692,6 +705,2 @@ function throwInvalidCharacter(char) { | ||
} | ||
function got() { | ||
const char = input.charAt(i); | ||
return char ? "but got '".concat(char, "'") : 'but reached end of input'; | ||
} | ||
function atEndOfBlockComment(i) { | ||
@@ -698,0 +707,0 @@ return input.charAt(i) === '*' && input.charAt(i + 1) === '/'; |
@@ -58,2 +58,5 @@ export const codeBackslash = 0x5c; // "\" | ||
const regexDelimiter = /^[,:[\]/{}()\n+]$/; | ||
export function isDelimiterExceptSlash(char) { | ||
return isDelimiter(char) && char !== '/'; | ||
} | ||
export function isStartOfValue(char) { | ||
@@ -60,0 +63,0 @@ return regexStartOfValue.test(char) || char && isQuote(char.charCodeAt(0)); |
@@ -36,2 +36,3 @@ export declare const codeBackslash = 92; | ||
export declare function isDelimiter(char: string): boolean; | ||
export declare function isDelimiterExceptSlash(char: string): boolean; | ||
export declare function isStartOfValue(char: string): boolean; | ||
@@ -38,0 +39,0 @@ export declare function isControlCharacter(code: number): boolean; |
@@ -71,2 +71,5 @@ (function (global, factory) { | ||
const regexDelimiter = /^[,:[\]/{}()\n+]$/; | ||
function isDelimiterExceptSlash(char) { | ||
return isDelimiter(char) && char !== '/'; | ||
} | ||
function isStartOfValue(char) { | ||
@@ -626,5 +629,10 @@ return regexStartOfValue.test(char) || char && isQuote(char.charCodeAt(0)); | ||
i++; | ||
if (expectDigitOrRepair(start)) { | ||
if (atEndOfNumber()) { | ||
repairNumberEndingWithNumericSymbol(start); | ||
return true; | ||
} | ||
if (!isDigit(text.charCodeAt(i))) { | ||
i = start; | ||
return false; | ||
} | ||
} | ||
@@ -641,5 +649,10 @@ | ||
i++; | ||
if (expectDigitOrRepair(start)) { | ||
if (atEndOfNumber()) { | ||
repairNumberEndingWithNumericSymbol(start); | ||
return true; | ||
} | ||
if (!isDigit(text.charCodeAt(i))) { | ||
i = start; | ||
return false; | ||
} | ||
while (isDigit(text.charCodeAt(i))) { | ||
@@ -654,5 +667,10 @@ i++; | ||
} | ||
if (expectDigitOrRepair(start)) { | ||
if (atEndOfNumber()) { | ||
repairNumberEndingWithNumericSymbol(start); | ||
return true; | ||
} | ||
if (!isDigit(text.charCodeAt(i))) { | ||
i = start; | ||
return false; | ||
} | ||
while (isDigit(text.charCodeAt(i))) { | ||
@@ -662,2 +680,8 @@ i++; | ||
} | ||
// if we're not at the end of the number by this point, allow this to be parsed as another type | ||
if (!atEndOfNumber()) { | ||
i = start; | ||
return false; | ||
} | ||
if (i > start) { | ||
@@ -692,3 +716,3 @@ // repair a number with leading zeros like "00789" | ||
/** | ||
* Repair and unquoted string by adding quotes around it | ||
* Repair an unquoted string by adding quotes around it | ||
* Repair a MongoDB function call like NumberLong("2") | ||
@@ -699,4 +723,5 @@ * Repair a JSONP function call like callback({...}); | ||
// note that the symbol can end with whitespaces: we stop at the next delimiter | ||
// also, note that we allow strings to contain a slash / in order to support repairing regular expressions | ||
const start = i; | ||
while (i < text.length && !isDelimiter(text[i]) && !isQuote(text.charCodeAt(i))) { | ||
while (i < text.length && !isDelimiterExceptSlash(text[i]) && !isQuote(text.charCodeAt(i))) { | ||
i++; | ||
@@ -744,19 +769,10 @@ } | ||
} | ||
function expectDigit(start) { | ||
if (!isDigit(text.charCodeAt(i))) { | ||
const numSoFar = text.slice(start, i); | ||
throw new JSONRepairError("Invalid number '".concat(numSoFar, "', expecting a digit ").concat(got()), i); | ||
} | ||
function atEndOfNumber() { | ||
return i >= text.length || isDelimiter(text[i]) || isWhitespace(text.charCodeAt(i)); | ||
} | ||
function expectDigitOrRepair(start) { | ||
if (i >= text.length) { | ||
// repair numbers cut off at the end | ||
// this will only be called when we end after a '.', '-', or 'e' and does not | ||
// change the number more than it needs to make it valid JSON | ||
output += text.slice(start, i) + '0'; | ||
return true; | ||
} else { | ||
expectDigit(start); | ||
return false; | ||
} | ||
function repairNumberEndingWithNumericSymbol(start) { | ||
// repair numbers cut off at the end | ||
// this will only be called when we end after a '.', '-', or 'e' and does not | ||
// change the number more than it needs to make it valid JSON | ||
output += text.slice(start, i) + '0'; | ||
} | ||
@@ -782,5 +798,2 @@ function throwInvalidCharacter(char) { | ||
} | ||
function got() { | ||
return text[i] ? "but got '".concat(text[i], "'") : 'but reached end of input'; | ||
} | ||
} | ||
@@ -787,0 +800,0 @@ function atEndOfBlockComment(text, i) { |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).JSONRepair={})}(this,function(t){"use strict";class x extends Error{constructor(t,e){super(t+" at position "+e),this.position=e}}const u=125,e=32,y=10,O=9,N=13,J=8,S=12,j=34,r=39,I=48,k=57,m=65,T=97,$=70,E=102,h=160,d=8192,l=8202,R=8239,U=8287,F=12288,n=8220,o=8221,c=8216,i=8217,f=96,a=180;function q(t){return t>=I&&t<=k}function z(t){return s.test(t)}const s=/^[,:[\]/{}()\n+]$/;function B(t){return A.test(t)||t&&G(t.charCodeAt(0))}const A=/^[[{\w-]$/;function D(t){return t===e||t===y||t===O||t===N}function G(t){return H(t)||L(t)}function H(t){return t===j||t===n||t===o}function K(t){return t===j}function L(t){return t===r||t===c||t===i||t===f||t===a}function M(t){return t===r}function P(t,e,r){r=2<arguments.length&&void 0!==r&&r,e=t.lastIndexOf(e);return-1!==e?t.substring(0,e)+(r?"":t.substring(e+1)):t}function Q(t,e){let r=t.length;if(!D(t.charCodeAt(r-1)))return t+e;for(;D(t.charCodeAt(r-1));)r--;return t.substring(0,r)+e+t.substring(r)}const V={"\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t"},W={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};t.JSONRepairError=x,t.jsonrepair=function(s){let A=0,C="";if(!c())throw new x("Unexpected end of json string",s.length);var t=i(44);if(t&&g(),B(s[A])&&/[,\n][ \t\r]*$/.test(C)){t||(C=Q(C,","));{let t=!0,e=!0;for(;e;)t?t=!1:i(44)||(C=Q(C,",")),e=c();e||(C=P(C,","));C="[\n".concat(C,"\n]")}}else t&&(C=P(C,","));for(;s.charCodeAt(A)===u||93===s.charCodeAt(A);)A++,g();if(A>=s.length)return C;throw new x("Unexpected character "+JSON.stringify(s[A]),A);function c(){g();var t=function(){if(123!==s.charCodeAt(A))return!1;{C+="{",A++,g();let e=!0;for(;A<s.length&&s.charCodeAt(A)!==u;){let t;if(e?(t=!0,e=!1):((t=i(44))||(C=Q(C,",")),g()),!(v()||f())){s.charCodeAt(A)===u||123===s.charCodeAt(A)||93===s.charCodeAt(A)||91===s.charCodeAt(A)||void 0===s[A]?C=P(C,","):function(){throw new x("Object key expected",A)}();break}g();var r=i(58),n=A>=s.length,o=(r||(B(s[A])||n?C=Q(C,":"):a()),c());o||(r||n?C+="null":a())}return s.charCodeAt(A)===u?(C+="}",A++):C=Q(C,"}"),!0}}()||function(){if(91!==s.charCodeAt(A))return!1;{C+="[",A++,g();let t=!0;for(;A<s.length&&93!==s.charCodeAt(A);){t?t=!1:i(44)||(C=Q(C,","));var e=c();if(!e){C=P(C,",");break}}return 93===s.charCodeAt(A)?(C+="]",A++):C=Q(C,"]"),!0}}()||v()||function(){var t=A;if(45===s.charCodeAt(A)&&(A++,o(t)))return!0;for(;q(s.charCodeAt(A));)A++;if(46===s.charCodeAt(A)){if(A++,o(t))return!0;for(;q(s.charCodeAt(A));)A++}if(101===s.charCodeAt(A)||69===s.charCodeAt(A)){if(A++,45!==s.charCodeAt(A)&&43!==s.charCodeAt(A)||A++,o(t))return!0;for(;q(s.charCodeAt(A));)A++}{var e;if(A>t)return t=s.slice(t,A),e=/^0\d/.test(t),C+=e?'"'.concat(t,'"'):t,!0}return!1}()||r("true","true")||r("false","false")||r("null","null")||r("True","true")||r("False","false")||r("None","null")||f();return g(),t}function g(){A;let t=e();for(;t=(t=function(){if(47===s.charCodeAt(A)&&42===s.charCodeAt(A+1)){for(;A<s.length&&!function(t,e){return"*"===t[e]&&"/"===t[e+1]}(s,A);)A++;A+=2}else{if(47!==s.charCodeAt(A)||47!==s.charCodeAt(A+1))return!1;for(;A<s.length&&s.charCodeAt(A)!==y;)A++}return!0}())&&e(););A}function e(){let t="";for(var e,r;(e=D(s.charCodeAt(A)))||(r=s.charCodeAt(A))===h||r>=d&&r<=l||r===R||r===U||r===F;)t+=e?s[A]:" ",A++;return 0<t.length&&(C+=t,!0)}function i(t){return s.charCodeAt(A)===t&&(C+=s[A],A++,!0)}function b(){92===s.charCodeAt(A)&&A++}function v(t){var r,n,o=0<arguments.length&&void 0!==t&&t;let c=92===s.charCodeAt(A);if(c&&(A++,c=!0),G(s.charCodeAt(A))){var i=K(s.charCodeAt(A))?K:M(s.charCodeAt(A))?M:L(s.charCodeAt(A))?L:H,f=A,a=C.length;let e='"';for(A++;;){if(A>=s.length)return u=w(A-1),!o&&z(s.charAt(u))?(A=f,C=C.substring(0,a),v(!0)):(e=Q(e,'"'),C+=e,!0);if(i(s.charCodeAt(A))){var u=A,h=e.length;if(e+='"',A++,C+=e,g(),o||A>=s.length||z(s.charAt(A))||G(s.charCodeAt(A))||q(s.charCodeAt(A)))return p(),!0;if(z(s.charAt(w(u-1))))return A=f,C=C.substring(0,a),v(!0);C=C.substring(0,a),A=u+1,e=e.substring(0,h)+"\\"+e.substring(h)}else{if(o&&z(s[A]))return e=Q(e,'"'),C+=e,p(),!0;if(92===s.charCodeAt(A)){h=s.charAt(A+1);if(void 0!==W[h])e+=s.slice(A,A+2),A+=2;else if("u"===h){let t=2;for(;t<6&&((n=s.charCodeAt(A+t))>=I&&n<=k||n>=m&&n<=$||n>=T&&n<=E);)t++;if(6===t)e+=s.slice(A,A+6),A+=6;else{if(!(A+t>=s.length))throw d=void 0,d=s.slice(A,A+6),new x('Invalid unicode character "'.concat(d,'"'),A);A=s.length}}else e+=h,A+=2}else{var d=s.charAt(A),l=s.charCodeAt(A);if(l===j&&92!==s.charCodeAt(A-1))e+="\\"+d;else if((r=l)===y||r===N||r===O||r===J||r===S)e+=V[d];else{if(!(32<=(r=l)&&r<=1114111))throw l=void 0,l=d,new x("Invalid character "+JSON.stringify(l),A);e+=d}A++}}c&&b()}}return!1}function p(){let t=!1;for(g();43===s.charCodeAt(A);){t=!0,A++,g();var e=(C=P(C,'"',!0)).length,r=v();C=r?(r=C,e=e,n=1,r.substring(0,e)+r.substring(e+n)):Q(C,'"')}var n;t}function r(t,e){return s.slice(A,A+t.length)===t&&(C+=e,A+=t.length,!0)}function f(){for(var t=A;A<s.length&&!z(s[A])&&!G(s.charCodeAt(A));)A++;if(A>t){if(40===s.charCodeAt(A))A++,c(),41===s.charCodeAt(A)&&(A++,59===s.charCodeAt(A))&&A++;else{for(;D(s.charCodeAt(A-1))&&0<A;)A--;t=s.slice(t,A);C+="undefined"===t?"null":JSON.stringify(t),s.charCodeAt(A)===j&&A++}return!0}}function w(t){let e=t;for(;0<e&&D(s.charCodeAt(e));)e--;return e}function n(t){if(!q(s.charCodeAt(A)))throw t=s.slice(t,A),new x("Invalid number '".concat(t,"', expecting a digit ").concat(s[A]?"but got '".concat(s[A],"'"):"but reached end of input"),A)}function o(t){if(A>=s.length)return C+=s.slice(t,A)+"0",1;n(t)}function a(){throw new x("Colon expected",A)}}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).JSONRepair={})}(this,function(t){"use strict";class x extends Error{constructor(t,e){super(t+" at position "+e),this.position=e}}const a=125,e=32,y=10,O=9,N=13,J=8,S=12,j=34,r=39,k=48,I=57,T=65,$=97,m=70,E=102,h=160,d=8192,l=8202,R=8239,U=8287,F=12288,n=8220,o=8221,c=8216,i=8217,f=96,u=180;function q(t){return t>=k&&t<=I}function z(t){return s.test(t)}const s=/^[,:[\]/{}()\n+]$/;function B(t){return A.test(t)||t&&G(t.charCodeAt(0))}const A=/^[[{\w-]$/;function D(t){return t===e||t===y||t===O||t===N}function G(t){return H(t)||L(t)}function H(t){return t===j||t===n||t===o}function K(t){return t===j}function L(t){return t===r||t===c||t===i||t===f||t===u}function M(t){return t===r}function P(t,e,r){r=2<arguments.length&&void 0!==r&&r,e=t.lastIndexOf(e);return-1!==e?t.substring(0,e)+(r?"":t.substring(e+1)):t}function Q(t,e){let r=t.length;if(!D(t.charCodeAt(r-1)))return t+e;for(;D(t.charCodeAt(r-1));)r--;return t.substring(0,r)+e+t.substring(r)}const V={"\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t"},W={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};t.JSONRepairError=x,t.jsonrepair=function(s){let A=0,C="";if(!c())throw new x("Unexpected end of json string",s.length);var t=i(44);if(t&&g(),B(s[A])&&/[,\n][ \t\r]*$/.test(C)){t||(C=Q(C,","));{let t=!0,e=!0;for(;e;)t?t=!1:i(44)||(C=Q(C,",")),e=c();e||(C=P(C,","));C="[\n".concat(C,"\n]")}}else t&&(C=P(C,","));for(;s.charCodeAt(A)===a||93===s.charCodeAt(A);)A++,g();if(A>=s.length)return C;throw new x("Unexpected character "+JSON.stringify(s[A]),A);function c(){g();var t=function(){if(123!==s.charCodeAt(A))return!1;{C+="{",A++,g();let e=!0;for(;A<s.length&&s.charCodeAt(A)!==a;){let t;if(e?(t=!0,e=!1):((t=i(44))||(C=Q(C,",")),g()),!(b()||f())){s.charCodeAt(A)===a||123===s.charCodeAt(A)||93===s.charCodeAt(A)||91===s.charCodeAt(A)||void 0===s[A]?C=P(C,","):function(){throw new x("Object key expected",A)}();break}g();var r=i(58),n=A>=s.length,o=(r||(B(s[A])||n?C=Q(C,":"):u()),c());o||(r||n?C+="null":u())}return s.charCodeAt(A)===a?(C+="}",A++):C=Q(C,"}"),!0}}()||function(){if(91!==s.charCodeAt(A))return!1;{C+="[",A++,g();let t=!0;for(;A<s.length&&93!==s.charCodeAt(A);){t?t=!1:i(44)||(C=Q(C,","));var e=c();if(!e){C=P(C,",");break}}return 93===s.charCodeAt(A)?(C+="]",A++):C=Q(C,"]"),!0}}()||b()||function(){var t=A;if(45===s.charCodeAt(A)){if(A++,n())return o(t),!0;if(!q(s.charCodeAt(A)))return A=t,!1}for(;q(s.charCodeAt(A));)A++;if(46===s.charCodeAt(A)){if(A++,n())return o(t),!0;if(!q(s.charCodeAt(A)))return A=t,!1;for(;q(s.charCodeAt(A));)A++}if(101===s.charCodeAt(A)||69===s.charCodeAt(A)){if(A++,45!==s.charCodeAt(A)&&43!==s.charCodeAt(A)||A++,n())return o(t),!0;if(!q(s.charCodeAt(A)))return A=t,!1;for(;q(s.charCodeAt(A));)A++}var e,r;if(n()){if(A>t)return e=s.slice(t,A),r=/^0\d/.test(e),C+=r?'"'.concat(e,'"'):e,!0}else A=t;return!1}()||r("true","true")||r("false","false")||r("null","null")||r("True","true")||r("False","false")||r("None","null")||f();return g(),t}function g(){A;let t=e();for(;t=(t=function(){if(47===s.charCodeAt(A)&&42===s.charCodeAt(A+1)){for(;A<s.length&&!function(t,e){return"*"===t[e]&&"/"===t[e+1]}(s,A);)A++;A+=2}else{if(47!==s.charCodeAt(A)||47!==s.charCodeAt(A+1))return!1;for(;A<s.length&&s.charCodeAt(A)!==y;)A++}return!0}())&&e(););A}function e(){let t="";for(var e,r;(e=D(s.charCodeAt(A)))||(r=s.charCodeAt(A))===h||r>=d&&r<=l||r===R||r===U||r===F;)t+=e?s[A]:" ",A++;return 0<t.length&&(C+=t,!0)}function i(t){return s.charCodeAt(A)===t&&(C+=s[A],A++,!0)}function v(){92===s.charCodeAt(A)&&A++}function b(t){var r,n,o=0<arguments.length&&void 0!==t&&t;let c=92===s.charCodeAt(A);if(c&&(A++,c=!0),G(s.charCodeAt(A))){var i=K(s.charCodeAt(A))?K:M(s.charCodeAt(A))?M:L(s.charCodeAt(A))?L:H,f=A,u=C.length;let e='"';for(A++;;){if(A>=s.length)return a=w(A-1),!o&&z(s.charAt(a))?(A=f,C=C.substring(0,u),b(!0)):(e=Q(e,'"'),C+=e,!0);if(i(s.charCodeAt(A))){var a=A,h=e.length;if(e+='"',A++,C+=e,g(),o||A>=s.length||z(s.charAt(A))||G(s.charCodeAt(A))||q(s.charCodeAt(A)))return p(),!0;if(z(s.charAt(w(a-1))))return A=f,C=C.substring(0,u),b(!0);C=C.substring(0,u),A=a+1,e=e.substring(0,h)+"\\"+e.substring(h)}else{if(o&&z(s[A]))return e=Q(e,'"'),C+=e,p(),!0;if(92===s.charCodeAt(A)){h=s.charAt(A+1);if(void 0!==W[h])e+=s.slice(A,A+2),A+=2;else if("u"===h){let t=2;for(;t<6&&((n=s.charCodeAt(A+t))>=k&&n<=I||n>=T&&n<=m||n>=$&&n<=E);)t++;if(6===t)e+=s.slice(A,A+6),A+=6;else{if(!(A+t>=s.length))throw d=void 0,d=s.slice(A,A+6),new x('Invalid unicode character "'.concat(d,'"'),A);A=s.length}}else e+=h,A+=2}else{var d=s.charAt(A),l=s.charCodeAt(A);if(l===j&&92!==s.charCodeAt(A-1))e+="\\"+d;else if((r=l)===y||r===N||r===O||r===J||r===S)e+=V[d];else{if(!(32<=(r=l)&&r<=1114111))throw l=void 0,l=d,new x("Invalid character "+JSON.stringify(l),A);e+=d}A++}}c&&v()}}return!1}function p(){let t=!1;for(g();43===s.charCodeAt(A);){t=!0,A++,g();var e=(C=P(C,'"',!0)).length,r=b();C=r?(r=C,e=e,n=1,r.substring(0,e)+r.substring(e+n)):Q(C,'"')}var n;t}function r(t,e){return s.slice(A,A+t.length)===t&&(C+=e,A+=t.length,!0)}function f(){for(var t,e=A;A<s.length&&(!z(t=s[A])||"/"===t)&&!G(s.charCodeAt(A));)A++;if(A>e){if(40===s.charCodeAt(A))A++,c(),41===s.charCodeAt(A)&&(A++,59===s.charCodeAt(A))&&A++;else{for(;D(s.charCodeAt(A-1))&&0<A;)A--;e=s.slice(e,A);C+="undefined"===e?"null":JSON.stringify(e),s.charCodeAt(A)===j&&A++}return!0}}function w(t){let e=t;for(;0<e&&D(s.charCodeAt(e));)e--;return e}function n(){return A>=s.length||z(s[A])||D(s.charCodeAt(A))}function o(t){C+=s.slice(t,A)+"0"}function u(){throw new x("Colon expected",A)}}}); |
{ | ||
"name": "jsonrepair", | ||
"version": "3.6.1", | ||
"version": "3.7.0", | ||
"description": "Repair broken JSON documents", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
480595
4563