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 1.0.4 to 1.0.5

2

dist/lossless-json.js

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

!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((r=r||self).LosslessJSON={})}(this,function(r){"use strict";var e=!0;function i(r){return r&&void 0!==r.circularRefs&&null!==r.circularRefs&&(e=!0===r.circularRefs),{circularRefs:e}}function o(r){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}function f(r,e){for(var n=0;n<e.length;n++){var t=e[n];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(r,t.key,t)}}var u=function(){function e(r){!function(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),this.value=function r(e){{if("string"==typeof e){if(!/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/.test(e))throw new Error('Invalid number (value: "'+e+'")');return e}if("number"!=typeof e)return r(e&&e.valueOf());if(15<a(e+"").length)throw new Error("Invalid number: contains more than 15 digits (value: "+e+")");if(isNaN(e))throw new Error("Invalid number: NaN");if(!isFinite(e))throw new Error("Invalid number: Infinity");return e+""}}(r),this.type="LosslessNumber",this.isLosslessNumber=!0}var r,n,t;return r=e,(n=[{key:"valueOf",value:function(){var r=parseFloat(this.value),e=a(this.value);if(15<e.length)throw new Error("Cannot convert to number: number would be truncated (value: "+this.value+")");if(!isFinite(r))throw new Error("Cannot convert to number: number would overflow (value: "+this.value+")");if(Math.abs(r)<Number.MIN_VALUE&&!/^0*$/.test(e))throw new Error("Cannot convert to number: number would underflow (value: "+this.value+")");return r}},{key:"toString",value:function(){return this.value}}])&&f(r.prototype,n),t&&f(r,t),e}();function a(r){return("string"!=typeof r?r+"":r).replace(/^-/,"").replace(/e.*$/,"").replace(/^0\.?0*|\./,"")}function l(r,e,n,t){return Array.isArray(n)?t.call(r,e,function(r,e){for(var n=[],t=0;t<r.length;t++)n[t]=l(r,t+"",r[t],e);return n}(n,t)):n&&"object"===o(n)&&!n.isLosslessNumber?t.call(r,e,function(r,e){var n={};for(var t in r)r.hasOwnProperty(t)&&(n[t]=l(r,t,r[t],e));return n}(n,t)):t.call(r,e,n)}function n(r){return encodeURIComponent(r.replace(/\//g,"~1").replace(/~/g,"~0"))}function c(r){return decodeURIComponent(r).replace(/~1/g,"/").replace(/~0/g,"~")}function s(r){return"#/"+r.map(n).join("/")}var v={NULL:0,DELIMITER:1,NUMBER:2,STRING:3,SYMBOL:4,UNKNOWN:5},t={"":!0,"{":!0,"}":!0,"[":!0,"]":!0,":":!0,",":!0},h={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"},p="",d=0,y="",b="",g=v.NULL,m=[],w=[];function I(){d++,y=p.charAt(d)}function E(){for(g=v.NULL,b="";" "===y||"\t"===y||"\n"===y||"\r"===y;)I();if(t[y])return g=v.DELIMITER,b=y,void I();if(L(y)||"-"===y){if(g=v.NUMBER,"-"===y){if(b+=y,I(),!L(y))throw R("Invalid number, digit expected",d)}else"0"===y&&(b+=y,I());for(;L(y);)b+=y,I();if("."===y){if(b+=y,I(),!L(y))throw R("Invalid number, digit expected",d);for(;L(y);)b+=y,I()}if("e"===y||"E"===y){if(b+=y,I(),"+"!==y&&"-"!==y||(b+=y,I()),!L(y))throw R("Invalid number, digit expected",d);for(;L(y);)b+=y,I()}}else if('"'!==y){if(!N(y)){for(g=v.UNKNOWN;""!==y;)b+=y,I();throw R('Syntax error in part "'+b+'"')}for(g=v.SYMBOL;N(y);)b+=y,I()}else{for(g=v.STRING,I();""!==y&&'"'!==y;)if("\\"===y){I();var r=h[y];if(void 0!==r)b+=r,I();else{if("u"!==y)throw R('Invalid escape character "\\'+y+'"',d);I();for(var e="",n=0;n<4;n++){if(!/^[0-9a-fA-F]/.test(y))throw R("Invalid unicode character");e+=y,I()}b+=String.fromCharCode(parseInt(e,16))}}else b+=y,I();if('"'!==y)throw R("End of string expected");I()}}function N(r){return/^[a-zA-Z_]/.test(r)}function L(r){return"0"<=r&&r<="9"}function R(r,e){void 0===e&&(e=d-b.length);var n=new SyntaxError(r+" (char "+e+")");return n.char=e,n}function S(){if(g!==v.DELIMITER||"{"!==b)return function(){if(g!==v.DELIMITER||"["!==b)return function(){if(g!==v.STRING)return function(){if(g!==v.NUMBER)return function(){if(g!==v.SYMBOL)return function(){throw R(""===b?"Unexpected end of json string":"Value expected")}();if("true"===b)return E(),!0;if("false"===b)return E(),!1;if("null"!==b)throw R('Unknown symbol "'+b+'"');return E(),null}();var r=new u(b);return E(),r}();var r=b;return E(),r}();E();var r=[];if(g===v.DELIMITER&&"]"===b)return E(),r;var e=w.length;w[e]=r;for(;m[e]=r.length+"",r.push(S()),g===v.DELIMITER&&","===b;)E();if(g===v.DELIMITER&&"]"===b)return E(),w.length=e,m.length=e,r;throw R('Comma or end of array "]" expected')}();var r,e;E();var n={};if(g===v.DELIMITER&&"}"===b)return E(),n;var t=w.length;for(w[t]=n;;){if(g!==v.STRING)throw R("Object key expected");if(e=b,E(),g!==v.DELIMITER||":"!==b)throw R("Colon expected");if(E(),n[m[t]=e]=S(),g!==v.DELIMITER||","!==b)break;E()}if(g!==v.DELIMITER||"}"!==b)throw R('Comma or end of object "}" expected');return E(),"string"==typeof(r=n).$ref&&1===Object.keys(r).length?function(r){if(!i().circularRefs)return r;for(var e=function(r){var e=r.split("/").map(c);if("#"!==e.shift())throw SyntaxError("Cannot parse JSON Pointer: no valid URI fragment");return""===e[e.length-1]&&e.pop(),e}(r.$ref),n=0;n<e.length;n++)if(e[n]!==m[n])throw new Error('Invalid circular reference "'+r.$ref+'"');return w[e.length]}(n):(w.length=t,m.length=t,n)}var M=[],O=[];function x(r,e,n){O=[],M=[];var t,o="function"==typeof e?e.call({"":r},"",r):r;return"number"==typeof n?10<n?t=A(" ",10):1<=n&&(t=A(" ",n)):"string"==typeof n&&""!==n&&(t=n),T(o,e,t,"")}function T(r,e,n,t){return"boolean"==typeof r||r instanceof Boolean||null===r||"number"==typeof r||r instanceof Number||"string"==typeof r||r instanceof String||r instanceof Date?JSON.stringify(r):r&&r.isLosslessNumber?r.value:Array.isArray(r)?function(r,e,n,t){var o=n?t+n:void 0,i=n?"[\n":"[";if(C(r))return D(r,e,n,t);var f=O.length;O[f]=r;for(var u=0;u<r.length;u++){var a=u+"",l="function"==typeof e?e.call(r,a,r[u]):r[u];n&&(i+=o),void 0!==l&&"function"!=typeof l?(M[f]=a,i+=T(l,e,n,o)):i+="null",u<r.length-1&&(i+=n?",\n":",")}return O.length=f,M.length=f,i+=n?"\n"+t+"]":"]"}(r,e,n,t):r&&"object"===o(r)?U(r,e,n,t):void 0}function U(r,e,n,t){var o=n?t+n:void 0,i=!0,f=n?"{\n":"{";if("function"==typeof r.toJSON)return x(r.toJSON(),e,n);if(C(r))return D(r,e,n,t);var u,a,l,c=O.length;for(var s in O[c]=r)if(r.hasOwnProperty(s)){var v="function"==typeof e?e.call(r,s,r[s]):r[s];u=s,l=e,void 0===(a=v)||"function"==typeof a||Array.isArray(l)&&!function(r,e){for(var n=0;n<r.length;n++)if(r[n]==e)return!0;return!1}(l,u)||(i?i=!1:f+=n?",\n":",",f+=n?o+'"'+s+'": ':'"'+s+'":',M[c]=s,f+=T(v,e,n,o))}return O.length=c,M.length=c,f+=n?"\n"+t+"}":"}"}function C(r){return-1!==O.indexOf(r)}function D(r,e,n,t){if(!i().circularRefs)throw new Error('Circular reference at "'+s(M)+'"');var o=O.indexOf(r);return U({$ref:s(M.slice(0,o))},e,n,t)}function A(r,e){for(var n="";0<e--;)n+=r;return n}r.LosslessNumber=u,r.config=i,r.parse=function(r,e){d=0,y=(p=r).charAt(0),b="",g=v.NULL,w=[],m=[],E();var n,t=S();if(""!==b)throw R("Unexpected characters");return e?l({"":n=t},"",n,e):t},r.stringify=x,Object.defineProperty(r,"__esModule",{value:!0})});
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((r="undefined"!=typeof globalThis?globalThis:r||self).LosslessJSON={})}(this,function(r){"use strict";var e=!0;function o(r){return r&&void 0!==r.circularRefs&&null!==r.circularRefs&&(e=!0===r.circularRefs),{circularRefs:e}}function i(r){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r})(r)}function f(r,e){for(var n=0;n<e.length;n++){var t=e[n];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(r,t.key,t)}}var u=function(){function e(r){!function(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),this.value=function r(e){{if("string"==typeof e){if(!l(e))throw new Error('Invalid number (value: "'+e+'")');return e}if("number"!=typeof e)return r(e&&e.valueOf());if(15<a(e+"").length)throw new Error("Invalid number: contains more than 15 digits (value: "+e+")");if(isNaN(e))throw new Error("Invalid number: NaN");if(!isFinite(e))throw new Error("Invalid number: Infinity");return e+""}}(r),this.type="LosslessNumber",this.isLosslessNumber=!0}var r,n,t;return r=e,(n=[{key:"valueOf",value:function(){var r=parseFloat(this.value),e=a(this.value);if(15<e.length)throw new Error("Cannot convert to number: number would be truncated (value: "+this.value+")");if(!isFinite(r))throw new Error("Cannot convert to number: number would overflow (value: "+this.value+")");if(Math.abs(r)<Number.MIN_VALUE&&!/^0*$/.test(e))throw new Error("Cannot convert to number: number would underflow (value: "+this.value+")");return r}},{key:"toString",value:function(){return this.value}}])&&f(r.prototype,n),t&&f(r,t),e}();function a(r){return("string"!=typeof r?r+"":r).replace(/^-/,"").replace(/e.*$/,"").replace(/^0\.?0*|\./,"")}function l(r){return/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/.test(r)}function c(r,e,n,t){return Array.isArray(n)?t.call(r,e,function(r,e){for(var n=[],t=0;t<r.length;t++)n[t]=c(r,t+"",r[t],e);return n}(n,t)):n&&"object"===i(n)&&!n.isLosslessNumber?t.call(r,e,function(r,e){var n,t={};for(n in r)r.hasOwnProperty(n)&&(t[n]=c(r,n,r[n],e));return t}(n,t)):t.call(r,e,n)}function n(r){return encodeURIComponent(r.replace(/\//g,"~1").replace(/~/g,"~0"))}function s(r){return decodeURIComponent(r).replace(/~1/g,"/").replace(/~0/g,"~")}function h(r){return"#/"+r.map(n).join("/")}var v={NULL:0,DELIMITER:1,NUMBER:2,STRING:3,SYMBOL:4,UNKNOWN:5},t={"":!0,"{":!0,"}":!0,"[":!0,"]":!0,":":!0,",":!0},p={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"},d="",y=0,b="",g="",m=v.NULL,w=[],I=[];function E(){y++,b=d.charAt(y)}function N(){for(m=v.NULL,g="";" "===b||"\t"===b||"\n"===b||"\r"===b;)E();if(t[b])return m=v.DELIMITER,g=b,void E();if(R(b)||"-"===b){if(m=v.NUMBER,"-"===b){if(g+=b,E(),!R(b))throw S("Invalid number, digit expected",y)}else"0"===b&&(g+=b,E());for(;R(b);)g+=b,E();if("."===b){if(g+=b,E(),!R(b))throw S("Invalid number, digit expected",y);for(;R(b);)g+=b,E()}if("e"===b||"E"===b){if(g+=b,E(),"+"!==b&&"-"!==b||(g+=b,E()),!R(b))throw S("Invalid number, digit expected",y);for(;R(b);)g+=b,E()}}else if('"'!==b){if(!L(b)){for(m=v.UNKNOWN;""!==b;)g+=b,E();throw S('Syntax error in part "'+g+'"')}for(m=v.SYMBOL;L(b);)g+=b,E()}else{for(m=v.STRING,E();""!==b&&'"'!==b;)if("\\"===b){E();var r=p[b];if(void 0!==r)g+=r,E();else{if("u"!==b)throw S('Invalid escape character "\\'+b+'"',y);E();for(var e="",n=0;n<4;n++){if(!/^[0-9a-fA-F]/.test(b))throw S("Invalid unicode character");e+=b,E()}g+=String.fromCharCode(parseInt(e,16))}}else g+=b,E();if('"'!==b)throw S("End of string expected");E()}}function L(r){return/^[a-zA-Z_]/.test(r)}function R(r){return"0"<=r&&r<="9"}function S(r,e){void 0===e&&(e=y-g.length);r=new SyntaxError(r+" (char "+e+")");return r.char=e,r}function O(){if(m!==v.DELIMITER||"{"!==g)return function(){if(m!==v.DELIMITER||"["!==g)return function(){if(m!==v.STRING)return function(){if(m!==v.NUMBER)return function(){if(m!==v.SYMBOL)return function(){throw S(""===g?"Unexpected end of json string":"Value expected")}();if("true"===g)return N(),!0;if("false"===g)return N(),!1;if("null"!==g)throw S('Unknown symbol "'+g+'"');return N(),null}();var r=new u(g);return N(),r}();var r=g;return N(),r}();N();var r=[];if(m===v.DELIMITER&&"]"===g)return N(),r;var e=I.length;I[e]=r;for(;w[e]=r.length+"",r.push(O()),m===v.DELIMITER&&","===g;)N();if(m===v.DELIMITER&&"]"===g)return N(),I.length=e,w.length=e,r;throw S('Comma or end of array "]" expected')}();var r,e;N();var n={};if(m===v.DELIMITER&&"}"===g)return N(),n;var t=I.length;for(I[t]=n;;){if(m!==v.STRING)throw S("Object key expected");if(e=g,N(),m!==v.DELIMITER||":"!==g)throw S("Colon expected");if(N(),n[w[t]=e]=O(),m!==v.DELIMITER||","!==g)break;N()}if(m!==v.DELIMITER||"}"!==g)throw S('Comma or end of object "}" expected');return N(),"string"==typeof(r=n).$ref&&1===Object.keys(r).length?function(r){if(!o().circularRefs)return r;for(var e=function(r){if("#"!==(r=r.split("/").map(s)).shift())throw SyntaxError("Cannot parse JSON Pointer: no valid URI fragment");return""===r[r.length-1]&&r.pop(),r}(r.$ref),n=0;n<e.length;n++)if(e[n]!==w[n])throw new Error('Invalid circular reference "'+r.$ref+'"');return I[e.length]}(n):(I.length=t,w.length=t,n)}var M=[],x=[];function T(r,e,n){x=[],M=[];var t,r="function"==typeof e?e.call({"":r},"",r):r;return"number"==typeof n?10<n?t=j(" ",10):1<=n&&(t=j(" ",n)):"string"==typeof n&&""!==n&&(t=n),U(r,e,t,"")}function U(r,e,n,t){return"boolean"==typeof r||r instanceof Boolean||null===r||"number"==typeof r||r instanceof Number||"string"==typeof r||r instanceof String||r instanceof Date?JSON.stringify(r):r&&r.isLosslessNumber?r.value:Array.isArray(r)?function(r,e,n,t){var o=n?t+n:void 0,i=n?"[\n":"[";if(D(r))return A(r,e,n,t);var f=x.length;x[f]=r;for(var u=0;u<r.length;u++){var a=u+"",l="function"==typeof e?e.call(r,a,r[u]):r[u];n&&(i+=o),void 0!==l&&"function"!=typeof l?(M[f]=a,i+=U(l,e,n,o)):i+="null",u<r.length-1&&(i+=n?",\n":",")}return x.length=f,M.length=f,i+=n?"\n"+t+"]":"]"}(r,e,n,t):r&&"object"===i(r)?C(r,e,n,t):void 0}function C(r,e,n,t){var o=n?t+n:void 0,i=!0,f=n?"{\n":"{";if("function"==typeof r.toJSON)return T(r.toJSON(),e,n);if(D(r))return A(r,e,n,t);var u,a,l,c,s,h=x.length;for(u in x[h]=r)r.hasOwnProperty(u)&&(a="function"==typeof e?e.call(r,u,r[u]):r[u],l=u,s=e,void 0===(c=a)||"function"==typeof c||Array.isArray(s)&&!function(r,e){for(var n=0;n<r.length;n++)if(r[n]==e)return!0;return!1}(s,l)||(i?i=!1:f+=n?",\n":",",l=JSON.stringify(u),f+=n?o+l+": ":l+":",M[h]=u,f+=U(a,e,n,o)));return x.length=h,M.length=h,f+=n?"\n"+t+"}":"}"}function D(r){return-1!==x.indexOf(r)}function A(r,e,n,t){if(!o().circularRefs)throw new Error('Circular reference at "'+h(M)+'"');r=x.indexOf(r);return C({$ref:h(M.slice(0,r))},e,n,t)}function j(r,e){for(var n="";0<e--;)n+=r;return n}r.LosslessNumber=u,r.config=o,r.parse=function(r,e){y=0,b=(d=r).charAt(0),g="",m=v.NULL,I=[],w=[],N();var n=O();if(""!==g)throw S("Unexpected characters");return e?c({"":r=n},"",r,e):n},r.stringify=T,Object.defineProperty(r,"__esModule",{value:!0})});
//# sourceMappingURL=lossless-json.js.map
# History
## 2021-07-22, version 1.0.5
- Fixed stringifing of object keys containing special characters like backslash,
see #239. Thanks @mengfanliao.
## 2020-05-08, version 1.0.4

@@ -5,0 +11,0 @@

The MIT License (MIT)
Copyright (c) 2016-2020 Jos de Jong
Copyright (c) 2016-2021 Jos de Jong

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

{
"name": "lossless-json",
"version": "1.0.4",
"version": "1.0.5",
"description": "Parse JSON without risk of losing numeric information",

@@ -29,7 +29,7 @@ "main": "./dist/lossless-json.js",

"devDependencies": {
"@babel/core": "7.9.6",
"@babel/preset-env": "7.9.6",
"@babel/register": "7.9.0",
"ava": "3.8.2",
"rollup": "2.8.2",
"@babel/core": "7.14.8",
"@babel/preset-env": "7.14.8",
"@babel/register": "7.14.5",
"ava": "3.15.0",
"rollup": "2.53.3",
"rollup-plugin-babel": "4.4.0",

@@ -36,0 +36,0 @@ "rollup-plugin-uglify": "6.0.4"

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