Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsonrepair

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonrepair - npm Package Compare versions

Comparing version 3.5.0 to 3.5.1

35

lib/cjs/regular/jsonrepair.js

@@ -286,3 +286,3 @@ "use strict";

// repair: wrap the output inside array brackets
output = `[\n${output}\n]`;
output = "[\n".concat(output, "\n]");
}

@@ -317,2 +317,3 @@

const iBefore = i;
const oBefore = output.length;
let str = '"';

@@ -374,13 +375,3 @@ i++;

}
// see whether we have an end quote followed by a valid delimiter
const hasEndQuote = (0, _stringUtils.isQuote)(text.charCodeAt(i));
const valid = hasEndQuote && (i + 1 >= text.length || (0, _stringUtils.isDelimiter)((0, _stringUtils.nextNonWhiteSpaceCharacter)(text, i + 1)));
if (!valid && !stopAtDelimiter) {
// we're dealing with a missing quote somewhere. Let's revert parsing
// this string and try again, running in a more conservative mode,
// stopping at the first next delimiter
i = iBefore;
return parseString(true);
}
if (hasEndQuote) {

@@ -394,2 +385,16 @@ str += '"';

output += str;
parseWhitespaceAndSkipComments();
// See whether we have:
// (a) An end quote which is not followed by a valid delimiter
// (b) No end quote and reached the end of the input
// If so, revert parsing this string and try again, running in a more
// conservative mode, stopping at the first next delimiter
const isAtEnd = i >= text.length;
const nextIsDelimiter = (0, _stringUtils.isDelimiter)(text.charAt(i));
if (!stopAtDelimiter && (hasEndQuote && !isAtEnd && !nextIsDelimiter || !hasEndQuote && isAtEnd)) {
i = iBefore;
output = output.substring(0, oBefore);
return parseString(true);
}
parseConcatenatedString();

@@ -471,3 +476,3 @@ return true;

const hasInvalidLeadingZero = /^0\d/.test(num);
output += hasInvalidLeadingZero ? `"${num}"` : num;
output += hasInvalidLeadingZero ? "\"".concat(num, "\"") : num;
return true;

@@ -543,3 +548,3 @@ }

const numSoFar = text.slice(start, i);
throw new _JSONRepairError.JSONRepairError(`Invalid number '${numSoFar}', expecting a digit ${got()}`, i);
throw new _JSONRepairError.JSONRepairError("Invalid number '".concat(numSoFar, "', expecting a digit ").concat(got()), i);
}

@@ -576,6 +581,6 @@ }

const chars = text.slice(i, i + 6);
throw new _JSONRepairError.JSONRepairError(`Invalid unicode character "${chars}"`, i);
throw new _JSONRepairError.JSONRepairError("Invalid unicode character \"".concat(chars, "\""), i);
}
function got() {
return text[i] ? `but got '${text[i]}'` : 'but reached end of input';
return text[i] ? "but got '".concat(text[i], "'") : 'but reached end of input';
}

@@ -582,0 +587,0 @@ }

@@ -14,7 +14,7 @@ "use strict";

if (index < offset) {
throw new Error(`${indexOutOfRangeMessage} (index: ${index}, offset: ${offset})`);
throw new Error("".concat(indexOutOfRangeMessage, " (index: ").concat(index, ", offset: ").concat(offset, ")"));
}
if (index >= currentLength) {
if (!closed) {
throw new Error(`${indexOutOfRangeMessage} (index: ${index})`);
throw new Error("".concat(indexOutOfRangeMessage, " (index: ").concat(index, ")"));
}

@@ -21,0 +21,0 @@ }

@@ -39,3 +39,3 @@ "use strict";

if (offset > 0) {
throw new Error(`Cannot unshift: ${flushedMessage}`);
throw new Error("Cannot unshift: ".concat(flushedMessage));
}

@@ -47,3 +47,3 @@ buffer = text + buffer;

if (start < offset) {
throw new Error(`Cannot remove: ${flushedMessage}`);
throw new Error("Cannot remove: ".concat(flushedMessage));
}

@@ -82,3 +82,3 @@ if (end !== undefined) {

if (bufferIndex <= 0) {
throw new Error(`Cannot insert: ${flushedMessage}`);
throw new Error("Cannot insert: ".concat(flushedMessage));
}

@@ -85,0 +85,0 @@ buffer = buffer.substring(0, bufferIndex) + textToInsert + buffer.substring(bufferIndex);

@@ -402,4 +402,5 @@ "use strict";

let stopAtDelimiter = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
const iBefore = i; // we may need to revert
// we may need to revert
const iBefore = i;
const oBefore = output.length();
let skipEscapeChars = input.charCodeAt(i) === _stringUtils.codeBackslash;

@@ -475,14 +476,3 @@ if (skipEscapeChars) {

}
// see whether we have an end quote followed by a valid delimiter
const hasEndQuote = (0, _stringUtils.isQuote)(input.charCodeAt(i));
const valid = hasEndQuote && (input.isEnd(i + 1) || (0, _stringUtils.isDelimiter)(nextNonWhiteSpaceCharacter(i + 1)));
if (!valid && !stopAtDelimiter) {
// we're dealing with a missing quote somewhere. Let's revert parsing
// this string and try again, running in a more conservative mode,
// stopping at the first next delimiter
i = iBefore;
output.remove(iBefore);
return parseString(true);
}
if (hasEndQuote) {

@@ -495,2 +485,16 @@ output.push('"');

}
parseWhitespaceAndSkipComments();
// See whether we have:
// (a) An end quote which is not followed by a valid delimiter
// (b) No end quote and reached the end of the input
// If so, revert parsing this string and try again, running in a more
// conservative mode, stopping at the first next delimiter
const isAtEnd = input.isEnd(i);
const nextIsDelimiter = (0, _stringUtils.isDelimiter)(input.charAt(i));
if (!stopAtDelimiter && (hasEndQuote && !isAtEnd && !nextIsDelimiter || !hasEndQuote && isAtEnd)) {
i = iBefore;
output.remove(oBefore);
return parseString(true);
}
parseConcatenatedString();

@@ -572,3 +576,3 @@ return stack.update(_stack.Caret.afterValue);

const hasInvalidLeadingZero = /^0\d/.test(num);
output.push(hasInvalidLeadingZero ? `"${num}"` : num);
output.push(hasInvalidLeadingZero ? "\"".concat(num, "\"") : num);
return stack.update(_stack.Caret.afterValue);

@@ -622,13 +626,6 @@ }

}
function nextNonWhiteSpaceCharacter(start) {
let i = start;
while ((0, _stringUtils.isWhitespace)(input.charCodeAt(i))) {
i++;
}
return input.charAt(i);
}
function expectDigit(start) {
if (!(0, _stringUtils.isDigit)(input.charCodeAt(i))) {
const numSoFar = input.substring(start, i);
throw new _JSONRepairError.JSONRepairError(`Invalid number '${numSoFar}', expecting a digit ${got()}`, i);
throw new _JSONRepairError.JSONRepairError("Invalid number '".concat(numSoFar, "', expecting a digit ").concat(got()), i);
}

@@ -665,7 +662,7 @@ }

const chars = input.substring(i, i + 6);
throw new _JSONRepairError.JSONRepairError(`Invalid unicode character "${chars}"`, i);
throw new _JSONRepairError.JSONRepairError("Invalid unicode character \"".concat(chars, "\""), i);
}
function got() {
const char = input.charAt(i);
return char ? `but got '${char}'` : 'but reached end of input';
return char ? "but got '".concat(char, "'") : 'but reached end of input';
}

@@ -672,0 +669,0 @@ function atEndOfBlockComment(i) {

@@ -12,4 +12,4 @@ "use strict";

onData: chunk => transform.push(chunk),
bufferSize: options?.bufferSize,
chunkSize: options?.chunkSize
bufferSize: options === null || options === void 0 ? void 0 : options.bufferSize,
chunkSize: options === null || options === void 0 ? void 0 : options.chunkSize
});

@@ -16,0 +16,0 @@ const transform = new _nodeStream.Transform({

@@ -22,3 +22,2 @@ "use strict";

exports.isWhitespace = isWhitespace;
exports.nextNonWhiteSpaceCharacter = nextNonWhiteSpaceCharacter;
exports.removeAtIndex = removeAtIndex;

@@ -180,9 +179,2 @@ exports.stripLastOccurrence = stripLastOccurrence;

}
function nextNonWhiteSpaceCharacter(text, start) {
let i = start;
while (isWhitespace(text.charCodeAt(i))) {
i++;
}
return text.charAt(i);
}
//# sourceMappingURL=stringUtils.js.map
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, nextNonWhiteSpaceCharacter, 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, isDigit, isDoubleQuote, isDoubleQuoteLike, isHex, isQuote, isSingleQuote, isSingleQuoteLike, isSpecialWhitespace, isStartOfValue, isValidStringCharacter, isWhitespace, removeAtIndex, stripLastOccurrence } from '../utils/stringUtils.js';
const controlCharacters = {

@@ -280,3 +280,3 @@ '\b': '\\b',

// repair: wrap the output inside array brackets
output = `[\n${output}\n]`;
output = "[\n".concat(output, "\n]");
}

@@ -311,2 +311,3 @@

const iBefore = i;
const oBefore = output.length;
let str = '"';

@@ -368,13 +369,3 @@ i++;

}
// see whether we have an end quote followed by a valid delimiter
const hasEndQuote = isQuote(text.charCodeAt(i));
const valid = hasEndQuote && (i + 1 >= text.length || isDelimiter(nextNonWhiteSpaceCharacter(text, i + 1)));
if (!valid && !stopAtDelimiter) {
// we're dealing with a missing quote somewhere. Let's revert parsing
// this string and try again, running in a more conservative mode,
// stopping at the first next delimiter
i = iBefore;
return parseString(true);
}
if (hasEndQuote) {

@@ -388,2 +379,16 @@ str += '"';

output += str;
parseWhitespaceAndSkipComments();
// See whether we have:
// (a) An end quote which is not followed by a valid delimiter
// (b) No end quote and reached the end of the input
// If so, revert parsing this string and try again, running in a more
// conservative mode, stopping at the first next delimiter
const isAtEnd = i >= text.length;
const nextIsDelimiter = isDelimiter(text.charAt(i));
if (!stopAtDelimiter && (hasEndQuote && !isAtEnd && !nextIsDelimiter || !hasEndQuote && isAtEnd)) {
i = iBefore;
output = output.substring(0, oBefore);
return parseString(true);
}
parseConcatenatedString();

@@ -465,3 +470,3 @@ return true;

const hasInvalidLeadingZero = /^0\d/.test(num);
output += hasInvalidLeadingZero ? `"${num}"` : num;
output += hasInvalidLeadingZero ? "\"".concat(num, "\"") : num;
return true;

@@ -537,3 +542,3 @@ }

const numSoFar = text.slice(start, i);
throw new JSONRepairError(`Invalid number '${numSoFar}', expecting a digit ${got()}`, i);
throw new JSONRepairError("Invalid number '".concat(numSoFar, "', expecting a digit ").concat(got()), i);
}

@@ -570,6 +575,6 @@ }

const chars = text.slice(i, i + 6);
throw new JSONRepairError(`Invalid unicode character "${chars}"`, i);
throw new JSONRepairError("Invalid unicode character \"".concat(chars, "\""), i);
}
function got() {
return text[i] ? `but got '${text[i]}'` : 'but reached end of input';
return text[i] ? "but got '".concat(text[i], "'") : 'but reached end of input';
}

@@ -576,0 +581,0 @@ }

@@ -8,7 +8,7 @@ export function createInputBuffer() {

if (index < offset) {
throw new Error(`${indexOutOfRangeMessage} (index: ${index}, offset: ${offset})`);
throw new Error("".concat(indexOutOfRangeMessage, " (index: ").concat(index, ", offset: ").concat(offset, ")"));
}
if (index >= currentLength) {
if (!closed) {
throw new Error(`${indexOutOfRangeMessage} (index: ${index})`);
throw new Error("".concat(indexOutOfRangeMessage, " (index: ").concat(index, ")"));
}

@@ -15,0 +15,0 @@ }

@@ -33,3 +33,3 @@ import { isWhitespace } from '../../utils/stringUtils.js';

if (offset > 0) {
throw new Error(`Cannot unshift: ${flushedMessage}`);
throw new Error("Cannot unshift: ".concat(flushedMessage));
}

@@ -41,3 +41,3 @@ buffer = text + buffer;

if (start < offset) {
throw new Error(`Cannot remove: ${flushedMessage}`);
throw new Error("Cannot remove: ".concat(flushedMessage));
}

@@ -76,3 +76,3 @@ if (end !== undefined) {

if (bufferIndex <= 0) {
throw new Error(`Cannot insert: ${flushedMessage}`);
throw new Error("Cannot insert: ".concat(flushedMessage));
}

@@ -79,0 +79,0 @@ buffer = buffer.substring(0, bufferIndex) + textToInsert + buffer.substring(bufferIndex);

@@ -396,4 +396,5 @@ import { createInputBuffer } from './buffer/InputBuffer.js';

let stopAtDelimiter = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
const iBefore = i; // we may need to revert
// we may need to revert
const iBefore = i;
const oBefore = output.length();
let skipEscapeChars = input.charCodeAt(i) === codeBackslash;

@@ -469,14 +470,3 @@ if (skipEscapeChars) {

}
// see whether we have an end quote followed by a valid delimiter
const hasEndQuote = isQuote(input.charCodeAt(i));
const valid = hasEndQuote && (input.isEnd(i + 1) || isDelimiter(nextNonWhiteSpaceCharacter(i + 1)));
if (!valid && !stopAtDelimiter) {
// we're dealing with a missing quote somewhere. Let's revert parsing
// this string and try again, running in a more conservative mode,
// stopping at the first next delimiter
i = iBefore;
output.remove(iBefore);
return parseString(true);
}
if (hasEndQuote) {

@@ -489,2 +479,16 @@ output.push('"');

}
parseWhitespaceAndSkipComments();
// See whether we have:
// (a) An end quote which is not followed by a valid delimiter
// (b) No end quote and reached the end of the input
// If so, revert parsing this string and try again, running in a more
// conservative mode, stopping at the first next delimiter
const isAtEnd = input.isEnd(i);
const nextIsDelimiter = isDelimiter(input.charAt(i));
if (!stopAtDelimiter && (hasEndQuote && !isAtEnd && !nextIsDelimiter || !hasEndQuote && isAtEnd)) {
i = iBefore;
output.remove(oBefore);
return parseString(true);
}
parseConcatenatedString();

@@ -566,3 +570,3 @@ return stack.update(Caret.afterValue);

const hasInvalidLeadingZero = /^0\d/.test(num);
output.push(hasInvalidLeadingZero ? `"${num}"` : num);
output.push(hasInvalidLeadingZero ? "\"".concat(num, "\"") : num);
return stack.update(Caret.afterValue);

@@ -616,13 +620,6 @@ }

}
function nextNonWhiteSpaceCharacter(start) {
let i = start;
while (isWhitespace(input.charCodeAt(i))) {
i++;
}
return input.charAt(i);
}
function expectDigit(start) {
if (!isDigit(input.charCodeAt(i))) {
const numSoFar = input.substring(start, i);
throw new JSONRepairError(`Invalid number '${numSoFar}', expecting a digit ${got()}`, i);
throw new JSONRepairError("Invalid number '".concat(numSoFar, "', expecting a digit ").concat(got()), i);
}

@@ -659,7 +656,7 @@ }

const chars = input.substring(i, i + 6);
throw new JSONRepairError(`Invalid unicode character "${chars}"`, i);
throw new JSONRepairError("Invalid unicode character \"".concat(chars, "\""), i);
}
function got() {
const char = input.charAt(i);
return char ? `but got '${char}'` : 'but reached end of input';
return char ? "but got '".concat(char, "'") : 'but reached end of input';
}

@@ -666,0 +663,0 @@ function atEndOfBlockComment(i) {

@@ -6,4 +6,4 @@ import { Transform } from 'node:stream';

onData: chunk => transform.push(chunk),
bufferSize: options?.bufferSize,
chunkSize: options?.chunkSize
bufferSize: options === null || options === void 0 ? void 0 : options.bufferSize,
chunkSize: options === null || options === void 0 ? void 0 : options.chunkSize
});

@@ -10,0 +10,0 @@ const transform = new Transform({

@@ -155,9 +155,2 @@ export const codeBackslash = 0x5c; // "\"

}
export function nextNonWhiteSpaceCharacter(text, start) {
let i = start;
while (isWhitespace(text.charCodeAt(i))) {
i++;
}
return text.charAt(i);
}
//# sourceMappingURL=stringUtils.js.map

@@ -83,3 +83,2 @@ export declare const codeBackslash = 92;

export declare function endsWithCommaOrNewline(text: string): boolean;
export declare function nextNonWhiteSpaceCharacter(text: string, start: number): string;
//# sourceMappingURL=stringUtils.d.ts.map

@@ -168,9 +168,2 @@ (function (global, factory) {

}
function nextNonWhiteSpaceCharacter(text, start) {
let i = start;
while (isWhitespace(text.charCodeAt(i))) {
i++;
}
return text.charAt(i);
}

@@ -454,3 +447,3 @@ const controlCharacters = {

// repair: wrap the output inside array brackets
output = `[\n${output}\n]`;
output = "[\n".concat(output, "\n]");
}

@@ -485,2 +478,3 @@

const iBefore = i;
const oBefore = output.length;
let str = '"';

@@ -539,13 +533,3 @@ i++;

}
// see whether we have an end quote followed by a valid delimiter
const hasEndQuote = isQuote(text.charCodeAt(i));
const valid = hasEndQuote && (i + 1 >= text.length || isDelimiter(nextNonWhiteSpaceCharacter(text, i + 1)));
if (!valid && !stopAtDelimiter) {
// we're dealing with a missing quote somewhere. Let's revert parsing
// this string and try again, running in a more conservative mode,
// stopping at the first next delimiter
i = iBefore;
return parseString(true);
}
if (hasEndQuote) {

@@ -559,2 +543,16 @@ str += '"';

output += str;
parseWhitespaceAndSkipComments();
// See whether we have:
// (a) An end quote which is not followed by a valid delimiter
// (b) No end quote and reached the end of the input
// If so, revert parsing this string and try again, running in a more
// conservative mode, stopping at the first next delimiter
const isAtEnd = i >= text.length;
const nextIsDelimiter = isDelimiter(text.charAt(i));
if (!stopAtDelimiter && (hasEndQuote && !isAtEnd && !nextIsDelimiter || !hasEndQuote && isAtEnd)) {
i = iBefore;
output = output.substring(0, oBefore);
return parseString(true);
}
parseConcatenatedString();

@@ -636,3 +634,3 @@ return true;

const hasInvalidLeadingZero = /^0\d/.test(num);
output += hasInvalidLeadingZero ? `"${num}"` : num;
output += hasInvalidLeadingZero ? "\"".concat(num, "\"") : num;
return true;

@@ -708,3 +706,3 @@ }

const numSoFar = text.slice(start, i);
throw new JSONRepairError(`Invalid number '${numSoFar}', expecting a digit ${got()}`, i);
throw new JSONRepairError("Invalid number '".concat(numSoFar, "', expecting a digit ").concat(got()), i);
}

@@ -741,6 +739,6 @@ }

const chars = text.slice(i, i + 6);
throw new JSONRepairError(`Invalid unicode character "${chars}"`, i);
throw new JSONRepairError("Invalid unicode character \"".concat(chars, "\""), i);
}
function got() {
return text[i] ? `but got '${text[i]}'` : 'but reached end of input';
return text[i] ? "but got '".concat(text[i], "'") : 'but reached end of input';
}

@@ -747,0 +745,0 @@ }

@@ -1,3 +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 p extends Error{constructor(t,e){super(t+" at position "+e),this.position=e}}const a=125,e=32,w=10,x=9,y=13,$=8,O=12,N=34,r=39,J=48,S=57,j=65,I=97,k=70,m=102,h=160,d=8192,l=8202,T=8239,E=8287,R=12288,n=8220,o=8221,c=8216,i=8217,f=96,u=180;function U(t){return t>=J&&t<=S}function F(t){return s.test(t)||B(t.charCodeAt(0))}const s=/^[,:[\]{}()\n+]$/;function q(t){return A.test(t)||t&&B(t.charCodeAt(0))}const A=/^[[{\w-]$/;function z(t){return t===e||t===w||t===x||t===y}function B(t){return D(t)||H(t)}function D(t){return t===N||t===n||t===o}function G(t){return t===N}function H(t){return t===r||t===c||t===i||t===f||t===u}function K(t){return t===r}function L(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 M(t,e){let r=t.length;if(!z(t.charCodeAt(r-1)))return t+e;for(;z(t.charCodeAt(r-1));)r--;return t.substring(0,r)+e+t.substring(r)}const P={"\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t"},Q={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};t.JSONRepairError=p,t.jsonrepair=function(s){let A=0,C="";if(!c())throw new p("Unexpected end of json string",s.length);var t=i(44);if(t&&g(),q(s[A])&&/[,\n][ \t\r]*$/.test(C)){t||(C=M(C,","));{let t=!0,e=!0;for(;e;)t?t=!1:i(44)||(C=M(C,",")),e=c();e||(C=L(C,","));C=`[
${C}
]`}}else t&&(C=L(C,","));for(;s.charCodeAt(A)===a||93===s.charCodeAt(A);)A++,g();if(A>=s.length)return C;throw new p("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=M(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=L(C,","):function(){throw new p("Object key expected",A)}();break}g();var r=i(58),n=A>=s.length,o=(r||(q(s[A])||n?C=M(C,":"):u()),c());o||(r||n?C+="null":u())}return s.charCodeAt(A)===a?(C+="}",A++):C=M(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=M(C,","));var e=c();if(!e){C=L(C,",");break}}return 93===s.charCodeAt(A)?(C+="]",A++):C=M(C,"]"),!0}}()||b()||function(){var t=A;if(45===s.charCodeAt(A)&&(A++,o(t)))return!0;for(;U(s.charCodeAt(A));)A++;if(46===s.charCodeAt(A)){if(A++,o(t))return!0;for(;U(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(;U(s.charCodeAt(A));)A++}{var e;if(A>t)return t=s.slice(t,A),e=/^0\d/.test(t),C+=e?`"${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)!==w;)A++}return!0}())&&e(););A}function e(){let t="";for(var e,r;(e=z(s.charCodeAt(A)))||(r=s.charCodeAt(A))===h||r>=d&&r<=l||r===T||r===E||r===R;)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,t=0<arguments.length&&void 0!==t&&t;let n=92===s.charCodeAt(A);if(n&&(A++,n=!0),B(s.charCodeAt(A))){const l=G(s.charCodeAt(A))?G:K(s.charCodeAt(A))?K:H(s.charCodeAt(A))?H:D;var o=A;let e='"';A++;for(var c=t?t=>F(s[t]):t=>l(s.charCodeAt(t));A<s.length&&!c(A);){if(92===s.charCodeAt(A)){var i=s.charAt(A+1);if(void 0!==Q[i])e+=s.slice(A,A+2),A+=2;else if("u"===i){let t=2;for(;t<6&&((r=s.charCodeAt(A+t))>=J&&r<=S||r>=j&&r<=k||r>=I&&r<=m);)t++;if(6===t)e+=s.slice(A,A+6),A+=6;else{if(!(A+t>=s.length))throw u=void 0,u=s.slice(A,A+6),new p(`Invalid unicode character "${u}"`,A);A=s.length}}else e+=i,A+=2}else{var f,u=s.charAt(A),i=s.charCodeAt(A);if(i===N&&92!==s.charCodeAt(A-1))e+="\\"+u;else if((f=i)===w||f===y||f===x||f===$||f===O)e+=P[u];else{if(!(32<=(f=i)&&f<=1114111))throw f=void 0,f=u,new p("Invalid character "+JSON.stringify(f),A);e+=u}A++}n&&v()}var a=B(s.charCodeAt(A));if(!(a&&(A+1>=s.length||F(function(t,e){let r=e;for(;z(t.charCodeAt(r));)r++;return t.charAt(r)}(s,A+1))))&&!t)return A=o,b(!0);a?(e+='"',A++):e=M(e,'"'),C+=e;{let t=!1;g();for(;43===s.charCodeAt(A);){t=!0,A++,g();var h=(C=L(C,'"',!0)).length,d=b();C=d?function(t,e,r){return t.substring(0,e)+t.substring(e+r)}(C,h,1):M(C,'"')}t}return!0}return!1}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&&!F(s[A]);)A++;if(A>t){if(40===s.charCodeAt(A))A++,c(),41===s.charCodeAt(A)&&(A++,59===s.charCodeAt(A))&&A++;else{for(;z(s.charCodeAt(A-1))&&0<A;)A--;t=s.slice(t,A);C+="undefined"===t?"null":JSON.stringify(t),s.charCodeAt(A)===N&&A++}return!0}}function n(t){if(!U(s.charCodeAt(A)))throw t=s.slice(t,A),new p(`Invalid number '${t}', expecting a digit `+(s[A]?`but got '${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 u(){throw new p("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 y extends Error{constructor(t,e){super(t+" at position "+e),this.position=e}}const u=125,e=32,O=10,N=9,J=13,S=8,j=12,I=34,r=39,k=48,m=57,T=65,$=97,E=70,R=102,h=160,d=8192,l=8202,s=8239,A=8287,C=12288,n=8220,o=8221,c=8216,i=8217,f=96,a=180;function U(t){return t>=k&&t<=m}function F(t){return g.test(t)||B(t.charCodeAt(0))}const g=/^[,:[\]{}()\n+]$/;function q(t){return v.test(t)||t&&B(t.charCodeAt(0))}const v=/^[[{\w-]$/;function z(t){return t===e||t===O||t===N||t===J}function B(t){return D(t)||H(t)}function D(t){return t===I||t===n||t===o}function G(t){return t===I}function H(t){return t===r||t===c||t===i||t===f||t===a}function K(t){return t===r}function L(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 M(t,e){let r=t.length;if(!z(t.charCodeAt(r-1)))return t+e;for(;z(t.charCodeAt(r-1));)r--;return t.substring(0,r)+e+t.substring(r)}const P={"\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t"},Q={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};t.JSONRepairError=y,t.jsonrepair=function(g){let v=0,b="";if(!c())throw new y("Unexpected end of json string",g.length);var t=i(44);if(t&&p(),q(g[v])&&/[,\n][ \t\r]*$/.test(b)){t||(b=M(b,","));{let t=!0,e=!0;for(;e;)t?t=!1:i(44)||(b=M(b,",")),e=c();e||(b=L(b,","));b="[\n".concat(b,"\n]")}}else t&&(b=L(b,","));for(;g.charCodeAt(v)===u||93===g.charCodeAt(v);)v++,p();if(v>=g.length)return b;throw new y("Unexpected character "+JSON.stringify(g[v]),v);function c(){p();var t=function(){if(123!==g.charCodeAt(v))return!1;{b+="{",v++,p();let e=!0;for(;v<g.length&&g.charCodeAt(v)!==u;){let t;if(e?(t=!0,e=!1):((t=i(44))||(b=M(b,",")),p()),!(x()||f())){g.charCodeAt(v)===u||123===g.charCodeAt(v)||93===g.charCodeAt(v)||91===g.charCodeAt(v)||void 0===g[v]?b=L(b,","):function(){throw new y("Object key expected",v)}();break}p();var r=i(58),n=v>=g.length,o=(r||(q(g[v])||n?b=M(b,":"):a()),c());o||(r||n?b+="null":a())}return g.charCodeAt(v)===u?(b+="}",v++):b=M(b,"}"),!0}}()||function(){if(91!==g.charCodeAt(v))return!1;{b+="[",v++,p();let t=!0;for(;v<g.length&&93!==g.charCodeAt(v);){t?t=!1:i(44)||(b=M(b,","));var e=c();if(!e){b=L(b,",");break}}return 93===g.charCodeAt(v)?(b+="]",v++):b=M(b,"]"),!0}}()||x()||function(){var t=v;if(45===g.charCodeAt(v)&&(v++,o(t)))return!0;for(;U(g.charCodeAt(v));)v++;if(46===g.charCodeAt(v)){if(v++,o(t))return!0;for(;U(g.charCodeAt(v));)v++}if(101===g.charCodeAt(v)||69===g.charCodeAt(v)){if(v++,45!==g.charCodeAt(v)&&43!==g.charCodeAt(v)||v++,o(t))return!0;for(;U(g.charCodeAt(v));)v++}{var e;if(v>t)return t=g.slice(t,v),e=/^0\d/.test(t),b+=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 p(),t}function p(){v;let t=e();for(;t=(t=function(){if(47===g.charCodeAt(v)&&42===g.charCodeAt(v+1)){for(;v<g.length&&!function(t,e){return"*"===t[e]&&"/"===t[e+1]}(g,v);)v++;v+=2}else{if(47!==g.charCodeAt(v)||47!==g.charCodeAt(v+1))return!1;for(;v<g.length&&g.charCodeAt(v)!==O;)v++}return!0}())&&e(););v}function e(){let t="";for(var e,r;(e=z(g.charCodeAt(v)))||(r=g.charCodeAt(v))===h||r>=d&&r<=l||r===s||r===A||r===C;)t+=e?g[v]:" ",v++;return 0<t.length&&(b+=t,!0)}function i(t){return g.charCodeAt(v)===t&&(b+=g[v],v++,!0)}function w(){92===g.charCodeAt(v)&&v++}function x(t){var r,t=0<arguments.length&&void 0!==t&&t;let n=92===g.charCodeAt(v);if(n&&(v++,n=!0),B(g.charCodeAt(v))){const C=G(g.charCodeAt(v))?G:K(g.charCodeAt(v))?K:H(g.charCodeAt(v))?H:D;var o=v,c=b.length;let e='"';v++;for(var i=t?t=>F(g[t]):t=>C(g.charCodeAt(t));v<g.length&&!i(v);){if(92===g.charCodeAt(v)){var f=g.charAt(v+1);if(void 0!==Q[f])e+=g.slice(v,v+2),v+=2;else if("u"===f){let t=2;for(;t<6&&((r=g.charCodeAt(v+t))>=k&&r<=m||r>=T&&r<=E||r>=$&&r<=R);)t++;if(6===t)e+=g.slice(v,v+6),v+=6;else{if(!(v+t>=g.length))throw u=void 0,u=g.slice(v,v+6),new y('Invalid unicode character "'.concat(u,'"'),v);v=g.length}}else e+=f,v+=2}else{var a,u=g.charAt(v),f=g.charCodeAt(v);if(f===I&&92!==g.charCodeAt(v-1))e+="\\"+u;else if((a=f)===O||a===J||a===N||a===S||a===j)e+=P[u];else{if(!(32<=(a=f)&&a<=1114111))throw a=void 0,a=u,new y("Invalid character "+JSON.stringify(a),v);e+=u}v++}n&&w()}var h=B(g.charCodeAt(v)),d=(h?(e+='"',v++):e=M(e,'"'),b+=e,p(),v>=g.length),l=F(g.charAt(v));if(!t&&(h&&!d&&!l||!h&&d))return v=o,b=b.substring(0,c),x(!0);{let t=!1;p();for(;43===g.charCodeAt(v);){t=!0,v++,p();var s=(b=L(b,'"',!0)).length,A=x();b=A?function(t,e,r){return t.substring(0,e)+t.substring(e+r)}(b,s,1):M(b,'"')}t}return!0}return!1}function r(t,e){return g.slice(v,v+t.length)===t&&(b+=e,v+=t.length,!0)}function f(){for(var t=v;v<g.length&&!F(g[v]);)v++;if(v>t){if(40===g.charCodeAt(v))v++,c(),41===g.charCodeAt(v)&&(v++,59===g.charCodeAt(v))&&v++;else{for(;z(g.charCodeAt(v-1))&&0<v;)v--;t=g.slice(t,v);b+="undefined"===t?"null":JSON.stringify(t),g.charCodeAt(v)===I&&v++}return!0}}function n(t){if(!U(g.charCodeAt(v)))throw t=g.slice(t,v),new y("Invalid number '".concat(t,"', expecting a digit ").concat(g[v]?"but got '".concat(g[v],"'"):"but reached end of input"),v)}function o(t){if(v>=g.length)return b+=g.slice(t,v)+"0",1;n(t)}function a(){throw new y("Colon expected",v)}}});
{
"name": "jsonrepair",
"version": "3.5.0",
"version": "3.5.1",
"description": "Repair broken JSON documents",

@@ -71,18 +71,18 @@ "repository": {

"@babel/cli": "7.23.4",
"@babel/core": "7.23.5",
"@babel/plugin-transform-typescript": "7.23.5",
"@babel/preset-env": "7.23.5",
"@babel/core": "7.23.7",
"@babel/plugin-transform-typescript": "7.23.6",
"@babel/preset-env": "7.23.8",
"@babel/preset-typescript": "7.23.3",
"@commitlint/cli": "18.4.3",
"@commitlint/config-conventional": "18.4.3",
"@types/node": "20.10.4",
"@typescript-eslint/eslint-plugin": "6.13.2",
"@typescript-eslint/parser": "6.13.2",
"@commitlint/cli": "18.4.4",
"@commitlint/config-conventional": "18.4.4",
"@types/node": "20.10.8",
"@typescript-eslint/eslint-plugin": "6.18.1",
"@typescript-eslint/parser": "6.18.1",
"benchmark": "2.1.4",
"cpy-cli": "5.0.0",
"del-cli": "5.1.0",
"eslint": "8.55.0",
"eslint": "8.56.0",
"eslint-config-standard": "17.1.0",
"eslint-plugin-import": "2.29.0",
"eslint-plugin-n": "16.3.1",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-n": "16.6.2",
"eslint-plugin-node": "11.1.0",

@@ -92,10 +92,10 @@ "eslint-plugin-promise": "6.1.1",

"npm-run-all": "4.1.5",
"prettier": "3.1.0",
"rollup": "4.6.1",
"prettier": "3.1.1",
"rollup": "4.9.4",
"standard-version": "9.5.0",
"ts-node": "10.9.1",
"ts-node": "10.9.2",
"typescript": "5.3.3",
"uglify-js": "3.17.4",
"vitest": "1.0.1"
"vitest": "1.1.3"
}
}

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc