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

lossless-json

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lossless-json - npm Package Compare versions

Comparing version 2.0.3 to 2.0.4

4

HISTORY.md
# History
## 2022-12-19, version 2.0.4
- Improved performance.
## 2022-12-01, version 2.0.3

@@ -4,0 +8,0 @@

108

lib/esm/parse.js

@@ -33,3 +33,3 @@ import { parseLosslessNumber } from './numberParsers.js';

function parseObject() {
if (text[i] === '{') {
if (text.charCodeAt(i) === codeOpeningBrace) {
i++;

@@ -39,3 +39,3 @@ skipWhitespace();

var initial = true;
while (i < text.length && text[i] !== '}') {
while (i < text.length && text.charCodeAt(i) !== codeClosingBrace) {
if (!initial) {

@@ -60,3 +60,3 @@ eatComma();

}
if (text[i] !== '}') {
if (text.charCodeAt(i) !== codeClosingBrace) {
throwObjectKeyOrEndExpected();

@@ -69,3 +69,3 @@ }

function parseArray() {
if (text[i] === '[') {
if (text.charCodeAt(i) === codeOpeningBracket) {
i++;

@@ -75,3 +75,3 @@ skipWhitespace();

var initial = true;
while (i < text.length && text[i] !== ']') {
while (i < text.length && text.charCodeAt(i) !== codeClosingBracket) {
if (!initial) {

@@ -86,3 +86,3 @@ eatComma();

}
if (text[i] !== ']') {
if (text.charCodeAt(i) !== codeClosingBracket) {
throwArrayItemOrEndExpected();

@@ -108,3 +108,3 @@ }

function skipWhitespace() {
while (isWhitespace(text[i])) {
while (isWhitespace(text.charCodeAt(i))) {
i++;

@@ -114,7 +114,7 @@ }

function parseString() {
if (text[i] === '"') {
if (text.charCodeAt(i) === codeDoubleQuote) {
i++;
var result = '';
while (i < text.length && text[i] !== '"') {
if (text[i] === '\\') {
while (i < text.length && text.charCodeAt(i) !== codeDoubleQuote) {
if (text.charCodeAt(i) === codeBackslash) {
var char = text[i + 1];

@@ -126,3 +126,3 @@ var escapeChar = escapeCharacters[char];

} else if (char === 'u') {
if (isHex(text[i + 2]) && isHex(text[i + 3]) && isHex(text[i + 4]) && isHex(text[i + 5])) {
if (isHex(text.charCodeAt(i + 2)) && isHex(text.charCodeAt(i + 3)) && isHex(text.charCodeAt(i + 4)) && isHex(text.charCodeAt(i + 5))) {
result += String.fromCharCode(parseInt(text.slice(i + 2, i + 6), 16));

@@ -137,7 +137,6 @@ i += 5;

} else {
var _char = text[i];
if (isValidStringCharacter(_char)) {
result += _char;
if (isValidStringCharacter(text.charCodeAt(i))) {
result += text[i];
} else {
throwInvalidCharacter(_char);
throwInvalidCharacter(text[i]);
}

@@ -154,28 +153,28 @@ }

var start = i;
if (text[i] === '-') {
if (text.charCodeAt(i) === codeMinus) {
i++;
expectDigit(start);
}
if (text[i] === '0') {
if (text.charCodeAt(i) === codeZero) {
i++;
} else if (isNonZeroDigit(text[i])) {
} else if (isNonZeroDigit(text.charCodeAt(i))) {
i++;
while (isDigit(text[i])) {
while (isDigit(text.charCodeAt(i))) {
i++;
}
}
if (text[i] === '.') {
if (text.charCodeAt(i) === codeDot) {
i++;
expectDigit(start);
while (isDigit(text[i])) {
while (isDigit(text.charCodeAt(i))) {
i++;
}
}
if (text[i] === 'e' || text[i] === 'E') {
if (text.charCodeAt(i) === codeLowercaseE || text.charCodeAt(i) === codeUppercaseE) {
i++;
if (text[i] === '-' || text[i] === '+') {
if (text.charCodeAt(i) === codeMinus || text.charCodeAt(i) === codePlus) {
i++;
}
expectDigit(start);
while (isDigit(text[i])) {
while (isDigit(text.charCodeAt(i))) {
i++;

@@ -189,3 +188,3 @@ }

function eatComma() {
if (text[i] !== ',') {
if (text.charCodeAt(i) !== codeComma) {
throw new SyntaxError("Comma ',' expected after value ".concat(gotAt()));

@@ -196,3 +195,3 @@ }

function eatColon() {
if (text[i] !== ':') {
if (text.charCodeAt(i) !== codeColon) {
throw new SyntaxError("Colon ':' expected after property name ".concat(gotAt()));

@@ -218,3 +217,3 @@ }

function expectDigit(start) {
if (!isDigit(text[i])) {
if (!isDigit(text.charCodeAt(i))) {
var numSoFar = text.slice(start, i);

@@ -225,3 +224,3 @@ throw new SyntaxError("Invalid number '".concat(numSoFar, "', expecting a digit ").concat(gotAt()));

function expectEndOfString() {
if (text[i] !== '"') {
if (text.charCodeAt(i) !== codeDoubleQuote) {
throw new SyntaxError("End of string '\"' expected ".concat(gotAt()));

@@ -263,3 +262,3 @@ }

function got() {
return text[i] ? "but got '".concat(text[i], "'") : 'but reached end of input';
return i < text.length ? "but got '".concat(text[i], "'") : 'but reached end of input';
}

@@ -270,16 +269,16 @@ function gotAt() {

}
function isWhitespace(char) {
return whitespaceCharacters[char] === true;
function isWhitespace(code) {
return code === codeSpace || code === codeNewline || code === codeTab || code === codeReturn;
}
function isHex(char) {
return /^[0-9a-fA-F]/.test(char);
function isHex(code) {
return code >= codeZero && code < codeNine || code >= codeUppercaseA && code <= codeUppercaseF || code >= codeLowercaseA && code <= codeLowercaseF;
}
function isDigit(char) {
return /[0-9]/.test(char);
function isDigit(code) {
return code >= codeZero && code <= codeNine;
}
function isNonZeroDigit(char) {
return /[1-9]/.test(char);
function isNonZeroDigit(code) {
return code >= codeOne && code <= codeNine;
}
function isValidStringCharacter(char) {
return /^(?:[ -\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])$/.test(char);
export function isValidStringCharacter(code) {
return code >= 0x20 && code <= 0x10ffff;
}

@@ -300,9 +299,26 @@

// map with all whitespace characters
var whitespaceCharacters = {
' ': true,
'\n': true,
'\t': true,
'\r': true
};
var codeBackslash = 0x5c; // "\"
var codeOpeningBrace = 0x7b; // "{"
var codeClosingBrace = 0x7d; // "}"
var codeOpeningBracket = 0x5b; // "["
var codeClosingBracket = 0x5d; // "]"
var codeSpace = 0x20; // " "
var codeNewline = 0xa; // "\n"
var codeTab = 0x9; // "\t"
var codeReturn = 0xd; // "\r"
var codeDoubleQuote = 0x0022; // "
var codePlus = 0x2b; // "+"
var codeMinus = 0x2d; // "-"
var codeZero = 0x30;
var codeOne = 0x31;
var codeNine = 0x39;
var codeComma = 0x2c; // ","
var codeDot = 0x2e; // "." (dot, period)
var codeColon = 0x3a; // ":"
export var codeUppercaseA = 0x41; // "A"
export var codeLowercaseA = 0x61; // "a"
export var codeUppercaseE = 0x45; // "E"
export var codeLowercaseE = 0x65; // "e"
export var codeUppercaseF = 0x46; // "F"
export var codeLowercaseF = 0x66; // "f"
//# sourceMappingURL=parse.js.map

@@ -26,2 +26,9 @@ import { JavaScriptValue } from './types';

export declare function parse(text: string, reviver?: Reviver, parseNumber?: NumberParser): JavaScriptValue;
export declare function isValidStringCharacter(code: number): boolean;
export declare const codeUppercaseA = 65;
export declare const codeLowercaseA = 97;
export declare const codeUppercaseE = 69;
export declare const codeLowercaseE = 101;
export declare const codeUppercaseF = 70;
export declare const codeLowercaseF = 102;
//# sourceMappingURL=parse.d.ts.map

@@ -1,1 +0,1 @@

!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).LosslessJSON={})}(this,(function(n){"use strict";function t(n){return r.test(n)}var r=/^-?[0-9]+$/;function e(n){return i.test(n)}var o,i=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;function u(n,r){var e=parseFloat(n),o=String(e),i=c(n),u=c(o);if(i===u)return!0;if(!0===(null==r?void 0:r.approx)){if(!t(n)&&u.length>=14&&i.startsWith(u.substring(0,14)))return!0}return!1}function a(r){if(!u(r,{approx:!1})){if(t(r))return n.UnsafeNumberReason.truncate_integer;var e=parseFloat(r);return isFinite(e)?0===e?n.UnsafeNumberReason.underflow:n.UnsafeNumberReason.truncate_float:n.UnsafeNumberReason.overflow}}function c(n){return n.replace(f,"").replace(s,"").replace(y,"").replace(l,"")}n.UnsafeNumberReason=void 0,(o=n.UnsafeNumberReason||(n.UnsafeNumberReason={})).underflow="underflow",o.overflow="overflow",o.truncate_integer="truncate_integer",o.truncate_float="truncate_float";var f=/[eE][+-]?\d+$/,l=/^-?(0*)?/,s=/\./,y=/0+$/;function v(n){return v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},v(n)}function p(n,t){for(var r=0;r<t.length;r++){var e=t[r];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(n,b(e.key),e)}}function b(n){var t=function(n,t){if("object"!==v(n)||null===n)return n;var r=n[Symbol.toPrimitive];if(void 0!==r){var e=r.call(n,t||"default");if("object"!==v(e))return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(n)}(n,"string");return"symbol"===v(t)?t:String(t)}var d=function(){function r(n){if(function(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r),function(n,t,r){(t=b(t))in n?Object.defineProperty(n,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):n[t]=r}(this,"isLosslessNumber",!0),!e(n))throw new Error('Invalid number (value: "'+n+'")');this.value=n}var o,i,u;return o=r,(i=[{key:"valueOf",value:function(){var r=a(this.value);if(void 0===r||r===n.UnsafeNumberReason.truncate_float)return parseFloat(this.value);if(t(this.value))return BigInt(this.value);throw new Error("Cannot safely convert to number: "+"the value '".concat(this.value,"' would ").concat(r," and become ").concat(parseFloat(this.value)))}},{key:"toString",value:function(){return this.value}}])&&p(o.prototype,i),u&&p(o,u),Object.defineProperty(o,"prototype",{writable:!1}),r}();function m(n){return n&&"object"===v(n)&&!0===n.isLosslessNumber||!1}function h(n){return new d(n)}function w(n){return w="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},w(n)}function g(n,t){return S({"":n},"",n,t)}function S(n,t,r,e){return Array.isArray(r)?e.call(n,t,function(n,t){for(var r=0;r<n.length;r++)n[r]=S(n,r+"",n[r],t);return n}(r,e)):r&&"object"===w(r)&&!m(r)?e.call(n,t,function(n,t){return Object.keys(n).forEach((function(r){var e=S(n,r,n[r],t);void 0!==e?n[r]=e:delete n[r]})),n}(r,e)):e.call(n,t,r)}function N(n){return!0===j[n]}function E(n){return/^[0-9a-fA-F]/.test(n)}function x(n){return/[0-9]/.test(n)}function F(n){return/[1-9]/.test(n)}function D(n){return/^(?:[ -\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])$/.test(n)}var O={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"},j={" ":!0,"\n":!0,"\t":!0,"\r":!0};function I(n){return I="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},I(n)}var A=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;n.LosslessNumber=d,n.config=function(n){throw new Error("config is deprecated, support for circularRefs is removed from the library. If you encounter circular references in your data structures, please rethink your datastructures: better prevent circular references in the first place.")},n.getUnsafeNumberReason=a,n.isInteger=t,n.isLosslessNumber=m,n.isNumber=e,n.isSafeNumber=u,n.parse=function(n,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:h,e=0,o=a();return p(o),d(),t?g(o,t):o;function i(){if("{"===n[e]){e++,f();for(var t={},r=!0;e<n.length&&"}"!==n[e];){r?r=!1:(y(),f());var o=l();void 0===o&&S(),Object.prototype.hasOwnProperty.call(t,o)&&j(o),f(),v(),t[o]=a()}return"}"!==n[e]&&I(),e++,t}}function u(){if("["===n[e]){e++,f();for(var t=[],r=!0;e<n.length&&"]"!==n[e];){r?r=!1:y();var o=a();b(o),t.push(o)}return"]"!==n[e]&&A(),e++,t}}function a(){var n,t,r,e,o,a;f();var y=null!==(n=null!==(t=null!==(r=null!==(e=null!==(o=null!==(a=l())&&void 0!==a?a:s())&&void 0!==o?o:i())&&void 0!==e?e:u())&&void 0!==r?r:c("true",!0))&&void 0!==t?t:c("false",!1))&&void 0!==n?n:c("null",null);return f(),y}function c(t,r){if(n.slice(e,e+t.length)===t)return e+=t.length,r}function f(){for(;N(n[e]);)e++}function l(){if('"'===n[e]){e++;for(var t="";e<n.length&&'"'!==n[e];){if("\\"===n[e]){var r=n[e+1],o=O[r];void 0!==o?(t+=o,e++):"u"===r?E(n[e+2])&&E(n[e+3])&&E(n[e+4])&&E(n[e+5])?(t+=String.fromCharCode(parseInt(n.slice(e+2,e+6),16)),e+=5):C(e):k(e)}else{var i=n[e];D(i)?t+=i:R(i)}e++}return w(),e++,t}}function s(){var t=e;if("-"===n[e]&&(e++,m(t)),"0"===n[e])e++;else if(F(n[e]))for(e++;x(n[e]);)e++;if("."===n[e])for(e++,m(t);x(n[e]);)e++;if("e"===n[e]||"E"===n[e])for(e++,"-"!==n[e]&&"+"!==n[e]||e++,m(t);x(n[e]);)e++;if(e>t)return r(n.slice(t,e))}function y(){if(","!==n[e])throw new SyntaxError("Comma ',' expected after value ".concat(J()));e++}function v(){if(":"!==n[e])throw new SyntaxError("Colon ':' expected after property name ".concat(J()));e++}function p(n){if(void 0===n)throw new SyntaxError("JSON value expected ".concat(J()))}function b(n){if(void 0===n)throw new SyntaxError("Array item expected ".concat(J()))}function d(){if(e<n.length)throw new SyntaxError("Expected end of input ".concat(J()))}function m(t){if(!x(n[e])){var r=n.slice(t,e);throw new SyntaxError("Invalid number '".concat(r,"', expecting a digit ").concat(J()))}}function w(){if('"'!==n[e])throw new SyntaxError("End of string '\"' expected ".concat(J()))}function S(){throw new SyntaxError("Quoted object key expected ".concat(J()))}function j(n){throw new SyntaxError("Duplicate key '".concat(n,"' encountered at position ").concat(e-n.length-1))}function I(){throw new SyntaxError("Quoted object key or end of object '}' expected ".concat(J()))}function A(){throw new SyntaxError("Array item or end of array ']' expected ".concat(J()))}function R(n){throw new SyntaxError("Invalid character '".concat(n,"' ").concat(U()))}function k(t){var r=n.slice(t,t+2);throw new SyntaxError("Invalid escape character '".concat(r,"' ").concat(U()))}function C(t){for(var r=t+2;/\w/.test(n[r]);)r++;var e=n.slice(t,r);throw new SyntaxError("Invalid unicode character '".concat(e,"' ").concat(U()))}function U(){return"at position ".concat(e)}function _(){return n[e]?"but got '".concat(n[e],"'"):"but reached end of input"}function J(){return _()+" "+U()}},n.parseLosslessNumber=h,n.parseNumberAndBigInt=function(n){return t(n)?BigInt(n):parseFloat(n)},n.reviveDate=function(n,t){return"string"==typeof t&&A.test(t)?new Date(t):t},n.stringify=function n(t,r,o,i){var u=function(n){if("number"==typeof n)return" ".repeat(n);if("string"==typeof n&&""!==n)return n;return}(o);return a("function"==typeof r?r.call({"":t},"",t):t,"");function a(t,c){if(Array.isArray(i)){var f=i.find((function(n){return n.test(t)}));if(f){var l=f.stringify(t);if("string"!=typeof l||!e(l))throw new Error("Invalid JSON number: output of a number stringifier must be a string containing a JSON number "+"(output: ".concat(l,")"));return l}}return"boolean"==typeof t||"number"==typeof t||"string"==typeof t||null===t||t instanceof Date||t instanceof Boolean||t instanceof Number||t instanceof String?JSON.stringify(t):t&&t.isLosslessNumber||"bigint"==typeof t?t.toString():Array.isArray(t)?function(n,t){for(var e=u?t+u:void 0,o=u?"[\n":"[",i=0;i<n.length;i++){var c="function"==typeof r?r.call(n,String(i),n[i]):n[i];u&&(o+=e),o+=void 0!==c&&"function"!=typeof c?a(c,e):"null",i<n.length-1&&(o+=u?",\n":",")}return o+=u?"\n"+t+"]":"]"}(t,c):t&&"object"===I(t)?function(t,e){if("function"==typeof t.toJSON)return n(t.toJSON(),r,o,void 0);var i=Array.isArray(r)?r.map(String):Object.keys(t),c=u?e+u:void 0,f=!0,l=u?"{\n":"{";return i.forEach((function(n){var e="function"==typeof r?r.call(t,n,t[n]):t[n];if(function(n,t){return void 0!==t&&"function"!=typeof t&&"symbol"!==I(t)}(0,e)){f?f=!1:l+=u?",\n":",";var o=JSON.stringify(n);l+=u?c+o+": ":o+":",l+=a(e,c)}})),l+=u?"\n"+e+"}":"}"}(t,c):void 0}},n.toLosslessNumber=function(n){if(c(n+"").length>15)throw new Error("Invalid number: contains more than 15 digits and is most likely truncated and unsafe by itself "+"(value: ".concat(n,")"));if(isNaN(n))throw new Error("Invalid number: NaN");if(!isFinite(n))throw new Error("Invalid number: "+n);return new d(String(n))},n.toSafeNumberOrThrow=function(t,r){var e=parseFloat(t),o=a(t);if(!0===(null==r?void 0:r.approx)?o&&o!==n.UnsafeNumberReason.truncate_float:o){var i=o.replace(/_\w+$/,"");throw new Error("Cannot safely convert to number: "+"the value '".concat(t,"' would ").concat(i," and become ").concat(e))}return e}}));//# sourceMappingURL=lossless-json.js.map
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self).LosslessJSON={})}(this,(function(t){"use strict";function r(t){return n.test(t)}var n=/^-?[0-9]+$/;function e(t){return a.test(t)}var o,a=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;function i(t,n){var e=parseFloat(t),o=String(e),a=u(t),i=u(o);if(a===i)return!0;if(!0===(null==n?void 0:n.approx)){if(!r(t)&&i.length>=14&&a.startsWith(i.substring(0,14)))return!0}return!1}function c(n){if(!i(n,{approx:!1})){if(r(n))return t.UnsafeNumberReason.truncate_integer;var e=parseFloat(n);return isFinite(e)?0===e?t.UnsafeNumberReason.underflow:t.UnsafeNumberReason.truncate_float:t.UnsafeNumberReason.overflow}}function u(t){return t.replace(f,"").replace(s,"").replace(d,"").replace(l,"")}t.UnsafeNumberReason=void 0,(o=t.UnsafeNumberReason||(t.UnsafeNumberReason={})).underflow="underflow",o.overflow="overflow",o.truncate_integer="truncate_integer",o.truncate_float="truncate_float";var f=/[eE][+-]?\d+$/,l=/^-?(0*)?/,s=/\./,d=/0+$/;function y(t){return y="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},y(t)}function p(t,r){for(var n=0;n<r.length;n++){var e=r[n];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,v(e.key),e)}}function v(t){var r=function(t,r){if("object"!==y(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var e=n.call(t,r||"default");if("object"!==y(e))return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"===y(r)?r:String(r)}var h=function(){function n(t){if(function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,n),function(t,r,n){(r=v(r))in t?Object.defineProperty(t,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[r]=n}(this,"isLosslessNumber",!0),!e(t))throw new Error('Invalid number (value: "'+t+'")');this.value=t}var o,a,i;return o=n,(a=[{key:"valueOf",value:function(){var n=c(this.value);if(void 0===n||n===t.UnsafeNumberReason.truncate_float)return parseFloat(this.value);if(r(this.value))return BigInt(this.value);throw new Error("Cannot safely convert to number: "+"the value '".concat(this.value,"' would ").concat(n," and become ").concat(parseFloat(this.value)))}},{key:"toString",value:function(){return this.value}}])&&p(o.prototype,a),i&&p(o,i),Object.defineProperty(o,"prototype",{writable:!1}),n}();function b(t){return t&&"object"===y(t)&&!0===t.isLosslessNumber||!1}function m(t){return new h(t)}function w(t){return w="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},w(t)}function g(t,r){return S({"":t},"",t,r)}function S(t,r,n,e){return Array.isArray(n)?e.call(t,r,function(t,r){for(var n=0;n<t.length;n++)t[n]=S(t,n+"",t[n],r);return t}(n,e)):n&&"object"===w(n)&&!b(n)?e.call(t,r,function(t,r){return Object.keys(t).forEach((function(n){var e=S(t,n,t[n],r);void 0!==e?t[n]=e:delete t[n]})),t}(n,e)):e.call(t,r,n)}function A(t){return t===_||t===F||t===J||t===L}function C(t){return t>=B&&t<Q||t>=z&&t<=M||t>=G&&t<=V}function N(t){return t>=B&&t<=Q}function x(t){return t>=D&&t<=Q}function E(t){return t>=32&&t<=1114111}var O={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"},j=92,I=123,R=125,k=91,U=93,_=32,F=10,J=9,L=13,P=34,T=43,$=45,B=48,D=49,Q=57,W=44,Z=46,q=58,z=65,G=97,H=69,K=101,M=70,V=102;function X(t){return X="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},X(t)}var Y=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;t.LosslessNumber=h,t.config=function(t){throw new Error("config is deprecated, support for circularRefs is removed from the library. If you encounter circular references in your data structures, please rethink your datastructures: better prevent circular references in the first place.")},t.getUnsafeNumberReason=c,t.isInteger=r,t.isLosslessNumber=b,t.isNumber=e,t.isSafeNumber=i,t.parse=function(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:m,e=0,o=c();return p(o),h(),r?g(o,r):o;function a(){if(t.charCodeAt(e)===I){e++,f();for(var r={},n=!0;e<t.length&&t.charCodeAt(e)!==R;){n?n=!1:(d(),f());var o=l();void 0===o&&S(),Object.prototype.hasOwnProperty.call(r,o)&&_(o),f(),y(),r[o]=c()}return t.charCodeAt(e)!==R&&F(),e++,r}}function i(){if(t.charCodeAt(e)===k){e++,f();for(var r=[],n=!0;e<t.length&&t.charCodeAt(e)!==U;){n?n=!1:d();var o=c();v(o),r.push(o)}return t.charCodeAt(e)!==U&&J(),e++,r}}function c(){var t,r,n,e,o,c;f();var d=null!==(t=null!==(r=null!==(n=null!==(e=null!==(o=null!==(c=l())&&void 0!==c?c:s())&&void 0!==o?o:a())&&void 0!==e?e:i())&&void 0!==n?n:u("true",!0))&&void 0!==r?r:u("false",!1))&&void 0!==t?t:u("null",null);return f(),d}function u(r,n){if(t.slice(e,e+r.length)===r)return e+=r.length,n}function f(){for(;A(t.charCodeAt(e));)e++}function l(){if(t.charCodeAt(e)===P){e++;for(var r="";e<t.length&&t.charCodeAt(e)!==P;){if(t.charCodeAt(e)===j){var n=t[e+1],o=O[n];void 0!==o?(r+=o,e++):"u"===n?C(t.charCodeAt(e+2))&&C(t.charCodeAt(e+3))&&C(t.charCodeAt(e+4))&&C(t.charCodeAt(e+5))?(r+=String.fromCharCode(parseInt(t.slice(e+2,e+6),16)),e+=5):Q(e):D(e)}else E(t.charCodeAt(e))?r+=t[e]:L(t[e]);e++}return w(),e++,r}}function s(){var r=e;if(t.charCodeAt(e)===$&&(e++,b(r)),t.charCodeAt(e)===B)e++;else if(x(t.charCodeAt(e)))for(e++;N(t.charCodeAt(e));)e++;if(t.charCodeAt(e)===Z)for(e++,b(r);N(t.charCodeAt(e));)e++;if(t.charCodeAt(e)===K||t.charCodeAt(e)===H)for(e++,t.charCodeAt(e)!==$&&t.charCodeAt(e)!==T||e++,b(r);N(t.charCodeAt(e));)e++;if(e>r)return n(t.slice(r,e))}function d(){if(t.charCodeAt(e)!==W)throw new SyntaxError("Comma ',' expected after value ".concat(M()));e++}function y(){if(t.charCodeAt(e)!==q)throw new SyntaxError("Colon ':' expected after property name ".concat(M()));e++}function p(t){if(void 0===t)throw new SyntaxError("JSON value expected ".concat(M()))}function v(t){if(void 0===t)throw new SyntaxError("Array item expected ".concat(M()))}function h(){if(e<t.length)throw new SyntaxError("Expected end of input ".concat(M()))}function b(r){if(!N(t.charCodeAt(e))){var n=t.slice(r,e);throw new SyntaxError("Invalid number '".concat(n,"', expecting a digit ").concat(M()))}}function w(){if(t.charCodeAt(e)!==P)throw new SyntaxError("End of string '\"' expected ".concat(M()))}function S(){throw new SyntaxError("Quoted object key expected ".concat(M()))}function _(t){throw new SyntaxError("Duplicate key '".concat(t,"' encountered at position ").concat(e-t.length-1))}function F(){throw new SyntaxError("Quoted object key or end of object '}' expected ".concat(M()))}function J(){throw new SyntaxError("Array item or end of array ']' expected ".concat(M()))}function L(t){throw new SyntaxError("Invalid character '".concat(t,"' ").concat(z()))}function D(r){var n=t.slice(r,r+2);throw new SyntaxError("Invalid escape character '".concat(n,"' ").concat(z()))}function Q(r){for(var n=r+2;/\w/.test(t[n]);)n++;var e=t.slice(r,n);throw new SyntaxError("Invalid unicode character '".concat(e,"' ").concat(z()))}function z(){return"at position ".concat(e)}function G(){return e<t.length?"but got '".concat(t[e],"'"):"but reached end of input"}function M(){return G()+" "+z()}},t.parseLosslessNumber=m,t.parseNumberAndBigInt=function(t){return r(t)?BigInt(t):parseFloat(t)},t.reviveDate=function(t,r){return"string"==typeof r&&Y.test(r)?new Date(r):r},t.stringify=function t(r,n,o,a){var i=function(t){if("number"==typeof t)return" ".repeat(t);if("string"==typeof t&&""!==t)return t;return}(o);return c("function"==typeof n?n.call({"":r},"",r):r,"");function c(r,u){if(Array.isArray(a)){var f=a.find((function(t){return t.test(r)}));if(f){var l=f.stringify(r);if("string"!=typeof l||!e(l))throw new Error("Invalid JSON number: output of a number stringifier must be a string containing a JSON number "+"(output: ".concat(l,")"));return l}}return"boolean"==typeof r||"number"==typeof r||"string"==typeof r||null===r||r instanceof Date||r instanceof Boolean||r instanceof Number||r instanceof String?JSON.stringify(r):r&&r.isLosslessNumber||"bigint"==typeof r?r.toString():Array.isArray(r)?function(t,r){for(var e=i?r+i:void 0,o=i?"[\n":"[",a=0;a<t.length;a++){var u="function"==typeof n?n.call(t,String(a),t[a]):t[a];i&&(o+=e),o+=void 0!==u&&"function"!=typeof u?c(u,e):"null",a<t.length-1&&(o+=i?",\n":",")}return o+=i?"\n"+r+"]":"]"}(r,u):r&&"object"===X(r)?function(r,e){if("function"==typeof r.toJSON)return t(r.toJSON(),n,o,void 0);var a=Array.isArray(n)?n.map(String):Object.keys(r),u=i?e+i:void 0,f=!0,l=i?"{\n":"{";return a.forEach((function(t){var e="function"==typeof n?n.call(r,t,r[t]):r[t];if(function(t,r){return void 0!==r&&"function"!=typeof r&&"symbol"!==X(r)}(0,e)){f?f=!1:l+=i?",\n":",";var o=JSON.stringify(t);l+=i?u+o+": ":o+":",l+=c(e,u)}})),l+=i?"\n"+e+"}":"}"}(r,u):void 0}},t.toLosslessNumber=function(t){if(u(t+"").length>15)throw new Error("Invalid number: contains more than 15 digits and is most likely truncated and unsafe by itself "+"(value: ".concat(t,")"));if(isNaN(t))throw new Error("Invalid number: NaN");if(!isFinite(t))throw new Error("Invalid number: "+t);return new h(String(t))},t.toSafeNumberOrThrow=function(r,n){var e=parseFloat(r),o=c(r);if(!0===(null==n?void 0:n.approx)?o&&o!==t.UnsafeNumberReason.truncate_float:o){var a=o.replace(/_\w+$/,"");throw new Error("Cannot safely convert to number: "+"the value '".concat(r,"' would ").concat(a," and become ").concat(e))}return e}}));//# sourceMappingURL=lossless-json.js.map
{
"name": "lossless-json",
"version": "2.0.3",
"version": "2.0.4",
"description": "Parse JSON without risk of losing numeric information",

@@ -5,0 +5,0 @@ "type": "module",

@@ -410,3 +410,3 @@ # lossless-json

## Deploy
## Publish

@@ -413,0 +413,0 @@ - Update version number in `package.json`, and run `npm install` to update the version number in `package-lock.json` too.

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