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.2 to 2.0.3

4

HISTORY.md
# History
## 2022-12-01, version 2.0.3
- Fix: `parse` not throwing an exception on illegal characters inside a string, like an unescaped new line.
## 2022-11-17, version 2.0.2

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

6

lib/esm/LosslessNumber.js
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import { extractSignificantDigits, getUnsafeNumberReason, isInteger, isNumber, UnsafeNumberReason } from './utils.js';

@@ -7,0 +9,0 @@

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

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

@@ -223,2 +228,5 @@ i++;

}
function throwInvalidCharacter(char) {
throw new SyntaxError("Invalid character '".concat(char, "' ").concat(pos()));
}
function throwInvalidEscapeCharacter(start) {

@@ -260,2 +268,5 @@ var chars = text.slice(start, start + 2);

}
function isValidStringCharacter(char) {
return /^(?:[ -\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])$/.test(char);
}

@@ -262,0 +273,0 @@ // map with all escape characters

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

export declare type JSONPrimitive = string | number | boolean | null;
export declare type JSONValue = {
export type JSONPrimitive = string | number | boolean | null;
export type JSONValue = {
[key: string]: JSONValue;
} | JSONValue[] | JSONPrimitive;
export declare type JSONObject = {
export type JSONObject = {
[key: string]: JSONValue;
};
export declare type JSONArray = JSONValue[];
export declare type JavaScriptPrimitive = string | number | boolean | null | bigint | Date | unknown;
export declare type JavaScriptValue = {
export type JSONArray = JSONValue[];
export type JavaScriptPrimitive = string | number | boolean | null | bigint | Date | unknown;
export type JavaScriptValue = {
[key: string]: JavaScriptValue;
} | JavaScriptValue[] | JavaScriptPrimitive;
export declare type JavaScriptObject = {
export type JavaScriptObject = {
[key: string]: JavaScriptValue;
};
export declare type JavaScriptArray = JavaScriptValue[];
export declare type Reviver = (key: string, value: JSONValue) => JavaScriptValue;
export declare type NumberParser = (value: string) => JavaScriptValue;
export declare type Replacer = ((key: string, value: JavaScriptObject) => JSONValue | undefined) | Array<string | number>;
export type JavaScriptArray = JavaScriptValue[];
export type Reviver = (key: string, value: JSONValue) => JavaScriptValue;
export type NumberParser = (value: string) => JavaScriptValue;
export type Replacer = ((key: string, value: JavaScriptObject) => JSONValue | undefined) | Array<string | number>;
export interface NumberStringifier {

@@ -24,5 +24,5 @@ test: (value: JavaScriptValue) => boolean;

}
export declare type GenericObject<T> = {
export type GenericObject<T> = {
[key: string]: T;
};
//# sourceMappingURL=types.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 e.test(n)}var e=/^-?[0-9]+$/;function r(n){return i.test(n)}var o,i=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;function a(n,e){var r=parseFloat(n),o=String(r),i=f(n),a=f(o);if(i===a)return!0;if(!0===(null==e?void 0:e.approx)){if(!t(n)&&a.length>=14&&i.startsWith(a.substring(0,14)))return!0}return!1}function u(e){if(!a(e,{approx:!1})){if(t(e))return n.UnsafeNumberReason.truncate_integer;var r=parseFloat(e);return isFinite(r)?0===r?n.UnsafeNumberReason.underflow:n.UnsafeNumberReason.truncate_float:n.UnsafeNumberReason.overflow}}function f(n){return n.replace(c,"").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 c=/[eE][+-]?\d+$/,l=/^-?(0*)?/,s=/\./,y=/0+$/;function p(n){return p="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},p(n)}function v(n,t){for(var e=0;e<t.length;e++){var r=t[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(n,r.key,r)}}var d=function(){function e(n){if(function(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),function(n,t,e){t in n?Object.defineProperty(n,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):n[t]=e}(this,"isLosslessNumber",!0),!r(n))throw new Error('Invalid number (value: "'+n+'")');this.value=n}var o,i,a;return o=e,(i=[{key:"valueOf",value:function(){var e=u(this.value);if(void 0===e||e===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(e," and become ").concat(parseFloat(this.value)))}},{key:"toString",value:function(){return this.value}}])&&v(o.prototype,i),a&&v(o,a),Object.defineProperty(o,"prototype",{writable:!1}),e}();function b(n){return n&&"object"===p(n)&&!0===n.isLosslessNumber||!1}function m(n){return new d(n)}function h(n){return h="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},h(n)}function w(n,t){return g({"":n},"",n,t)}function g(n,t,e,r){return Array.isArray(e)?r.call(n,t,function(n,t){for(var e=0;e<n.length;e++)n[e]=g(n,e+"",n[e],t);return n}(e,r)):e&&"object"===h(e)&&!b(e)?r.call(n,t,function(n,t){return Object.keys(n).forEach((function(e){var r=g(n,e,n[e],t);void 0!==r?n[e]=r:delete n[e]})),n}(e,r)):r.call(n,t,e)}function S(n){return!0===I[n]}function N(n){return/^[0-9a-fA-F]/.test(n)}function x(n){return/[0-9]/.test(n)}function E(n){return/[1-9]/.test(n)}var O={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"},I={" ":!0,"\n":!0,"\t":!0,"\r":!0};function j(n){return j="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},j(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=u,n.isInteger=t,n.isLosslessNumber=b,n.isNumber=r,n.isSafeNumber=a,n.parse=function(n,t){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:m,r=0,o=u();return v(o),b(),t?w(o,t):o;function i(){if("{"===n[r]){r++,c();for(var t={},e=!0;r<n.length&&"}"!==n[r];){e?e=!1:(y(),c());var o=l();void 0===o&&I(),Object.prototype.hasOwnProperty.call(t,o)&&j(o),c(),p(),t[o]=u()}return"}"!==n[r]&&A(),r++,t}}function a(){if("["===n[r]){r++,c();for(var t=[],e=!0;r<n.length&&"]"!==n[r];){e?e=!1:y();var o=u();d(o),t.push(o)}return"]"!==n[r]&&R(),r++,t}}function u(){var n,t,e,r,o,u;c();var y=null!==(n=null!==(t=null!==(e=null!==(r=null!==(o=null!==(u=l())&&void 0!==u?u:s())&&void 0!==o?o:i())&&void 0!==r?r:a())&&void 0!==e?e:f("true",!0))&&void 0!==t?t:f("false",!1))&&void 0!==n?n:f("null",null);return c(),y}function f(t,e){if(n.slice(r,r+t.length)===t)return r+=t.length,e}function c(){for(;S(n[r]);)r++}function l(){if('"'===n[r]){r++;for(var t="";r<n.length&&'"'!==n[r];){if("\\"===n[r]){var e=n[r+1],o=O[e];void 0!==o?(t+=o,r++):"u"===e?N(n[r+2])&&N(n[r+3])&&N(n[r+4])&&N(n[r+5])?(t+=String.fromCharCode(parseInt(n.slice(r+2,r+6),16)),r+=5):U(r):k(r)}else t+=n[r];r++}return g(),r++,t}}function s(){var t=r;if("-"===n[r]&&(r++,h(t)),"0"===n[r])r++;else if(E(n[r]))for(r++;x(n[r]);)r++;if("."===n[r])for(r++,h(t);x(n[r]);)r++;if("e"===n[r]||"E"===n[r])for(r++,"-"!==n[r]&&"+"!==n[r]||r++,h(t);x(n[r]);)r++;if(r>t)return e(n.slice(t,r))}function y(){if(","!==n[r])throw new SyntaxError("Comma ',' expected after value ".concat(J()));r++}function p(){if(":"!==n[r])throw new SyntaxError("Colon ':' expected after property name ".concat(J()));r++}function v(n){if(void 0===n)throw new SyntaxError("JSON value expected ".concat(J()))}function d(n){if(void 0===n)throw new SyntaxError("Array item expected ".concat(J()))}function b(){if(r<n.length)throw new SyntaxError("Expected end of input ".concat(J()))}function h(t){if(!x(n[r])){var e=n.slice(t,r);throw new SyntaxError("Invalid number '".concat(e,"', expecting a digit ").concat(J()))}}function g(){if('"'!==n[r])throw new SyntaxError("End of string '\"' expected ".concat(J()))}function I(){throw new SyntaxError("Quoted object key expected ".concat(J()))}function j(n){throw new SyntaxError("Duplicate key '".concat(n,"' encountered at position ").concat(r-n.length-1))}function A(){throw new SyntaxError("Quoted object key or end of object '}' expected ".concat(J()))}function R(){throw new SyntaxError("Array item or end of array ']' expected ".concat(J()))}function k(t){var e=n.slice(t,t+2);throw new SyntaxError("Invalid escape character '".concat(e,"' ").concat(F()))}function U(t){for(var e=t+2;/\w/.test(n[e]);)e++;var r=n.slice(t,e);throw new SyntaxError("Invalid unicode character '".concat(r,"' ").concat(F()))}function F(){return"at position ".concat(r)}function _(){return n[r]?"but got '".concat(n[r],"'"):"but reached end of input"}function J(){return _()+" "+F()}},n.parseLosslessNumber=m,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,e,o,i){var a=function(n){if("number"==typeof n)return" ".repeat(n);if("string"==typeof n&&""!==n)return n;return}(o);return u("function"==typeof e?e.call({"":t},"",t):t,"");function u(t,f){if(Array.isArray(i)){var c=i.find((function(n){return n.test(t)}));if(c){var l=c.stringify(t);if("string"!=typeof l||!r(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 r=a?t+a:void 0,o=a?"[\n":"[",i=0;i<n.length;i++){var f="function"==typeof e?e.call(n,String(i),n[i]):n[i];a&&(o+=r),o+=void 0!==f&&"function"!=typeof f?u(f,r):"null",i<n.length-1&&(o+=a?",\n":",")}return o+=a?"\n"+t+"]":"]"}(t,f):t&&"object"===j(t)?function(t,r){if("function"==typeof t.toJSON)return n(t.toJSON(),e,o,void 0);var i=Array.isArray(e)?e.map(String):Object.keys(t),f=a?r+a:void 0,c=!0,l=a?"{\n":"{";return i.forEach((function(n){var r="function"==typeof e?e.call(t,n,t[n]):t[n];if(function(n,t){return void 0!==t&&"function"!=typeof t&&"symbol"!==j(t)}(0,r)){c?c=!1:l+=a?",\n":",";var o=JSON.stringify(n);l+=a?f+o+": ":o+":",l+=u(r,f)}})),l+=a?"\n"+r+"}":"}"}(t,f):void 0}},n.toLosslessNumber=function(n){if(f(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,e){var r=parseFloat(t),o=u(t);if(!0===(null==e?void 0:e.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(r))}return r}}));//# sourceMappingURL=lossless-json.js.map
!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
{
"name": "lossless-json",
"version": "2.0.2",
"version": "2.0.3",
"description": "Parse JSON without risk of losing numeric information",

@@ -52,11 +52,12 @@ "type": "module",

"@babel/cli": "7.19.3",
"@babel/core": "7.20.2",
"@babel/core": "7.20.5",
"@babel/plugin-transform-typescript": "7.20.2",
"@babel/preset-env": "7.20.2",
"@babel/preset-typescript": "7.18.6",
"@rollup/plugin-terser": "0.1.0",
"@types/benchmark": "2.1.2",
"@types/jest": "29.2.3",
"@typescript-eslint/eslint-plugin": "5.43.0",
"@typescript-eslint/parser": "5.43.0",
"@rollup/plugin-terser": "0.1.0",
"@types/node": "18.11.10",
"@typescript-eslint/eslint-plugin": "5.45.0",
"@typescript-eslint/parser": "5.45.0",
"benchmark": "2.1.4",

@@ -66,3 +67,3 @@ "cpy-cli": "4.2.0",

"del-cli": "5.0.0",
"eslint": "8.27.0",
"eslint": "8.28.0",
"eslint-config-standard": "17.0.0",

@@ -75,6 +76,6 @@ "eslint-plugin-import": "2.26.0",

"npm-run-all": "4.1.5",
"prettier": "2.7.1",
"rollup": "3.3.0",
"prettier": "2.8.0",
"rollup": "3.5.1",
"ts-jest": "29.0.3",
"typescript": "4.8.4"
"typescript": "4.9.3"
},

@@ -81,0 +82,0 @@ "files": [

@@ -29,2 +29,3 @@ # lossless-json

- No risk of losing numeric information when working with big numbers.
- Maintain the formatting of numbers.
- Parse error on duplicate keys.

@@ -31,0 +32,0 @@ - Built-in support for `bigint`.

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