@jsonurl/jsonurl
Advanced tools
Comparing version
@@ -307,2 +307,19 @@ 'use strict'; | ||
function parseStringLiteral(text, pos, end, removeQuotes) { | ||
var ret = removeQuotes ? text.substring(pos + 1, end - 1) : text.substring(pos, end); | ||
ret = ret.replace(rx_decode_space, " "); | ||
ret = decodeURIComponent(ret); | ||
return ret; | ||
} | ||
function encodeStringLiteral(text) { | ||
var ret = encodeURIComponent(text); | ||
ret = ret.replace(rx_encode_pctspace, "+"); | ||
ret = ret.replace(",", "%x2C"); | ||
ret = ret.replace(":", "%x3A"); | ||
ret = ret.replace("(", "%x28"); | ||
ret = ret.replace(")", "%x29"); | ||
return ret; | ||
} | ||
function toJsonURLText_Boolean() { | ||
@@ -317,2 +334,6 @@ return this === true ? "true" : "false"; | ||
function toJsonURLText_String(options, depth, isKey) { | ||
if (options.impliedStringLiterals) { | ||
return encodeStringLiteral(this); | ||
} | ||
if (this.length === 0) { | ||
@@ -364,4 +385,3 @@ return "''"; | ||
var ret = encodeURIComponent(this); | ||
ret = ret.replace(rx_encode_pctspace, "+"); | ||
var ret = encodeStringLiteral(this); | ||
@@ -727,2 +747,8 @@ if (ret.charCodeAt(0) == CHAR_QUOTE) { | ||
var forceString = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; | ||
var impliedStringLiteral = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; | ||
if (impliedStringLiteral === true) { | ||
return parseStringLiteral(text, pos, end, false); | ||
} | ||
var c1, c2, c3, c4, c5; | ||
@@ -785,13 +811,3 @@ | ||
var ret; | ||
if (isQuotedString) { | ||
ret = text.substring(pos + 1, end - 1); | ||
} else { | ||
ret = text.substring(pos, end); | ||
} | ||
ret = ret.replace(rx_decode_space, " "); | ||
ret = decodeURIComponent(ret); | ||
return ret; | ||
return parseStringLiteral(text, pos, end, isQuotedString); | ||
} | ||
@@ -822,2 +838,4 @@ /** | ||
* combined with prop.impliedArray or prop.impliedObject. | ||
* @param {boolean} options.impliedStringLiterals Assume all literals | ||
* are strings. | ||
* @throws SyntaxError if there is a syntax error in the given text | ||
@@ -883,3 +901,3 @@ * @throws Error if a limit given in the constructor (or its default) | ||
return this.parseLiteral(text, 0, end, false); | ||
return this.parseLiteral(text, 0, end, false, options.impliedStringLiterals); | ||
} else { | ||
@@ -959,3 +977,3 @@ stateStack.push(STATE_PAREN); | ||
c = text.charCodeAt(_lvpos); | ||
lv = this.parseLiteral(text, pos, _lvpos, c === CHAR_COLON); | ||
lv = this.parseLiteral(text, pos, _lvpos, c === CHAR_COLON, options.impliedStringLiterals); | ||
pos = _lvpos; | ||
@@ -1042,3 +1060,3 @@ | ||
valueStack.checkValueLimit(pos); | ||
lv = this.parseLiteral(text, pos, _lvpos, false); | ||
lv = this.parseLiteral(text, pos, _lvpos, false, options.impliedStringLiterals); | ||
pos = _lvpos; | ||
@@ -1121,3 +1139,3 @@ | ||
valueStack.checkValueLimit(pos); | ||
lv = this.parseLiteral(text, pos, _lvpos, false); | ||
lv = this.parseLiteral(text, pos, _lvpos, false, options.impliedStringLiterals); | ||
pos = _lvpos; | ||
@@ -1219,3 +1237,3 @@ | ||
lv = this.parseLiteral(text, pos, _lvpos, true); | ||
lv = this.parseLiteral(text, pos, _lvpos, true, options.impliedStringLiterals); | ||
pos = _lvpos + 1; | ||
@@ -1253,2 +1271,4 @@ stateStack.replace(STATE_OBJECT_HAVE_KEY); | ||
* array or object. | ||
* @param {boolean} options.impliedStringLiterals Assume all literals | ||
* are strings. | ||
* @returns {string} JSON->URL text, or undefined if the given value | ||
@@ -1262,3 +1282,4 @@ * is undefined. | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { | ||
ignoreUndefinedObjectMembers: true | ||
ignoreUndefinedObjectMembers: true, | ||
impliedStringLiterals: false | ||
}; | ||
@@ -1265,0 +1286,0 @@ |
@@ -296,2 +296,19 @@ import _classCallCheck from '@babel/runtime/helpers/classCallCheck'; | ||
function parseStringLiteral(text, pos, end, removeQuotes) { | ||
var ret = removeQuotes ? text.substring(pos + 1, end - 1) : text.substring(pos, end); | ||
ret = ret.replace(rx_decode_space, " "); | ||
ret = decodeURIComponent(ret); | ||
return ret; | ||
} | ||
function encodeStringLiteral(text) { | ||
var ret = encodeURIComponent(text); | ||
ret = ret.replace(rx_encode_pctspace, "+"); | ||
ret = ret.replace(",", "%x2C"); | ||
ret = ret.replace(":", "%x3A"); | ||
ret = ret.replace("(", "%x28"); | ||
ret = ret.replace(")", "%x29"); | ||
return ret; | ||
} | ||
function toJsonURLText_Boolean() { | ||
@@ -306,2 +323,6 @@ return this === true ? "true" : "false"; | ||
function toJsonURLText_String(options, depth, isKey) { | ||
if (options.impliedStringLiterals) { | ||
return encodeStringLiteral(this); | ||
} | ||
if (this.length === 0) { | ||
@@ -353,4 +374,3 @@ return "''"; | ||
var ret = encodeURIComponent(this); | ||
ret = ret.replace(rx_encode_pctspace, "+"); | ||
var ret = encodeStringLiteral(this); | ||
@@ -716,2 +736,8 @@ if (ret.charCodeAt(0) == CHAR_QUOTE) { | ||
var forceString = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; | ||
var impliedStringLiteral = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; | ||
if (impliedStringLiteral === true) { | ||
return parseStringLiteral(text, pos, end, false); | ||
} | ||
var c1, c2, c3, c4, c5; | ||
@@ -774,13 +800,3 @@ | ||
var ret; | ||
if (isQuotedString) { | ||
ret = text.substring(pos + 1, end - 1); | ||
} else { | ||
ret = text.substring(pos, end); | ||
} | ||
ret = ret.replace(rx_decode_space, " "); | ||
ret = decodeURIComponent(ret); | ||
return ret; | ||
return parseStringLiteral(text, pos, end, isQuotedString); | ||
} | ||
@@ -811,2 +827,4 @@ /** | ||
* combined with prop.impliedArray or prop.impliedObject. | ||
* @param {boolean} options.impliedStringLiterals Assume all literals | ||
* are strings. | ||
* @throws SyntaxError if there is a syntax error in the given text | ||
@@ -872,3 +890,3 @@ * @throws Error if a limit given in the constructor (or its default) | ||
return this.parseLiteral(text, 0, end, false); | ||
return this.parseLiteral(text, 0, end, false, options.impliedStringLiterals); | ||
} else { | ||
@@ -948,3 +966,3 @@ stateStack.push(STATE_PAREN); | ||
c = text.charCodeAt(_lvpos); | ||
lv = this.parseLiteral(text, pos, _lvpos, c === CHAR_COLON); | ||
lv = this.parseLiteral(text, pos, _lvpos, c === CHAR_COLON, options.impliedStringLiterals); | ||
pos = _lvpos; | ||
@@ -1031,3 +1049,3 @@ | ||
valueStack.checkValueLimit(pos); | ||
lv = this.parseLiteral(text, pos, _lvpos, false); | ||
lv = this.parseLiteral(text, pos, _lvpos, false, options.impliedStringLiterals); | ||
pos = _lvpos; | ||
@@ -1110,3 +1128,3 @@ | ||
valueStack.checkValueLimit(pos); | ||
lv = this.parseLiteral(text, pos, _lvpos, false); | ||
lv = this.parseLiteral(text, pos, _lvpos, false, options.impliedStringLiterals); | ||
pos = _lvpos; | ||
@@ -1208,3 +1226,3 @@ | ||
lv = this.parseLiteral(text, pos, _lvpos, true); | ||
lv = this.parseLiteral(text, pos, _lvpos, true, options.impliedStringLiterals); | ||
pos = _lvpos + 1; | ||
@@ -1242,2 +1260,4 @@ stateStack.replace(STATE_OBJECT_HAVE_KEY); | ||
* array or object. | ||
* @param {boolean} options.impliedStringLiterals Assume all literals | ||
* are strings. | ||
* @returns {string} JSON->URL text, or undefined if the given value | ||
@@ -1251,3 +1271,4 @@ * is undefined. | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { | ||
ignoreUndefinedObjectMembers: true | ||
ignoreUndefinedObjectMembers: true, | ||
impliedStringLiterals: false | ||
}; | ||
@@ -1254,0 +1275,0 @@ |
@@ -446,2 +446,19 @@ (function (global, factory) { | ||
function parseStringLiteral(text, pos, end, removeQuotes) { | ||
var ret = removeQuotes ? text.substring(pos + 1, end - 1) : text.substring(pos, end); | ||
ret = ret.replace(rx_decode_space, " "); | ||
ret = decodeURIComponent(ret); | ||
return ret; | ||
} | ||
function encodeStringLiteral(text) { | ||
var ret = encodeURIComponent(text); | ||
ret = ret.replace(rx_encode_pctspace, "+"); | ||
ret = ret.replace(",", "%x2C"); | ||
ret = ret.replace(":", "%x3A"); | ||
ret = ret.replace("(", "%x28"); | ||
ret = ret.replace(")", "%x29"); | ||
return ret; | ||
} | ||
function toJsonURLText_Boolean() { | ||
@@ -456,2 +473,6 @@ return this === true ? "true" : "false"; | ||
function toJsonURLText_String(options, depth, isKey) { | ||
if (options.impliedStringLiterals) { | ||
return encodeStringLiteral(this); | ||
} | ||
if (this.length === 0) { | ||
@@ -503,4 +524,3 @@ return "''"; | ||
var ret = encodeURIComponent(this); | ||
ret = ret.replace(rx_encode_pctspace, "+"); | ||
var ret = encodeStringLiteral(this); | ||
@@ -866,2 +886,8 @@ if (ret.charCodeAt(0) == CHAR_QUOTE) { | ||
var forceString = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; | ||
var impliedStringLiteral = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; | ||
if (impliedStringLiteral === true) { | ||
return parseStringLiteral(text, pos, end, false); | ||
} | ||
var c1, c2, c3, c4, c5; | ||
@@ -924,13 +950,3 @@ | ||
var ret; | ||
if (isQuotedString) { | ||
ret = text.substring(pos + 1, end - 1); | ||
} else { | ||
ret = text.substring(pos, end); | ||
} | ||
ret = ret.replace(rx_decode_space, " "); | ||
ret = decodeURIComponent(ret); | ||
return ret; | ||
return parseStringLiteral(text, pos, end, isQuotedString); | ||
} | ||
@@ -961,2 +977,4 @@ /** | ||
* combined with prop.impliedArray or prop.impliedObject. | ||
* @param {boolean} options.impliedStringLiterals Assume all literals | ||
* are strings. | ||
* @throws SyntaxError if there is a syntax error in the given text | ||
@@ -1022,3 +1040,3 @@ * @throws Error if a limit given in the constructor (or its default) | ||
return this.parseLiteral(text, 0, end, false); | ||
return this.parseLiteral(text, 0, end, false, options.impliedStringLiterals); | ||
} else { | ||
@@ -1098,3 +1116,3 @@ stateStack.push(STATE_PAREN); | ||
c = text.charCodeAt(_lvpos); | ||
lv = this.parseLiteral(text, pos, _lvpos, c === CHAR_COLON); | ||
lv = this.parseLiteral(text, pos, _lvpos, c === CHAR_COLON, options.impliedStringLiterals); | ||
pos = _lvpos; | ||
@@ -1181,3 +1199,3 @@ | ||
valueStack.checkValueLimit(pos); | ||
lv = this.parseLiteral(text, pos, _lvpos, false); | ||
lv = this.parseLiteral(text, pos, _lvpos, false, options.impliedStringLiterals); | ||
pos = _lvpos; | ||
@@ -1260,3 +1278,3 @@ | ||
valueStack.checkValueLimit(pos); | ||
lv = this.parseLiteral(text, pos, _lvpos, false); | ||
lv = this.parseLiteral(text, pos, _lvpos, false, options.impliedStringLiterals); | ||
pos = _lvpos; | ||
@@ -1358,3 +1376,3 @@ | ||
lv = this.parseLiteral(text, pos, _lvpos, true); | ||
lv = this.parseLiteral(text, pos, _lvpos, true, options.impliedStringLiterals); | ||
pos = _lvpos + 1; | ||
@@ -1392,2 +1410,4 @@ stateStack.replace(STATE_OBJECT_HAVE_KEY); | ||
* array or object. | ||
* @param {boolean} options.impliedStringLiterals Assume all literals | ||
* are strings. | ||
* @returns {string} JSON->URL text, or undefined if the given value | ||
@@ -1401,3 +1421,4 @@ * is undefined. | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { | ||
ignoreUndefinedObjectMembers: true | ||
ignoreUndefinedObjectMembers: true, | ||
impliedStringLiterals: false | ||
}; | ||
@@ -1404,0 +1425,0 @@ |
@@ -6,2 +6,2 @@ /*! | ||
*/ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).JsonURL=r()}(this,(function(){"use strict";function e(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function r(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function t(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}function n(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),r&&o(e,r)}function i(e){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function o(e,r){return(o=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e})(e,r)}function a(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function u(e,r,t){return(u=a()?Reflect.construct:function(e,r,t){var n=[null];n.push.apply(n,r);var i=new(Function.bind.apply(e,n));return t&&o(i,t.prototype),i}).apply(null,arguments)}function c(e){var r="function"==typeof Map?new Map:void 0;return(c=function(e){if(null===e||(t=e,-1===Function.toString.call(t).indexOf("[native code]")))return e;var t;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(e))return r.get(e);r.set(e,n)}function n(){return u(e,arguments,i(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),o(n,e)})(e)}function s(e,r){return!r||"object"!=typeof r&&"function"!=typeof r?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):r}function l(e){var r=a();return function(){var t,n=i(e);if(r){var o=i(this).constructor;t=Reflect.construct(n,arguments,o)}else t=n.apply(this,arguments);return s(this,t)}}var p=/\+/g,f=/%20/g,h=/ /g,d=/^[-A-Za-z0-9._~!$*;=@?/ ][-A-Za-z0-9._~!$*;=@?/' ]*$/,y=/^[-A-Za-z0-9._~!$*,;=@?/(),: ]+$/,w=/^(?:true|false|null|(?:[-]?[0-9]+(?:[.][0-9]+)?(?:[eE][-+]?[0-9]+)?))$/,v=40,m=41,x=44,b=58,A=38,O=101,S=108,E=117,g="JSON->URL: expected comma, open paren, or close paren",V="JSON->URL: expected comma or close paren",j="JSON->URL: expected value",U="JSON->URL: expected literal value",L="JSON->URL: unexpected character",R="JSON->URL: internal error",C="JSON->URL: unexpected end of text inside composite",P="JSON->URL: unexpected text after composite",J="JSON->URL: MaxParseChars exceeded",k="JSON->URL: MaxParseValues exceeded";function _(e,r,t){for(var n=0;r<t;r++)switch(e.charCodeAt(r)){case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:n++;continue;default:return n}return n}function N(e,r,t){var n=0;switch(e.charCodeAt(r)){case 69:case O:r++,n++;break;default:return 0}switch(e.charCodeAt(r)){case 43:case 45:r++,n++}var i=_(e,r,t);return 0===i?0:n+i}function T(e,r,t){if(46!==e.charCodeAt(r))return 0;var n=_(e,r+1,t);return 0===n?0:1+n}function F(e,r,t){return 48===e.charCodeAt(r)?1:_(e,r,t)}function M(e){return"function"==typeof e.emptyValue?e.emptyValue():e.emptyValue}function I(e){return"function"==typeof e.nullValue?e.nullValue():e.nullValue}function D(e,r){return void 0===r?e:e+" at position "+r}function $(e,r,t,n){var i=!1,o=r;if(r===t)throw new SyntaxError(D(n,r));for(39===e.charCodeAt(r)&&(i=!0,r++);r<t;r++){var a=e.charCodeAt(r);if(!(a>=65&&a<=90)&&!(a>=97&&a<=122||a>=48&&a<=57))switch(a){case 39:if(i)return r+1;case 45:case 46:case 95:case 126:case 37:case 33:case 36:case 42:case 43:case 59:case 47:case 63:case 64:continue;case x:case b:case v:case m:if(!i){if(r===o)throw new SyntaxError(D(n,o));return r}continue;case A:case 61:if(r===o)throw new SyntaxError(D(n,o));return r;default:throw new SyntaxError(D(L,r))}}if(i)throw new SyntaxError(D("JSON->URL: quoted string still open",r));return t}Object.defineProperty(Array.prototype,"toJsonURLText",{value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,t=void 0;return this.forEach((function(n){if("function"==typeof n){if(!e.callFunctions)return;for(;"function"==typeof n;)n=n()}if(void 0===n){if(e.ignoreUndefinedArrayMembers)return;n="null"}else if(null===n){if(e.ignoreNullArrayMembers)return;n="null"}else n=n.toJsonURLText(e,r+1);void 0===t?t=n:!e.wwwFormUrlEncoded||r>0?t+=","+n:t+="&"+n})),!e.isImplied||r>0?void 0===t?"()":"("+t+")":void 0===t?"":t}}),Object.defineProperty(Boolean.prototype,"toJsonURLText",{value:function(){return!0===this?"true":"false"}}),Object.defineProperty(Number.prototype,"toJsonURLText",{value:function(){return String(this)}}),Object.defineProperty(Object.prototype,"toJsonURLText",{value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,t=void 0,n=Object.keys(this),i=this;return n.forEach((function(n){if(null!=n){var o=i[n];if("function"==typeof o){if(!e.callFunctions)return;for(;"function"==typeof o;)o=o()}if(void 0===o){if(e.ignoreUndefinedObjectMembers)return;o="null"}else if(null===o){if(e.ignoreNullObjectMembers)return;o="null"}else o=o.toJsonURLText(e,r+1);var a=n.toJsonURLText(e,r,!0);void 0===t?t=!e.wwwFormUrlEncoded||r>0?a+":"+o:a+"="+o:!e.wwwFormUrlEncoded||r>0?t+=","+a+":"+o:t+="&"+a+"="+o}})),!e.isImplied||r>0?void 0===t?"()":"("+t+")":void 0===t?"":t}}),Object.defineProperty(String.prototype,"toJsonURLText",{value:function(e,r,t){if(0===this.length)return"''";if(w.test(this))return!0===t?this:-1==this.indexOf("+")?"'"+this+"'":encodeURIComponent(this);if(d.test(this))return-1==this.indexOf(" ")?this:this.replace(h,"+");if(y.test(this))return-1==this.indexOf(" ")?"'"+this+"'":"'"+this.replace(h,"+")+"'";var n=encodeURIComponent(this);return 39==(n=n.replace(f,"+")).charCodeAt(0)?"%27"+n.substring(1):n}});var z=function(r){n(o,r);var i=l(o);function o(r){var t;return e(this,o),(t=i.call(this)).parser=r,t._depth=0,t}return t(o,[{key:"replaceAndPush",value:function(e,r,t){if(this[this._depth]=r,++this._depth>=this.parser.maxParseDepth)throw new Error(D("JSON->URL: MaxParseDepth exceeded",e));this.push(t)}},{key:"replace",value:function(e){this[this._depth]=e}},{key:"depth",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return e&&(this._depth--,this.pop()),this._depth}}]),o}(c(Array)),Z=function(r){n(o,r);var i=l(o);function o(r){var t;return e(this,o),(t=i.call(this)).parser=r,t.numValues=0,t}return t(o,[{key:"popObjectValue",value:function(e){e=e||this.pop();var r=this.pop(),t=this[this.length-1];return t[r]=e,t}},{key:"popArrayValue",value:function(e){e=e||this.pop();var r=this[this.length-1];return r.push(e),r}},{key:"checkValueLimit",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(this.numValues+=r,this.numValues>this.parser.maxParseValues+1)throw new Error(D(k,e))}},{key:"appendArrayValue",value:function(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;this.checkValueLimit(e,t),this.push(r)}}]),o}(c(Array));return function(){function r(t){for(e(this,r);"function"==typeof t;)t=t();void 0===t&&(t={}),this.maxParseDepth="number"==typeof t.maxParseDepth?parseInt(t.maxParseDepth):32,this.maxParseValues="number"==typeof t.maxParseValues?parseInt(t.maxParseValues):4096,this.maxParseChars="number"==typeof t.maxParseChars?parseInt(t.maxParseChars):32768,this.emptyValue=void 0===t.emptyValue?{}:t.emptyValue,this.nullValue=void 0===t.nullValue?null:t.nullValue}return t(r,[{key:"parseLiteral",value:function(e){var r,t,n,i,o,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,c=arguments.length>3&&void 0!==arguments[3]&&arguments[3];switch(u-a){case 4:if(r=e.charCodeAt(a),t=e.charCodeAt(a+1),n=e.charCodeAt(a+2),i=e.charCodeAt(a+3),116===r&&114===t&&n===E&&i===O)return!c||"true";if(110===r&&t===E&&n===S&&i===S)return c?"null":I(this);break;case 5:if(r=e.charCodeAt(a),t=e.charCodeAt(a+1),n=e.charCodeAt(a+2),i=e.charCodeAt(a+3),o=e.charCodeAt(a+4),102===r&&97===t&&n===S&&115===i&&o===O)return!!c&&"false"}var s,l=!1,f=a,h=e.charCodeAt(a);switch(h){case 45:f++;break;case 39:l=!0}if(!l){var d=F(e,f,u);if(d>0&&(f+=d,f+=T(e,f,u),(f+=N(e,f,u))===u)){var y=e.substring(a,u);return c?y:Number(y)}}return s=(s=l?e.substring(a+1,u-1):e.substring(a,u)).replace(p," "),s=decodeURIComponent(s)}},{key:"parse",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(void 0!==e){var t=(e=String(e)).length;if(0===t){if(void 0!==r.impliedArray)return r.impliedArray;if(void 0!==r.impliedObject)return r.impliedObject;throw new SyntaxError(D(j,0))}if(t>this.maxParseChars)throw new Error(J);var n=new Z(this),i=new z(this),o=0;if(void 0!==r.impliedObject)n.push(r.impliedObject),i.push(6);else if(void 0!==r.impliedArray)n.push(r.impliedArray),i.push(2);else{if(e.charCodeAt(0)!==v){var a=$(e,0,t,U);if(a!==t)throw new SyntaxError(D(U,0));return this.parseLiteral(e,0,t,!1)}i.push(1),o=1}for(;;){if(o===t)throw new SyntaxError(D(C,o));var u=e.charCodeAt(o),c=void 0,s=void 0;switch(i[i.depth()]){case 1:switch(u){case v:n.appendArrayValue(o,[]),i.replaceAndPush(o,3,1),o++;continue;case m:if(o++,-1===i.depth(!0)){if(o===t)return M(this);throw new SyntaxError(D(P,o))}if(n.appendArrayValue(o,M(this)),o===t&&0===i.depth()){if(r.impliedArray)return n.popArrayValue();if(r.impliedObject)return n.popObjectValue();throw new SyntaxError(D(C,o))}continue}if((s=$(e,o,t,j))===t)throw new SyntaxError(D(C,t));switch(n.checkValueLimit(o),u=e.charCodeAt(s),c=this.parseLiteral(e,o,s,u===b),o=s,u){case A:if(!r.wwwFormUrlEncoded||i.depth()>0)throw new SyntaxError(D(L,o));case x:i.replace(3),n.appendArrayValue(o,[]),n.push(c);continue;case m:switch(o++,n.appendArrayValue(o,[c]),i.depth(!0)){case-1:if(o===t)return n[0];throw new SyntaxError(D(P,o));case 0:if(o===t){if(r.impliedArray)return n.popArrayValue();if(r.impliedObject)return n.popObjectValue();throw new SyntaxError(D(C,o))}}continue;case 61:if(!r.wwwFormUrlEncoded||i.depth()>0)throw new SyntaxError(D(L,o));case b:i.replace(4),n.push({},c),o++;continue;default:throw new SyntaxError(D(U,o))}case 2:if(u===v){i.replaceAndPush(o,3,1),o++;continue}if(s=$(e,o,t,j),n.checkValueLimit(o),c=this.parseLiteral(e,o,s,!1),(o=s)===t){if(0===i.depth()&&r.impliedArray)return n.popArrayValue(c);throw new SyntaxError(D(C,t))}i.replace(3),n.push(c);continue;case 3:switch(n.popArrayValue(),u){case A:if(!r.wwwFormUrlEncoded||i.depth()>0)throw new SyntaxError(D(L,o));case x:i.replace(2),o++;continue;case m:switch(o++,i.depth(!0)){case-1:if(o===t&&!r.impliedArray)return n[0];throw new SyntaxError(D(P,o));case 0:if(o===t){if(r.impliedArray)return n.popArrayValue();if(r.impliedObject)return n.popObjectValue();throw new SyntaxError(D(C,o))}}continue}throw new SyntaxError(D(V,o));case 4:if(u===v){i.replaceAndPush(o,5,1),o++;continue}if(s=$(e,o,t,j),n.checkValueLimit(o),c=this.parseLiteral(e,o,s,!1),o=s,s===t){if(0===i.depth()&&r.impliedObject)return n.popObjectValue(c);throw new SyntaxError(D(C,t))}i.replace(5),n.push(c);continue;case 5:switch(n.popObjectValue(),u){case A:if(!r.wwwFormUrlEncoded||i.depth()>0)throw new SyntaxError(D(L,o));case x:i.replace(6),o++;continue;case m:switch(o++,i.depth(!0)){case-1:if(o===t&&!r.impliedObject)return n[0];throw new SyntaxError(D(P,o));case 0:if(o===t){if(r.impliedArray)return n.popArrayValue();if(r.impliedObject)return n.popObjectValue();throw new SyntaxError(D(P,o))}}continue}throw new SyntaxError(D(g,o));case 6:if((s=$(e,o,t,U))===t)throw new SyntaxError(D(C,t));switch(u=e.charCodeAt(s)){case 61:if(!r.wwwFormUrlEncoded||i.depth()>0)throw new SyntaxError(D(L,o));case b:break;default:throw new SyntaxError(s)}c=this.parseLiteral(e,o,s,!0),o=s+1,i.replace(4),n.push(c);continue;default:throw new SyntaxError(D(R,o))}}}}}],[{key:"stringify",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{ignoreUndefinedObjectMembers:!0};if(void 0!==e)return null===e?"null":e.toJsonURLText(r,0)}}]),r}()})); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).JsonURL=r()}(this,(function(){"use strict";function e(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function r(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function t(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}function n(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),r&&o(e,r)}function i(e){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function o(e,r){return(o=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e})(e,r)}function a(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function u(e,r,t){return(u=a()?Reflect.construct:function(e,r,t){var n=[null];n.push.apply(n,r);var i=new(Function.bind.apply(e,n));return t&&o(i,t.prototype),i}).apply(null,arguments)}function c(e){var r="function"==typeof Map?new Map:void 0;return(c=function(e){if(null===e||(t=e,-1===Function.toString.call(t).indexOf("[native code]")))return e;var t;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(e))return r.get(e);r.set(e,n)}function n(){return u(e,arguments,i(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),o(n,e)})(e)}function s(e,r){return!r||"object"!=typeof r&&"function"!=typeof r?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):r}function l(e){var r=a();return function(){var t,n=i(e);if(r){var o=i(this).constructor;t=Reflect.construct(n,arguments,o)}else t=n.apply(this,arguments);return s(this,t)}}var p=/\+/g,f=/%20/g,h=/ /g,d=/^[-A-Za-z0-9._~!$*;=@?/ ][-A-Za-z0-9._~!$*;=@?/' ]*$/,y=/^[-A-Za-z0-9._~!$*,;=@?/(),: ]+$/,w=/^(?:true|false|null|(?:[-]?[0-9]+(?:[.][0-9]+)?(?:[eE][-+]?[0-9]+)?))$/,v=40,m=41,x=44,b=58,A=38,S=101,O=108,g=117,E="JSON->URL: expected comma, open paren, or close paren",V="JSON->URL: expected comma or close paren",L="JSON->URL: expected value",j="JSON->URL: expected literal value",U="JSON->URL: unexpected character",C="JSON->URL: internal error",R="JSON->URL: unexpected end of text inside composite",P="JSON->URL: unexpected text after composite",J="JSON->URL: MaxParseChars exceeded",k="JSON->URL: MaxParseValues exceeded";function _(e,r,t){for(var n=0;r<t;r++)switch(e.charCodeAt(r)){case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:n++;continue;default:return n}return n}function N(e,r,t){var n=0;switch(e.charCodeAt(r)){case 69:case S:r++,n++;break;default:return 0}switch(e.charCodeAt(r)){case 43:case 45:r++,n++}var i=_(e,r,t);return 0===i?0:n+i}function T(e,r,t){if(46!==e.charCodeAt(r))return 0;var n=_(e,r+1,t);return 0===n?0:1+n}function F(e,r,t){return 48===e.charCodeAt(r)?1:_(e,r,t)}function M(e){return"function"==typeof e.emptyValue?e.emptyValue():e.emptyValue}function I(e){return"function"==typeof e.nullValue?e.nullValue():e.nullValue}function D(e,r){return void 0===r?e:e+" at position "+r}function $(e,r,t,n){var i=!1,o=r;if(r===t)throw new SyntaxError(D(n,r));for(39===e.charCodeAt(r)&&(i=!0,r++);r<t;r++){var a=e.charCodeAt(r);if(!(a>=65&&a<=90)&&!(a>=97&&a<=122||a>=48&&a<=57))switch(a){case 39:if(i)return r+1;case 45:case 46:case 95:case 126:case 37:case 33:case 36:case 42:case 43:case 59:case 47:case 63:case 64:continue;case x:case b:case v:case m:if(!i){if(r===o)throw new SyntaxError(D(n,o));return r}continue;case A:case 61:if(r===o)throw new SyntaxError(D(n,o));return r;default:throw new SyntaxError(D(U,r))}}if(i)throw new SyntaxError(D("JSON->URL: quoted string still open",r));return t}function z(e,r,t,n){var i=n?e.substring(r+1,t-1):e.substring(r,t);return i=i.replace(p," "),i=decodeURIComponent(i)}function Z(e){var r=encodeURIComponent(e);return r=(r=(r=(r=(r=r.replace(f,"+")).replace(",","%x2C")).replace(":","%x3A")).replace("(","%x28")).replace(")","%x29")}Object.defineProperty(Array.prototype,"toJsonURLText",{value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,t=void 0;return this.forEach((function(n){if("function"==typeof n){if(!e.callFunctions)return;for(;"function"==typeof n;)n=n()}if(void 0===n){if(e.ignoreUndefinedArrayMembers)return;n="null"}else if(null===n){if(e.ignoreNullArrayMembers)return;n="null"}else n=n.toJsonURLText(e,r+1);void 0===t?t=n:!e.wwwFormUrlEncoded||r>0?t+=","+n:t+="&"+n})),!e.isImplied||r>0?void 0===t?"()":"("+t+")":void 0===t?"":t}}),Object.defineProperty(Boolean.prototype,"toJsonURLText",{value:function(){return!0===this?"true":"false"}}),Object.defineProperty(Number.prototype,"toJsonURLText",{value:function(){return String(this)}}),Object.defineProperty(Object.prototype,"toJsonURLText",{value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,t=void 0,n=Object.keys(this),i=this;return n.forEach((function(n){if(null!=n){var o=i[n];if("function"==typeof o){if(!e.callFunctions)return;for(;"function"==typeof o;)o=o()}if(void 0===o){if(e.ignoreUndefinedObjectMembers)return;o="null"}else if(null===o){if(e.ignoreNullObjectMembers)return;o="null"}else o=o.toJsonURLText(e,r+1);var a=n.toJsonURLText(e,r,!0);void 0===t?t=!e.wwwFormUrlEncoded||r>0?a+":"+o:a+"="+o:!e.wwwFormUrlEncoded||r>0?t+=","+a+":"+o:t+="&"+a+"="+o}})),!e.isImplied||r>0?void 0===t?"()":"("+t+")":void 0===t?"":t}}),Object.defineProperty(String.prototype,"toJsonURLText",{value:function(e,r,t){if(e.impliedStringLiterals)return Z(this);if(0===this.length)return"''";if(w.test(this))return!0===t?this:-1==this.indexOf("+")?"'"+this+"'":encodeURIComponent(this);if(d.test(this))return-1==this.indexOf(" ")?this:this.replace(h,"+");if(y.test(this))return-1==this.indexOf(" ")?"'"+this+"'":"'"+this.replace(h,"+")+"'";var n=Z(this);return 39==n.charCodeAt(0)?"%27"+n.substring(1):n}});var q=function(r){n(o,r);var i=l(o);function o(r){var t;return e(this,o),(t=i.call(this)).parser=r,t._depth=0,t}return t(o,[{key:"replaceAndPush",value:function(e,r,t){if(this[this._depth]=r,++this._depth>=this.parser.maxParseDepth)throw new Error(D("JSON->URL: MaxParseDepth exceeded",e));this.push(t)}},{key:"replace",value:function(e){this[this._depth]=e}},{key:"depth",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return e&&(this._depth--,this.pop()),this._depth}}]),o}(c(Array)),B=function(r){n(o,r);var i=l(o);function o(r){var t;return e(this,o),(t=i.call(this)).parser=r,t.numValues=0,t}return t(o,[{key:"popObjectValue",value:function(e){e=e||this.pop();var r=this.pop(),t=this[this.length-1];return t[r]=e,t}},{key:"popArrayValue",value:function(e){e=e||this.pop();var r=this[this.length-1];return r.push(e),r}},{key:"checkValueLimit",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(this.numValues+=r,this.numValues>this.parser.maxParseValues+1)throw new Error(D(k,e))}},{key:"appendArrayValue",value:function(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;this.checkValueLimit(e,t),this.push(r)}}]),o}(c(Array));return function(){function r(t){for(e(this,r);"function"==typeof t;)t=t();void 0===t&&(t={}),this.maxParseDepth="number"==typeof t.maxParseDepth?parseInt(t.maxParseDepth):32,this.maxParseValues="number"==typeof t.maxParseValues?parseInt(t.maxParseValues):4096,this.maxParseChars="number"==typeof t.maxParseChars?parseInt(t.maxParseChars):32768,this.emptyValue=void 0===t.emptyValue?{}:t.emptyValue,this.nullValue=void 0===t.nullValue?null:t.nullValue}return t(r,[{key:"parseLiteral",value:function(e){var r,t,n,i,o,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,c=arguments.length>3&&void 0!==arguments[3]&&arguments[3],s=arguments.length>4&&void 0!==arguments[4]&&arguments[4];if(!0===s)return z(e,a,u,!1);switch(u-a){case 4:if(r=e.charCodeAt(a),t=e.charCodeAt(a+1),n=e.charCodeAt(a+2),i=e.charCodeAt(a+3),116===r&&114===t&&n===g&&i===S)return!c||"true";if(110===r&&t===g&&n===O&&i===O)return c?"null":I(this);break;case 5:if(r=e.charCodeAt(a),t=e.charCodeAt(a+1),n=e.charCodeAt(a+2),i=e.charCodeAt(a+3),o=e.charCodeAt(a+4),102===r&&97===t&&n===O&&115===i&&o===S)return!!c&&"false"}var l=!1,p=a,f=e.charCodeAt(a);switch(f){case 45:p++;break;case 39:l=!0}if(!l){var h=F(e,p,u);if(h>0&&(p+=h,p+=T(e,p,u),(p+=N(e,p,u))===u)){var d=e.substring(a,u);return c?d:Number(d)}}return z(e,a,u,l)}},{key:"parse",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(void 0!==e){var t=(e=String(e)).length;if(0===t){if(void 0!==r.impliedArray)return r.impliedArray;if(void 0!==r.impliedObject)return r.impliedObject;throw new SyntaxError(D(L,0))}if(t>this.maxParseChars)throw new Error(J);var n=new B(this),i=new q(this),o=0;if(void 0!==r.impliedObject)n.push(r.impliedObject),i.push(6);else if(void 0!==r.impliedArray)n.push(r.impliedArray),i.push(2);else{if(e.charCodeAt(0)!==v){var a=$(e,0,t,j);if(a!==t)throw new SyntaxError(D(j,0));return this.parseLiteral(e,0,t,!1,r.impliedStringLiterals)}i.push(1),o=1}for(;;){if(o===t)throw new SyntaxError(D(R,o));var u=e.charCodeAt(o),c=void 0,s=void 0;switch(i[i.depth()]){case 1:switch(u){case v:n.appendArrayValue(o,[]),i.replaceAndPush(o,3,1),o++;continue;case m:if(o++,-1===i.depth(!0)){if(o===t)return M(this);throw new SyntaxError(D(P,o))}if(n.appendArrayValue(o,M(this)),o===t&&0===i.depth()){if(r.impliedArray)return n.popArrayValue();if(r.impliedObject)return n.popObjectValue();throw new SyntaxError(D(R,o))}continue}if((s=$(e,o,t,L))===t)throw new SyntaxError(D(R,t));switch(n.checkValueLimit(o),u=e.charCodeAt(s),c=this.parseLiteral(e,o,s,u===b,r.impliedStringLiterals),o=s,u){case A:if(!r.wwwFormUrlEncoded||i.depth()>0)throw new SyntaxError(D(U,o));case x:i.replace(3),n.appendArrayValue(o,[]),n.push(c);continue;case m:switch(o++,n.appendArrayValue(o,[c]),i.depth(!0)){case-1:if(o===t)return n[0];throw new SyntaxError(D(P,o));case 0:if(o===t){if(r.impliedArray)return n.popArrayValue();if(r.impliedObject)return n.popObjectValue();throw new SyntaxError(D(R,o))}}continue;case 61:if(!r.wwwFormUrlEncoded||i.depth()>0)throw new SyntaxError(D(U,o));case b:i.replace(4),n.push({},c),o++;continue;default:throw new SyntaxError(D(j,o))}case 2:if(u===v){i.replaceAndPush(o,3,1),o++;continue}if(s=$(e,o,t,L),n.checkValueLimit(o),c=this.parseLiteral(e,o,s,!1,r.impliedStringLiterals),(o=s)===t){if(0===i.depth()&&r.impliedArray)return n.popArrayValue(c);throw new SyntaxError(D(R,t))}i.replace(3),n.push(c);continue;case 3:switch(n.popArrayValue(),u){case A:if(!r.wwwFormUrlEncoded||i.depth()>0)throw new SyntaxError(D(U,o));case x:i.replace(2),o++;continue;case m:switch(o++,i.depth(!0)){case-1:if(o===t&&!r.impliedArray)return n[0];throw new SyntaxError(D(P,o));case 0:if(o===t){if(r.impliedArray)return n.popArrayValue();if(r.impliedObject)return n.popObjectValue();throw new SyntaxError(D(R,o))}}continue}throw new SyntaxError(D(V,o));case 4:if(u===v){i.replaceAndPush(o,5,1),o++;continue}if(s=$(e,o,t,L),n.checkValueLimit(o),c=this.parseLiteral(e,o,s,!1,r.impliedStringLiterals),o=s,s===t){if(0===i.depth()&&r.impliedObject)return n.popObjectValue(c);throw new SyntaxError(D(R,t))}i.replace(5),n.push(c);continue;case 5:switch(n.popObjectValue(),u){case A:if(!r.wwwFormUrlEncoded||i.depth()>0)throw new SyntaxError(D(U,o));case x:i.replace(6),o++;continue;case m:switch(o++,i.depth(!0)){case-1:if(o===t&&!r.impliedObject)return n[0];throw new SyntaxError(D(P,o));case 0:if(o===t){if(r.impliedArray)return n.popArrayValue();if(r.impliedObject)return n.popObjectValue();throw new SyntaxError(D(P,o))}}continue}throw new SyntaxError(D(E,o));case 6:if((s=$(e,o,t,j))===t)throw new SyntaxError(D(R,t));switch(u=e.charCodeAt(s)){case 61:if(!r.wwwFormUrlEncoded||i.depth()>0)throw new SyntaxError(D(U,o));case b:break;default:throw new SyntaxError(s)}c=this.parseLiteral(e,o,s,!0,r.impliedStringLiterals),o=s+1,i.replace(4),n.push(c);continue;default:throw new SyntaxError(D(C,o))}}}}}],[{key:"stringify",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{ignoreUndefinedObjectMembers:!0,impliedStringLiterals:!1};if(void 0!==e)return null===e?"null":e.toJsonURLText(r,0)}}]),r}()})); |
{ | ||
"name": "@jsonurl/jsonurl", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
148536
2.31%3340
1.67%