jsonrepair
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -454,3 +454,2 @@ "use strict"; | ||
if (i > start) { | ||
var symbol = text.slice(start, i); | ||
if (text.charCodeAt(i) === _stringUtils.codeOpenParenthesis) { | ||
@@ -472,2 +471,8 @@ // repair a MongoDB function call like NumberLong("2") | ||
// repair unquoted string | ||
// first, go back to prevent getting trailing whitespaces in the string | ||
while ((0, _stringUtils.isWhitespace)(text.charCodeAt(i - 1)) && i > 0) { | ||
i--; | ||
} | ||
var symbol = text.slice(start, i); | ||
output += JSON.stringify(symbol); | ||
@@ -474,0 +479,0 @@ return true; |
@@ -94,8 +94,9 @@ "use strict"; | ||
var codeIdeographicSpace = 0x3000; | ||
var codeDoubleQuoteLeft = 0x201c; | ||
var codeDoubleQuoteRight = 0x201d; | ||
var codeQuoteLeft = 0x2018; | ||
var codeQuoteRight = 0x2019; | ||
var codeGraveAccent = 0x0060; | ||
var codeAcuteAccent = 0x00b4; | ||
var codeDoubleQuoteLeft = 0x201c; // “ | ||
var codeDoubleQuoteRight = 0x201d; // ” | ||
var codeQuoteLeft = 0x2018; // ‘ | ||
var codeQuoteRight = 0x2019; // ’ | ||
var codeGraveAccent = 0x0060; // ` | ||
var codeAcuteAccent = 0x00b4; // ´ | ||
function isHex(code) { | ||
@@ -114,9 +115,11 @@ return code >= codeZero && code < codeNine || code >= codeUppercaseA && code <= codeUppercaseF || code >= codeLowercaseA && code <= codeLowercaseF; | ||
function isDelimiter(char) { | ||
return regexDelimiter.test(char); | ||
return regexDelimiter.test(char) || char && isQuote(char.charCodeAt(0)); | ||
} | ||
var regexDelimiter = /^[,:[\]{}()\n"]$/; | ||
var regexDelimiter = /^[,:[\]{}()\n]$/; | ||
function isStartOfValue(char) { | ||
return regexStartOfValue.test(char); | ||
return regexStartOfValue.test(char) || char && isQuote(char.charCodeAt(0)); | ||
} | ||
var regexStartOfValue = /^[[{\w"-_]$/; | ||
// alpha, number, minus, or opening bracket or brace | ||
var regexStartOfValue = /^[[{\w-]$/; | ||
function isControlCharacter(code) { | ||
@@ -172,5 +175,5 @@ return code === codeNewline || code === codeReturn || code === codeTab || code === codeBackspace || code === codeFormFeed; | ||
function stripLastOccurrence(text, textToStrip) { | ||
var stripWhitespace = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
var stripRemainingText = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
var index = text.lastIndexOf(textToStrip); | ||
return index !== -1 ? text.substring(0, index) + (stripWhitespace ? '' : text.substring(index + 1)) : text; | ||
return index !== -1 ? text.substring(0, index) + (stripRemainingText ? '' : text.substring(index + 1)) : text; | ||
} | ||
@@ -177,0 +180,0 @@ function insertBeforeLastWhitespace(text, textToInsert) { |
@@ -448,3 +448,2 @@ import { JSONRepairError } from './JSONRepairError.js'; | ||
if (i > start) { | ||
var symbol = text.slice(start, i); | ||
if (text.charCodeAt(i) === codeOpenParenthesis) { | ||
@@ -466,2 +465,8 @@ // repair a MongoDB function call like NumberLong("2") | ||
// repair unquoted string | ||
// first, go back to prevent getting trailing whitespaces in the string | ||
while (isWhitespace(text.charCodeAt(i - 1)) && i > 0) { | ||
i--; | ||
} | ||
var symbol = text.slice(start, i); | ||
output += JSON.stringify(symbol); | ||
@@ -468,0 +473,0 @@ return true; |
@@ -40,8 +40,9 @@ // TODO: sort the codes | ||
var codeIdeographicSpace = 0x3000; | ||
var codeDoubleQuoteLeft = 0x201c; | ||
var codeDoubleQuoteRight = 0x201d; | ||
var codeQuoteLeft = 0x2018; | ||
var codeQuoteRight = 0x2019; | ||
var codeGraveAccent = 0x0060; | ||
var codeAcuteAccent = 0x00b4; | ||
var codeDoubleQuoteLeft = 0x201c; // “ | ||
var codeDoubleQuoteRight = 0x201d; // ” | ||
var codeQuoteLeft = 0x2018; // ‘ | ||
var codeQuoteRight = 0x2019; // ’ | ||
var codeGraveAccent = 0x0060; // ` | ||
var codeAcuteAccent = 0x00b4; // ´ | ||
export function isHex(code) { | ||
@@ -60,9 +61,11 @@ return code >= codeZero && code < codeNine || code >= codeUppercaseA && code <= codeUppercaseF || code >= codeLowercaseA && code <= codeLowercaseF; | ||
export function isDelimiter(char) { | ||
return regexDelimiter.test(char); | ||
return regexDelimiter.test(char) || char && isQuote(char.charCodeAt(0)); | ||
} | ||
var regexDelimiter = /^[,:[\]{}()\n"]$/; | ||
var regexDelimiter = /^[,:[\]{}()\n]$/; | ||
export function isStartOfValue(char) { | ||
return regexStartOfValue.test(char); | ||
return regexStartOfValue.test(char) || char && isQuote(char.charCodeAt(0)); | ||
} | ||
var regexStartOfValue = /^[[{\w"-_]$/; | ||
// alpha, number, minus, or opening bracket or brace | ||
var regexStartOfValue = /^[[{\w-]$/; | ||
export function isControlCharacter(code) { | ||
@@ -118,5 +121,5 @@ return code === codeNewline || code === codeReturn || code === codeTab || code === codeBackspace || code === codeFormFeed; | ||
export function stripLastOccurrence(text, textToStrip) { | ||
var stripWhitespace = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
var stripRemainingText = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
var index = text.lastIndexOf(textToStrip); | ||
return index !== -1 ? text.substring(0, index) + (stripWhitespace ? '' : text.substring(index + 1)) : text; | ||
return index !== -1 ? text.substring(0, index) + (stripRemainingText ? '' : text.substring(index + 1)) : text; | ||
} | ||
@@ -123,0 +126,0 @@ export function insertBeforeLastWhitespace(text, textToInsert) { |
@@ -68,3 +68,3 @@ export declare const codeBackslash = 92; | ||
*/ | ||
export declare function stripLastOccurrence(text: string, textToStrip: string, stripWhitespace?: boolean): string; | ||
export declare function stripLastOccurrence(text: string, textToStrip: string, stripRemainingText?: boolean): string; | ||
export declare function insertBeforeLastWhitespace(text: string, textToInsert: string): string; | ||
@@ -71,0 +71,0 @@ export declare function removeAtIndex(text: string, start: number, count: number): string; |
@@ -73,8 +73,9 @@ (function (global, factory) { | ||
var codeIdeographicSpace = 0x3000; | ||
var codeDoubleQuoteLeft = 0x201c; | ||
var codeDoubleQuoteRight = 0x201d; | ||
var codeQuoteLeft = 0x2018; | ||
var codeQuoteRight = 0x2019; | ||
var codeGraveAccent = 0x0060; | ||
var codeAcuteAccent = 0x00b4; | ||
var codeDoubleQuoteLeft = 0x201c; // “ | ||
var codeDoubleQuoteRight = 0x201d; // ” | ||
var codeQuoteLeft = 0x2018; // ‘ | ||
var codeQuoteRight = 0x2019; // ’ | ||
var codeGraveAccent = 0x0060; // ` | ||
var codeAcuteAccent = 0x00b4; // ´ | ||
function isHex(code) { | ||
@@ -93,9 +94,11 @@ return code >= codeZero && code < codeNine || code >= codeUppercaseA && code <= codeUppercaseF || code >= codeLowercaseA && code <= codeLowercaseF; | ||
function isDelimiter(char) { | ||
return regexDelimiter.test(char); | ||
return regexDelimiter.test(char) || char && isQuote(char.charCodeAt(0)); | ||
} | ||
var regexDelimiter = /^[,:[\]{}()\n"]$/; | ||
var regexDelimiter = /^[,:[\]{}()\n]$/; | ||
function isStartOfValue(char) { | ||
return regexStartOfValue.test(char); | ||
return regexStartOfValue.test(char) || char && isQuote(char.charCodeAt(0)); | ||
} | ||
var regexStartOfValue = /^[[{\w"-_]$/; | ||
// alpha, number, minus, or opening bracket or brace | ||
var regexStartOfValue = /^[[{\w-]$/; | ||
function isControlCharacter(code) { | ||
@@ -151,5 +154,5 @@ return code === codeNewline || code === codeReturn || code === codeTab || code === codeBackspace || code === codeFormFeed; | ||
function stripLastOccurrence(text, textToStrip) { | ||
var stripWhitespace = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
var stripRemainingText = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
var index = text.lastIndexOf(textToStrip); | ||
return index !== -1 ? text.substring(0, index) + (stripWhitespace ? '' : text.substring(index + 1)) : text; | ||
return index !== -1 ? text.substring(0, index) + (stripRemainingText ? '' : text.substring(index + 1)) : text; | ||
} | ||
@@ -616,3 +619,2 @@ function insertBeforeLastWhitespace(text, textToInsert) { | ||
if (i > start) { | ||
var symbol = text.slice(start, i); | ||
if (text.charCodeAt(i) === codeOpenParenthesis) { | ||
@@ -634,2 +636,8 @@ // repair a MongoDB function call like NumberLong("2") | ||
// repair unquoted string | ||
// first, go back to prevent getting trailing whitespaces in the string | ||
while (isWhitespace(text.charCodeAt(i - 1)) && i > 0) { | ||
i--; | ||
} | ||
var symbol = text.slice(start, i); | ||
output += JSON.stringify(symbol); | ||
@@ -636,0 +644,0 @@ return true; |
@@ -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";function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function u(r){var n=c();return function(){var t,e=a(r),e=(t=n?(t=a(this).constructor,Reflect.construct(e,arguments,t)):e.apply(this,arguments),this);if(t&&("object"===o(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");if(void 0!==e)return e;throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}}function e(t){var r="function"==typeof Map?new Map:void 0;return function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,e)}function e(){return n(t,arguments,a(this).constructor)}return e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),f(e,t)}(t)}function n(t,e,r){return(n=c()?Reflect.construct.bind():function(t,e,r){var n=[null];n.push.apply(n,e);e=new(Function.bind.apply(t,n));return r&&f(e,r.prototype),e}).apply(null,arguments)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function f(t,e){return(f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function a(t){return(a=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var y=function(t){var e=c;if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&f(e,t);var r,n,o=u(c);function c(t,e){if(this instanceof c)return(t=o.call(this,t+" at position "+e)).position=e,t;throw new TypeError("Cannot call a class as a function")}return e=c,r&&i(e.prototype,r),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}(e(Error)),r=32,C=10,A=9,v=13,g=8,w=12,O=34,l=39,j=48,m=49,x=57,h=65,d=97,s=70,p=102,S=160,P=8192,$=8202,B=8239,M=8287,U=12288,b=8220,D=8221,q=8216,z=8217,G=96,H=180;function R(t){return j<=t&&t<x||h<=t&&t<=s||d<=t&&t<=p}function _(t){return j<=t&&t<=x}var K=/^[,:[\]{}()\n"]$/;function E(t){return L.test(t)}var L=/^[[{\w"-_]$/;function T(t){return t===r||t===C||t===A||t===v}function N(t){return J(t)||k(t)}function J(t){return t===O||t===b||t===D}function k(t){return t===l||t===q||t===z||t===G||t===H}function I(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 F(t,e){var r=t.length;if(!T(t.charCodeAt(r-1)))return t+e;for(;T(t.charCodeAt(r-1));)r--;return t.substring(0,r)+e+t.substring(r)}var Q={"\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t"},V={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};t.JSONRepairError=y,t.jsonrepair=function(u){var f=0,a="";if(!n())throw new y("Unexpected end of json string",u.length);var t=c(44);if(t&&l(),E(u[f])&&/[,\n][ \t\r]*$/.test(a)){t||(a=F(a,","));for(var e=!0,r=!0;r;)e?e=!1:c(44)||(a=F(a,",")),r=n();r||(a=I(a,",")),a="[\n".concat(a,"\n]")}else t&&(a=I(a,","));if(f>=u.length)return a;throw new y("Unexpected character "+JSON.stringify(u[f]),f);function n(){l();var t=function(){if(123!==u.charCodeAt(f))return!1;a+="{",f++,l();var t=!0;for(;f<u.length&&125!==u.charCodeAt(f);){if(t?t=!!0:(c(44)||(a=F(a,",")),l()),!(d()||s())){125===u.charCodeAt(f)||123===u.charCodeAt(f)||93===u.charCodeAt(f)||91===u.charCodeAt(f)||void 0===u[f]?a=I(a,","):function(){throw new y("Object key expected",f)}();break}l();var e=c(58);e||(E(u[f])?a=F(a,":"):b()),n()||(e?function(){throw new y("Object value expected",f)}:b)()}125===u.charCodeAt(f)?(a+="}",f++):a=F(a,"}");return!0}()||function(){if(91!==u.charCodeAt(f))return!1;a+="[",f++,l();var t=!0;for(;f<u.length&&93!==u.charCodeAt(f);)if(t?t=!1:c(44)||(a=F(a,",")),!n()){a=I(a,",");break}93===u.charCodeAt(f)?(a+="]",f++):a=F(a,"]");return!0}()||d()||function(){var t=f;45===u.charCodeAt(f)&&(f++,p(t));if(u.charCodeAt(f)===j)f++;else if(function(t){return m<=t&&t<=x}(u.charCodeAt(f)))for(f++;_(u.charCodeAt(f));)f++;if(46===u.charCodeAt(f))for(f++,p(t);_(u.charCodeAt(f));)f++;if(101===u.charCodeAt(f)||69===u.charCodeAt(f))for(f++,45!==u.charCodeAt(f)&&43!==u.charCodeAt(f)||f++,p(t);_(u.charCodeAt(f));)f++;if(t<f)return a+=u.slice(t,f),!0;return!1}()||i("true","true")||i("false","false")||i("null","null")||i("True","true")||i("False","false")||i("None","null")||s();return l(),t}function l(){for(o();function(){if(47===u.charCodeAt(f)&&42===u.charCodeAt(f+1)){for(;f<u.length&&!function(t,e){return"*"===t[e]&&"/"===t[e+1]}(u,f);)f++;f+=2}else{if(47!==u.charCodeAt(f)||47!==u.charCodeAt(f+1))return!1;for(;f<u.length&&u.charCodeAt(f)!==C;)f++}return!0}()&&o(););}function o(){for(var t,e,r="";(t=T(u.charCodeAt(f)))||(e=u.charCodeAt(f))===S||P<=e&&e<=$||e===B||e===M||e===U;)r+=t?u[f]:" ",f++;return 0<r.length&&(a+=r,!0)}function c(t){return u.charCodeAt(f)===t&&(a+=u[f],f++,!0)}function h(){92===u.charCodeAt(f)&&f++}function d(){var t,e=92===u.charCodeAt(f);if(e&&(f++,e=!0),N(u.charCodeAt(f))){var r=k(u.charCodeAt(f))?k:J;for(u.charCodeAt(f),a+='"',f++;f<u.length&&!r(u.charCodeAt(f));){if(92===u.charCodeAt(f)){var n=u[f+1];if(void 0!==V[n])a+=u.slice(f,f+2),f+=2;else if("u"===n){if(!(R(u.charCodeAt(f+2))&&R(u.charCodeAt(f+3))&&R(u.charCodeAt(f+4))&&R(u.charCodeAt(f+5)))){c=o=void 0;for(var o=f,c=o+2;/\w/.test(u[c]);)c++;throw o=u.slice(o,c),new y('Invalid unicode character "'.concat(o,'"'),f)}a+=u.slice(f,f+6),f+=6}else a+=n,f+=2}else{o=u[f],n=u.charCodeAt(f);if(n===O&&92!==u.charCodeAt(f-1))a+="\\"+o;else if((t=n)===C||t===v||t===A||t===g||t===w)a+=Q[o];else{if(!(32<=(t=n)&&t<=1114111))throw new y("Invalid character "+JSON.stringify(o),f);a+=o}f++}e&&h()}N(u.charCodeAt(f))?(u.charCodeAt(f),a+='"',f++):a+='"';for(l();43===u.charCodeAt(f);){f++,l();var i=(a=I(a,'"',!0)).length;d(),a=function(t,e,r){return t.substring(0,e)+t.substring(e+r)}(a,i,1)}return!0}return!1}function i(t,e){return u.slice(f,f+t.length)===t&&(a+=e,f+=t.length,!0)}function s(){for(var t,e=f;f<u.length&&(t=u[f],!K.test(t));)f++;if(e<f)return e=u.slice(e,f),40===u.charCodeAt(f)?(f++,n(),41===u.charCodeAt(f)&&(f++,59===u.charCodeAt(f))&&f++):a+=JSON.stringify(e),!0}function p(t){if(!_(u.charCodeAt(f)))throw t=u.slice(t,f),new y("Invalid number '".concat(t,"', expecting a digit ").concat(u[f]?"but got '".concat(u[f],"'"):"but reached end of input"),2)}function b(){throw new y("Colon expected",f)}}}); | ||
!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";function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function u(r){var n=c();return function(){var t,e=a(r),e=(t=n?(t=a(this).constructor,Reflect.construct(e,arguments,t)):e.apply(this,arguments),this);if(t&&("object"===o(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");if(void 0!==e)return e;throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}}function e(t){var r="function"==typeof Map?new Map:void 0;return function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,e)}function e(){return n(t,arguments,a(this).constructor)}return e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),f(e,t)}(t)}function n(t,e,r){return(n=c()?Reflect.construct.bind():function(t,e,r){var n=[null];n.push.apply(n,e);e=new(Function.bind.apply(t,n));return r&&f(e,r.prototype),e}).apply(null,arguments)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function f(t,e){return(f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function a(t){return(a=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var y=function(t){var e=c;if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&f(e,t);var r,n,o=u(c);function c(t,e){if(this instanceof c)return(t=o.call(this,t+" at position "+e)).position=e,t;throw new TypeError("Cannot call a class as a function")}return e=c,r&&i(e.prototype,r),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}(e(Error)),r=32,C=10,A=9,v=13,g=8,w=12,O=34,l=39,j=48,m=49,x=57,h=65,d=97,s=70,p=102,S=160,P=8192,$=8202,B=8239,M=8287,U=12288,b=8220,D=8221,q=8216,z=8217,G=96,H=180;function R(t){return j<=t&&t<x||h<=t&&t<=s||d<=t&&t<=p}function _(t){return j<=t&&t<=x}var K=/^[,:[\]{}()\n]$/;function E(t){return L.test(t)||t&&N(t.charCodeAt(0))}var L=/^[[{\w-]$/;function T(t){return t===r||t===C||t===A||t===v}function N(t){return J(t)||k(t)}function J(t){return t===O||t===b||t===D}function k(t){return t===l||t===q||t===z||t===G||t===H}function I(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 F(t,e){var r=t.length;if(!T(t.charCodeAt(r-1)))return t+e;for(;T(t.charCodeAt(r-1));)r--;return t.substring(0,r)+e+t.substring(r)}var Q={"\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t"},V={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};t.JSONRepairError=y,t.jsonrepair=function(u){var f=0,a="";if(!n())throw new y("Unexpected end of json string",u.length);var t=c(44);if(t&&l(),E(u[f])&&/[,\n][ \t\r]*$/.test(a)){t||(a=F(a,","));for(var e=!0,r=!0;r;)e?e=!1:c(44)||(a=F(a,",")),r=n();r||(a=I(a,",")),a="[\n".concat(a,"\n]")}else t&&(a=I(a,","));if(f>=u.length)return a;throw new y("Unexpected character "+JSON.stringify(u[f]),f);function n(){l();var t=function(){if(123!==u.charCodeAt(f))return!1;a+="{",f++,l();var t=!0;for(;f<u.length&&125!==u.charCodeAt(f);){if(t?t=!!0:(c(44)||(a=F(a,",")),l()),!(d()||s())){125===u.charCodeAt(f)||123===u.charCodeAt(f)||93===u.charCodeAt(f)||91===u.charCodeAt(f)||void 0===u[f]?a=I(a,","):function(){throw new y("Object key expected",f)}();break}l();var e=c(58);e||(E(u[f])?a=F(a,":"):b()),n()||(e?function(){throw new y("Object value expected",f)}:b)()}125===u.charCodeAt(f)?(a+="}",f++):a=F(a,"}");return!0}()||function(){if(91!==u.charCodeAt(f))return!1;a+="[",f++,l();var t=!0;for(;f<u.length&&93!==u.charCodeAt(f);)if(t?t=!1:c(44)||(a=F(a,",")),!n()){a=I(a,",");break}93===u.charCodeAt(f)?(a+="]",f++):a=F(a,"]");return!0}()||d()||function(){var t=f;45===u.charCodeAt(f)&&(f++,p(t));if(u.charCodeAt(f)===j)f++;else if(function(t){return m<=t&&t<=x}(u.charCodeAt(f)))for(f++;_(u.charCodeAt(f));)f++;if(46===u.charCodeAt(f))for(f++,p(t);_(u.charCodeAt(f));)f++;if(101===u.charCodeAt(f)||69===u.charCodeAt(f))for(f++,45!==u.charCodeAt(f)&&43!==u.charCodeAt(f)||f++,p(t);_(u.charCodeAt(f));)f++;if(t<f)return a+=u.slice(t,f),!0;return!1}()||i("true","true")||i("false","false")||i("null","null")||i("True","true")||i("False","false")||i("None","null")||s();return l(),t}function l(){for(o();function(){if(47===u.charCodeAt(f)&&42===u.charCodeAt(f+1)){for(;f<u.length&&!function(t,e){return"*"===t[e]&&"/"===t[e+1]}(u,f);)f++;f+=2}else{if(47!==u.charCodeAt(f)||47!==u.charCodeAt(f+1))return!1;for(;f<u.length&&u.charCodeAt(f)!==C;)f++}return!0}()&&o(););}function o(){for(var t,e,r="";(t=T(u.charCodeAt(f)))||(e=u.charCodeAt(f))===S||P<=e&&e<=$||e===B||e===M||e===U;)r+=t?u[f]:" ",f++;return 0<r.length&&(a+=r,!0)}function c(t){return u.charCodeAt(f)===t&&(a+=u[f],f++,!0)}function h(){92===u.charCodeAt(f)&&f++}function d(){var t,e=92===u.charCodeAt(f);if(e&&(f++,e=!0),N(u.charCodeAt(f))){var r=k(u.charCodeAt(f))?k:J;for(u.charCodeAt(f),a+='"',f++;f<u.length&&!r(u.charCodeAt(f));){if(92===u.charCodeAt(f)){var n=u[f+1];if(void 0!==V[n])a+=u.slice(f,f+2),f+=2;else if("u"===n){if(!(R(u.charCodeAt(f+2))&&R(u.charCodeAt(f+3))&&R(u.charCodeAt(f+4))&&R(u.charCodeAt(f+5)))){c=o=void 0;for(var o=f,c=o+2;/\w/.test(u[c]);)c++;throw o=u.slice(o,c),new y('Invalid unicode character "'.concat(o,'"'),f)}a+=u.slice(f,f+6),f+=6}else a+=n,f+=2}else{o=u[f],n=u.charCodeAt(f);if(n===O&&92!==u.charCodeAt(f-1))a+="\\"+o;else if((t=n)===C||t===v||t===A||t===g||t===w)a+=Q[o];else{if(!(32<=(t=n)&&t<=1114111))throw new y("Invalid character "+JSON.stringify(o),f);a+=o}f++}e&&h()}N(u.charCodeAt(f))?(u.charCodeAt(f),a+='"',f++):a+='"';for(l();43===u.charCodeAt(f);){f++,l();var i=(a=I(a,'"',!0)).length;d(),a=function(t,e,r){return t.substring(0,e)+t.substring(e+r)}(a,i,1)}return!0}return!1}function i(t,e){return u.slice(f,f+t.length)===t&&(a+=e,f+=t.length,!0)}function s(){for(var t,e=f;f<u.length&&(t=u[f],!(K.test(t)||t&&N(t.charCodeAt(0))));)f++;if(e<f){if(40===u.charCodeAt(f))f++,n(),41===u.charCodeAt(f)&&(f++,59===u.charCodeAt(f))&&f++;else{for(;T(u.charCodeAt(f-1))&&0<f;)f--;e=u.slice(e,f);a+=JSON.stringify(e)}return!0}}function p(t){if(!_(u.charCodeAt(f)))throw t=u.slice(t,f),new y("Invalid number '".concat(t,"', expecting a digit ").concat(u[f]?"but got '".concat(u[f],"'"):"but reached end of input"),2)}function b(){throw new y("Colon expected",f)}}}); |
{ | ||
"name": "jsonrepair", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Repair broken JSON documents", | ||
@@ -34,3 +34,3 @@ "repository": { | ||
"test": "mocha", | ||
"test:lib": "mocha test-lib/*.test.*", | ||
"test:it": "mocha test-lib/*.test.*", | ||
"build": "npm-run-all build:**", | ||
@@ -46,4 +46,9 @@ "build:clean": "del-cli lib", | ||
"benchmark": "npm run build:esm && node tools/benchmark/run.mjs", | ||
"build-and-test": "npm run lint && npm run build && npm run test:lib", | ||
"prepublishOnly": "npm run build-and-test" | ||
"build-and-test": "npm run lint && npm run build && npm run test:it", | ||
"release:build-and-test": "npm run build-and-test", | ||
"release:version": "standard-version", | ||
"release:push": "git push && git push --tag", | ||
"prepublishOnly": "npm-run-all release:**", | ||
"publish-dry-run": "npm run build-and-test && standard-version --dry-run", | ||
"prepare": "husky install" | ||
}, | ||
@@ -63,2 +68,4 @@ "files": [ | ||
"@babel/preset-typescript": "7.18.6", | ||
"@commitlint/cli": "17.3.0", | ||
"@commitlint/config-conventional": "17.3.0", | ||
"@types/mocha": "10.0.1", | ||
@@ -77,2 +84,3 @@ "@types/node": "18.11.13", | ||
"eslint-plugin-promise": "6.1.1", | ||
"husky": "8.0.2", | ||
"mocha": "10.1.0", | ||
@@ -82,2 +90,3 @@ "npm-run-all": "4.1.5", | ||
"rollup": "3.3.0", | ||
"standard-version": "9.5.0", | ||
"ts-node": "10.9.1", | ||
@@ -84,0 +93,0 @@ "typescript": "4.9.4", |
@@ -86,3 +86,3 @@ # jsonrepair | ||
``` | ||
```ts | ||
// @throws JSONRepairError | ||
@@ -165,5 +165,21 @@ jsonrepair(json: string) : string | ||
### Publish | ||
To publish: | ||
``` | ||
$ npm publish | ||
``` | ||
This will list, test, and build the project. Then it will up the version number (using `standard-version`), push the changes to git, add a git version tag, and then publish the npm package. | ||
To try the build and see the change list without actually publishing: | ||
``` | ||
$ npm publish-dry-run | ||
``` | ||
## License | ||
Released under the [ISC license](LICENSE.md). |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
260545
2293
184
0
29