@jsonurl/jsonurl
Advanced tools
Comparing version
'use strict'; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
var _classCallCheck = require('@babel/runtime/helpers/classCallCheck'); | ||
var _createClass = require('@babel/runtime/helpers/createClass'); | ||
var _inherits = require('@babel/runtime/helpers/inherits'); | ||
var _possibleConstructorReturn = require('@babel/runtime/helpers/possibleConstructorReturn'); | ||
var _getPrototypeOf = require('@babel/runtime/helpers/getPrototypeOf'); | ||
var _wrapNativeSuper = require('@babel/runtime/helpers/wrapNativeSuper'); | ||
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 _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck); | ||
var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass); | ||
var _inherits__default = /*#__PURE__*/_interopDefaultLegacy(_inherits); | ||
var _possibleConstructorReturn__default = /*#__PURE__*/_interopDefaultLegacy(_possibleConstructorReturn); | ||
var _getPrototypeOf__default = /*#__PURE__*/_interopDefaultLegacy(_getPrototypeOf); | ||
var _wrapNativeSuper__default = /*#__PURE__*/_interopDefaultLegacy(_wrapNativeSuper); | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _construct(Parent, args, Class) { | ||
if (_isNativeReflectConstruct()) { | ||
_construct = Reflect.construct; | ||
} else { | ||
_construct = function _construct(Parent, args, Class) { | ||
var a = [null]; | ||
a.push.apply(a, args); | ||
var Constructor = Function.bind.apply(Parent, a); | ||
var instance = new Constructor(); | ||
if (Class) _setPrototypeOf(instance, Class.prototype); | ||
return instance; | ||
}; | ||
} | ||
return _construct.apply(null, arguments); | ||
} | ||
function _isNativeFunction(fn) { | ||
return Function.toString.call(fn).indexOf("[native code]") !== -1; | ||
} | ||
function _wrapNativeSuper(Class) { | ||
var _cache = typeof Map === "function" ? new Map() : undefined; | ||
_wrapNativeSuper = function _wrapNativeSuper(Class) { | ||
if (Class === null || !_isNativeFunction(Class)) return Class; | ||
if (typeof Class !== "function") { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
if (typeof _cache !== "undefined") { | ||
if (_cache.has(Class)) return _cache.get(Class); | ||
_cache.set(Class, Wrapper); | ||
} | ||
function Wrapper() { | ||
return _construct(Class, arguments, _getPrototypeOf(this).constructor); | ||
} | ||
Wrapper.prototype = Object.create(Class.prototype, { | ||
constructor: { | ||
value: Wrapper, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
return _setPrototypeOf(Wrapper, Class); | ||
}; | ||
return _wrapNativeSuper(Class); | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
/* | ||
@@ -182,2 +42,7 @@ MIT License | ||
*/ | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } | ||
var rx_decode_space = /\+/g; | ||
@@ -211,2 +76,4 @@ var rx_encode_pctspace = /%20/g; | ||
var CHAR_TILDE = 0x7e; | ||
var CHAR_EQUALS = 0x3d; | ||
var CHAR_AMP = 0x26; | ||
var CHAR_0 = 0x30; | ||
@@ -230,2 +97,3 @@ var CHAR_E = 0x45; | ||
var ERR_MSG_EXPECT_STRUCTCHAR = "JSON->URL: expected comma, open paren, or close paren"; | ||
var ERR_MSG_EXPECT_MOREARRAY = "JSON->URL: expected comma or close paren"; | ||
var ERR_MSG_EXPECT_VALUE = "JSON->URL: expected value"; | ||
@@ -240,2 +108,3 @@ var ERR_MSG_EXPECT_LITERAL = "JSON->URL: expected literal value"; | ||
var ERR_MSG_LIMIT_MAXVALUES = "JSON->URL: MaxParseValues exceeded"; | ||
var ERR_MSG_EXPECT_QUOTE = "JSON->URL: quoted string still open"; | ||
@@ -329,3 +198,3 @@ function parseDigitsLength(text, i, len) { | ||
if (typeof p.emptyValue === "function") { | ||
return new p.emptyValue(); | ||
return p.emptyValue(); | ||
} | ||
@@ -336,2 +205,10 @@ | ||
function newNullValue(p) { | ||
if (typeof p.nullValue === "function") { | ||
return p.nullValue(); | ||
} | ||
return p.nullValue; | ||
} | ||
function errorMessage(msg, pos) { | ||
@@ -345,7 +222,7 @@ if (pos === undefined) { | ||
function parseLiteralLength(text, i, len, errmsg) { | ||
function parseLiteralLength(text, i, end, errmsg) { | ||
var isQuote = false; | ||
var start = i; | ||
if (i === len) { | ||
if (i === end) { | ||
throw new SyntaxError(errorMessage(errmsg, i)); | ||
@@ -359,3 +236,3 @@ } | ||
for (; i < len; i++) { | ||
for (; i < end; i++) { | ||
var c = text.charCodeAt(i); | ||
@@ -415,2 +292,13 @@ | ||
case CHAR_AMP: | ||
case CHAR_EQUALS: | ||
// | ||
// these are forbidden, quoted or otherwise. | ||
// | ||
if (i === start) { | ||
throw new SyntaxError(errorMessage(errmsg, start)); | ||
} | ||
return i; | ||
default: | ||
@@ -421,3 +309,7 @@ throw new SyntaxError(errorMessage(ERR_MSG_BADCHAR, i)); | ||
return len; | ||
if (isQuote) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXPECT_QUOTE, i)); | ||
} | ||
return end; | ||
} | ||
@@ -433,3 +325,3 @@ | ||
function toJsonURLText_String(isKey) { | ||
function toJsonURLText_String(options, depth, isKey) { | ||
if (this.length === 0) { | ||
@@ -495,28 +387,51 @@ return "''"; | ||
function toJsonURLText_Array() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var ret = undefined; | ||
this.forEach(function (e) { | ||
while (typeof e === "function") { | ||
e = e(); | ||
if (typeof e === "function") { | ||
if (!options.callFunctions) { | ||
return; | ||
} | ||
while (typeof e === "function") { | ||
e = e(); | ||
} | ||
} | ||
if (e === undefined || e === null) { | ||
if (ret === undefined) { | ||
ret = "null"; | ||
} else { | ||
ret += ",null"; | ||
if (e === undefined) { | ||
if (options.ignoreUndefinedArrayMembers) { | ||
return; | ||
} | ||
return; | ||
e = "null"; | ||
} else if (e === null) { | ||
if (options.ignoreNullArrayMembers) { | ||
return; | ||
} | ||
e = "null"; | ||
} else { | ||
e = e.toJsonURLText(options, depth + 1); | ||
} | ||
if (ret === undefined) { | ||
ret = e.toJsonURLText(); | ||
ret = e; | ||
} else if (!options.wwwFormUrlEncoded || depth > 0) { | ||
ret += "," + e; | ||
} else { | ||
ret += "," + e.toJsonURLText(); | ||
ret += "&" + e; | ||
} | ||
}); | ||
return ret === undefined ? "()" : "(" + ret + ")"; | ||
if (!options.isImplied || depth > 0) { | ||
return ret === undefined ? "()" : "(" + ret + ")"; | ||
} | ||
return ret === undefined ? "" : ret; | ||
} | ||
function toJsonURLText_Object() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var ret = undefined; | ||
@@ -527,2 +442,5 @@ var keys = Object.keys(this); | ||
if (k === undefined || k === null) { | ||
// | ||
// I'm not sure this can actually happen. But, handling just in case. | ||
// | ||
return; | ||
@@ -533,16 +451,50 @@ } | ||
while (typeof v === "function") { | ||
v = v(); | ||
if (typeof v === "function") { | ||
if (!options.callFunctions) { | ||
return; | ||
} | ||
while (typeof v === "function") { | ||
v = v(); | ||
} | ||
} | ||
var jk = k.toJsonURLText(true); | ||
var jv = v === undefined || v === null ? "null" : v.toJsonURLText(); | ||
if (v === undefined) { | ||
if (options.ignoreUndefinedObjectMembers) { | ||
return; | ||
} | ||
v = "null"; | ||
} else if (v === null) { | ||
if (options.ignoreNullObjectMembers) { | ||
return; | ||
} | ||
v = "null"; | ||
} else { | ||
v = v.toJsonURLText(options, depth + 1); | ||
} | ||
var jk = k.toJsonURLText(options, depth, true); | ||
if (ret === undefined) { | ||
ret = jk + ":" + jv; | ||
if (!options.wwwFormUrlEncoded || depth > 0) { | ||
ret = jk + ":" + v; | ||
} else { | ||
ret = jk + "=" + v; | ||
} | ||
} else { | ||
ret += "," + jk + ":" + jv; | ||
if (!options.wwwFormUrlEncoded || depth > 0) { | ||
ret += "," + jk + ":" + v; | ||
} else { | ||
ret += "&" + jk + "=" + v; | ||
} | ||
} | ||
}); | ||
return ret === undefined ? "()" : "(" + ret + ")"; | ||
if (!options.isImplied || depth > 0) { | ||
return ret === undefined ? "()" : "(" + ret + ")"; | ||
} | ||
return ret === undefined ? "" : ret; | ||
} | ||
@@ -567,6 +519,7 @@ | ||
* A class for managing values during parse | ||
* @private | ||
*/ | ||
var StateStack = /*#__PURE__*/function (_Array) { | ||
_inherits(StateStack, _Array); | ||
_inherits__default['default'](StateStack, _Array); | ||
@@ -578,3 +531,3 @@ var _super = _createSuper(StateStack); | ||
_classCallCheck(this, StateStack); | ||
_classCallCheck__default['default'](this, StateStack); | ||
@@ -593,3 +546,3 @@ _this = _super.call(this); | ||
_createClass(StateStack, [{ | ||
_createClass__default['default'](StateStack, [{ | ||
key: "replaceAndPush", | ||
@@ -634,5 +587,6 @@ value: function replaceAndPush(pos, r, p) { | ||
return StateStack; | ||
}( /*#__PURE__*/_wrapNativeSuper(Array)); | ||
}( /*#__PURE__*/_wrapNativeSuper__default['default'](Array)); | ||
/** | ||
* A class for managing values during parse | ||
* @private | ||
*/ | ||
@@ -642,3 +596,3 @@ | ||
var ValueStack = /*#__PURE__*/function (_Array2) { | ||
_inherits(ValueStack, _Array2); | ||
_inherits__default['default'](ValueStack, _Array2); | ||
@@ -650,3 +604,3 @@ var _super2 = _createSuper(ValueStack); | ||
_classCallCheck(this, ValueStack); | ||
_classCallCheck__default['default'](this, ValueStack); | ||
@@ -664,3 +618,3 @@ _this2 = _super2.call(this); | ||
_createClass(ValueStack, [{ | ||
_createClass__default['default'](ValueStack, [{ | ||
key: "popObjectValue", | ||
@@ -720,5 +674,6 @@ value: function popObjectValue(value) { | ||
return ValueStack; | ||
}( /*#__PURE__*/_wrapNativeSuper(Array)); | ||
}( /*#__PURE__*/_wrapNativeSuper__default['default'](Array)); | ||
/** | ||
* A class for parsing JSON->URL text. | ||
* @public | ||
*/ | ||
@@ -730,2 +685,9 @@ | ||
* Construct a new JsonURL class. | ||
* | ||
* Each instance of this class contains a number of properties that manage | ||
* the behavior of the parser and the values it returns; these are documented | ||
* below. The class instance does not manage parse state -- that is local to | ||
* the parse() function itself. As long as you don't need different | ||
* properties (e.g. limits, null value, etc) you may re-use the same Parser | ||
* instance, even by multiple Workers. | ||
* @param {Object} prop Initialization properties. | ||
@@ -753,3 +715,3 @@ * You may provide zero more more of the following. Reasonable defaults | ||
function JsonURL(prop) { | ||
_classCallCheck(this, JsonURL); | ||
_classCallCheck__default['default'](this, JsonURL); | ||
@@ -780,3 +742,3 @@ while (typeof prop === "function") { | ||
_createClass(JsonURL, [{ | ||
_createClass__default['default'](JsonURL, [{ | ||
key: "parseLiteral", | ||
@@ -796,3 +758,3 @@ value: function parseLiteral(text) { | ||
if (c1 === CHAR_t && c2 === CHAR_r && c3 === CHAR_u && c4 === CHAR_e) return forceString ? "true" : true; | ||
if (c1 === CHAR_n && c2 === CHAR_u && c3 === CHAR_l && c4 === CHAR_l) return forceString ? "null" : this.nullValue; | ||
if (c1 === CHAR_n && c2 === CHAR_u && c3 === CHAR_l && c4 === CHAR_l) return forceString ? "null" : newNullValue(this); | ||
break; | ||
@@ -860,2 +822,23 @@ | ||
* @param {string} text The text to parse. | ||
* @param {Object} options parse options. | ||
* You may provide zero more more of the following. | ||
* @param {array} options.impliedArray An implied array. | ||
* The parse() method implements a parser for the grammar oulined in | ||
* section 2.7 of the JSON->URL specification. The given parse text | ||
* is assumed to be an array, and the leading and trailing parens must | ||
* not be present. The given prop.impliedArray value will be populated | ||
* and returned. | ||
* @param {object} options.impliedObject An implied object. | ||
* The parse() method implements a parser for the grammar oulined in | ||
* section 2.8 of the JSON->URL specification. The given parse text | ||
* is assumed to be an object, and the leading and trailing parens must | ||
* not be present. The given prop.impliedObject value will be populated | ||
* and returned. | ||
* @param {boolean} options.wwwFormUrlEncoded Enable support for | ||
* x-www-form-urlencoded content. | ||
* The parse() method implements a parser for the grammar oulined in | ||
* section 2.9 of the JSON->URL specification. The given parse text | ||
* is may use ampersand and equal characters as the value and member | ||
* separator characters, respetively, at the top-level. This may be | ||
* combined with prop.impliedArray or prop.impliedObject. | ||
* @throws SyntaxError if there is a syntax error in the given text | ||
@@ -870,2 +853,7 @@ * @throws Error if a limit given in the constructor (or its default) | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (text === undefined) { | ||
return undefined; | ||
} | ||
text = String(text); | ||
@@ -875,3 +863,11 @@ var end = text.length; | ||
if (end === 0) { | ||
return undefined; | ||
if (options.impliedArray !== undefined) { | ||
return options.impliedArray; | ||
} | ||
if (options.impliedObject !== undefined) { | ||
return options.impliedObject; | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXPECT_VALUE, 0)); | ||
} | ||
@@ -887,6 +883,6 @@ | ||
if (options.impliedObject) { | ||
if (options.impliedObject !== undefined) { | ||
valueStack.push(options.impliedObject); | ||
stateStack.push(STATE_IN_OBJECT); | ||
} else if (options.impliedArray) { | ||
} else if (options.impliedArray !== undefined) { | ||
valueStack.push(options.impliedArray); | ||
@@ -944,16 +940,26 @@ stateStack.push(STATE_IN_ARRAY); | ||
case CHAR_PAREN_CLOSE: | ||
pos++; | ||
if (stateStack.depth(true) === -1) { | ||
if (pos + 1 != end) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXTRACHARS, pos)); | ||
if (pos === end) { | ||
return newEmptyValue(this); | ||
} | ||
if (valueStack.length === 0) { | ||
return newEmptyValue(this); | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXTRACHARS, pos)); | ||
} | ||
valueStack.appendArrayValue(pos, newEmptyValue(this)); | ||
if (pos === end && stateStack.depth() === 0) { | ||
if (options.impliedArray) { | ||
return valueStack.popArrayValue(); | ||
} | ||
return valueStack[0]; | ||
if (options.impliedObject) { | ||
return valueStack.popObjectValue(); | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_STILLOPEN, pos)); | ||
} | ||
valueStack.appendArrayValue(pos, newEmptyValue(this)); | ||
pos++; | ||
continue; | ||
@@ -981,2 +987,9 @@ } // | ||
switch (c) { | ||
case CHAR_AMP: | ||
if (!options.wwwFormUrlEncoded || stateStack.depth() > 0) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_BADCHAR, pos)); | ||
} | ||
// fall through | ||
case CHAR_COMMA: | ||
@@ -992,18 +1005,41 @@ // | ||
case CHAR_PAREN_CLOSE: | ||
// | ||
pos++; // | ||
// single element array | ||
// | ||
valueStack.appendArrayValue(pos, [lv]); | ||
if (stateStack.depth(true) === -1) { | ||
if (pos + 1 === end) { | ||
return valueStack[0]; | ||
} | ||
switch (stateStack.depth(true)) { | ||
case -1: | ||
if (pos === end) { | ||
return valueStack[0]; | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXTRACHARS, pos)); | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXTRACHARS, pos)); | ||
case 0: | ||
if (pos === end) { | ||
if (options.impliedArray) { | ||
return valueStack.popArrayValue(); | ||
} | ||
if (options.impliedObject) { | ||
return valueStack.popObjectValue(); | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_STILLOPEN, pos)); | ||
} | ||
break; | ||
} | ||
pos++; | ||
continue; | ||
case CHAR_EQUALS: | ||
if (!options.wwwFormUrlEncoded || stateStack.depth() > 0) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_BADCHAR, pos)); | ||
} | ||
// fall through | ||
case CHAR_COLON: | ||
@@ -1034,3 +1070,3 @@ // | ||
if (_lvpos === end) { | ||
if (pos === end) { | ||
if (stateStack.depth() === 0 && options.impliedArray) { | ||
@@ -1051,2 +1087,9 @@ return valueStack.popArrayValue(lv); | ||
switch (c) { | ||
case CHAR_AMP: | ||
if (!options.wwwFormUrlEncoded || stateStack.depth() > 0) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_BADCHAR, pos)); | ||
} | ||
// fall through | ||
case CHAR_COMMA: | ||
@@ -1058,2 +1101,4 @@ stateStack.replace(STATE_IN_ARRAY); | ||
case CHAR_PAREN_CLOSE: | ||
pos++; | ||
switch (stateStack.depth(true)) { | ||
@@ -1064,3 +1109,3 @@ case -1: | ||
// | ||
if (pos + 1 == end) { | ||
if (pos === end && !options.impliedArray) { | ||
return valueStack[0]; | ||
@@ -1075,3 +1120,3 @@ } | ||
// | ||
if (pos + 1 == end) { | ||
if (pos === end) { | ||
if (options.impliedArray) { | ||
@@ -1084,2 +1129,4 @@ return valueStack.popArrayValue(); | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_STILLOPEN, pos)); | ||
} | ||
@@ -1090,7 +1137,6 @@ | ||
pos++; | ||
continue; | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXPECT_STRUCTCHAR, pos)); | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXPECT_MOREARRAY, pos)); | ||
@@ -1125,2 +1171,9 @@ case STATE_OBJECT_HAVE_KEY: | ||
switch (c) { | ||
case CHAR_AMP: | ||
if (!options.wwwFormUrlEncoded || stateStack.depth() > 0) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_BADCHAR, pos)); | ||
} | ||
// fall through | ||
case CHAR_COMMA: | ||
@@ -1132,5 +1185,7 @@ stateStack.replace(STATE_IN_OBJECT); | ||
case CHAR_PAREN_CLOSE: | ||
pos++; | ||
switch (stateStack.depth(true)) { | ||
case -1: | ||
if (pos + 1 === end) { | ||
if (pos === end && !options.impliedObject) { | ||
// | ||
@@ -1148,3 +1203,3 @@ // end of a "real" object | ||
// | ||
if (pos + 1 == end) { | ||
if (pos === end) { | ||
if (options.impliedArray) { | ||
@@ -1157,2 +1212,4 @@ return valueStack.popArrayValue(); | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXTRACHARS, pos)); | ||
} | ||
@@ -1163,3 +1220,2 @@ | ||
pos++; | ||
continue; | ||
@@ -1174,2 +1230,6 @@ } | ||
if (_lvpos === end) { | ||
// | ||
// I don't know that this is actually possible -- I haven't | ||
// found a test case yet. But, if it is possible, it's an error. | ||
// | ||
throw new SyntaxError(errorMessage(ERR_MSG_STILLOPEN, end)); | ||
@@ -1180,4 +1240,15 @@ } | ||
if (c !== CHAR_COLON) { | ||
throw new SyntaxError((_lvpos)); | ||
switch (c) { | ||
case CHAR_EQUALS: | ||
if (!options.wwwFormUrlEncoded || stateStack.depth() > 0) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_BADCHAR, pos)); | ||
} | ||
// fall through | ||
case CHAR_COLON: | ||
break; | ||
default: | ||
throw new SyntaxError((_lvpos)); | ||
} | ||
@@ -1192,2 +1263,5 @@ | ||
default: | ||
// | ||
// this shouldn't be possible, but handle it just in case | ||
// | ||
throw new SyntaxError(errorMessage(ERR_MSG_INTERNAL, pos)); | ||
@@ -1200,2 +1274,18 @@ } | ||
* @param {*} value Any value | ||
* @param {Object} options stringify options. | ||
* You may provide zero more more of the following. | ||
* @param {boolean} options.ignoreNullArrayMembers Ignore null array members. | ||
* This is false by default. | ||
* @param {boolean} options.ignoreNullObjectMembers Ignore null object members. | ||
* This is false by default. | ||
* @param {boolean} options.ignoreUndefinedArrayMembers Ignore undefined array members. | ||
* This is false by default. They will be stringified as null because | ||
* undefined is not a valid JSON value. | ||
* @param {boolean} options.ignoreUndefinedObjectMembers Ignore undefined object members. | ||
* This is true by default. They will be omitted from the stringified | ||
* output. This mimics the behavior JSON.stringify(). | ||
* @param {boolean} options.wwwFormUrlEncoded Enable x-www-form-urlencoded | ||
* structural characters. | ||
* @param {boolean} options.isImplied Create JSON->URL text for an implied | ||
* array or object. | ||
* @returns {string} JSON->URL text, or undefined if the given value | ||
@@ -1208,2 +1298,6 @@ * is undefined. | ||
value: function stringify(value) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { | ||
ignoreUndefinedObjectMembers: true | ||
}; | ||
if (value === undefined) { | ||
@@ -1217,3 +1311,3 @@ return undefined; | ||
return value.toJsonURLText(); | ||
return value.toJsonURLText(options, 0); | ||
} | ||
@@ -1220,0 +1314,0 @@ }]); |
@@ -1,157 +0,8 @@ | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
import _classCallCheck from '@babel/runtime/helpers/classCallCheck'; | ||
import _createClass from '@babel/runtime/helpers/createClass'; | ||
import _inherits from '@babel/runtime/helpers/inherits'; | ||
import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn'; | ||
import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf'; | ||
import _wrapNativeSuper from '@babel/runtime/helpers/wrapNativeSuper'; | ||
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 _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _construct(Parent, args, Class) { | ||
if (_isNativeReflectConstruct()) { | ||
_construct = Reflect.construct; | ||
} else { | ||
_construct = function _construct(Parent, args, Class) { | ||
var a = [null]; | ||
a.push.apply(a, args); | ||
var Constructor = Function.bind.apply(Parent, a); | ||
var instance = new Constructor(); | ||
if (Class) _setPrototypeOf(instance, Class.prototype); | ||
return instance; | ||
}; | ||
} | ||
return _construct.apply(null, arguments); | ||
} | ||
function _isNativeFunction(fn) { | ||
return Function.toString.call(fn).indexOf("[native code]") !== -1; | ||
} | ||
function _wrapNativeSuper(Class) { | ||
var _cache = typeof Map === "function" ? new Map() : undefined; | ||
_wrapNativeSuper = function _wrapNativeSuper(Class) { | ||
if (Class === null || !_isNativeFunction(Class)) return Class; | ||
if (typeof Class !== "function") { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
if (typeof _cache !== "undefined") { | ||
if (_cache.has(Class)) return _cache.get(Class); | ||
_cache.set(Class, Wrapper); | ||
} | ||
function Wrapper() { | ||
return _construct(Class, arguments, _getPrototypeOf(this).constructor); | ||
} | ||
Wrapper.prototype = Object.create(Class.prototype, { | ||
constructor: { | ||
value: Wrapper, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
return _setPrototypeOf(Wrapper, Class); | ||
}; | ||
return _wrapNativeSuper(Class); | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
/* | ||
@@ -180,2 +31,7 @@ MIT License | ||
*/ | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } | ||
var rx_decode_space = /\+/g; | ||
@@ -209,2 +65,4 @@ var rx_encode_pctspace = /%20/g; | ||
var CHAR_TILDE = 0x7e; | ||
var CHAR_EQUALS = 0x3d; | ||
var CHAR_AMP = 0x26; | ||
var CHAR_0 = 0x30; | ||
@@ -228,2 +86,3 @@ var CHAR_E = 0x45; | ||
var ERR_MSG_EXPECT_STRUCTCHAR = "JSON->URL: expected comma, open paren, or close paren"; | ||
var ERR_MSG_EXPECT_MOREARRAY = "JSON->URL: expected comma or close paren"; | ||
var ERR_MSG_EXPECT_VALUE = "JSON->URL: expected value"; | ||
@@ -238,2 +97,3 @@ var ERR_MSG_EXPECT_LITERAL = "JSON->URL: expected literal value"; | ||
var ERR_MSG_LIMIT_MAXVALUES = "JSON->URL: MaxParseValues exceeded"; | ||
var ERR_MSG_EXPECT_QUOTE = "JSON->URL: quoted string still open"; | ||
@@ -327,3 +187,3 @@ function parseDigitsLength(text, i, len) { | ||
if (typeof p.emptyValue === "function") { | ||
return new p.emptyValue(); | ||
return p.emptyValue(); | ||
} | ||
@@ -334,2 +194,10 @@ | ||
function newNullValue(p) { | ||
if (typeof p.nullValue === "function") { | ||
return p.nullValue(); | ||
} | ||
return p.nullValue; | ||
} | ||
function errorMessage(msg, pos) { | ||
@@ -343,7 +211,7 @@ if (pos === undefined) { | ||
function parseLiteralLength(text, i, len, errmsg) { | ||
function parseLiteralLength(text, i, end, errmsg) { | ||
var isQuote = false; | ||
var start = i; | ||
if (i === len) { | ||
if (i === end) { | ||
throw new SyntaxError(errorMessage(errmsg, i)); | ||
@@ -357,3 +225,3 @@ } | ||
for (; i < len; i++) { | ||
for (; i < end; i++) { | ||
var c = text.charCodeAt(i); | ||
@@ -413,2 +281,13 @@ | ||
case CHAR_AMP: | ||
case CHAR_EQUALS: | ||
// | ||
// these are forbidden, quoted or otherwise. | ||
// | ||
if (i === start) { | ||
throw new SyntaxError(errorMessage(errmsg, start)); | ||
} | ||
return i; | ||
default: | ||
@@ -419,3 +298,7 @@ throw new SyntaxError(errorMessage(ERR_MSG_BADCHAR, i)); | ||
return len; | ||
if (isQuote) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXPECT_QUOTE, i)); | ||
} | ||
return end; | ||
} | ||
@@ -431,3 +314,3 @@ | ||
function toJsonURLText_String(isKey) { | ||
function toJsonURLText_String(options, depth, isKey) { | ||
if (this.length === 0) { | ||
@@ -493,28 +376,51 @@ return "''"; | ||
function toJsonURLText_Array() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var ret = undefined; | ||
this.forEach(function (e) { | ||
while (typeof e === "function") { | ||
e = e(); | ||
if (typeof e === "function") { | ||
if (!options.callFunctions) { | ||
return; | ||
} | ||
while (typeof e === "function") { | ||
e = e(); | ||
} | ||
} | ||
if (e === undefined || e === null) { | ||
if (ret === undefined) { | ||
ret = "null"; | ||
} else { | ||
ret += ",null"; | ||
if (e === undefined) { | ||
if (options.ignoreUndefinedArrayMembers) { | ||
return; | ||
} | ||
return; | ||
e = "null"; | ||
} else if (e === null) { | ||
if (options.ignoreNullArrayMembers) { | ||
return; | ||
} | ||
e = "null"; | ||
} else { | ||
e = e.toJsonURLText(options, depth + 1); | ||
} | ||
if (ret === undefined) { | ||
ret = e.toJsonURLText(); | ||
ret = e; | ||
} else if (!options.wwwFormUrlEncoded || depth > 0) { | ||
ret += "," + e; | ||
} else { | ||
ret += "," + e.toJsonURLText(); | ||
ret += "&" + e; | ||
} | ||
}); | ||
return ret === undefined ? "()" : "(" + ret + ")"; | ||
if (!options.isImplied || depth > 0) { | ||
return ret === undefined ? "()" : "(" + ret + ")"; | ||
} | ||
return ret === undefined ? "" : ret; | ||
} | ||
function toJsonURLText_Object() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var ret = undefined; | ||
@@ -525,2 +431,5 @@ var keys = Object.keys(this); | ||
if (k === undefined || k === null) { | ||
// | ||
// I'm not sure this can actually happen. But, handling just in case. | ||
// | ||
return; | ||
@@ -531,16 +440,50 @@ } | ||
while (typeof v === "function") { | ||
v = v(); | ||
if (typeof v === "function") { | ||
if (!options.callFunctions) { | ||
return; | ||
} | ||
while (typeof v === "function") { | ||
v = v(); | ||
} | ||
} | ||
var jk = k.toJsonURLText(true); | ||
var jv = v === undefined || v === null ? "null" : v.toJsonURLText(); | ||
if (v === undefined) { | ||
if (options.ignoreUndefinedObjectMembers) { | ||
return; | ||
} | ||
v = "null"; | ||
} else if (v === null) { | ||
if (options.ignoreNullObjectMembers) { | ||
return; | ||
} | ||
v = "null"; | ||
} else { | ||
v = v.toJsonURLText(options, depth + 1); | ||
} | ||
var jk = k.toJsonURLText(options, depth, true); | ||
if (ret === undefined) { | ||
ret = jk + ":" + jv; | ||
if (!options.wwwFormUrlEncoded || depth > 0) { | ||
ret = jk + ":" + v; | ||
} else { | ||
ret = jk + "=" + v; | ||
} | ||
} else { | ||
ret += "," + jk + ":" + jv; | ||
if (!options.wwwFormUrlEncoded || depth > 0) { | ||
ret += "," + jk + ":" + v; | ||
} else { | ||
ret += "&" + jk + "=" + v; | ||
} | ||
} | ||
}); | ||
return ret === undefined ? "()" : "(" + ret + ")"; | ||
if (!options.isImplied || depth > 0) { | ||
return ret === undefined ? "()" : "(" + ret + ")"; | ||
} | ||
return ret === undefined ? "" : ret; | ||
} | ||
@@ -565,2 +508,3 @@ | ||
* A class for managing values during parse | ||
* @private | ||
*/ | ||
@@ -633,2 +577,3 @@ | ||
* A class for managing values during parse | ||
* @private | ||
*/ | ||
@@ -716,2 +661,3 @@ | ||
* A class for parsing JSON->URL text. | ||
* @public | ||
*/ | ||
@@ -723,2 +669,9 @@ | ||
* Construct a new JsonURL class. | ||
* | ||
* Each instance of this class contains a number of properties that manage | ||
* the behavior of the parser and the values it returns; these are documented | ||
* below. The class instance does not manage parse state -- that is local to | ||
* the parse() function itself. As long as you don't need different | ||
* properties (e.g. limits, null value, etc) you may re-use the same Parser | ||
* instance, even by multiple Workers. | ||
* @param {Object} prop Initialization properties. | ||
@@ -787,3 +740,3 @@ * You may provide zero more more of the following. Reasonable defaults | ||
if (c1 === CHAR_t && c2 === CHAR_r && c3 === CHAR_u && c4 === CHAR_e) return forceString ? "true" : true; | ||
if (c1 === CHAR_n && c2 === CHAR_u && c3 === CHAR_l && c4 === CHAR_l) return forceString ? "null" : this.nullValue; | ||
if (c1 === CHAR_n && c2 === CHAR_u && c3 === CHAR_l && c4 === CHAR_l) return forceString ? "null" : newNullValue(this); | ||
break; | ||
@@ -851,2 +804,23 @@ | ||
* @param {string} text The text to parse. | ||
* @param {Object} options parse options. | ||
* You may provide zero more more of the following. | ||
* @param {array} options.impliedArray An implied array. | ||
* The parse() method implements a parser for the grammar oulined in | ||
* section 2.7 of the JSON->URL specification. The given parse text | ||
* is assumed to be an array, and the leading and trailing parens must | ||
* not be present. The given prop.impliedArray value will be populated | ||
* and returned. | ||
* @param {object} options.impliedObject An implied object. | ||
* The parse() method implements a parser for the grammar oulined in | ||
* section 2.8 of the JSON->URL specification. The given parse text | ||
* is assumed to be an object, and the leading and trailing parens must | ||
* not be present. The given prop.impliedObject value will be populated | ||
* and returned. | ||
* @param {boolean} options.wwwFormUrlEncoded Enable support for | ||
* x-www-form-urlencoded content. | ||
* The parse() method implements a parser for the grammar oulined in | ||
* section 2.9 of the JSON->URL specification. The given parse text | ||
* is may use ampersand and equal characters as the value and member | ||
* separator characters, respetively, at the top-level. This may be | ||
* combined with prop.impliedArray or prop.impliedObject. | ||
* @throws SyntaxError if there is a syntax error in the given text | ||
@@ -861,2 +835,7 @@ * @throws Error if a limit given in the constructor (or its default) | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (text === undefined) { | ||
return undefined; | ||
} | ||
text = String(text); | ||
@@ -866,3 +845,11 @@ var end = text.length; | ||
if (end === 0) { | ||
return undefined; | ||
if (options.impliedArray !== undefined) { | ||
return options.impliedArray; | ||
} | ||
if (options.impliedObject !== undefined) { | ||
return options.impliedObject; | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXPECT_VALUE, 0)); | ||
} | ||
@@ -878,6 +865,6 @@ | ||
if (options.impliedObject) { | ||
if (options.impliedObject !== undefined) { | ||
valueStack.push(options.impliedObject); | ||
stateStack.push(STATE_IN_OBJECT); | ||
} else if (options.impliedArray) { | ||
} else if (options.impliedArray !== undefined) { | ||
valueStack.push(options.impliedArray); | ||
@@ -935,16 +922,26 @@ stateStack.push(STATE_IN_ARRAY); | ||
case CHAR_PAREN_CLOSE: | ||
pos++; | ||
if (stateStack.depth(true) === -1) { | ||
if (pos + 1 != end) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXTRACHARS, pos)); | ||
if (pos === end) { | ||
return newEmptyValue(this); | ||
} | ||
if (valueStack.length === 0) { | ||
return newEmptyValue(this); | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXTRACHARS, pos)); | ||
} | ||
valueStack.appendArrayValue(pos, newEmptyValue(this)); | ||
if (pos === end && stateStack.depth() === 0) { | ||
if (options.impliedArray) { | ||
return valueStack.popArrayValue(); | ||
} | ||
return valueStack[0]; | ||
if (options.impliedObject) { | ||
return valueStack.popObjectValue(); | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_STILLOPEN, pos)); | ||
} | ||
valueStack.appendArrayValue(pos, newEmptyValue(this)); | ||
pos++; | ||
continue; | ||
@@ -972,2 +969,9 @@ } // | ||
switch (c) { | ||
case CHAR_AMP: | ||
if (!options.wwwFormUrlEncoded || stateStack.depth() > 0) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_BADCHAR, pos)); | ||
} | ||
// fall through | ||
case CHAR_COMMA: | ||
@@ -983,18 +987,41 @@ // | ||
case CHAR_PAREN_CLOSE: | ||
// | ||
pos++; // | ||
// single element array | ||
// | ||
valueStack.appendArrayValue(pos, [lv]); | ||
if (stateStack.depth(true) === -1) { | ||
if (pos + 1 === end) { | ||
return valueStack[0]; | ||
} | ||
switch (stateStack.depth(true)) { | ||
case -1: | ||
if (pos === end) { | ||
return valueStack[0]; | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXTRACHARS, pos)); | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXTRACHARS, pos)); | ||
case 0: | ||
if (pos === end) { | ||
if (options.impliedArray) { | ||
return valueStack.popArrayValue(); | ||
} | ||
if (options.impliedObject) { | ||
return valueStack.popObjectValue(); | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_STILLOPEN, pos)); | ||
} | ||
break; | ||
} | ||
pos++; | ||
continue; | ||
case CHAR_EQUALS: | ||
if (!options.wwwFormUrlEncoded || stateStack.depth() > 0) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_BADCHAR, pos)); | ||
} | ||
// fall through | ||
case CHAR_COLON: | ||
@@ -1025,3 +1052,3 @@ // | ||
if (_lvpos === end) { | ||
if (pos === end) { | ||
if (stateStack.depth() === 0 && options.impliedArray) { | ||
@@ -1042,2 +1069,9 @@ return valueStack.popArrayValue(lv); | ||
switch (c) { | ||
case CHAR_AMP: | ||
if (!options.wwwFormUrlEncoded || stateStack.depth() > 0) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_BADCHAR, pos)); | ||
} | ||
// fall through | ||
case CHAR_COMMA: | ||
@@ -1049,2 +1083,4 @@ stateStack.replace(STATE_IN_ARRAY); | ||
case CHAR_PAREN_CLOSE: | ||
pos++; | ||
switch (stateStack.depth(true)) { | ||
@@ -1055,3 +1091,3 @@ case -1: | ||
// | ||
if (pos + 1 == end) { | ||
if (pos === end && !options.impliedArray) { | ||
return valueStack[0]; | ||
@@ -1066,3 +1102,3 @@ } | ||
// | ||
if (pos + 1 == end) { | ||
if (pos === end) { | ||
if (options.impliedArray) { | ||
@@ -1075,2 +1111,4 @@ return valueStack.popArrayValue(); | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_STILLOPEN, pos)); | ||
} | ||
@@ -1081,7 +1119,6 @@ | ||
pos++; | ||
continue; | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXPECT_STRUCTCHAR, pos)); | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXPECT_MOREARRAY, pos)); | ||
@@ -1116,2 +1153,9 @@ case STATE_OBJECT_HAVE_KEY: | ||
switch (c) { | ||
case CHAR_AMP: | ||
if (!options.wwwFormUrlEncoded || stateStack.depth() > 0) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_BADCHAR, pos)); | ||
} | ||
// fall through | ||
case CHAR_COMMA: | ||
@@ -1123,5 +1167,7 @@ stateStack.replace(STATE_IN_OBJECT); | ||
case CHAR_PAREN_CLOSE: | ||
pos++; | ||
switch (stateStack.depth(true)) { | ||
case -1: | ||
if (pos + 1 === end) { | ||
if (pos === end && !options.impliedObject) { | ||
// | ||
@@ -1139,3 +1185,3 @@ // end of a "real" object | ||
// | ||
if (pos + 1 == end) { | ||
if (pos === end) { | ||
if (options.impliedArray) { | ||
@@ -1148,2 +1194,4 @@ return valueStack.popArrayValue(); | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXTRACHARS, pos)); | ||
} | ||
@@ -1154,3 +1202,2 @@ | ||
pos++; | ||
continue; | ||
@@ -1165,2 +1212,6 @@ } | ||
if (_lvpos === end) { | ||
// | ||
// I don't know that this is actually possible -- I haven't | ||
// found a test case yet. But, if it is possible, it's an error. | ||
// | ||
throw new SyntaxError(errorMessage(ERR_MSG_STILLOPEN, end)); | ||
@@ -1171,4 +1222,15 @@ } | ||
if (c !== CHAR_COLON) { | ||
throw new SyntaxError((_lvpos)); | ||
switch (c) { | ||
case CHAR_EQUALS: | ||
if (!options.wwwFormUrlEncoded || stateStack.depth() > 0) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_BADCHAR, pos)); | ||
} | ||
// fall through | ||
case CHAR_COLON: | ||
break; | ||
default: | ||
throw new SyntaxError((_lvpos)); | ||
} | ||
@@ -1183,2 +1245,5 @@ | ||
default: | ||
// | ||
// this shouldn't be possible, but handle it just in case | ||
// | ||
throw new SyntaxError(errorMessage(ERR_MSG_INTERNAL, pos)); | ||
@@ -1191,2 +1256,18 @@ } | ||
* @param {*} value Any value | ||
* @param {Object} options stringify options. | ||
* You may provide zero more more of the following. | ||
* @param {boolean} options.ignoreNullArrayMembers Ignore null array members. | ||
* This is false by default. | ||
* @param {boolean} options.ignoreNullObjectMembers Ignore null object members. | ||
* This is false by default. | ||
* @param {boolean} options.ignoreUndefinedArrayMembers Ignore undefined array members. | ||
* This is false by default. They will be stringified as null because | ||
* undefined is not a valid JSON value. | ||
* @param {boolean} options.ignoreUndefinedObjectMembers Ignore undefined object members. | ||
* This is true by default. They will be omitted from the stringified | ||
* output. This mimics the behavior JSON.stringify(). | ||
* @param {boolean} options.wwwFormUrlEncoded Enable x-www-form-urlencoded | ||
* structural characters. | ||
* @param {boolean} options.isImplied Create JSON->URL text for an implied | ||
* array or object. | ||
* @returns {string} JSON->URL text, or undefined if the given value | ||
@@ -1199,2 +1280,6 @@ * is undefined. | ||
value: function stringify(value) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { | ||
ignoreUndefinedObjectMembers: true | ||
}; | ||
if (value === undefined) { | ||
@@ -1208,3 +1293,3 @@ return undefined; | ||
return value.toJsonURLText(); | ||
return value.toJsonURLText(options, 0); | ||
} | ||
@@ -1211,0 +1296,0 @@ }]); |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = global || self, global.JsonURL = factory()); | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.JsonURL = factory()); | ||
}(this, (function () { 'use strict'; | ||
@@ -214,2 +214,4 @@ | ||
var CHAR_TILDE = 0x7e; | ||
var CHAR_EQUALS = 0x3d; | ||
var CHAR_AMP = 0x26; | ||
var CHAR_0 = 0x30; | ||
@@ -233,2 +235,3 @@ var CHAR_E = 0x45; | ||
var ERR_MSG_EXPECT_STRUCTCHAR = "JSON->URL: expected comma, open paren, or close paren"; | ||
var ERR_MSG_EXPECT_MOREARRAY = "JSON->URL: expected comma or close paren"; | ||
var ERR_MSG_EXPECT_VALUE = "JSON->URL: expected value"; | ||
@@ -243,2 +246,3 @@ var ERR_MSG_EXPECT_LITERAL = "JSON->URL: expected literal value"; | ||
var ERR_MSG_LIMIT_MAXVALUES = "JSON->URL: MaxParseValues exceeded"; | ||
var ERR_MSG_EXPECT_QUOTE = "JSON->URL: quoted string still open"; | ||
@@ -332,3 +336,3 @@ function parseDigitsLength(text, i, len) { | ||
if (typeof p.emptyValue === "function") { | ||
return new p.emptyValue(); | ||
return p.emptyValue(); | ||
} | ||
@@ -339,2 +343,10 @@ | ||
function newNullValue(p) { | ||
if (typeof p.nullValue === "function") { | ||
return p.nullValue(); | ||
} | ||
return p.nullValue; | ||
} | ||
function errorMessage(msg, pos) { | ||
@@ -348,7 +360,7 @@ if (pos === undefined) { | ||
function parseLiteralLength(text, i, len, errmsg) { | ||
function parseLiteralLength(text, i, end, errmsg) { | ||
var isQuote = false; | ||
var start = i; | ||
if (i === len) { | ||
if (i === end) { | ||
throw new SyntaxError(errorMessage(errmsg, i)); | ||
@@ -362,3 +374,3 @@ } | ||
for (; i < len; i++) { | ||
for (; i < end; i++) { | ||
var c = text.charCodeAt(i); | ||
@@ -418,2 +430,13 @@ | ||
case CHAR_AMP: | ||
case CHAR_EQUALS: | ||
// | ||
// these are forbidden, quoted or otherwise. | ||
// | ||
if (i === start) { | ||
throw new SyntaxError(errorMessage(errmsg, start)); | ||
} | ||
return i; | ||
default: | ||
@@ -424,3 +447,7 @@ throw new SyntaxError(errorMessage(ERR_MSG_BADCHAR, i)); | ||
return len; | ||
if (isQuote) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXPECT_QUOTE, i)); | ||
} | ||
return end; | ||
} | ||
@@ -436,3 +463,3 @@ | ||
function toJsonURLText_String(isKey) { | ||
function toJsonURLText_String(options, depth, isKey) { | ||
if (this.length === 0) { | ||
@@ -498,28 +525,51 @@ return "''"; | ||
function toJsonURLText_Array() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var ret = undefined; | ||
this.forEach(function (e) { | ||
while (typeof e === "function") { | ||
e = e(); | ||
if (typeof e === "function") { | ||
if (!options.callFunctions) { | ||
return; | ||
} | ||
while (typeof e === "function") { | ||
e = e(); | ||
} | ||
} | ||
if (e === undefined || e === null) { | ||
if (ret === undefined) { | ||
ret = "null"; | ||
} else { | ||
ret += ",null"; | ||
if (e === undefined) { | ||
if (options.ignoreUndefinedArrayMembers) { | ||
return; | ||
} | ||
return; | ||
e = "null"; | ||
} else if (e === null) { | ||
if (options.ignoreNullArrayMembers) { | ||
return; | ||
} | ||
e = "null"; | ||
} else { | ||
e = e.toJsonURLText(options, depth + 1); | ||
} | ||
if (ret === undefined) { | ||
ret = e.toJsonURLText(); | ||
ret = e; | ||
} else if (!options.wwwFormUrlEncoded || depth > 0) { | ||
ret += "," + e; | ||
} else { | ||
ret += "," + e.toJsonURLText(); | ||
ret += "&" + e; | ||
} | ||
}); | ||
return ret === undefined ? "()" : "(" + ret + ")"; | ||
if (!options.isImplied || depth > 0) { | ||
return ret === undefined ? "()" : "(" + ret + ")"; | ||
} | ||
return ret === undefined ? "" : ret; | ||
} | ||
function toJsonURLText_Object() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var ret = undefined; | ||
@@ -530,2 +580,5 @@ var keys = Object.keys(this); | ||
if (k === undefined || k === null) { | ||
// | ||
// I'm not sure this can actually happen. But, handling just in case. | ||
// | ||
return; | ||
@@ -536,16 +589,50 @@ } | ||
while (typeof v === "function") { | ||
v = v(); | ||
if (typeof v === "function") { | ||
if (!options.callFunctions) { | ||
return; | ||
} | ||
while (typeof v === "function") { | ||
v = v(); | ||
} | ||
} | ||
var jk = k.toJsonURLText(true); | ||
var jv = v === undefined || v === null ? "null" : v.toJsonURLText(); | ||
if (v === undefined) { | ||
if (options.ignoreUndefinedObjectMembers) { | ||
return; | ||
} | ||
v = "null"; | ||
} else if (v === null) { | ||
if (options.ignoreNullObjectMembers) { | ||
return; | ||
} | ||
v = "null"; | ||
} else { | ||
v = v.toJsonURLText(options, depth + 1); | ||
} | ||
var jk = k.toJsonURLText(options, depth, true); | ||
if (ret === undefined) { | ||
ret = jk + ":" + jv; | ||
if (!options.wwwFormUrlEncoded || depth > 0) { | ||
ret = jk + ":" + v; | ||
} else { | ||
ret = jk + "=" + v; | ||
} | ||
} else { | ||
ret += "," + jk + ":" + jv; | ||
if (!options.wwwFormUrlEncoded || depth > 0) { | ||
ret += "," + jk + ":" + v; | ||
} else { | ||
ret += "&" + jk + "=" + v; | ||
} | ||
} | ||
}); | ||
return ret === undefined ? "()" : "(" + ret + ")"; | ||
if (!options.isImplied || depth > 0) { | ||
return ret === undefined ? "()" : "(" + ret + ")"; | ||
} | ||
return ret === undefined ? "" : ret; | ||
} | ||
@@ -570,2 +657,3 @@ | ||
* A class for managing values during parse | ||
* @private | ||
*/ | ||
@@ -638,2 +726,3 @@ | ||
* A class for managing values during parse | ||
* @private | ||
*/ | ||
@@ -721,2 +810,3 @@ | ||
* A class for parsing JSON->URL text. | ||
* @public | ||
*/ | ||
@@ -728,2 +818,9 @@ | ||
* Construct a new JsonURL class. | ||
* | ||
* Each instance of this class contains a number of properties that manage | ||
* the behavior of the parser and the values it returns; these are documented | ||
* below. The class instance does not manage parse state -- that is local to | ||
* the parse() function itself. As long as you don't need different | ||
* properties (e.g. limits, null value, etc) you may re-use the same Parser | ||
* instance, even by multiple Workers. | ||
* @param {Object} prop Initialization properties. | ||
@@ -792,3 +889,3 @@ * You may provide zero more more of the following. Reasonable defaults | ||
if (c1 === CHAR_t && c2 === CHAR_r && c3 === CHAR_u && c4 === CHAR_e) return forceString ? "true" : true; | ||
if (c1 === CHAR_n && c2 === CHAR_u && c3 === CHAR_l && c4 === CHAR_l) return forceString ? "null" : this.nullValue; | ||
if (c1 === CHAR_n && c2 === CHAR_u && c3 === CHAR_l && c4 === CHAR_l) return forceString ? "null" : newNullValue(this); | ||
break; | ||
@@ -856,2 +953,23 @@ | ||
* @param {string} text The text to parse. | ||
* @param {Object} options parse options. | ||
* You may provide zero more more of the following. | ||
* @param {array} options.impliedArray An implied array. | ||
* The parse() method implements a parser for the grammar oulined in | ||
* section 2.7 of the JSON->URL specification. The given parse text | ||
* is assumed to be an array, and the leading and trailing parens must | ||
* not be present. The given prop.impliedArray value will be populated | ||
* and returned. | ||
* @param {object} options.impliedObject An implied object. | ||
* The parse() method implements a parser for the grammar oulined in | ||
* section 2.8 of the JSON->URL specification. The given parse text | ||
* is assumed to be an object, and the leading and trailing parens must | ||
* not be present. The given prop.impliedObject value will be populated | ||
* and returned. | ||
* @param {boolean} options.wwwFormUrlEncoded Enable support for | ||
* x-www-form-urlencoded content. | ||
* The parse() method implements a parser for the grammar oulined in | ||
* section 2.9 of the JSON->URL specification. The given parse text | ||
* is may use ampersand and equal characters as the value and member | ||
* separator characters, respetively, at the top-level. This may be | ||
* combined with prop.impliedArray or prop.impliedObject. | ||
* @throws SyntaxError if there is a syntax error in the given text | ||
@@ -866,2 +984,7 @@ * @throws Error if a limit given in the constructor (or its default) | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (text === undefined) { | ||
return undefined; | ||
} | ||
text = String(text); | ||
@@ -871,3 +994,11 @@ var end = text.length; | ||
if (end === 0) { | ||
return undefined; | ||
if (options.impliedArray !== undefined) { | ||
return options.impliedArray; | ||
} | ||
if (options.impliedObject !== undefined) { | ||
return options.impliedObject; | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXPECT_VALUE, 0)); | ||
} | ||
@@ -883,6 +1014,6 @@ | ||
if (options.impliedObject) { | ||
if (options.impliedObject !== undefined) { | ||
valueStack.push(options.impliedObject); | ||
stateStack.push(STATE_IN_OBJECT); | ||
} else if (options.impliedArray) { | ||
} else if (options.impliedArray !== undefined) { | ||
valueStack.push(options.impliedArray); | ||
@@ -940,16 +1071,26 @@ stateStack.push(STATE_IN_ARRAY); | ||
case CHAR_PAREN_CLOSE: | ||
pos++; | ||
if (stateStack.depth(true) === -1) { | ||
if (pos + 1 != end) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXTRACHARS, pos)); | ||
if (pos === end) { | ||
return newEmptyValue(this); | ||
} | ||
if (valueStack.length === 0) { | ||
return newEmptyValue(this); | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXTRACHARS, pos)); | ||
} | ||
valueStack.appendArrayValue(pos, newEmptyValue(this)); | ||
if (pos === end && stateStack.depth() === 0) { | ||
if (options.impliedArray) { | ||
return valueStack.popArrayValue(); | ||
} | ||
return valueStack[0]; | ||
if (options.impliedObject) { | ||
return valueStack.popObjectValue(); | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_STILLOPEN, pos)); | ||
} | ||
valueStack.appendArrayValue(pos, newEmptyValue(this)); | ||
pos++; | ||
continue; | ||
@@ -977,2 +1118,9 @@ } // | ||
switch (c) { | ||
case CHAR_AMP: | ||
if (!options.wwwFormUrlEncoded || stateStack.depth() > 0) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_BADCHAR, pos)); | ||
} | ||
// fall through | ||
case CHAR_COMMA: | ||
@@ -988,18 +1136,41 @@ // | ||
case CHAR_PAREN_CLOSE: | ||
// | ||
pos++; // | ||
// single element array | ||
// | ||
valueStack.appendArrayValue(pos, [lv]); | ||
if (stateStack.depth(true) === -1) { | ||
if (pos + 1 === end) { | ||
return valueStack[0]; | ||
} | ||
switch (stateStack.depth(true)) { | ||
case -1: | ||
if (pos === end) { | ||
return valueStack[0]; | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXTRACHARS, pos)); | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXTRACHARS, pos)); | ||
case 0: | ||
if (pos === end) { | ||
if (options.impliedArray) { | ||
return valueStack.popArrayValue(); | ||
} | ||
if (options.impliedObject) { | ||
return valueStack.popObjectValue(); | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_STILLOPEN, pos)); | ||
} | ||
break; | ||
} | ||
pos++; | ||
continue; | ||
case CHAR_EQUALS: | ||
if (!options.wwwFormUrlEncoded || stateStack.depth() > 0) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_BADCHAR, pos)); | ||
} | ||
// fall through | ||
case CHAR_COLON: | ||
@@ -1030,3 +1201,3 @@ // | ||
if (_lvpos === end) { | ||
if (pos === end) { | ||
if (stateStack.depth() === 0 && options.impliedArray) { | ||
@@ -1047,2 +1218,9 @@ return valueStack.popArrayValue(lv); | ||
switch (c) { | ||
case CHAR_AMP: | ||
if (!options.wwwFormUrlEncoded || stateStack.depth() > 0) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_BADCHAR, pos)); | ||
} | ||
// fall through | ||
case CHAR_COMMA: | ||
@@ -1054,2 +1232,4 @@ stateStack.replace(STATE_IN_ARRAY); | ||
case CHAR_PAREN_CLOSE: | ||
pos++; | ||
switch (stateStack.depth(true)) { | ||
@@ -1060,3 +1240,3 @@ case -1: | ||
// | ||
if (pos + 1 == end) { | ||
if (pos === end && !options.impliedArray) { | ||
return valueStack[0]; | ||
@@ -1071,3 +1251,3 @@ } | ||
// | ||
if (pos + 1 == end) { | ||
if (pos === end) { | ||
if (options.impliedArray) { | ||
@@ -1080,2 +1260,4 @@ return valueStack.popArrayValue(); | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_STILLOPEN, pos)); | ||
} | ||
@@ -1086,7 +1268,6 @@ | ||
pos++; | ||
continue; | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXPECT_STRUCTCHAR, pos)); | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXPECT_MOREARRAY, pos)); | ||
@@ -1121,2 +1302,9 @@ case STATE_OBJECT_HAVE_KEY: | ||
switch (c) { | ||
case CHAR_AMP: | ||
if (!options.wwwFormUrlEncoded || stateStack.depth() > 0) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_BADCHAR, pos)); | ||
} | ||
// fall through | ||
case CHAR_COMMA: | ||
@@ -1128,5 +1316,7 @@ stateStack.replace(STATE_IN_OBJECT); | ||
case CHAR_PAREN_CLOSE: | ||
pos++; | ||
switch (stateStack.depth(true)) { | ||
case -1: | ||
if (pos + 1 === end) { | ||
if (pos === end && !options.impliedObject) { | ||
// | ||
@@ -1144,3 +1334,3 @@ // end of a "real" object | ||
// | ||
if (pos + 1 == end) { | ||
if (pos === end) { | ||
if (options.impliedArray) { | ||
@@ -1153,2 +1343,4 @@ return valueStack.popArrayValue(); | ||
} | ||
throw new SyntaxError(errorMessage(ERR_MSG_EXTRACHARS, pos)); | ||
} | ||
@@ -1159,3 +1351,2 @@ | ||
pos++; | ||
continue; | ||
@@ -1170,2 +1361,6 @@ } | ||
if (_lvpos === end) { | ||
// | ||
// I don't know that this is actually possible -- I haven't | ||
// found a test case yet. But, if it is possible, it's an error. | ||
// | ||
throw new SyntaxError(errorMessage(ERR_MSG_STILLOPEN, end)); | ||
@@ -1176,4 +1371,15 @@ } | ||
if (c !== CHAR_COLON) { | ||
throw new SyntaxError((_lvpos)); | ||
switch (c) { | ||
case CHAR_EQUALS: | ||
if (!options.wwwFormUrlEncoded || stateStack.depth() > 0) { | ||
throw new SyntaxError(errorMessage(ERR_MSG_BADCHAR, pos)); | ||
} | ||
// fall through | ||
case CHAR_COLON: | ||
break; | ||
default: | ||
throw new SyntaxError((_lvpos)); | ||
} | ||
@@ -1188,2 +1394,5 @@ | ||
default: | ||
// | ||
// this shouldn't be possible, but handle it just in case | ||
// | ||
throw new SyntaxError(errorMessage(ERR_MSG_INTERNAL, pos)); | ||
@@ -1196,2 +1405,18 @@ } | ||
* @param {*} value Any value | ||
* @param {Object} options stringify options. | ||
* You may provide zero more more of the following. | ||
* @param {boolean} options.ignoreNullArrayMembers Ignore null array members. | ||
* This is false by default. | ||
* @param {boolean} options.ignoreNullObjectMembers Ignore null object members. | ||
* This is false by default. | ||
* @param {boolean} options.ignoreUndefinedArrayMembers Ignore undefined array members. | ||
* This is false by default. They will be stringified as null because | ||
* undefined is not a valid JSON value. | ||
* @param {boolean} options.ignoreUndefinedObjectMembers Ignore undefined object members. | ||
* This is true by default. They will be omitted from the stringified | ||
* output. This mimics the behavior JSON.stringify(). | ||
* @param {boolean} options.wwwFormUrlEncoded Enable x-www-form-urlencoded | ||
* structural characters. | ||
* @param {boolean} options.isImplied Create JSON->URL text for an implied | ||
* array or object. | ||
* @returns {string} JSON->URL text, or undefined if the given value | ||
@@ -1204,2 +1429,6 @@ * is undefined. | ||
value: function stringify(value) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { | ||
ignoreUndefinedObjectMembers: true | ||
}; | ||
if (value === undefined) { | ||
@@ -1213,3 +1442,3 @@ return undefined; | ||
return value.toJsonURLText(); | ||
return value.toJsonURLText(options, 0); | ||
} | ||
@@ -1216,0 +1445,0 @@ }]); |
@@ -6,2 +6,2 @@ /*! | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).JsonURL=t()}(this,(function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function r(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}function n(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&o(e,t)}function a(e){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function o(e,t){return(o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function i(){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,t,r){return(u=i()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var a=new(Function.bind.apply(e,n));return r&&o(a,r.prototype),a}).apply(null,arguments)}function c(e){var t="function"==typeof Map?new Map:void 0;return(c=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return u(e,arguments,a(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,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function p(e){var t=i();return function(){var r,n=a(e);if(t){var o=a(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return s(this,r)}}var h=/\+/g,l=/%20/g,f=/ /g,d=/^[-A-Za-z0-9._~!$*;=@?/ ][-A-Za-z0-9._~!$*;=@?/' ]*$/,y=/^[-A-Za-z0-9._~!$*,;=@?/(),: ]+$/,v=/^(?:true|false|null|(?:[-]?[0-9]+(?:[.][0-9]+)?(?:[eE][-+]?[0-9]+)?))$/,w="JSON->URL: expected comma, open paren, or close paren",x="JSON->URL: expected literal value",m="JSON->URL: unexpected end of text inside composite",b="JSON->URL: unexpected text after composite";function A(e,t,r){for(var n=0;t<r;t++)switch(e.charCodeAt(t)){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 O(e,t,r){var n=0;switch(e.charCodeAt(t)){case 69:case 101:t++,n++;break;default:return 0}switch(e.charCodeAt(t)){case 43:case 45:t++,n++}var a=A(e,t,r);return 0===a?0:n+a}function V(e,t,r){if(46!==e.charCodeAt(t))return 0;var n=A(e,t+1,r);return 0===n?0:1+n}function S(e,t,r){return 48===e.charCodeAt(t)?1:A(e,t,r)}function L(e){return"function"==typeof e.emptyValue?new e.emptyValue:e.emptyValue}function g(e,t){return void 0===t?e:e+" at position "+t}function R(e,t,r,n){var a=!1,o=t;if(t===r)throw new SyntaxError(g(n,t));for(39===e.charCodeAt(t)&&(a=!0,t++);t<r;t++){var i=e.charCodeAt(t);if(!(i>=65&&i<=90)&&!(i>=97&&i<=122||i>=48&&i<=57))switch(i){case 39:if(a)return t+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 44:case 58:case 40:case 41:if(!a){if(t===o)throw new SyntaxError(g(n,o));return t}continue;default:throw new SyntaxError(g("JSON->URL: unexpected character",t))}}return r}Object.defineProperty(Array.prototype,"toJsonURLText",{value:function(){var e=void 0;return this.forEach((function(t){for(;"function"==typeof t;)t=t();null!=t?void 0===e?e=t.toJsonURLText():e+=","+t.toJsonURLText():void 0===e?e="null":e+=",null"})),void 0===e?"()":"("+e+")"}}),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=void 0,t=Object.keys(this),r=this;return t.forEach((function(t){if(null!=t){for(var n=r[t];"function"==typeof n;)n=n();var a=t.toJsonURLText(!0),o=null==n?"null":n.toJsonURLText();void 0===e?e=a+":"+o:e+=","+a+":"+o}})),void 0===e?"()":"("+e+")"}}),Object.defineProperty(String.prototype,"toJsonURLText",{value:function(e){if(0===this.length)return"''";if(v.test(this))return!0===e?this:-1==this.indexOf("+")?"'"+this+"'":encodeURIComponent(this);if(d.test(this))return-1==this.indexOf(" ")?this:this.replace(f,"+");if(y.test(this))return-1==this.indexOf(" ")?"'"+this+"'":"'"+this.replace(f,"+")+"'";var t=encodeURIComponent(this);return 39==(t=t.replace(l,"+")).charCodeAt(0)?"%27"+t.substring(1):t}});var C=function(t){n(o,t);var a=p(o);function o(t){var r;return e(this,o),(r=a.call(this)).parser=t,r._depth=0,r}return r(o,[{key:"replaceAndPush",value:function(e,t,r){if(this[this._depth]=t,++this._depth>=this.parser.maxParseDepth)throw new Error(g("JSON->URL: MaxParseDepth exceeded",e));this.push(r)}},{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)),P=function(t){n(o,t);var a=p(o);function o(t){var r;return e(this,o),(r=a.call(this)).parser=t,r.numValues=0,r}return r(o,[{key:"popObjectValue",value:function(e){e=e||this.pop();var t=this.pop(),r=this[this.length-1];return r[t]=e,r}},{key:"popArrayValue",value:function(e){e=e||this.pop();var t=this[this.length-1];return t.push(e),t}},{key:"checkValueLimit",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(this.numValues+=t,this.numValues>this.parser.maxParseValues+1)throw new Error(g("JSON->URL: MaxParseValues exceeded",e))}},{key:"appendArrayValue",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;this.checkValueLimit(e,r),this.push(t)}}]),o}(c(Array));return function(){function t(r){for(e(this,t);"function"==typeof r;)r=r();void 0===r&&(r={}),this.maxParseDepth="number"==typeof r.maxParseDepth?parseInt(r.maxParseDepth):32,this.maxParseValues="number"==typeof r.maxParseValues?parseInt(r.maxParseValues):4096,this.maxParseChars="number"==typeof r.maxParseChars?parseInt(r.maxParseChars):32768,this.emptyValue=void 0===r.emptyValue?{}:r.emptyValue,this.nullValue=void 0===r.nullValue?null:r.nullValue}return r(t,[{key:"parseLiteral",value:function(e){var t,r,n,a,o,i=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-i){case 4:if(t=e.charCodeAt(i),r=e.charCodeAt(i+1),n=e.charCodeAt(i+2),a=e.charCodeAt(i+3),116===t&&114===r&&117===n&&101===a)return!c||"true";if(110===t&&117===r&&108===n&&108===a)return c?"null":this.nullValue;break;case 5:if(t=e.charCodeAt(i),r=e.charCodeAt(i+1),n=e.charCodeAt(i+2),a=e.charCodeAt(i+3),o=e.charCodeAt(i+4),102===t&&97===r&&108===n&&115===a&&101===o)return!!c&&"false"}var s,p=!1,l=i,f=e.charCodeAt(i);switch(f){case 45:l++;break;case 39:p=!0}if(!p){var d=S(e,l,u);if(d>0&&(l+=d,l+=V(e,l,u),(l+=O(e,l,u))===u)){var y=e.substring(i,u);return c?y:Number(y)}}return s=(s=p?e.substring(i+1,u-1):e.substring(i,u)).replace(h," "),s=decodeURIComponent(s)}},{key:"parse",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=(e=String(e)).length;if(0!==r){if(r>this.maxParseChars)throw new Error("JSON->URL: MaxParseChars exceeded");var n=new P(this),a=new C(this),o=0;if(t.impliedObject)n.push(t.impliedObject),a.push(6);else if(t.impliedArray)n.push(t.impliedArray),a.push(2);else{if(40!==e.charCodeAt(0)){var i=R(e,0,r,x);if(i!==r)throw new SyntaxError(g(x,0));return this.parseLiteral(e,0,r,!1)}a.push(1),o=1}for(;;){if(o===r)throw new SyntaxError(g(m,o));var u=e.charCodeAt(o),c=void 0,s=void 0;switch(a[a.depth()]){case 1:switch(u){case 40:n.appendArrayValue(o,[]),a.replaceAndPush(o,3,1),o++;continue;case 41:if(-1===a.depth(!0)){if(o+1!=r)throw new SyntaxError(g(b,o));return 0===n.length?L(this):n[0]}n.appendArrayValue(o,L(this)),o++;continue}if((s=R(e,o,r,"JSON->URL: expected value"))===r)throw new SyntaxError(g(m,r));switch(n.checkValueLimit(o),u=e.charCodeAt(s),c=this.parseLiteral(e,o,s,58===u),o=s,u){case 44:a.replace(3),n.appendArrayValue(o,[]),n.push(c);continue;case 41:if(n.appendArrayValue(o,[c]),-1===a.depth(!0)){if(o+1===r)return n[0];throw new SyntaxError(g(b,o))}o++;continue;case 58:a.replace(4),n.push({},c),o++;continue;default:throw new SyntaxError(g(x,o))}case 2:if(40===u){a.replaceAndPush(o,3,1),o++;continue}if(s=R(e,o,r,"JSON->URL: expected value"),n.checkValueLimit(o),c=this.parseLiteral(e,o,s,!1),o=s,s===r){if(0===a.depth()&&t.impliedArray)return n.popArrayValue(c);throw new SyntaxError(g(m,r))}a.replace(3),n.push(c);continue;case 3:switch(n.popArrayValue(),u){case 44:a.replace(2),o++;continue;case 41:switch(a.depth(!0)){case-1:if(o+1==r)return n[0];throw new SyntaxError(g(b,o));case 0:if(o+1==r){if(t.impliedArray)return n.popArrayValue();if(t.impliedObject)return n.popObjectValue()}}o++;continue}throw new SyntaxError(g(w,o));case 4:if(40===u){a.replaceAndPush(o,5,1),o++;continue}if(s=R(e,o,r,"JSON->URL: expected value"),n.checkValueLimit(o),c=this.parseLiteral(e,o,s,!1),o=s,s===r){if(0===a.depth()&&t.impliedObject)return n.popObjectValue(c);throw new SyntaxError(g(m,r))}a.replace(5),n.push(c);continue;case 5:switch(n.popObjectValue(),u){case 44:a.replace(6),o++;continue;case 41:switch(a.depth(!0)){case-1:if(o+1===r)return n[0];throw new SyntaxError(g(b,o));case 0:if(o+1==r){if(t.impliedArray)return n.popArrayValue();if(t.impliedObject)return n.popObjectValue()}}o++;continue}throw new SyntaxError(g(w,o));case 6:if((s=R(e,o,r,x))===r)throw new SyntaxError(g(m,r));if(58!==(u=e.charCodeAt(s)))throw new SyntaxError(s);c=this.parseLiteral(e,o,s,!0),o=s+1,a.replace(4),n.push(c);continue;default:throw new SyntaxError(g("JSON->URL: internal error",o))}}}}}],[{key:"stringify",value:function(e){if(void 0!==e)return null===e?"null":e.toJsonURLText()}}]),t}()})); | ||
!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}()})); |
{ | ||
"name": "@jsonurl/jsonurl", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"description": "JSON->URL defines a text format for the JSON data model suitable for use within a URL/URI (as described by RFC3986).", | ||
@@ -31,25 +34,33 @@ "main": "dist/jsonurl.common.js", | ||
"homepage": "https://www.jsonurl.org/", | ||
"dependencies": { | ||
"@babel/runtime": "^7.11.2" | ||
}, | ||
"devDependencies": { | ||
"@babel/preset-env": "^7.10.4", | ||
"@rollup/plugin-commonjs": "^11.1.0", | ||
"@rollup/plugin-node-resolve": "^7.1.3", | ||
"babel-cli": "^6.26.0", | ||
"babel-jest": "^26.1.0", | ||
"@babel/cli": "^7.11.6", | ||
"@babel/plugin-transform-runtime": "^7.11.5", | ||
"@babel/preset-env": "^7.11.5", | ||
"@rollup/plugin-babel": "^5.2.1", | ||
"@rollup/plugin-commonjs": "^15.1.0", | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
"babel-jest": "^26.5.2", | ||
"editorconfig": "^0.15.3", | ||
"eslint": "^7.3.1", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-plugin-jest": "^23.17.1", | ||
"eslint": "^7.9.0", | ||
"eslint-config-prettier": "^6.12.0", | ||
"eslint-plugin-jest": "^23.20.0", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"jest": "^26.1.0", | ||
"jsdoc": "^3.6.4", | ||
"prettier": "^2.0.5", | ||
"rollup": "^2.18.2", | ||
"rollup-plugin-babel": "^4.4.0", | ||
"rollup-plugin-eslint": "^7", | ||
"rollup-plugin-terser": "^6.1.0" | ||
"jest": "^26.4.2", | ||
"jsdoc": "^3.6.6", | ||
"prettier": "^2.1.2", | ||
"rollup": "^2.28.1", | ||
"rollup-plugin-eslint": "^7.0.0", | ||
"rollup-plugin-terser": "^7.0.2" | ||
}, | ||
"browserslist": "defaults", | ||
"files": [ | ||
"dist" | ||
"CODE_OF_CONDUCT.md", | ||
"CONTRIBUTING.md", | ||
"dist", | ||
"NEWS.md", | ||
"SECURITY.md" | ||
] | ||
} |
@@ -5,2 +5,8 @@ # JSON→URL | ||
 | ||
[](https://sonarcloud.io/dashboard?id=jsonurl-js) | ||
[](https://sonarcloud.io/dashboard?id=jsonurl-js) | ||
[](https://sonarcloud.io/dashboard?id=jsonurl-js) | ||
[](https://sonarcloud.io/dashboard?id=jsonurl-js) | ||
[](https://sonarcloud.io/dashboard?id=jsonurl-js) | ||
[](https://sonarcloud.io/dashboard?id=jsonurl-js) | ||
[](https://snyk.io/test/github/jsonurl/jsonurl-js?targetFile=package.json) | ||
@@ -39,4 +45,4 @@ [](https://app.fossa.com/projects/git%2Bgithub.com%2Fjsonurl%2Fjsonurl-js?ref=badge_shield) | ||
<script | ||
src="https://cdn.jsdelivr.net/npm/@jsonurl/jsonurl@1.0.0" | ||
integrity="sha384-8tLcpqfENLTqlnqIfsn3sokUQIe6vEu3kx2Sw1D+VKKCwnzPy2C2n837+blkJG8F" | ||
src="https://cdn.jsdelivr.net/npm/@jsonurl/jsonurl@1.0.1" | ||
integrity="sha384-X9eggnze0lccwuooEyVZu+LN9+HDcchxa9L9K1NObZelfMNcGSzT822Ikr2eZ3WD" | ||
crossorigin="anonymous"></script> | ||
@@ -43,0 +49,0 @@ ``` |
145181
26.79%11
37.5%3285
11.47%73
8.96%1
Infinity%18
5.88%+ Added
+ Added