diff --git a/dist/index-es.js b/dist/index-es.js index 076914f..3b11fdf 100644 --- a/dist/index-es.js +++ b/dist/index-es.js @@ -480,7 +480,7 @@ JSONPath.prototype.evaluate = function (expr, json, callback, otherTypeCallback) return wrap ? [] : undefined; } - if (result.length === 1 && !wrap && !Array.isArray(result[0].value)) { + if (!wrap && result.length === 1 && !result[0].hasArrExpr) { return this._getPreferredOutput(result[0]); } @@ -541,11 +541,12 @@ JSONPath.prototype._handleCallback = function (fullRetObj, callback, type) { * @param {string} parentPropName * @param {JSONPathCallback} callback * @param {boolean} literalPriority + * @param {boolean} hasArrExpr * @returns {ReturnObject|ReturnObject[]} */ -JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, callback, literalPriority) { +JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, callback, hasArrExpr, literalPriority) { // No expr to follow? return path and value as the result of // this trace branch var retObj; @@ -556,7 +557,8 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c path: path, value: val, parent: parent, - parentProperty: parentPropName + parentProperty: parentPropName, + hasArrExpr: hasArrExpr }; this._handleCallback(retObj, callback, 'value'); @@ -590,16 +592,16 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c if ((typeof loc !== 'string' || literalPriority) && val && hasOwnProp.call(val, loc)) { // simple case--directly follow property - addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback)); + addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr)); } else if (loc === '*') { // all child properties this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) { - addRet(that._trace(unshift(m, _x), v, p, par, pr, cb, true)); + addRet(that._trace(unshift(m, _x), v, p, par, pr, cb, true, true)); }); } else if (loc === '..') { // all descendent parent properties // Check remaining expression with val's immediate children - addRet(this._trace(x, val, path, parent, parentPropName, callback)); + addRet(this._trace(x, val, path, parent, parentPropName, callback, hasArrExpr)); this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) { // We don't join m and x here because we only want parents, @@ -607,7 +609,7 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c if (_typeof(v[m]) === 'object') { // Keep going with recursive descent on val's // object children - addRet(that._trace(unshift(l, _x), v[m], push(p, m), v, m, cb)); + addRet(that._trace(unshift(l, _x), v[m], push(p, m), v, m, cb, true)); } }); // The parent sel computation is handled in the frame above using the // ancestor object of val @@ -634,7 +636,7 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c return retObj; } else if (loc === '$') { // root only - addRet(this._trace(x, val, path, null, null, callback)); + addRet(this._trace(x, val, path, null, null, callback, hasArrExpr)); } else if (/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(loc)) { // [start:end:step] Python slice syntax addRet(this._slice(loc, x, val, path, parent, parentPropName, callback)); @@ -646,7 +648,7 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) { if (that._eval(l.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/, '$1'), v[m], m, p, par, pr)) { - addRet(that._trace(unshift(m, _x), v, p, par, pr, cb)); + addRet(that._trace(unshift(m, _x), v, p, par, pr, cb, true)); } }); } else if (loc[0] === '(') { @@ -658,7 +660,7 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c // parent of the property to which this expression will resolve - addRet(this._trace(unshift(this._eval(loc, val, path[path.length - 1], path.slice(0, -1), parent, parentPropName), x), val, path, parent, parentPropName, callback)); + addRet(this._trace(unshift(this._eval(loc, val, path[path.length - 1], path.slice(0, -1), parent, parentPropName), x), val, path, parent, parentPropName, callback, hasArrExpr)); } else if (loc[0] === '@') { // value type: @boolean(), etc. var addType = false; @@ -750,7 +752,7 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c } else if (loc[0] === '`' && val && hasOwnProp.call(val, loc.slice(1))) { var locProp = loc.slice(1); - addRet(this._trace(x, val[locProp], push(path, locProp), val, locProp, callback, true)); + addRet(this._trace(x, val[locProp], push(path, locProp), val, locProp, callback, hasArrExpr, true)); } else if (loc.includes(',')) { // [name1,name2,...] var parts = loc.split(','); @@ -761,7 +763,7 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c try { for (var _iterator = parts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var part = _step.value; - addRet(this._trace(unshift(part, x), val, path, parent, parentPropName, callback)); + addRet(this._trace(unshift(part, x), val, path, parent, parentPropName, callback, true)); } // simple case--directly follow property } catch (err) { @@ -779,7 +781,7 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c } } } else if (!literalPriority && val && hasOwnProp.call(val, loc)) { - addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, true)); + addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr, true)); } // We check the resulting values for parent selections. For parent // selections we discard the value object and continue the trace with the // current val object @@ -790,7 +792,7 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c var rett = ret[t]; if (rett.isParentSelector) { - var tmp = that._trace(rett.expr, val, rett.path, parent, parentPropName, callback); + var tmp = that._trace(rett.expr, val, rett.path, parent, parentPropName, callback, hasArrExpr); if (Array.isArray(tmp)) { ret[t] = tmp[0]; @@ -841,7 +843,7 @@ JSONPath.prototype._slice = function (loc, expr, val, path, parent, parentPropNa var ret = []; for (var i = start; i < end; i += step) { - var tmp = this._trace(unshift(i, expr), val, path, parent, parentPropName, callback); + var tmp = this._trace(unshift(i, expr), val, path, parent, parentPropName, callback, true); if (Array.isArray(tmp)) { // This was causing excessive stack size in Node (with or diff --git a/dist/index-es.min.js b/dist/index-es.min.js index b40ef82..2aa9305 100644 --- a/dist/index-es.min.js +++ b/dist/index-es.min.js @@ -1,2 +1,2 @@ -function t(r){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(r)}function r(t){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function e(t,r){return(e=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t})(t,r)}function n(t,r,a){return(n=function(){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(t){return!1}}()?Reflect.construct:function(t,r,n){var a=[null];a.push.apply(a,r);var u=new(Function.bind.apply(t,a));return n&&e(u,n.prototype),u}).apply(null,arguments)}function a(t){var u="function"==typeof Map?new Map:void 0;return(a=function(t){if(null===t||(a=t,-1===Function.toString.call(a).indexOf("[native code]")))return t;var a;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==u){if(u.has(t))return u.get(t);u.set(t,o)}function o(){return n(t,arguments,r(this).constructor)}return o.prototype=Object.create(t.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),e(o,t)})(t)}function u(t,r){return!r||"object"!=typeof r&&"function"!=typeof r?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):r}function o(t){return function(t){if(Array.isArray(t)){for(var r=0,e=new Array(t.length);r-1?t.slice(0,i+1)+" return "+t.slice(i+1):" return "+t;return n(Function,o(e).concat([c])).apply(void 0,o(u))}};function p(t,r){return(t=t.slice()).push(r),t}function s(t,r){return(r=r.slice()).unshift(t),r}var h=function(t){function n(t){var e;return function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,n),(e=u(this,r(n).call(this,'JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)'))).avoidNew=!0,e.value=t,e.name="NewError",e}return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),r&&e(t,r)}(n,a(Error)),n}();function f(r,e,n,a,u){if(!(this instanceof f))try{return new f(r,e,n,a,u)}catch(t){if(!t.avoidNew)throw t;return t.value}"string"==typeof r&&(u=a,a=n,n=e,e=r,r=null);var o=r&&"object"===t(r);if(r=r||{},this.json=r.json||n,this.path=r.path||e,this.resultType=r.resultType&&r.resultType.toLowerCase()||"value",this.flatten=r.flatten||!1,this.wrap=!c.call(r,"wrap")||r.wrap,this.sandbox=r.sandbox||{},this.preventEval=r.preventEval||!1,this.parent=r.parent||null,this.parentProperty=r.parentProperty||null,this.callback=r.callback||a||null,this.otherTypeCallback=r.otherTypeCallback||u||function(){throw new TypeError("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==r.autostart){var i={path:o?r.path:e};o?"json"in r&&(i.json=r.json):i.json=n;var l=this.evaluate(i);if(!l||"object"!==t(l))throw new h(l);return l}}f.prototype.evaluate=function(r,e,n,a){var u=this,o=this.parent,l=this.parentProperty,p=this.flatten,s=this.wrap;if(this.currResultType=this.resultType,this.currPreventEval=this.preventEval,this.currSandbox=this.sandbox,n=n||this.callback,this.currOtherTypeCallback=a||this.otherTypeCallback,e=e||this.json,(r=r||this.path)&&"object"===t(r)){if(!r.path)throw new TypeError('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');if(!("json"in r))throw new TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');e=c.call(r,"json")?r.json:e,p=c.call(r,"flatten")?r.flatten:p,this.currResultType=c.call(r,"resultType")?r.resultType:this.currResultType,this.currSandbox=c.call(r,"sandbox")?r.sandbox:this.currSandbox,s=c.call(r,"wrap")?r.wrap:s,this.currPreventEval=c.call(r,"preventEval")?r.preventEval:this.currPreventEval,n=c.call(r,"callback")?r.callback:n,this.currOtherTypeCallback=c.call(r,"otherTypeCallback")?r.otherTypeCallback:this.currOtherTypeCallback,o=c.call(r,"parent")?r.parent:o,l=c.call(r,"parentProperty")?r.parentProperty:l,r=r.path}if(o=o||null,l=l||null,Array.isArray(r)&&(r=f.toPathString(r)),r&&e&&i.includes(this.currResultType)){this._obj=e;var h=f.toPathArray(r);"$"===h[0]&&h.length>1&&h.shift(),this._hasParentSelector=null;var F=this._trace(h,e,["$"],o,l,n).filter((function(t){return t&&!t.isParentSelector}));return F.length?1!==F.length||s||Array.isArray(F[0].value)?F.reduce((function(t,r){var e=u._getPreferredOutput(r);return p&&Array.isArray(e)?t=t.concat(e):t.push(e),t}),[]):this._getPreferredOutput(F[0]):s?[]:void 0}},f.prototype._getPreferredOutput=function(t){var r=this.currResultType;switch(r){default:throw new TypeError("Unknown result type");case"all":return t.pointer=f.toPointer(t.path),t.path="string"==typeof t.path?t.path:f.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[r];case"path":return f.toPathString(t[r]);case"pointer":return f.toPointer(t.path)}},f.prototype._handleCallback=function(t,r,e){if(r){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:f.toPathString(t.path),r(n,e,t)}},f.prototype._trace=function(r,e,n,a,u,o,i){var l,h=this;if(!r.length)return l={path:n,value:e,parent:a,parentProperty:u},this._handleCallback(l,o,"value"),l;var f=r[0],F=r.slice(1),y=[];function v(t){Array.isArray(t)?t.forEach((function(t){y.push(t)})):y.push(t)}if(("string"!=typeof f||i)&&e&&c.call(e,f))v(this._trace(F,e[f],p(n,f),e,f,o));else if("*"===f)this._walk(f,F,e,n,a,u,o,(function(t,r,e,n,a,u,o,i){v(h._trace(s(t,e),n,a,u,o,i,!0))}));else if(".."===f)v(this._trace(F,e,n,a,u,o)),this._walk(f,F,e,n,a,u,o,(function(r,e,n,a,u,o,i,c){"object"===t(a[r])&&v(h._trace(s(e,n),a[r],p(u,r),a,r,c))}));else{if("^"===f)return this._hasParentSelector=!0,n.length?{path:n.slice(0,-1),expr:F,isParentSelector:!0}:[];if("~"===f)return l={path:p(n,f),value:u,parent:a,parentProperty:null},this._handleCallback(l,o,"property"),l;if("$"===f)v(this._trace(F,e,n,null,null,o));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(f))v(this._slice(f,F,e,n,a,u,o));else if(0===f.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");this._walk(f,F,e,n,a,u,o,(function(t,r,e,n,a,u,o,i){h._eval(r.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/,"$1"),n[t],t,a,u,o)&&v(h._trace(s(t,e),n,a,u,o,i))}))}else if("("===f[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");v(this._trace(s(this._eval(f,e,n[n.length-1],n.slice(0,-1),a,u),F),e,n,a,u,o))}else if("@"===f[0]){var b=!1,D=f.slice(1,-2);switch(D){default:throw new TypeError("Unknown value type "+D);case"scalar":e&&["object","function"].includes(t(e))||(b=!0);break;case"boolean":case"string":case"undefined":case"function":t(e)===D&&(b=!0);break;case"number":t(e)===D&&isFinite(e)&&(b=!0);break;case"nonFinite":"number"!=typeof e||isFinite(e)||(b=!0);break;case"object":e&&t(e)===D&&(b=!0);break;case"array":Array.isArray(e)&&(b=!0);break;case"other":b=this.currOtherTypeCallback(e,n,a,u);break;case"integer":e!==Number(e)||!isFinite(e)||e%1||(b=!0);break;case"null":null===e&&(b=!0)}if(b)return l={path:n,value:e,parent:a,parentProperty:u},this._handleCallback(l,o,"value"),l}else if("`"===f[0]&&e&&c.call(e,f.slice(1))){var g=f.slice(1);v(this._trace(F,e[g],p(n,g),e,g,o,!0))}else if(f.includes(",")){var d=f.split(","),_=!0,w=!1,P=void 0;try{for(var x,E=d[Symbol.iterator]();!(_=(x=E.next()).done);_=!0){var S=x.value;v(this._trace(s(S,F),e,n,a,u,o))}}catch(t){w=!0,P=t}finally{try{_||null==E.return||E.return()}finally{if(w)throw P}}}else!i&&e&&c.call(e,f)&&v(this._trace(F,e[f],p(n,f),e,f,o,!0))}if(this._hasParentSelector)for(var j=0;j-1?t.slice(0,i+1)+" return "+t.slice(i+1):" return "+t;return n(Function,o(e).concat([c])).apply(void 0,o(u))}};function p(t,r){return(t=t.slice()).push(r),t}function s(t,r){return(r=r.slice()).unshift(t),r}var h=function(t){function n(t){var e;return function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,n),(e=u(this,r(n).call(this,'JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)'))).avoidNew=!0,e.value=t,e.name="NewError",e}return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),r&&e(t,r)}(n,a(Error)),n}();function f(r,e,n,a,u){if(!(this instanceof f))try{return new f(r,e,n,a,u)}catch(t){if(!t.avoidNew)throw t;return t.value}"string"==typeof r&&(u=a,a=n,n=e,e=r,r=null);var o=r&&"object"===t(r);if(r=r||{},this.json=r.json||n,this.path=r.path||e,this.resultType=r.resultType&&r.resultType.toLowerCase()||"value",this.flatten=r.flatten||!1,this.wrap=!c.call(r,"wrap")||r.wrap,this.sandbox=r.sandbox||{},this.preventEval=r.preventEval||!1,this.parent=r.parent||null,this.parentProperty=r.parentProperty||null,this.callback=r.callback||a||null,this.otherTypeCallback=r.otherTypeCallback||u||function(){throw new TypeError("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==r.autostart){var i={path:o?r.path:e};o?"json"in r&&(i.json=r.json):i.json=n;var l=this.evaluate(i);if(!l||"object"!==t(l))throw new h(l);return l}}f.prototype.evaluate=function(r,e,n,a){var u=this,o=this.parent,l=this.parentProperty,p=this.flatten,s=this.wrap;if(this.currResultType=this.resultType,this.currPreventEval=this.preventEval,this.currSandbox=this.sandbox,n=n||this.callback,this.currOtherTypeCallback=a||this.otherTypeCallback,e=e||this.json,(r=r||this.path)&&"object"===t(r)){if(!r.path)throw new TypeError('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');if(!("json"in r))throw new TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');e=c.call(r,"json")?r.json:e,p=c.call(r,"flatten")?r.flatten:p,this.currResultType=c.call(r,"resultType")?r.resultType:this.currResultType,this.currSandbox=c.call(r,"sandbox")?r.sandbox:this.currSandbox,s=c.call(r,"wrap")?r.wrap:s,this.currPreventEval=c.call(r,"preventEval")?r.preventEval:this.currPreventEval,n=c.call(r,"callback")?r.callback:n,this.currOtherTypeCallback=c.call(r,"otherTypeCallback")?r.otherTypeCallback:this.currOtherTypeCallback,o=c.call(r,"parent")?r.parent:o,l=c.call(r,"parentProperty")?r.parentProperty:l,r=r.path}if(o=o||null,l=l||null,Array.isArray(r)&&(r=f.toPathString(r)),r&&e&&i.includes(this.currResultType)){this._obj=e;var h=f.toPathArray(r);"$"===h[0]&&h.length>1&&h.shift(),this._hasParentSelector=null;var F=this._trace(h,e,["$"],o,l,n).filter((function(t){return t&&!t.isParentSelector}));return F.length?s||1!==F.length||F[0].hasArrExpr?F.reduce((function(t,r){var e=u._getPreferredOutput(r);return p&&Array.isArray(e)?t=t.concat(e):t.push(e),t}),[]):this._getPreferredOutput(F[0]):s?[]:void 0}},f.prototype._getPreferredOutput=function(t){var r=this.currResultType;switch(r){default:throw new TypeError("Unknown result type");case"all":return t.pointer=f.toPointer(t.path),t.path="string"==typeof t.path?t.path:f.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[r];case"path":return f.toPathString(t[r]);case"pointer":return f.toPointer(t.path)}},f.prototype._handleCallback=function(t,r,e){if(r){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:f.toPathString(t.path),r(n,e,t)}},f.prototype._trace=function(r,e,n,a,u,o,i,l){var h,f=this;if(!r.length)return h={path:n,value:e,parent:a,parentProperty:u,hasArrExpr:i},this._handleCallback(h,o,"value"),h;var F=r[0],y=r.slice(1),v=[];function b(t){Array.isArray(t)?t.forEach((function(t){v.push(t)})):v.push(t)}if(("string"!=typeof F||l)&&e&&c.call(e,F))b(this._trace(y,e[F],p(n,F),e,F,o,i));else if("*"===F)this._walk(F,y,e,n,a,u,o,(function(t,r,e,n,a,u,o,i){b(f._trace(s(t,e),n,a,u,o,i,!0,!0))}));else if(".."===F)b(this._trace(y,e,n,a,u,o,i)),this._walk(F,y,e,n,a,u,o,(function(r,e,n,a,u,o,i,c){"object"===t(a[r])&&b(f._trace(s(e,n),a[r],p(u,r),a,r,c,!0))}));else{if("^"===F)return this._hasParentSelector=!0,n.length?{path:n.slice(0,-1),expr:y,isParentSelector:!0}:[];if("~"===F)return h={path:p(n,F),value:u,parent:a,parentProperty:null},this._handleCallback(h,o,"property"),h;if("$"===F)b(this._trace(y,e,n,null,null,o,i));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(F))b(this._slice(F,y,e,n,a,u,o));else if(0===F.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");this._walk(F,y,e,n,a,u,o,(function(t,r,e,n,a,u,o,i){f._eval(r.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/,"$1"),n[t],t,a,u,o)&&b(f._trace(s(t,e),n,a,u,o,i,!0))}))}else if("("===F[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");b(this._trace(s(this._eval(F,e,n[n.length-1],n.slice(0,-1),a,u),y),e,n,a,u,o,i))}else if("@"===F[0]){var D=!1,g=F.slice(1,-2);switch(g){default:throw new TypeError("Unknown value type "+g);case"scalar":e&&["object","function"].includes(t(e))||(D=!0);break;case"boolean":case"string":case"undefined":case"function":t(e)===g&&(D=!0);break;case"number":t(e)===g&&isFinite(e)&&(D=!0);break;case"nonFinite":"number"!=typeof e||isFinite(e)||(D=!0);break;case"object":e&&t(e)===g&&(D=!0);break;case"array":Array.isArray(e)&&(D=!0);break;case"other":D=this.currOtherTypeCallback(e,n,a,u);break;case"integer":e!==Number(e)||!isFinite(e)||e%1||(D=!0);break;case"null":null===e&&(D=!0)}if(D)return h={path:n,value:e,parent:a,parentProperty:u},this._handleCallback(h,o,"value"),h}else if("`"===F[0]&&e&&c.call(e,F.slice(1))){var d=F.slice(1);b(this._trace(y,e[d],p(n,d),e,d,o,i,!0))}else if(F.includes(",")){var _=F.split(","),w=!0,P=!1,x=void 0;try{for(var E,S=_[Symbol.iterator]();!(w=(E=S.next()).done);w=!0){var j=E.value;b(this._trace(s(j,y),e,n,a,u,o,!0))}}catch(t){P=!0,x=t}finally{try{w||null==S.return||S.return()}finally{if(P)throw x}}}else!l&&e&&c.call(e,F)&&b(this._trace(y,e[F],p(n,F),e,F,o,i,!0))}if(this._hasParentSelector)for(var m=0;m {\n return typeof context[key] === 'function';\n });\n // Todo[engine:node@>=8]: Use the next line instead of the\n // succeeding\n // const values = Object.values(context);\n const values = keys.map((vr, i) => {\n return context[vr];\n });\n const funcString = funcs.reduce((s, func) => {\n let fString = context[func].toString();\n if (!(/function/u).exec(fString)) {\n fString = 'function ' + fString;\n }\n return 'var ' + func + '=' + fString + ';' + s;\n }, '');\n\n expr = funcString + expr;\n\n // Mitigate http://perfectionkills.com/global-eval-what-are-the-options/#new_function\n if (!expr.match(/(['\"])use strict\\1/u) &&\n !keys.includes('arguments')\n ) {\n expr = 'var arguments = undefined;' + expr;\n }\n\n // Remove last semi so `return` will be inserted before\n // the previous one instead, allowing for the return\n // of a bare ending expression\n expr = expr.replace(/;\\s*$/u, '');\n\n // Insert `return`\n const lastStatementEnd = expr.lastIndexOf(';');\n const code = (lastStatementEnd > -1\n ? expr.slice(0, lastStatementEnd + 1) +\n ' return ' + expr.slice(lastStatementEnd + 1)\n : ' return ' + expr);\n\n // eslint-disable-next-line no-new-func\n return (new Function(...keys, code))(...values);\n }\n };\n\n/**\n * Copies array and then pushes item into it.\n * @param {GenericArray} arr Array to copy and into which to push\n * @param {any} item Array item to add (to end)\n * @returns {GenericArray} Copy of the original array\n */\nfunction push (arr, item) {\n arr = arr.slice();\n arr.push(item);\n return arr;\n}\n/**\n * Copies array and then unshifts item into it.\n * @param {any} item Array item to add (to beginning)\n * @param {GenericArray} arr Array to copy and into which to unshift\n * @returns {GenericArray} Copy of the original array\n */\nfunction unshift (item, arr) {\n arr = arr.slice();\n arr.unshift(item);\n return arr;\n}\n\n/**\n * Caught when JSONPath is used without `new` but rethrown if with `new`\n * @extends Error\n */\nclass NewError extends Error {\n /**\n * @param {any} value The evaluated scalar value\n */\n constructor (value) {\n super(\n 'JSONPath should not be called with \"new\" (it prevents return ' +\n 'of (unwrapped) scalar values)'\n );\n this.avoidNew = true;\n this.value = value;\n this.name = 'NewError';\n }\n}\n\n/**\n* @typedef {PlainObject} ReturnObject\n* @property {string} path\n* @property {JSONObject} value\n* @property {PlainObject|GenericArray} parent\n* @property {string} parentProperty\n*/\n\n/**\n* @callback JSONPathCallback\n* @param {string|PlainObject} preferredOutput\n* @param {\"value\"|\"property\"} type\n* @param {ReturnObject} fullRetObj\n* @returns {void}\n*/\n\n/**\n* @callback OtherTypeCallback\n* @param {JSONObject} val\n* @param {string} path\n* @param {PlainObject|GenericArray} parent\n* @param {string} parentPropName\n* @returns {boolean}\n*/\n\n/**\n * @typedef {PlainObject} JSONPathOptions\n * @property {JSON} json\n * @property {string|string[]} path\n * @property {\"value\"|\"path\"|\"pointer\"|\"parent\"|\"parentProperty\"|\"all\"}\n * [resultType=\"value\"]\n * @property {boolean} [flatten=false]\n * @property {boolean} [wrap=true]\n * @property {PlainObject} [sandbox={}]\n * @property {boolean} [preventEval=false]\n * @property {PlainObject|GenericArray|null} [parent=null]\n * @property {string|null} [parentProperty=null]\n * @property {JSONPathCallback} [callback]\n * @property {OtherTypeCallback} [otherTypeCallback] Defaults to\n * function which throws on encountering `@other`\n * @property {boolean} [autostart=true]\n */\n\n/**\n * @param {string|JSONPathOptions} opts If a string, will be treated as `expr`\n * @param {string} [expr] JSON path to evaluate\n * @param {JSON} [obj] JSON object to evaluate against\n * @param {JSONPathCallback} [callback] Passed 3 arguments: 1) desired payload\n * per `resultType`, 2) `\"value\"|\"property\"`, 3) Full returned object with\n * all payloads\n * @param {OtherTypeCallback} [otherTypeCallback] If `@other()` is at the end\n * of one's query, this will be invoked with the value of the item, its\n * path, its parent, and its parent's property name, and it should return\n * a boolean indicating whether the supplied value belongs to the \"other\"\n * type or not (or it may handle transformations and return `false`).\n * @returns {JSONPath}\n * @class\n */\nfunction JSONPath (opts, expr, obj, callback, otherTypeCallback) {\n // eslint-disable-next-line no-restricted-syntax\n if (!(this instanceof JSONPath)) {\n try {\n return new JSONPath(opts, expr, obj, callback, otherTypeCallback);\n } catch (e) {\n if (!e.avoidNew) {\n throw e;\n }\n return e.value;\n }\n }\n\n if (typeof opts === 'string') {\n otherTypeCallback = callback;\n callback = obj;\n obj = expr;\n expr = opts;\n opts = null;\n }\n const optObj = opts && typeof opts === 'object';\n opts = opts || {};\n this.json = opts.json || obj;\n this.path = opts.path || expr;\n this.resultType = (opts.resultType && opts.resultType.toLowerCase()) ||\n 'value';\n this.flatten = opts.flatten || false;\n this.wrap = hasOwnProp.call(opts, 'wrap') ? opts.wrap : true;\n this.sandbox = opts.sandbox || {};\n this.preventEval = opts.preventEval || false;\n this.parent = opts.parent || null;\n this.parentProperty = opts.parentProperty || null;\n this.callback = opts.callback || callback || null;\n this.otherTypeCallback = opts.otherTypeCallback ||\n otherTypeCallback ||\n function () {\n throw new TypeError(\n 'You must supply an otherTypeCallback callback option ' +\n 'with the @other() operator.'\n );\n };\n\n if (opts.autostart !== false) {\n const args = {\n path: (optObj ? opts.path : expr)\n };\n if (!optObj) {\n args.json = obj;\n } else if ('json' in opts) {\n args.json = opts.json;\n }\n const ret = this.evaluate(args);\n if (!ret || typeof ret !== 'object') {\n throw new NewError(ret);\n }\n return ret;\n }\n}\n\n// PUBLIC METHODS\nJSONPath.prototype.evaluate = function (\n expr, json, callback, otherTypeCallback\n) {\n const that = this;\n let currParent = this.parent,\n currParentProperty = this.parentProperty;\n let {flatten, wrap} = this;\n\n this.currResultType = this.resultType;\n this.currPreventEval = this.preventEval;\n this.currSandbox = this.sandbox;\n callback = callback || this.callback;\n this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback;\n\n json = json || this.json;\n expr = expr || this.path;\n if (expr && typeof expr === 'object') {\n if (!expr.path) {\n throw new TypeError(\n 'You must supply a \"path\" property when providing an object ' +\n 'argument to JSONPath.evaluate().'\n );\n }\n if (!('json' in expr)) {\n throw new TypeError(\n 'You must supply a \"json\" property when providing an object ' +\n 'argument to JSONPath.evaluate().'\n );\n }\n json = hasOwnProp.call(expr, 'json') ? expr.json : json;\n flatten = hasOwnProp.call(expr, 'flatten') ? expr.flatten : flatten;\n this.currResultType = hasOwnProp.call(expr, 'resultType')\n ? expr.resultType\n : this.currResultType;\n this.currSandbox = hasOwnProp.call(expr, 'sandbox')\n ? expr.sandbox\n : this.currSandbox;\n wrap = hasOwnProp.call(expr, 'wrap') ? expr.wrap : wrap;\n this.currPreventEval = hasOwnProp.call(expr, 'preventEval')\n ? expr.preventEval\n : this.currPreventEval;\n callback = hasOwnProp.call(expr, 'callback') ? expr.callback : callback;\n this.currOtherTypeCallback = hasOwnProp.call(expr, 'otherTypeCallback')\n ? expr.otherTypeCallback\n : this.currOtherTypeCallback;\n currParent = hasOwnProp.call(expr, 'parent') ? expr.parent : currParent;\n currParentProperty = hasOwnProp.call(expr, 'parentProperty')\n ? expr.parentProperty\n : currParentProperty;\n expr = expr.path;\n }\n currParent = currParent || null;\n currParentProperty = currParentProperty || null;\n\n if (Array.isArray(expr)) {\n expr = JSONPath.toPathString(expr);\n }\n if (!expr || !json || !allowedResultTypes.includes(this.currResultType)) {\n return undefined;\n }\n this._obj = json;\n\n const exprList = JSONPath.toPathArray(expr);\n if (exprList[0] === '$' && exprList.length > 1) { exprList.shift(); }\n this._hasParentSelector = null;\n const result = this\n ._trace(exprList, json, ['$'], currParent, currParentProperty, callback)\n .filter(function (ea) { return ea && !ea.isParentSelector; });\n\n if (!result.length) { return wrap ? [] : undefined; }\n if (result.length === 1 && !wrap && !Array.isArray(result[0].value)) {\n return this._getPreferredOutput(result[0]);\n }\n return result.reduce(function (rslt, ea) {\n const valOrPath = that._getPreferredOutput(ea);\n if (flatten && Array.isArray(valOrPath)) {\n rslt = rslt.concat(valOrPath);\n } else {\n rslt.push(valOrPath);\n }\n return rslt;\n }, []);\n};\n\n// PRIVATE METHODS\n\nJSONPath.prototype._getPreferredOutput = function (ea) {\n const resultType = this.currResultType;\n switch (resultType) {\n default:\n throw new TypeError('Unknown result type');\n case 'all':\n ea.pointer = JSONPath.toPointer(ea.path);\n ea.path = typeof ea.path === 'string'\n ? ea.path\n : JSONPath.toPathString(ea.path);\n return ea;\n case 'value': case 'parent': case 'parentProperty':\n return ea[resultType];\n case 'path':\n return JSONPath.toPathString(ea[resultType]);\n case 'pointer':\n return JSONPath.toPointer(ea.path);\n }\n};\n\nJSONPath.prototype._handleCallback = function (fullRetObj, callback, type) {\n if (callback) {\n const preferredOutput = this._getPreferredOutput(fullRetObj);\n fullRetObj.path = typeof fullRetObj.path === 'string'\n ? fullRetObj.path\n : JSONPath.toPathString(fullRetObj.path);\n // eslint-disable-next-line callback-return\n callback(preferredOutput, type, fullRetObj);\n }\n};\n\n/**\n *\n * @param {string} expr\n * @param {JSONObject} val\n * @param {string} path\n * @param {PlainObject|GenericArray} parent\n * @param {string} parentPropName\n * @param {JSONPathCallback} callback\n * @param {boolean} literalPriority\n * @returns {ReturnObject|ReturnObject[]}\n */\nJSONPath.prototype._trace = function (\n expr, val, path, parent, parentPropName, callback, literalPriority\n) {\n // No expr to follow? return path and value as the result of\n // this trace branch\n let retObj;\n const that = this;\n if (!expr.length) {\n retObj = {path, value: val, parent, parentProperty: parentPropName};\n this._handleCallback(retObj, callback, 'value');\n return retObj;\n }\n\n const loc = expr[0], x = expr.slice(1);\n\n // We need to gather the return value of recursive trace calls in order to\n // do the parent sel computation.\n const ret = [];\n /**\n *\n * @param {ReturnObject|ReturnObject[]} elems\n * @returns {void}\n */\n function addRet (elems) {\n if (Array.isArray(elems)) {\n // This was causing excessive stack size in Node (with or\n // without Babel) against our performance test:\n // `ret.push(...elems);`\n elems.forEach((t) => {\n ret.push(t);\n });\n } else {\n ret.push(elems);\n }\n }\n\n if ((typeof loc !== 'string' || literalPriority) && val &&\n hasOwnProp.call(val, loc)\n ) { // simple case--directly follow property\n addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback));\n } else if (loc === '*') { // all child properties\n this._walk(\n loc, x, val, path, parent, parentPropName, callback,\n function (m, l, _x, v, p, par, pr, cb) {\n addRet(that._trace(unshift(m, _x), v, p, par, pr, cb, true));\n }\n );\n } else if (loc === '..') { // all descendent parent properties\n // Check remaining expression with val's immediate children\n addRet(\n this._trace(x, val, path, parent, parentPropName, callback)\n );\n this._walk(\n loc, x, val, path, parent, parentPropName, callback,\n function (m, l, _x, v, p, par, pr, cb) {\n // We don't join m and x here because we only want parents,\n // not scalar values\n if (typeof v[m] === 'object') {\n // Keep going with recursive descent on val's\n // object children\n addRet(that._trace(\n unshift(l, _x), v[m], push(p, m), v, m, cb\n ));\n }\n }\n );\n // The parent sel computation is handled in the frame above using the\n // ancestor object of val\n } else if (loc === '^') {\n // This is not a final endpoint, so we do not invoke the callback here\n this._hasParentSelector = true;\n return path.length\n ? {\n path: path.slice(0, -1),\n expr: x,\n isParentSelector: true\n }\n : [];\n } else if (loc === '~') { // property name\n retObj = {\n path: push(path, loc),\n value: parentPropName,\n parent,\n parentProperty: null\n };\n this._handleCallback(retObj, callback, 'property');\n return retObj;\n } else if (loc === '$') { // root only\n addRet(this._trace(x, val, path, null, null, callback));\n } else if ((/^(-?\\d*):(-?\\d*):?(\\d*)$/u).test(loc)) { // [start:end:step] Python slice syntax\n addRet(\n this._slice(loc, x, val, path, parent, parentPropName, callback)\n );\n } else if (loc.indexOf('?(') === 0) { // [?(expr)] (filtering)\n if (this.currPreventEval) {\n throw new Error('Eval [?(expr)] prevented in JSONPath expression.');\n }\n this._walk(\n loc, x, val, path, parent, parentPropName, callback,\n function (m, l, _x, v, p, par, pr, cb) {\n if (that._eval(l.replace(/^\\?\\((.*?)\\)$/u, '$1'), v[m], m, p, par, pr)) {\n addRet(that._trace(unshift(m, _x), v, p, par, pr, cb));\n }\n }\n );\n } else if (loc[0] === '(') { // [(expr)] (dynamic property/index)\n if (this.currPreventEval) {\n throw new Error('Eval [(expr)] prevented in JSONPath expression.');\n }\n // As this will resolve to a property name (but we don't know it\n // yet), property and parent information is relative to the\n // parent of the property to which this expression will resolve\n addRet(this._trace(unshift(\n this._eval(\n loc, val, path[path.length - 1],\n path.slice(0, -1), parent, parentPropName\n ),\n x\n ), val, path, parent, parentPropName, callback));\n } else if (loc[0] === '@') { // value type: @boolean(), etc.\n let addType = false;\n const valueType = loc.slice(1, -2);\n switch (valueType) {\n default:\n throw new TypeError('Unknown value type ' + valueType);\n case 'scalar':\n if (!val || !(['object', 'function'].includes(typeof val))) {\n addType = true;\n }\n break;\n case 'boolean': case 'string': case 'undefined': case 'function':\n // eslint-disable-next-line valid-typeof\n if (typeof val === valueType) {\n addType = true;\n }\n break;\n case 'number':\n // eslint-disable-next-line valid-typeof\n if (typeof val === valueType && isFinite(val)) {\n addType = true;\n }\n break;\n case 'nonFinite':\n if (typeof val === 'number' && !isFinite(val)) {\n addType = true;\n }\n break;\n case 'object':\n // eslint-disable-next-line valid-typeof\n if (val && typeof val === valueType) {\n addType = true;\n }\n break;\n case 'array':\n if (Array.isArray(val)) {\n addType = true;\n }\n break;\n case 'other':\n addType = this.currOtherTypeCallback(\n val, path, parent, parentPropName\n );\n break;\n case 'integer':\n if (val === Number(val) && isFinite(val) && !(val % 1)) {\n addType = true;\n }\n break;\n case 'null':\n if (val === null) {\n addType = true;\n }\n break;\n }\n if (addType) {\n retObj = {path, value: val, parent, parentProperty: parentPropName};\n this._handleCallback(retObj, callback, 'value');\n return retObj;\n }\n // `-escaped property\n } else if (loc[0] === '`' && val && hasOwnProp.call(val, loc.slice(1))) {\n const locProp = loc.slice(1);\n addRet(this._trace(\n x, val[locProp], push(path, locProp), val, locProp, callback, true\n ));\n } else if (loc.includes(',')) { // [name1,name2,...]\n const parts = loc.split(',');\n for (const part of parts) {\n addRet(this._trace(\n unshift(part, x), val, path, parent, parentPropName, callback\n ));\n }\n // simple case--directly follow property\n } else if (!literalPriority && val && hasOwnProp.call(val, loc)) {\n addRet(\n this._trace(x, val[loc], push(path, loc), val, loc, callback, true)\n );\n }\n\n // We check the resulting values for parent selections. For parent\n // selections we discard the value object and continue the trace with the\n // current val object\n if (this._hasParentSelector) {\n for (let t = 0; t < ret.length; t++) {\n const rett = ret[t];\n if (rett.isParentSelector) {\n const tmp = that._trace(\n rett.expr, val, rett.path, parent, parentPropName, callback\n );\n if (Array.isArray(tmp)) {\n ret[t] = tmp[0];\n const tl = tmp.length;\n for (let tt = 1; tt < tl; tt++) {\n t++;\n ret.splice(t, 0, tmp[tt]);\n }\n } else {\n ret[t] = tmp;\n }\n }\n }\n }\n return ret;\n};\n\nJSONPath.prototype._walk = function (\n loc, expr, val, path, parent, parentPropName, callback, f\n) {\n if (Array.isArray(val)) {\n const n = val.length;\n for (let i = 0; i < n; i++) {\n f(i, loc, expr, val, path, parent, parentPropName, callback);\n }\n } else if (typeof val === 'object') {\n for (const m in val) {\n if (hasOwnProp.call(val, m)) {\n f(m, loc, expr, val, path, parent, parentPropName, callback);\n }\n }\n }\n};\n\nJSONPath.prototype._slice = function (\n loc, expr, val, path, parent, parentPropName, callback\n) {\n if (!Array.isArray(val)) { return undefined; }\n const len = val.length, parts = loc.split(':'),\n step = (parts[2] && parseInt(parts[2])) || 1;\n let start = (parts[0] && parseInt(parts[0])) || 0,\n end = (parts[1] && parseInt(parts[1])) || len;\n start = (start < 0) ? Math.max(0, start + len) : Math.min(len, start);\n end = (end < 0) ? Math.max(0, end + len) : Math.min(len, end);\n const ret = [];\n for (let i = start; i < end; i += step) {\n const tmp = this._trace(\n unshift(i, expr), val, path, parent, parentPropName, callback\n );\n if (Array.isArray(tmp)) {\n // This was causing excessive stack size in Node (with or\n // without Babel) against our performance test: `ret.push(...tmp);`\n tmp.forEach((t) => {\n ret.push(t);\n });\n } else {\n ret.push(tmp);\n }\n }\n return ret;\n};\n\nJSONPath.prototype._eval = function (\n code, _v, _vname, path, parent, parentPropName\n) {\n if (!this._obj || !_v) { return false; }\n if (code.includes('@parentProperty')) {\n this.currSandbox._$_parentProperty = parentPropName;\n code = code.replace(/@parentProperty/gu, '_$_parentProperty');\n }\n if (code.includes('@parent')) {\n this.currSandbox._$_parent = parent;\n code = code.replace(/@parent/gu, '_$_parent');\n }\n if (code.includes('@property')) {\n this.currSandbox._$_property = _vname;\n code = code.replace(/@property/gu, '_$_property');\n }\n if (code.includes('@path')) {\n this.currSandbox._$_path = JSONPath.toPathString(path.concat([_vname]));\n code = code.replace(/@path/gu, '_$_path');\n }\n if (code.includes('@root')) {\n this.currSandbox._$_root = this.json;\n code = code.replace(/@root/gu, '_$_root');\n }\n if (code.match(/@([.\\s)[])/u)) {\n this.currSandbox._$_v = _v;\n code = code.replace(/@([.\\s)[])/gu, '_$_v$1');\n }\n try {\n return vm.runInNewContext(code, this.currSandbox);\n } catch (e) {\n // eslint-disable-next-line no-console\n console.log(e);\n throw new Error('jsonPath: ' + e.message + ': ' + code);\n }\n};\n\n// PUBLIC CLASS PROPERTIES AND METHODS\n\n// Could store the cache object itself\nJSONPath.cache = {};\n\n/**\n * @param {string[]} pathArr Array to convert\n * @returns {string} The path string\n */\nJSONPath.toPathString = function (pathArr) {\n const x = pathArr, n = x.length;\n let p = '$';\n for (let i = 1; i < n; i++) {\n if (!(/^(~|\\^|@.*?\\(\\))$/u).test(x[i])) {\n p += (/^[0-9*]+$/u).test(x[i]) ? ('[' + x[i] + ']') : (\"['\" + x[i] + \"']\");\n }\n }\n return p;\n};\n\n/**\n * @param {string} pointer JSON Path\n * @returns {string} JSON Pointer\n */\nJSONPath.toPointer = function (pointer) {\n const x = pointer, n = x.length;\n let p = '';\n for (let i = 1; i < n; i++) {\n if (!(/^(~|\\^|@.*?\\(\\))$/u).test(x[i])) {\n p += '/' + x[i].toString()\n .replace(/~/gu, '~0')\n .replace(/\\//gu, '~1');\n }\n }\n return p;\n};\n\n/**\n * @param {string} expr Expression to convert\n * @returns {string[]}\n */\nJSONPath.toPathArray = function (expr) {\n const {cache} = JSONPath;\n if (cache[expr]) { return cache[expr].concat(); }\n const subx = [];\n const normalized = expr\n // Properties\n .replace(\n /@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\\(\\)/gu,\n ';$&;'\n )\n // Parenthetical evaluations (filtering and otherwise), directly\n // within brackets or single quotes\n .replace(/[['](\\??\\(.*?\\))[\\]']/gu, function ($0, $1) {\n return '[#' + (subx.push($1) - 1) + ']';\n })\n // Escape periods and tildes within properties\n .replace(/\\['([^'\\]]*)'\\]/gu, function ($0, prop) {\n return \"['\" + prop\n .replace(/\\./gu, '%@%')\n .replace(/~/gu, '%%@@%%') +\n \"']\";\n })\n // Properties operator\n .replace(/~/gu, ';~;')\n // Split by property boundaries\n .replace(/'?\\.'?(?![^[]*\\])|\\['?/gu, ';')\n // Reinsert periods within properties\n .replace(/%@%/gu, '.')\n // Reinsert tildes within properties\n .replace(/%%@@%%/gu, '~')\n // Parent\n .replace(/(?:;)?(\\^+)(?:;)?/gu, function ($0, ups) {\n return ';' + ups.split('').join(';') + ';';\n })\n // Descendents\n .replace(/;;;|;;/gu, ';..;')\n // Remove trailing\n .replace(/;$|'?\\]|'$/gu, '');\n\n const exprList = normalized.split(';').map(function (exp) {\n const match = exp.match(/#(\\d+)/u);\n return !match || !match[1] ? exp : subx[match[1]];\n });\n cache[expr] = exprList;\n return cache[expr];\n};\n\nexport {JSONPath};\n"],"names":["allowedResultTypes","hasOwnProp","Object","prototype","hasOwnProperty","vm","toString","call","global","process","e","supportsNodeVM","require","runInNewContext","expr","context","keys","funcs","source","target","conditionCb","il","length","i","push","splice","moveToAnotherArray","key","values","map","vr","reduce","s","func","fString","exec","match","includes","lastStatementEnd","replace","lastIndexOf","code","slice","_construct","Function","arr","item","unshift","NewError","value","avoidNew","name","Error","JSONPath","opts","obj","callback","otherTypeCallback","this","optObj","_typeof","json","path","resultType","toLowerCase","flatten","wrap","sandbox","preventEval","parent","parentProperty","TypeError","autostart","args","ret","evaluate","that","currParent","currParentProperty","currResultType","currPreventEval","currSandbox","currOtherTypeCallback","Array","isArray","toPathString","_obj","exprList","toPathArray","shift","_hasParentSelector","result","_trace","filter","ea","isParentSelector","rslt","valOrPath","_getPreferredOutput","concat","undefined","pointer","toPointer","_handleCallback","fullRetObj","type","preferredOutput","val","parentPropName","literalPriority","retObj","loc","x","addRet","elems","forEach","t","_walk","m","l","_x","v","p","par","pr","cb","test","_slice","indexOf","_eval","addType","valueType","isFinite","Number","locProp","parts","split","part","rett","tmp","tl","tt","f","n","len","step","parseInt","start","end","Math","max","min","_v","_vname","_$_parentProperty","_$_parent","_$_property","_$_path","_$_root","_$_v","console","log","message","cache","pathArr","subx","$0","$1","prop","ups","join","exp"],"mappings":"63DAGA,IASMA,EAAqB,CACvB,QAAS,OAAQ,UAAW,SAAU,iBAAkB,OAErCC,EAAcC,OAAOC,UAArCC,eA8BDC,EA1CiB,qBAIT,qBAFCH,OAAOC,UAAUG,SAASC,KAC7BC,OAAOC,SAEb,MAAOC,UACE,GAoCJC,GACLC,QAAQ,MACR,CAOEC,yBAAi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Q,wLAA2B,SAAU+H,EAAIC,SACvC,MAAQF,EAAK7I,KAAK+I,GAAM,GAAK,OAGvChI,QAAQ,2JAAqB,SAAU+H,EAAIE,SACjC,KAAOA,EACTjI,QAAQ,MAAQ,OAChBA,QAAQ,KAAO,UAChB,QAGPA,QAAQ,KAAO,OAEfA,QAAQ,8JAA4B,KAEpCA,QAAQ,OAAS,KAEjBA,QAAQ,UAAY,KAEpBA,QAAQ,sBAAuB,SAAU+H,EAAIG,SACnC,IAAMA,EAAIjC,MAAM,IAAIkC,KAAK,KAAO,OAG1CnI,QAAQ,UAAY,QAEpBA,QAAQ,cAAgB,IAEDiG,MAAM,KAAK3G,KAAI,SAAU8I,OAC3CvI,EAAQuI,EAAIvI,MAAM,oBAChBA,GAAUA,EAAM,GAAWiI,EAAKjI,EAAM,IAAjBuI,YAEjCR,EAAMrJ,GAAQyE,EACP4E,EAAMrJ"} \ No newline at end of file +{"version":3,"file":"index-es.min.js","sources":["../src/jsonpath.js"],"sourcesContent":["/* eslint-disable prefer-named-capture-group */\n// Disabled `prefer-named-capture-group` due to https://github.com/babel/babel/issues/8951#issuecomment-508045524\n// Only Node.JS has a process variable that is of [[Class]] process\nconst supportsNodeVM = function () {\n try {\n return Object.prototype.toString.call(\n global.process\n ) === '[object process]';\n } catch (e) {\n return false;\n }\n};\nconst allowedResultTypes = [\n 'value', 'path', 'pointer', 'parent', 'parentProperty', 'all'\n];\nconst {hasOwnProperty: hasOwnProp} = Object.prototype;\n\n/**\n* @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject\n*/\n\n/**\n* @callback ConditionCallback\n* @param item\n* @returns {boolean}\n*/\n\n/**\n * Copy items out of one array into another.\n * @param {GenericArray} source Array with items to copy\n * @param {GenericArray} target Array to which to copy\n * @param {ConditionCallback} conditionCb Callback passed the current item;\n * will move item if evaluates to `true`\n * @returns {undefined}\n */\nconst moveToAnotherArray = function (source, target, conditionCb) {\n const il = source.length;\n for (let i = 0; i < il; i++) {\n const item = source[i];\n if (conditionCb(item)) {\n target.push(source.splice(i--, 1)[0]);\n }\n }\n};\n\nconst vm = supportsNodeVM()\n ? require('vm')\n : {\n /**\n * @param {string} expr Expression to evaluate\n * @param {PlainObject} context Object whose items will be added\n * to evaluation\n * @returns {any} Result of evaluated code\n */\n runInNewContext (expr, context) {\n const keys = Object.keys(context);\n const funcs = [];\n moveToAnotherArray(keys, funcs, (key) => {\n return typeof context[key] === 'function';\n });\n // Todo[engine:node@>=8]: Use the next line instead of the\n // succeeding\n // const values = Object.values(context);\n const values = keys.map((vr, i) => {\n return context[vr];\n });\n const funcString = funcs.reduce((s, func) => {\n let fString = context[func].toString();\n if (!(/function/u).exec(fString)) {\n fString = 'function ' + fString;\n }\n return 'var ' + func + '=' + fString + ';' + s;\n }, '');\n\n expr = funcString + expr;\n\n // Mitigate http://perfectionkills.com/global-eval-what-are-the-options/#new_function\n if (!expr.match(/(['\"])use strict\\1/u) &&\n !keys.includes('arguments')\n ) {\n expr = 'var arguments = undefined;' + expr;\n }\n\n // Remove last semi so `return` will be inserted before\n // the previous one instead, allowing for the return\n // of a bare ending expression\n expr = expr.replace(/;\\s*$/u, '');\n\n // Insert `return`\n const lastStatementEnd = expr.lastIndexOf(';');\n const code = (lastStatementEnd > -1\n ? expr.slice(0, lastStatementEnd + 1) +\n ' return ' + expr.slice(lastStatementEnd + 1)\n : ' return ' + expr);\n\n // eslint-disable-next-line no-new-func\n return (new Function(...keys, code))(...values);\n }\n };\n\n/**\n * Copies array and then pushes item into it.\n * @param {GenericArray} arr Array to copy and into which to push\n * @param {any} item Array item to add (to end)\n * @returns {GenericArray} Copy of the original array\n */\nfunction push (arr, item) {\n arr = arr.slice();\n arr.push(item);\n return arr;\n}\n/**\n * Copies array and then unshifts item into it.\n * @param {any} item Array item to add (to beginning)\n * @param {GenericArray} arr Array to copy and into which to unshift\n * @returns {GenericArray} Copy of the original array\n */\nfunction unshift (item, arr) {\n arr = arr.slice();\n arr.unshift(item);\n return arr;\n}\n\n/**\n * Caught when JSONPath is used without `new` but rethrown if with `new`\n * @extends Error\n */\nclass NewError extends Error {\n /**\n * @param {any} value The evaluated scalar value\n */\n constructor (value) {\n super(\n 'JSONPath should not be called with \"new\" (it prevents return ' +\n 'of (unwrapped) scalar values)'\n );\n this.avoidNew = true;\n this.value = value;\n this.name = 'NewError';\n }\n}\n\n/**\n* @typedef {PlainObject} ReturnObject\n* @property {string} path\n* @property {JSONObject} value\n* @property {PlainObject|GenericArray} parent\n* @property {string} parentProperty\n*/\n\n/**\n* @callback JSONPathCallback\n* @param {string|PlainObject} preferredOutput\n* @param {\"value\"|\"property\"} type\n* @param {ReturnObject} fullRetObj\n* @returns {void}\n*/\n\n/**\n* @callback OtherTypeCallback\n* @param {JSONObject} val\n* @param {string} path\n* @param {PlainObject|GenericArray} parent\n* @param {string} parentPropName\n* @returns {boolean}\n*/\n\n/**\n * @typedef {PlainObject} JSONPathOptions\n * @property {JSON} json\n * @property {string|string[]} path\n * @property {\"value\"|\"path\"|\"pointer\"|\"parent\"|\"parentProperty\"|\"all\"}\n * [resultType=\"value\"]\n * @property {boolean} [flatten=false]\n * @property {boolean} [wrap=true]\n * @property {PlainObject} [sandbox={}]\n * @property {boolean} [preventEval=false]\n * @property {PlainObject|GenericArray|null} [parent=null]\n * @property {string|null} [parentProperty=null]\n * @property {JSONPathCallback} [callback]\n * @property {OtherTypeCallback} [otherTypeCallback] Defaults to\n * function which throws on encountering `@other`\n * @property {boolean} [autostart=true]\n */\n\n/**\n * @param {string|JSONPathOptions} opts If a string, will be treated as `expr`\n * @param {string} [expr] JSON path to evaluate\n * @param {JSON} [obj] JSON object to evaluate against\n * @param {JSONPathCallback} [callback] Passed 3 arguments: 1) desired payload\n * per `resultType`, 2) `\"value\"|\"property\"`, 3) Full returned object with\n * all payloads\n * @param {OtherTypeCallback} [otherTypeCallback] If `@other()` is at the end\n * of one's query, this will be invoked with the value of the item, its\n * path, its parent, and its parent's property name, and it should return\n * a boolean indicating whether the supplied value belongs to the \"other\"\n * type or not (or it may handle transformations and return `false`).\n * @returns {JSONPath}\n * @class\n */\nfunction JSONPath (opts, expr, obj, callback, otherTypeCallback) {\n // eslint-disable-next-line no-restricted-syntax\n if (!(this instanceof JSONPath)) {\n try {\n return new JSONPath(opts, expr, obj, callback, otherTypeCallback);\n } catch (e) {\n if (!e.avoidNew) {\n throw e;\n }\n return e.value;\n }\n }\n\n if (typeof opts === 'string') {\n otherTypeCallback = callback;\n callback = obj;\n obj = expr;\n expr = opts;\n opts = null;\n }\n const optObj = opts && typeof opts === 'object';\n opts = opts || {};\n this.json = opts.json || obj;\n this.path = opts.path || expr;\n this.resultType = (opts.resultType && opts.resultType.toLowerCase()) ||\n 'value';\n this.flatten = opts.flatten || false;\n this.wrap = hasOwnProp.call(opts, 'wrap') ? opts.wrap : true;\n this.sandbox = opts.sandbox || {};\n this.preventEval = opts.preventEval || false;\n this.parent = opts.parent || null;\n this.parentProperty = opts.parentProperty || null;\n this.callback = opts.callback || callback || null;\n this.otherTypeCallback = opts.otherTypeCallback ||\n otherTypeCallback ||\n function () {\n throw new TypeError(\n 'You must supply an otherTypeCallback callback option ' +\n 'with the @other() operator.'\n );\n };\n\n if (opts.autostart !== false) {\n const args = {\n path: (optObj ? opts.path : expr)\n };\n if (!optObj) {\n args.json = obj;\n } else if ('json' in opts) {\n args.json = opts.json;\n }\n const ret = this.evaluate(args);\n if (!ret || typeof ret !== 'object') {\n throw new NewError(ret);\n }\n return ret;\n }\n}\n\n// PUBLIC METHODS\nJSONPath.prototype.evaluate = function (\n expr, json, callback, otherTypeCallback\n) {\n const that = this;\n let currParent = this.parent,\n currParentProperty = this.parentProperty;\n let {flatten, wrap} = this;\n\n this.currResultType = this.resultType;\n this.currPreventEval = this.preventEval;\n this.currSandbox = this.sandbox;\n callback = callback || this.callback;\n this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback;\n\n json = json || this.json;\n expr = expr || this.path;\n if (expr && typeof expr === 'object') {\n if (!expr.path) {\n throw new TypeError(\n 'You must supply a \"path\" property when providing an object ' +\n 'argument to JSONPath.evaluate().'\n );\n }\n if (!('json' in expr)) {\n throw new TypeError(\n 'You must supply a \"json\" property when providing an object ' +\n 'argument to JSONPath.evaluate().'\n );\n }\n json = hasOwnProp.call(expr, 'json') ? expr.json : json;\n flatten = hasOwnProp.call(expr, 'flatten') ? expr.flatten : flatten;\n this.currResultType = hasOwnProp.call(expr, 'resultType')\n ? expr.resultType\n : this.currResultType;\n this.currSandbox = hasOwnProp.call(expr, 'sandbox')\n ? expr.sandbox\n : this.currSandbox;\n wrap = hasOwnProp.call(expr, 'wrap') ? expr.wrap : wrap;\n this.currPreventEval = hasOwnProp.call(expr, 'preventEval')\n ? expr.preventEval\n : this.currPreventEval;\n callback = hasOwnProp.call(expr, 'callback') ? expr.callback : callback;\n this.currOtherTypeCallback = hasOwnProp.call(expr, 'otherTypeCallback')\n ? expr.otherTypeCallback\n : this.currOtherTypeCallback;\n currParent = hasOwnProp.call(expr, 'parent') ? expr.parent : currParent;\n currParentProperty = hasOwnProp.call(expr, 'parentProperty')\n ? expr.parentProperty\n : currParentProperty;\n expr = expr.path;\n }\n currParent = currParent || null;\n currParentProperty = currParentProperty || null;\n\n if (Array.isArray(expr)) {\n expr = JSONPath.toPathString(expr);\n }\n if (!expr || !json || !allowedResultTypes.includes(this.currResultType)) {\n return undefined;\n }\n this._obj = json;\n\n const exprList = JSONPath.toPathArray(expr);\n if (exprList[0] === '$' && exprList.length > 1) { exprList.shift(); }\n this._hasParentSelector = null;\n const result = this\n ._trace(exprList, json, ['$'], currParent, currParentProperty, callback)\n .filter(function (ea) { return ea && !ea.isParentSelector; });\n\n if (!result.length) { return wrap ? [] : undefined; }\n if (!wrap && result.length === 1 && !result[0].hasArrExpr) {\n return this._getPreferredOutput(result[0]);\n }\n return result.reduce(function (rslt, ea) {\n const valOrPath = that._getPreferredOutput(ea);\n if (flatten && Array.isArray(valOrPath)) {\n rslt = rslt.concat(valOrPath);\n } else {\n rslt.push(valOrPath);\n }\n return rslt;\n }, []);\n};\n\n// PRIVATE METHODS\n\nJSONPath.prototype._getPreferredOutput = function (ea) {\n const resultType = this.currResultType;\n switch (resultType) {\n default:\n throw new TypeError('Unknown result type');\n case 'all':\n ea.pointer = JSONPath.toPointer(ea.path);\n ea.path = typeof ea.path === 'string'\n ? ea.path\n : JSONPath.toPathString(ea.path);\n return ea;\n case 'value': case 'parent': case 'parentProperty':\n return ea[resultType];\n case 'path':\n return JSONPath.toPathString(ea[resultType]);\n case 'pointer':\n return JSONPath.toPointer(ea.path);\n }\n};\n\nJSONPath.prototype._handleCallback = function (fullRetObj, callback, type) {\n if (callback) {\n const preferredOutput = this._getPreferredOutput(fullRetObj);\n fullRetObj.path = typeof fullRetObj.path === 'string'\n ? fullRetObj.path\n : JSONPath.toPathString(fullRetObj.path);\n // eslint-disable-next-line callback-return\n callback(preferredOutput, type, fullRetObj);\n }\n};\n\n/**\n *\n * @param {string} expr\n * @param {JSONObject} val\n * @param {string} path\n * @param {PlainObject|GenericArray} parent\n * @param {string} parentPropName\n * @param {JSONPathCallback} callback\n * @param {boolean} literalPriority\n * @param {boolean} hasArrExpr\n * @returns {ReturnObject|ReturnObject[]}\n */\nJSONPath.prototype._trace = function (\n expr, val, path, parent, parentPropName, callback, hasArrExpr, literalPriority\n) {\n // No expr to follow? return path and value as the result of\n // this trace branch\n let retObj;\n const that = this;\n if (!expr.length) {\n retObj = {path, value: val, parent, parentProperty: parentPropName, hasArrExpr};\n this._handleCallback(retObj, callback, 'value');\n return retObj;\n }\n\n const loc = expr[0], x = expr.slice(1);\n\n // We need to gather the return value of recursive trace calls in order to\n // do the parent sel computation.\n const ret = [];\n /**\n *\n * @param {ReturnObject|ReturnObject[]} elems\n * @returns {void}\n */\n function addRet (elems) {\n if (Array.isArray(elems)) {\n // This was causing excessive stack size in Node (with or\n // without Babel) against our performance test:\n // `ret.push(...elems);`\n elems.forEach((t) => {\n ret.push(t);\n });\n } else {\n ret.push(elems);\n }\n }\n if ((typeof loc !== 'string' || literalPriority) && val &&\n hasOwnProp.call(val, loc)\n ) { // simple case--directly follow property\n addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr));\n } else if (loc === '*') { // all child properties\n this._walk(\n loc, x, val, path, parent, parentPropName, callback,\n function (m, l, _x, v, p, par, pr, cb) {\n addRet(that._trace(unshift(m, _x), v, p, par, pr, cb, true, true));\n }\n );\n } else if (loc === '..') { // all descendent parent properties\n // Check remaining expression with val's immediate children\n addRet(\n this._trace(x, val, path, parent, parentPropName, callback, hasArrExpr)\n );\n this._walk(\n loc, x, val, path, parent, parentPropName, callback,\n function (m, l, _x, v, p, par, pr, cb) {\n // We don't join m and x here because we only want parents,\n // not scalar values\n if (typeof v[m] === 'object') {\n // Keep going with recursive descent on val's\n // object children\n addRet(that._trace(\n unshift(l, _x), v[m], push(p, m), v, m, cb, true\n ));\n }\n }\n );\n // The parent sel computation is handled in the frame above using the\n // ancestor object of val\n } else if (loc === '^') {\n // This is not a final endpoint, so we do not invoke the callback here\n this._hasParentSelector = true;\n return path.length\n ? {\n path: path.slice(0, -1),\n expr: x,\n isParentSelector: true\n }\n : [];\n } else if (loc === '~') { // property name\n retObj = {\n path: push(path, loc),\n value: parentPropName,\n parent,\n parentProperty: null\n };\n this._handleCallback(retObj, callback, 'property');\n return retObj;\n } else if (loc === '$') { // root only\n addRet(this._trace(x, val, path, null, null, callback, hasArrExpr));\n } else if ((/^(-?\\d*):(-?\\d*):?(\\d*)$/u).test(loc)) { // [start:end:step] Python slice syntax\n addRet(\n this._slice(loc, x, val, path, parent, parentPropName, callback)\n );\n } else if (loc.indexOf('?(') === 0) { // [?(expr)] (filtering)\n if (this.currPreventEval) {\n throw new Error('Eval [?(expr)] prevented in JSONPath expression.');\n }\n this._walk(\n loc, x, val, path, parent, parentPropName, callback,\n function (m, l, _x, v, p, par, pr, cb) {\n if (that._eval(l.replace(/^\\?\\((.*?)\\)$/u, '$1'), v[m], m, p, par, pr)) {\n addRet(that._trace(unshift(m, _x), v, p, par, pr, cb, true));\n }\n }\n );\n } else if (loc[0] === '(') { // [(expr)] (dynamic property/index)\n if (this.currPreventEval) {\n throw new Error('Eval [(expr)] prevented in JSONPath expression.');\n }\n // As this will resolve to a property name (but we don't know it\n // yet), property and parent information is relative to the\n // parent of the property to which this expression will resolve\n addRet(this._trace(unshift(\n this._eval(\n loc, val, path[path.length - 1],\n path.slice(0, -1), parent, parentPropName\n ),\n x\n ), val, path, parent, parentPropName, callback, hasArrExpr));\n } else if (loc[0] === '@') { // value type: @boolean(), etc.\n let addType = false;\n const valueType = loc.slice(1, -2);\n switch (valueType) {\n default:\n throw new TypeError('Unknown value type ' + valueType);\n case 'scalar':\n if (!val || !(['object', 'function'].includes(typeof val))) {\n addType = true;\n }\n break;\n case 'boolean': case 'string': case 'undefined': case 'function':\n // eslint-disable-next-line valid-typeof\n if (typeof val === valueType) {\n addType = true;\n }\n break;\n case 'number':\n // eslint-disable-next-line valid-typeof\n if (typeof val === valueType && isFinite(val)) {\n addType = true;\n }\n break;\n case 'nonFinite':\n if (typeof val === 'number' && !isFinite(val)) {\n addType = true;\n }\n break;\n case 'object':\n // eslint-disable-next-line valid-typeof\n if (val && typeof val === valueType) {\n addType = true;\n }\n break;\n case 'array':\n if (Array.isArray(val)) {\n addType = true;\n }\n break;\n case 'other':\n addType = this.currOtherTypeCallback(\n val, path, parent, parentPropName\n );\n break;\n case 'integer':\n if (val === Number(val) && isFinite(val) && !(val % 1)) {\n addType = true;\n }\n break;\n case 'null':\n if (val === null) {\n addType = true;\n }\n break;\n }\n if (addType) {\n retObj = {path, value: val, parent, parentProperty: parentPropName};\n this._handleCallback(retObj, callback, 'value');\n return retObj;\n }\n // `-escaped property\n } else if (loc[0] === '`' && val && hasOwnProp.call(val, loc.slice(1))) {\n const locProp = loc.slice(1);\n addRet(this._trace(\n x, val[locProp], push(path, locProp), val, locProp, callback, hasArrExpr, true\n ));\n } else if (loc.includes(',')) { // [name1,name2,...]\n const parts = loc.split(',');\n for (const part of parts) {\n addRet(this._trace(\n unshift(part, x), val, path, parent, parentPropName, callback, true\n ));\n }\n // simple case--directly follow property\n } else if (!literalPriority && val && hasOwnProp.call(val, loc)) {\n addRet(\n this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr, true)\n );\n }\n\n // We check the resulting values for parent selections. For parent\n // selections we discard the value object and continue the trace with the\n // current val object\n if (this._hasParentSelector) {\n for (let t = 0; t < ret.length; t++) {\n const rett = ret[t];\n if (rett.isParentSelector) {\n const tmp = that._trace(\n rett.expr, val, rett.path, parent, parentPropName, callback, hasArrExpr\n );\n if (Array.isArray(tmp)) {\n ret[t] = tmp[0];\n const tl = tmp.length;\n for (let tt = 1; tt < tl; tt++) {\n t++;\n ret.splice(t, 0, tmp[tt]);\n }\n } else {\n ret[t] = tmp;\n }\n }\n }\n }\n return ret;\n};\n\nJSONPath.prototype._walk = function (\n loc, expr, val, path, parent, parentPropName, callback, f\n) {\n if (Array.isArray(val)) {\n const n = val.length;\n for (let i = 0; i < n; i++) {\n f(i, loc, expr, val, path, parent, parentPropName, callback);\n }\n } else if (typeof val === 'object') {\n for (const m in val) {\n if (hasOwnProp.call(val, m)) {\n f(m, loc, expr, val, path, parent, parentPropName, callback);\n }\n }\n }\n};\n\nJSONPath.prototype._slice = function (\n loc, expr, val, path, parent, parentPropName, callback\n) {\n if (!Array.isArray(val)) { return undefined; }\n const len = val.length, parts = loc.split(':'),\n step = (parts[2] && parseInt(parts[2])) || 1;\n let start = (parts[0] && parseInt(parts[0])) || 0,\n end = (parts[1] && parseInt(parts[1])) || len;\n start = (start < 0) ? Math.max(0, start + len) : Math.min(len, start);\n end = (end < 0) ? Math.max(0, end + len) : Math.min(len, end);\n const ret = [];\n for (let i = start; i < end; i += step) {\n const tmp = this._trace(\n unshift(i, expr), val, path, parent, parentPropName, callback, true\n );\n if (Array.isArray(tmp)) {\n // This was causing excessive stack size in Node (with or\n // without Babel) against our performance test: `ret.push(...tmp);`\n tmp.forEach((t) => {\n ret.push(t);\n });\n } else {\n ret.push(tmp);\n }\n }\n return ret;\n};\n\nJSONPath.prototype._eval = function (\n code, _v, _vname, path, parent, parentPropName\n) {\n if (!this._obj || !_v) { return false; }\n if (code.includes('@parentProperty')) {\n this.currSandbox._$_parentProperty = parentPropName;\n code = code.replace(/@parentProperty/gu, '_$_parentProperty');\n }\n if (code.includes('@parent')) {\n this.currSandbox._$_parent = parent;\n code = code.replace(/@parent/gu, '_$_parent');\n }\n if (code.includes('@property')) {\n this.currSandbox._$_property = _vname;\n code = code.replace(/@property/gu, '_$_property');\n }\n if (code.includes('@path')) {\n this.currSandbox._$_path = JSONPath.toPathString(path.concat([_vname]));\n code = code.replace(/@path/gu, '_$_path');\n }\n if (code.includes('@root')) {\n this.currSandbox._$_root = this.json;\n code = code.replace(/@root/gu, '_$_root');\n }\n if (code.match(/@([.\\s)[])/u)) {\n this.currSandbox._$_v = _v;\n code = code.replace(/@([.\\s)[])/gu, '_$_v$1');\n }\n try {\n return vm.runInNewContext(code, this.currSandbox);\n } catch (e) {\n // eslint-disable-next-line no-console\n console.log(e);\n throw new Error('jsonPath: ' + e.message + ': ' + code);\n }\n};\n\n// PUBLIC CLASS PROPERTIES AND METHODS\n\n// Could store the cache object itself\nJSONPath.cache = {};\n\n/**\n * @param {string[]} pathArr Array to convert\n * @returns {string} The path string\n */\nJSONPath.toPathString = function (pathArr) {\n const x = pathArr, n = x.length;\n let p = '$';\n for (let i = 1; i < n; i++) {\n if (!(/^(~|\\^|@.*?\\(\\))$/u).test(x[i])) {\n p += (/^[0-9*]+$/u).test(x[i]) ? ('[' + x[i] + ']') : (\"['\" + x[i] + \"']\");\n }\n }\n return p;\n};\n\n/**\n * @param {string} pointer JSON Path\n * @returns {string} JSON Pointer\n */\nJSONPath.toPointer = function (pointer) {\n const x = pointer, n = x.length;\n let p = '';\n for (let i = 1; i < n; i++) {\n if (!(/^(~|\\^|@.*?\\(\\))$/u).test(x[i])) {\n p += '/' + x[i].toString()\n .replace(/~/gu, '~0')\n .replace(/\\//gu, '~1');\n }\n }\n return p;\n};\n\n/**\n * @param {string} expr Expression to convert\n * @returns {string[]}\n */\nJSONPath.toPathArray = function (expr) {\n const {cache} = JSONPath;\n if (cache[expr]) { return cache[expr].concat(); }\n const subx = [];\n const normalized = expr\n // Properties\n .replace(\n /@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\\(\\)/gu,\n ';$&;'\n )\n // Parenthetical evaluations (filtering and otherwise), directly\n // within brackets or single quotes\n .replace(/[['](\\??\\(.*?\\))[\\]']/gu, function ($0, $1) {\n return '[#' + (subx.push($1) - 1) + ']';\n })\n // Escape periods and tildes within properties\n .replace(/\\['([^'\\]]*)'\\]/gu, function ($0, prop) {\n return \"['\" + prop\n .replace(/\\./gu, '%@%')\n .replace(/~/gu, '%%@@%%') +\n \"']\";\n })\n // Properties operator\n .replace(/~/gu, ';~;')\n // Split by property boundaries\n .replace(/'?\\.'?(?![^[]*\\])|\\['?/gu, ';')\n // Reinsert periods within properties\n .replace(/%@%/gu, '.')\n // Reinsert tildes within properties\n .replace(/%%@@%%/gu, '~')\n // Parent\n .replace(/(?:;)?(\\^+)(?:;)?/gu, function ($0, ups) {\n return ';' + ups.split('').join(';') + ';';\n })\n // Descendents\n .replace(/;;;|;;/gu, ';..;')\n // Remove trailing\n .replace(/;$|'?\\]|'$/gu, '');\n\n const exprList = normalized.split(';').map(function (exp) {\n const match = exp.match(/#(\\d+)/u);\n return !match || !match[1] ? exp : subx[match[1]];\n });\n cache[expr] = exprList;\n return cache[expr];\n};\n\nexport {JSONPath};\n"],"names":["allowedResultTypes","hasOwnProp","Object","prototype","hasOwnProperty","vm","toString","call","global","process","e","supportsNodeVM","require","runInNewContext","expr","context","keys","funcs","source","target","conditionCb","il","length","i","push","splice","moveToAnotherArray","key","values","map","vr","reduce","s","func","fString","exec","match","includes","lastStatementEnd","replace","lastIndexOf","code","slice","_construct","Function","arr","item","unshift","NewError","value","avoidNew","name","Error","JSONPath","opts","obj","callback","otherTypeCallback","this","optObj","_typeof","json","path","resultType","toLowerCase","flatten","wrap","sandbox","preventEval","parent","parentProperty","TypeError","autostart","args","ret","evaluate","that","currParent","currParentProperty","currResultType","currPreventEval","currSandbox","currOtherTypeCallback","Array","isArray","toPathString","_obj","exprList","toPathArray","shift","_hasParentSelector","result","_trace","filter","ea","isParentSelector","hasArrExpr","rslt","valOrPath","_getPreferredOutput","concat","undefined","pointer","toPointer","_handleCallback","fullRetObj","type","preferredOutput","val","parentPropName","literalPriority","retObj","loc","x","addRet","elems","forEach","t","_walk","m","l","_x","v","p","par","pr","cb","test","_slice","indexOf","_eval","addType","valueType","isFinite","Number","locProp","parts","split","part","rett","tmp","tl","tt","f","n","len","step","parseInt","start","end","Math","max","min","_v","_vname","_$_parentProperty","_$_parent","_$_property","_$_path","_$_root","_$_v","console","log","message","cache","pathArr","subx","$0","$1","prop","ups","join","exp"],"mappings":"63DAGA,IASMA,EAAqB,CACvB,QAAS,OAAQ,UAAW,SAAU,iBAAkB,OAErCC,EAAcC,OAAOC,UAArCC,eA8BDC,EA1CiB,qBAIT,qBAFCH,OAAOC,UAAUG,SAASC,KAC7BC,OAAOC,SAEb,MAAOC,UACE,GAoCJC,GACLC,QAAQ,MACR,CAOEC,yBAAiBC,EAAMC,OACbC,EAAOd,OAAOc,KAAKD,GACnBE,EAAQ,IArBC,SAAUC,EAAQC,EAAQC,WAC3CC,EAAKH,EAAOI,OACTC,EAAI,EAAGA,EAAIF,EAAIE,IAAK,CAErBH,EADSF,EAAOK,KAEhBJ,EAAOK,KAAKN,EAAOO,OAAOF,IAAK,GAAG,KAiBlCG,CAAmBV,EAAMC,GAAO,SAACU,SACE,mBAAjBZ,EAAQY,UAKpBC,EAASZ,EAAKa,KAAI,SAACC,EAAIP,UAClBR,EAAQe,OAUnBhB,EARmBG,EAAMc,QAAO,SAACC,EAAGC,OAC5BC,EAAUnB,EAAQkB,GAAM3B,iBACtB,WAAa6B,KAAK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AAK,KAAO,OAG1CpI,QAAQ,UAAY,QAEpBA,QAAQ,cAAgB,IAEDkG,MAAM,KAAK5G,KAAI,SAAU+I,OAC3CxI,EAAQwI,EAAIxI,MAAM,oBAChBA,GAAUA,EAAM,GAAWkI,EAAKlI,EAAM,IAAjBwI,YAEjCR,EAAMtJ,GAAQyE,EACP6E,EAAMtJ"} \ No newline at end of file diff --git a/dist/index-umd.js b/dist/index-umd.js index 480f73f..0e7b510 100644 --- a/dist/index-umd.js +++ b/dist/index-umd.js @@ -486,7 +486,7 @@ return wrap ? [] : undefined; } - if (result.length === 1 && !wrap && !Array.isArray(result[0].value)) { + if (!wrap && result.length === 1 && !result[0].hasArrExpr) { return this._getPreferredOutput(result[0]); } @@ -547,11 +547,12 @@ * @param {string} parentPropName * @param {JSONPathCallback} callback * @param {boolean} literalPriority + * @param {boolean} hasArrExpr * @returns {ReturnObject|ReturnObject[]} */ - JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, callback, literalPriority) { + JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, callback, hasArrExpr, literalPriority) { // No expr to follow? return path and value as the result of // this trace branch var retObj; @@ -562,7 +563,8 @@ path: path, value: val, parent: parent, - parentProperty: parentPropName + parentProperty: parentPropName, + hasArrExpr: hasArrExpr }; this._handleCallback(retObj, callback, 'value'); @@ -596,16 +598,16 @@ if ((typeof loc !== 'string' || literalPriority) && val && hasOwnProp.call(val, loc)) { // simple case--directly follow property - addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback)); + addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr)); } else if (loc === '*') { // all child properties this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) { - addRet(that._trace(unshift(m, _x), v, p, par, pr, cb, true)); + addRet(that._trace(unshift(m, _x), v, p, par, pr, cb, true, true)); }); } else if (loc === '..') { // all descendent parent properties // Check remaining expression with val's immediate children - addRet(this._trace(x, val, path, parent, parentPropName, callback)); + addRet(this._trace(x, val, path, parent, parentPropName, callback, hasArrExpr)); this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) { // We don't join m and x here because we only want parents, @@ -613,7 +615,7 @@ if (_typeof(v[m]) === 'object') { // Keep going with recursive descent on val's // object children - addRet(that._trace(unshift(l, _x), v[m], push(p, m), v, m, cb)); + addRet(that._trace(unshift(l, _x), v[m], push(p, m), v, m, cb, true)); } }); // The parent sel computation is handled in the frame above using the // ancestor object of val @@ -640,7 +642,7 @@ return retObj; } else if (loc === '$') { // root only - addRet(this._trace(x, val, path, null, null, callback)); + addRet(this._trace(x, val, path, null, null, callback, hasArrExpr)); } else if (/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(loc)) { // [start:end:step] Python slice syntax addRet(this._slice(loc, x, val, path, parent, parentPropName, callback)); @@ -652,7 +654,7 @@ this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) { if (that._eval(l.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/, '$1'), v[m], m, p, par, pr)) { - addRet(that._trace(unshift(m, _x), v, p, par, pr, cb)); + addRet(that._trace(unshift(m, _x), v, p, par, pr, cb, true)); } }); } else if (loc[0] === '(') { @@ -664,7 +666,7 @@ // parent of the property to which this expression will resolve - addRet(this._trace(unshift(this._eval(loc, val, path[path.length - 1], path.slice(0, -1), parent, parentPropName), x), val, path, parent, parentPropName, callback)); + addRet(this._trace(unshift(this._eval(loc, val, path[path.length - 1], path.slice(0, -1), parent, parentPropName), x), val, path, parent, parentPropName, callback, hasArrExpr)); } else if (loc[0] === '@') { // value type: @boolean(), etc. var addType = false; @@ -756,7 +758,7 @@ } else if (loc[0] === '`' && val && hasOwnProp.call(val, loc.slice(1))) { var locProp = loc.slice(1); - addRet(this._trace(x, val[locProp], push(path, locProp), val, locProp, callback, true)); + addRet(this._trace(x, val[locProp], push(path, locProp), val, locProp, callback, hasArrExpr, true)); } else if (loc.includes(',')) { // [name1,name2,...] var parts = loc.split(','); @@ -767,7 +769,7 @@ try { for (var _iterator = parts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var part = _step.value; - addRet(this._trace(unshift(part, x), val, path, parent, parentPropName, callback)); + addRet(this._trace(unshift(part, x), val, path, parent, parentPropName, callback, true)); } // simple case--directly follow property } catch (err) { @@ -785,7 +787,7 @@ } } } else if (!literalPriority && val && hasOwnProp.call(val, loc)) { - addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, true)); + addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr, true)); } // We check the resulting values for parent selections. For parent // selections we discard the value object and continue the trace with the // current val object @@ -796,7 +798,7 @@ var rett = ret[t]; if (rett.isParentSelector) { - var tmp = that._trace(rett.expr, val, rett.path, parent, parentPropName, callback); + var tmp = that._trace(rett.expr, val, rett.path, parent, parentPropName, callback, hasArrExpr); if (Array.isArray(tmp)) { ret[t] = tmp[0]; @@ -847,7 +849,7 @@ var ret = []; for (var i = start; i < end; i += step) { - var tmp = this._trace(unshift(i, expr), val, path, parent, parentPropName, callback); + var tmp = this._trace(unshift(i, expr), val, path, parent, parentPropName, callback, true); if (Array.isArray(tmp)) { // This was causing excessive stack size in Node (with or diff --git a/dist/index-umd.min.js b/dist/index-umd.min.js index 7336174..8e5e33f 100644 --- a/dist/index-umd.min.js +++ b/dist/index-umd.min.js @@ -1,2 +1,2 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).JSONPath={})}(this,(function(t){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(t){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function n(t,e){return(n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function a(t,e,r){return(a=function(){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(t){return!1}}()?Reflect.construct:function(t,e,r){var a=[null];a.push.apply(a,e);var u=new(Function.bind.apply(t,a));return r&&n(u,r.prototype),u}).apply(null,arguments)}function u(t){var e="function"==typeof Map?new Map:void 0;return(u=function(t){if(null===t||(u=t,-1===Function.toString.call(u).indexOf("[native code]")))return t;var u;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,o)}function o(){return a(t,arguments,r(this).constructor)}return o.prototype=Object.create(t.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),n(o,t)})(t)}function o(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function i(t){return function(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e-1?t.slice(0,o+1)+" return "+t.slice(o+1):" return "+t;return a(Function,i(r).concat([c])).apply(void 0,i(u))}};function p(t,e){return(t=t.slice()).push(e),t}function h(t,e){return(e=e.slice()).unshift(t),e}var f=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=o(this,r(e).call(this,'JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)'))).avoidNew=!0,n.value=t,n.name="NewError",n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&n(t,e)}(e,t),e}(u(Error));function y(t,r,n,a,u){if(!(this instanceof y))try{return new y(t,r,n,a,u)}catch(t){if(!t.avoidNew)throw t;return t.value}"string"==typeof t&&(u=a,a=n,n=r,r=t,t=null);var o=t&&"object"===e(t);if(t=t||{},this.json=t.json||n,this.path=t.path||r,this.resultType=t.resultType&&t.resultType.toLowerCase()||"value",this.flatten=t.flatten||!1,this.wrap=!l.call(t,"wrap")||t.wrap,this.sandbox=t.sandbox||{},this.preventEval=t.preventEval||!1,this.parent=t.parent||null,this.parentProperty=t.parentProperty||null,this.callback=t.callback||a||null,this.otherTypeCallback=t.otherTypeCallback||u||function(){throw new TypeError("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==t.autostart){var i={path:o?t.path:r};o?"json"in t&&(i.json=t.json):i.json=n;var c=this.evaluate(i);if(!c||"object"!==e(c))throw new f(c);return c}}y.prototype.evaluate=function(t,r,n,a){var u=this,o=this.parent,i=this.parentProperty,s=this.flatten,p=this.wrap;if(this.currResultType=this.resultType,this.currPreventEval=this.preventEval,this.currSandbox=this.sandbox,n=n||this.callback,this.currOtherTypeCallback=a||this.otherTypeCallback,r=r||this.json,(t=t||this.path)&&"object"===e(t)){if(!t.path)throw new TypeError('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');if(!("json"in t))throw new TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');r=l.call(t,"json")?t.json:r,s=l.call(t,"flatten")?t.flatten:s,this.currResultType=l.call(t,"resultType")?t.resultType:this.currResultType,this.currSandbox=l.call(t,"sandbox")?t.sandbox:this.currSandbox,p=l.call(t,"wrap")?t.wrap:p,this.currPreventEval=l.call(t,"preventEval")?t.preventEval:this.currPreventEval,n=l.call(t,"callback")?t.callback:n,this.currOtherTypeCallback=l.call(t,"otherTypeCallback")?t.otherTypeCallback:this.currOtherTypeCallback,o=l.call(t,"parent")?t.parent:o,i=l.call(t,"parentProperty")?t.parentProperty:i,t=t.path}if(o=o||null,i=i||null,Array.isArray(t)&&(t=y.toPathString(t)),t&&r&&c.includes(this.currResultType)){this._obj=r;var h=y.toPathArray(t);"$"===h[0]&&h.length>1&&h.shift(),this._hasParentSelector=null;var f=this._trace(h,r,["$"],o,i,n).filter((function(t){return t&&!t.isParentSelector}));return f.length?1!==f.length||p||Array.isArray(f[0].value)?f.reduce((function(t,e){var r=u._getPreferredOutput(e);return s&&Array.isArray(r)?t=t.concat(r):t.push(r),t}),[]):this._getPreferredOutput(f[0]):p?[]:void 0}},y.prototype._getPreferredOutput=function(t){var e=this.currResultType;switch(e){default:throw new TypeError("Unknown result type");case"all":return t.pointer=y.toPointer(t.path),t.path="string"==typeof t.path?t.path:y.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[e];case"path":return y.toPathString(t[e]);case"pointer":return y.toPointer(t.path)}},y.prototype._handleCallback=function(t,e,r){if(e){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:y.toPathString(t.path),e(n,r,t)}},y.prototype._trace=function(t,r,n,a,u,o,i){var c,s=this;if(!t.length)return c={path:n,value:r,parent:a,parentProperty:u},this._handleCallback(c,o,"value"),c;var f=t[0],y=t.slice(1),F=[];function v(t){Array.isArray(t)?t.forEach((function(t){F.push(t)})):F.push(t)}if(("string"!=typeof f||i)&&r&&l.call(r,f))v(this._trace(y,r[f],p(n,f),r,f,o));else if("*"===f)this._walk(f,y,r,n,a,u,o,(function(t,e,r,n,a,u,o,i){v(s._trace(h(t,r),n,a,u,o,i,!0))}));else if(".."===f)v(this._trace(y,r,n,a,u,o)),this._walk(f,y,r,n,a,u,o,(function(t,r,n,a,u,o,i,c){"object"===e(a[t])&&v(s._trace(h(r,n),a[t],p(u,t),a,t,c))}));else{if("^"===f)return this._hasParentSelector=!0,n.length?{path:n.slice(0,-1),expr:y,isParentSelector:!0}:[];if("~"===f)return c={path:p(n,f),value:u,parent:a,parentProperty:null},this._handleCallback(c,o,"property"),c;if("$"===f)v(this._trace(y,r,n,null,null,o));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(f))v(this._slice(f,y,r,n,a,u,o));else if(0===f.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");this._walk(f,y,r,n,a,u,o,(function(t,e,r,n,a,u,o,i){s._eval(e.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/,"$1"),n[t],t,a,u,o)&&v(s._trace(h(t,r),n,a,u,o,i))}))}else if("("===f[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");v(this._trace(h(this._eval(f,r,n[n.length-1],n.slice(0,-1),a,u),y),r,n,a,u,o))}else if("@"===f[0]){var b=!1,D=f.slice(1,-2);switch(D){default:throw new TypeError("Unknown value type "+D);case"scalar":r&&["object","function"].includes(e(r))||(b=!0);break;case"boolean":case"string":case"undefined":case"function":e(r)===D&&(b=!0);break;case"number":e(r)===D&&isFinite(r)&&(b=!0);break;case"nonFinite":"number"!=typeof r||isFinite(r)||(b=!0);break;case"object":r&&e(r)===D&&(b=!0);break;case"array":Array.isArray(r)&&(b=!0);break;case"other":b=this.currOtherTypeCallback(r,n,a,u);break;case"integer":r!==Number(r)||!isFinite(r)||r%1||(b=!0);break;case"null":null===r&&(b=!0)}if(b)return c={path:n,value:r,parent:a,parentProperty:u},this._handleCallback(c,o,"value"),c}else if("`"===f[0]&&r&&l.call(r,f.slice(1))){var d=f.slice(1);v(this._trace(y,r[d],p(n,d),r,d,o,!0))}else if(f.includes(",")){var g=f.split(","),_=!0,w=!1,P=void 0;try{for(var x,S=g[Symbol.iterator]();!(_=(x=S.next()).done);_=!0){var j=x.value;v(this._trace(h(j,y),r,n,a,u,o))}}catch(t){w=!0,P=t}finally{try{_||null==S.return||S.return()}finally{if(w)throw P}}}else!i&&r&&l.call(r,f)&&v(this._trace(y,r[f],p(n,f),r,f,o,!0))}if(this._hasParentSelector)for(var E=0;E-1?t.slice(0,o+1)+" return "+t.slice(o+1):" return "+t;return a(Function,i(r).concat([c])).apply(void 0,i(u))}};function p(t,e){return(t=t.slice()).push(e),t}function h(t,e){return(e=e.slice()).unshift(t),e}var f=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=o(this,r(e).call(this,'JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)'))).avoidNew=!0,n.value=t,n.name="NewError",n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&n(t,e)}(e,t),e}(u(Error));function F(t,r,n,a,u){if(!(this instanceof F))try{return new F(t,r,n,a,u)}catch(t){if(!t.avoidNew)throw t;return t.value}"string"==typeof t&&(u=a,a=n,n=r,r=t,t=null);var o=t&&"object"===e(t);if(t=t||{},this.json=t.json||n,this.path=t.path||r,this.resultType=t.resultType&&t.resultType.toLowerCase()||"value",this.flatten=t.flatten||!1,this.wrap=!l.call(t,"wrap")||t.wrap,this.sandbox=t.sandbox||{},this.preventEval=t.preventEval||!1,this.parent=t.parent||null,this.parentProperty=t.parentProperty||null,this.callback=t.callback||a||null,this.otherTypeCallback=t.otherTypeCallback||u||function(){throw new TypeError("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==t.autostart){var i={path:o?t.path:r};o?"json"in t&&(i.json=t.json):i.json=n;var c=this.evaluate(i);if(!c||"object"!==e(c))throw new f(c);return c}}F.prototype.evaluate=function(t,r,n,a){var u=this,o=this.parent,i=this.parentProperty,s=this.flatten,p=this.wrap;if(this.currResultType=this.resultType,this.currPreventEval=this.preventEval,this.currSandbox=this.sandbox,n=n||this.callback,this.currOtherTypeCallback=a||this.otherTypeCallback,r=r||this.json,(t=t||this.path)&&"object"===e(t)){if(!t.path)throw new TypeError('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');if(!("json"in t))throw new TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');r=l.call(t,"json")?t.json:r,s=l.call(t,"flatten")?t.flatten:s,this.currResultType=l.call(t,"resultType")?t.resultType:this.currResultType,this.currSandbox=l.call(t,"sandbox")?t.sandbox:this.currSandbox,p=l.call(t,"wrap")?t.wrap:p,this.currPreventEval=l.call(t,"preventEval")?t.preventEval:this.currPreventEval,n=l.call(t,"callback")?t.callback:n,this.currOtherTypeCallback=l.call(t,"otherTypeCallback")?t.otherTypeCallback:this.currOtherTypeCallback,o=l.call(t,"parent")?t.parent:o,i=l.call(t,"parentProperty")?t.parentProperty:i,t=t.path}if(o=o||null,i=i||null,Array.isArray(t)&&(t=F.toPathString(t)),t&&r&&c.includes(this.currResultType)){this._obj=r;var h=F.toPathArray(t);"$"===h[0]&&h.length>1&&h.shift(),this._hasParentSelector=null;var f=this._trace(h,r,["$"],o,i,n).filter((function(t){return t&&!t.isParentSelector}));return f.length?p||1!==f.length||f[0].hasArrExpr?f.reduce((function(t,e){var r=u._getPreferredOutput(e);return s&&Array.isArray(r)?t=t.concat(r):t.push(r),t}),[]):this._getPreferredOutput(f[0]):p?[]:void 0}},F.prototype._getPreferredOutput=function(t){var e=this.currResultType;switch(e){default:throw new TypeError("Unknown result type");case"all":return t.pointer=F.toPointer(t.path),t.path="string"==typeof t.path?t.path:F.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[e];case"path":return F.toPathString(t[e]);case"pointer":return F.toPointer(t.path)}},F.prototype._handleCallback=function(t,e,r){if(e){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:F.toPathString(t.path),e(n,r,t)}},F.prototype._trace=function(t,r,n,a,u,o,i,c){var s,f=this;if(!t.length)return s={path:n,value:r,parent:a,parentProperty:u,hasArrExpr:i},this._handleCallback(s,o,"value"),s;var F=t[0],y=t.slice(1),v=[];function b(t){Array.isArray(t)?t.forEach((function(t){v.push(t)})):v.push(t)}if(("string"!=typeof F||c)&&r&&l.call(r,F))b(this._trace(y,r[F],p(n,F),r,F,o,i));else if("*"===F)this._walk(F,y,r,n,a,u,o,(function(t,e,r,n,a,u,o,i){b(f._trace(h(t,r),n,a,u,o,i,!0,!0))}));else if(".."===F)b(this._trace(y,r,n,a,u,o,i)),this._walk(F,y,r,n,a,u,o,(function(t,r,n,a,u,o,i,c){"object"===e(a[t])&&b(f._trace(h(r,n),a[t],p(u,t),a,t,c,!0))}));else{if("^"===F)return this._hasParentSelector=!0,n.length?{path:n.slice(0,-1),expr:y,isParentSelector:!0}:[];if("~"===F)return s={path:p(n,F),value:u,parent:a,parentProperty:null},this._handleCallback(s,o,"property"),s;if("$"===F)b(this._trace(y,r,n,null,null,o,i));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(F))b(this._slice(F,y,r,n,a,u,o));else if(0===F.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");this._walk(F,y,r,n,a,u,o,(function(t,e,r,n,a,u,o,i){f._eval(e.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/,"$1"),n[t],t,a,u,o)&&b(f._trace(h(t,r),n,a,u,o,i,!0))}))}else if("("===F[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");b(this._trace(h(this._eval(F,r,n[n.length-1],n.slice(0,-1),a,u),y),r,n,a,u,o,i))}else if("@"===F[0]){var D=!1,d=F.slice(1,-2);switch(d){default:throw new TypeError("Unknown value type "+d);case"scalar":r&&["object","function"].includes(e(r))||(D=!0);break;case"boolean":case"string":case"undefined":case"function":e(r)===d&&(D=!0);break;case"number":e(r)===d&&isFinite(r)&&(D=!0);break;case"nonFinite":"number"!=typeof r||isFinite(r)||(D=!0);break;case"object":r&&e(r)===d&&(D=!0);break;case"array":Array.isArray(r)&&(D=!0);break;case"other":D=this.currOtherTypeCallback(r,n,a,u);break;case"integer":r!==Number(r)||!isFinite(r)||r%1||(D=!0);break;case"null":null===r&&(D=!0)}if(D)return s={path:n,value:r,parent:a,parentProperty:u},this._handleCallback(s,o,"value"),s}else if("`"===F[0]&&r&&l.call(r,F.slice(1))){var g=F.slice(1);b(this._trace(y,r[g],p(n,g),r,g,o,i,!0))}else if(F.includes(",")){var _=F.split(","),w=!0,P=!1,x=void 0;try{for(var E,S=_[Symbol.iterator]();!(w=(E=S.next()).done);w=!0){var j=E.value;b(this._trace(h(j,y),r,n,a,u,o,!0))}}catch(t){P=!0,x=t}finally{try{w||null==S.return||S.return()}finally{if(P)throw x}}}else!c&&r&&l.call(r,F)&&b(this._trace(y,r[F],p(n,F),r,F,o,i,!0))}if(this._hasParentSelector)for(var m=0;m {\n return typeof context[key] === 'function';\n });\n // Todo[engine:node@>=8]: Use the next line instead of the\n // succeeding\n // const values = Object.values(context);\n const values = keys.map((vr, i) => {\n return context[vr];\n });\n const funcString = funcs.reduce((s, func) => {\n let fString = context[func].toString();\n if (!(/function/u).exec(fString)) {\n fString = 'function ' + fString;\n }\n return 'var ' + func + '=' + fString + ';' + s;\n }, '');\n\n expr = funcString + expr;\n\n // Mitigate http://perfectionkills.com/global-eval-what-are-the-options/#new_function\n if (!expr.match(/(['\"])use strict\\1/u) &&\n !keys.includes('arguments')\n ) {\n expr = 'var arguments = undefined;' + expr;\n }\n\n // Remove last semi so `return` will be inserted before\n // the previous one instead, allowing for the return\n // of a bare ending expression\n expr = expr.replace(/;\\s*$/u, '');\n\n // Insert `return`\n const lastStatementEnd = expr.lastIndexOf(';');\n const code = (lastStatementEnd > -1\n ? expr.slice(0, lastStatementEnd + 1) +\n ' return ' + expr.slice(lastStatementEnd + 1)\n : ' return ' + expr);\n\n // eslint-disable-next-line no-new-func\n return (new Function(...keys, code))(...values);\n }\n };\n\n/**\n * Copies array and then pushes item into it.\n * @param {GenericArray} arr Array to copy and into which to push\n * @param {any} item Array item to add (to end)\n * @returns {GenericArray} Copy of the original array\n */\nfunction push (arr, item) {\n arr = arr.slice();\n arr.push(item);\n return arr;\n}\n/**\n * Copies array and then unshifts item into it.\n * @param {any} item Array item to add (to beginning)\n * @param {GenericArray} arr Array to copy and into which to unshift\n * @returns {GenericArray} Copy of the original array\n */\nfunction unshift (item, arr) {\n arr = arr.slice();\n arr.unshift(item);\n return arr;\n}\n\n/**\n * Caught when JSONPath is used without `new` but rethrown if with `new`\n * @extends Error\n */\nclass NewError extends Error {\n /**\n * @param {any} value The evaluated scalar value\n */\n constructor (value) {\n super(\n 'JSONPath should not be called with \"new\" (it prevents return ' +\n 'of (unwrapped) scalar values)'\n );\n this.avoidNew = true;\n this.value = value;\n this.name = 'NewError';\n }\n}\n\n/**\n* @typedef {PlainObject} ReturnObject\n* @property {string} path\n* @property {JSONObject} value\n* @property {PlainObject|GenericArray} parent\n* @property {string} parentProperty\n*/\n\n/**\n* @callback JSONPathCallback\n* @param {string|PlainObject} preferredOutput\n* @param {\"value\"|\"property\"} type\n* @param {ReturnObject} fullRetObj\n* @returns {void}\n*/\n\n/**\n* @callback OtherTypeCallback\n* @param {JSONObject} val\n* @param {string} path\n* @param {PlainObject|GenericArray} parent\n* @param {string} parentPropName\n* @returns {boolean}\n*/\n\n/**\n * @typedef {PlainObject} JSONPathOptions\n * @property {JSON} json\n * @property {string|string[]} path\n * @property {\"value\"|\"path\"|\"pointer\"|\"parent\"|\"parentProperty\"|\"all\"}\n * [resultType=\"value\"]\n * @property {boolean} [flatten=false]\n * @property {boolean} [wrap=true]\n * @property {PlainObject} [sandbox={}]\n * @property {boolean} [preventEval=false]\n * @property {PlainObject|GenericArray|null} [parent=null]\n * @property {string|null} [parentProperty=null]\n * @property {JSONPathCallback} [callback]\n * @property {OtherTypeCallback} [otherTypeCallback] Defaults to\n * function which throws on encountering `@other`\n * @property {boolean} [autostart=true]\n */\n\n/**\n * @param {string|JSONPathOptions} opts If a string, will be treated as `expr`\n * @param {string} [expr] JSON path to evaluate\n * @param {JSON} [obj] JSON object to evaluate against\n * @param {JSONPathCallback} [callback] Passed 3 arguments: 1) desired payload\n * per `resultType`, 2) `\"value\"|\"property\"`, 3) Full returned object with\n * all payloads\n * @param {OtherTypeCallback} [otherTypeCallback] If `@other()` is at the end\n * of one's query, this will be invoked with the value of the item, its\n * path, its parent, and its parent's property name, and it should return\n * a boolean indicating whether the supplied value belongs to the \"other\"\n * type or not (or it may handle transformations and return `false`).\n * @returns {JSONPath}\n * @class\n */\nfunction JSONPath (opts, expr, obj, callback, otherTypeCallback) {\n // eslint-disable-next-line no-restricted-syntax\n if (!(this instanceof JSONPath)) {\n try {\n return new JSONPath(opts, expr, obj, callback, otherTypeCallback);\n } catch (e) {\n if (!e.avoidNew) {\n throw e;\n }\n return e.value;\n }\n }\n\n if (typeof opts === 'string') {\n otherTypeCallback = callback;\n callback = obj;\n obj = expr;\n expr = opts;\n opts = null;\n }\n const optObj = opts && typeof opts === 'object';\n opts = opts || {};\n this.json = opts.json || obj;\n this.path = opts.path || expr;\n this.resultType = (opts.resultType && opts.resultType.toLowerCase()) ||\n 'value';\n this.flatten = opts.flatten || false;\n this.wrap = hasOwnProp.call(opts, 'wrap') ? opts.wrap : true;\n this.sandbox = opts.sandbox || {};\n this.preventEval = opts.preventEval || false;\n this.parent = opts.parent || null;\n this.parentProperty = opts.parentProperty || null;\n this.callback = opts.callback || callback || null;\n this.otherTypeCallback = opts.otherTypeCallback ||\n otherTypeCallback ||\n function () {\n throw new TypeError(\n 'You must supply an otherTypeCallback callback option ' +\n 'with the @other() operator.'\n );\n };\n\n if (opts.autostart !== false) {\n const args = {\n path: (optObj ? opts.path : expr)\n };\n if (!optObj) {\n args.json = obj;\n } else if ('json' in opts) {\n args.json = opts.json;\n }\n const ret = this.evaluate(args);\n if (!ret || typeof ret !== 'object') {\n throw new NewError(ret);\n }\n return ret;\n }\n}\n\n// PUBLIC METHODS\nJSONPath.prototype.evaluate = function (\n expr, json, callback, otherTypeCallback\n) {\n const that = this;\n let currParent = this.parent,\n currParentProperty = this.parentProperty;\n let {flatten, wrap} = this;\n\n this.currResultType = this.resultType;\n this.currPreventEval = this.preventEval;\n this.currSandbox = this.sandbox;\n callback = callback || this.callback;\n this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback;\n\n json = json || this.json;\n expr = expr || this.path;\n if (expr && typeof expr === 'object') {\n if (!expr.path) {\n throw new TypeError(\n 'You must supply a \"path\" property when providing an object ' +\n 'argument to JSONPath.evaluate().'\n );\n }\n if (!('json' in expr)) {\n throw new TypeError(\n 'You must supply a \"json\" property when providing an object ' +\n 'argument to JSONPath.evaluate().'\n );\n }\n json = hasOwnProp.call(expr, 'json') ? expr.json : json;\n flatten = hasOwnProp.call(expr, 'flatten') ? expr.flatten : flatten;\n this.currResultType = hasOwnProp.call(expr, 'resultType')\n ? expr.resultType\n : this.currResultType;\n this.currSandbox = hasOwnProp.call(expr, 'sandbox')\n ? expr.sandbox\n : this.currSandbox;\n wrap = hasOwnProp.call(expr, 'wrap') ? expr.wrap : wrap;\n this.currPreventEval = hasOwnProp.call(expr, 'preventEval')\n ? expr.preventEval\n : this.currPreventEval;\n callback = hasOwnProp.call(expr, 'callback') ? expr.callback : callback;\n this.currOtherTypeCallback = hasOwnProp.call(expr, 'otherTypeCallback')\n ? expr.otherTypeCallback\n : this.currOtherTypeCallback;\n currParent = hasOwnProp.call(expr, 'parent') ? expr.parent : currParent;\n currParentProperty = hasOwnProp.call(expr, 'parentProperty')\n ? expr.parentProperty\n : currParentProperty;\n expr = expr.path;\n }\n currParent = currParent || null;\n currParentProperty = currParentProperty || null;\n\n if (Array.isArray(expr)) {\n expr = JSONPath.toPathString(expr);\n }\n if (!expr || !json || !allowedResultTypes.includes(this.currResultType)) {\n return undefined;\n }\n this._obj = json;\n\n const exprList = JSONPath.toPathArray(expr);\n if (exprList[0] === '$' && exprList.length > 1) { exprList.shift(); }\n this._hasParentSelector = null;\n const result = this\n ._trace(exprList, json, ['$'], currParent, currParentProperty, callback)\n .filter(function (ea) { return ea && !ea.isParentSelector; });\n\n if (!result.length) { return wrap ? [] : undefined; }\n if (result.length === 1 && !wrap && !Array.isArray(result[0].value)) {\n return this._getPreferredOutput(result[0]);\n }\n return result.reduce(function (rslt, ea) {\n const valOrPath = that._getPreferredOutput(ea);\n if (flatten && Array.isArray(valOrPath)) {\n rslt = rslt.concat(valOrPath);\n } else {\n rslt.push(valOrPath);\n }\n return rslt;\n }, []);\n};\n\n// PRIVATE METHODS\n\nJSONPath.prototype._getPreferredOutput = function (ea) {\n const resultType = this.currResultType;\n switch (resultType) {\n default:\n throw new TypeError('Unknown result type');\n case 'all':\n ea.pointer = JSONPath.toPointer(ea.path);\n ea.path = typeof ea.path === 'string'\n ? ea.path\n : JSONPath.toPathString(ea.path);\n return ea;\n case 'value': case 'parent': case 'parentProperty':\n return ea[resultType];\n case 'path':\n return JSONPath.toPathString(ea[resultType]);\n case 'pointer':\n return JSONPath.toPointer(ea.path);\n }\n};\n\nJSONPath.prototype._handleCallback = function (fullRetObj, callback, type) {\n if (callback) {\n const preferredOutput = this._getPreferredOutput(fullRetObj);\n fullRetObj.path = typeof fullRetObj.path === 'string'\n ? fullRetObj.path\n : JSONPath.toPathString(fullRetObj.path);\n // eslint-disable-next-line callback-return\n callback(preferredOutput, type, fullRetObj);\n }\n};\n\n/**\n *\n * @param {string} expr\n * @param {JSONObject} val\n * @param {string} path\n * @param {PlainObject|GenericArray} parent\n * @param {string} parentPropName\n * @param {JSONPathCallback} callback\n * @param {boolean} literalPriority\n * @returns {ReturnObject|ReturnObject[]}\n */\nJSONPath.prototype._trace = function (\n expr, val, path, parent, parentPropName, callback, literalPriority\n) {\n // No expr to follow? return path and value as the result of\n // this trace branch\n let retObj;\n const that = this;\n if (!expr.length) {\n retObj = {path, value: val, parent, parentProperty: parentPropName};\n this._handleCallback(retObj, callback, 'value');\n return retObj;\n }\n\n const loc = expr[0], x = expr.slice(1);\n\n // We need to gather the return value of recursive trace calls in order to\n // do the parent sel computation.\n const ret = [];\n /**\n *\n * @param {ReturnObject|ReturnObject[]} elems\n * @returns {void}\n */\n function addRet (elems) {\n if (Array.isArray(elems)) {\n // This was causing excessive stack size in Node (with or\n // without Babel) against our performance test:\n // `ret.push(...elems);`\n elems.forEach((t) => {\n ret.push(t);\n });\n } else {\n ret.push(elems);\n }\n }\n\n if ((typeof loc !== 'string' || literalPriority) && val &&\n hasOwnProp.call(val, loc)\n ) { // simple case--directly follow property\n addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback));\n } else if (loc === '*') { // all child properties\n this._walk(\n loc, x, val, path, parent, parentPropName, callback,\n function (m, l, _x, v, p, par, pr, cb) {\n addRet(that._trace(unshift(m, _x), v, p, par, pr, cb, true));\n }\n );\n } else if (loc === '..') { // all descendent parent properties\n // Check remaining expression with val's immediate children\n addRet(\n this._trace(x, val, path, parent, parentPropName, callback)\n );\n this._walk(\n loc, x, val, path, parent, parentPropName, callback,\n function (m, l, _x, v, p, par, pr, cb) {\n // We don't join m and x here because we only want parents,\n // not scalar values\n if (typeof v[m] === 'object') {\n // Keep going with recursive descent on val's\n // object children\n addRet(that._trace(\n unshift(l, _x), v[m], push(p, m), v, m, cb\n ));\n }\n }\n );\n // The parent sel computation is handled in the frame above using the\n // ancestor object of val\n } else if (loc === '^') {\n // This is not a final endpoint, so we do not invoke the callback here\n this._hasParentSelector = true;\n return path.length\n ? {\n path: path.slice(0, -1),\n expr: x,\n isParentSelector: true\n }\n : [];\n } else if (loc === '~') { // property name\n retObj = {\n path: push(path, loc),\n value: parentPropName,\n parent,\n parentProperty: null\n };\n this._handleCallback(retObj, callback, 'property');\n return retObj;\n } else if (loc === '$') { // root only\n addRet(this._trace(x, val, path, null, null, callback));\n } else if ((/^(-?\\d*):(-?\\d*):?(\\d*)$/u).test(loc)) { // [start:end:step] Python slice syntax\n addRet(\n this._slice(loc, x, val, path, parent, parentPropName, callback)\n );\n } else if (loc.indexOf('?(') === 0) { // [?(expr)] (filtering)\n if (this.currPreventEval) {\n throw new Error('Eval [?(expr)] prevented in JSONPath expression.');\n }\n this._walk(\n loc, x, val, path, parent, parentPropName, callback,\n function (m, l, _x, v, p, par, pr, cb) {\n if (that._eval(l.replace(/^\\?\\((.*?)\\)$/u, '$1'), v[m], m, p, par, pr)) {\n addRet(that._trace(unshift(m, _x), v, p, par, pr, cb));\n }\n }\n );\n } else if (loc[0] === '(') { // [(expr)] (dynamic property/index)\n if (this.currPreventEval) {\n throw new Error('Eval [(expr)] prevented in JSONPath expression.');\n }\n // As this will resolve to a property name (but we don't know it\n // yet), property and parent information is relative to the\n // parent of the property to which this expression will resolve\n addRet(this._trace(unshift(\n this._eval(\n loc, val, path[path.length - 1],\n path.slice(0, -1), parent, parentPropName\n ),\n x\n ), val, path, parent, parentPropName, callback));\n } else if (loc[0] === '@') { // value type: @boolean(), etc.\n let addType = false;\n const valueType = loc.slice(1, -2);\n switch (valueType) {\n default:\n throw new TypeError('Unknown value type ' + valueType);\n case 'scalar':\n if (!val || !(['object', 'function'].includes(typeof val))) {\n addType = true;\n }\n break;\n case 'boolean': case 'string': case 'undefined': case 'function':\n // eslint-disable-next-line valid-typeof\n if (typeof val === valueType) {\n addType = true;\n }\n break;\n case 'number':\n // eslint-disable-next-line valid-typeof\n if (typeof val === valueType && isFinite(val)) {\n addType = true;\n }\n break;\n case 'nonFinite':\n if (typeof val === 'number' && !isFinite(val)) {\n addType = true;\n }\n break;\n case 'object':\n // eslint-disable-next-line valid-typeof\n if (val && typeof val === valueType) {\n addType = true;\n }\n break;\n case 'array':\n if (Array.isArray(val)) {\n addType = true;\n }\n break;\n case 'other':\n addType = this.currOtherTypeCallback(\n val, path, parent, parentPropName\n );\n break;\n case 'integer':\n if (val === Number(val) && isFinite(val) && !(val % 1)) {\n addType = true;\n }\n break;\n case 'null':\n if (val === null) {\n addType = true;\n }\n break;\n }\n if (addType) {\n retObj = {path, value: val, parent, parentProperty: parentPropName};\n this._handleCallback(retObj, callback, 'value');\n return retObj;\n }\n // `-escaped property\n } else if (loc[0] === '`' && val && hasOwnProp.call(val, loc.slice(1))) {\n const locProp = loc.slice(1);\n addRet(this._trace(\n x, val[locProp], push(path, locProp), val, locProp, callback, true\n ));\n } else if (loc.includes(',')) { // [name1,name2,...]\n const parts = loc.split(',');\n for (const part of parts) {\n addRet(this._trace(\n unshift(part, x), val, path, parent, parentPropName, callback\n ));\n }\n // simple case--directly follow property\n } else if (!literalPriority && val && hasOwnProp.call(val, loc)) {\n addRet(\n this._trace(x, val[loc], push(path, loc), val, loc, callback, true)\n );\n }\n\n // We check the resulting values for parent selections. For parent\n // selections we discard the value object and continue the trace with the\n // current val object\n if (this._hasParentSelector) {\n for (let t = 0; t < ret.length; t++) {\n const rett = ret[t];\n if (rett.isParentSelector) {\n const tmp = that._trace(\n rett.expr, val, rett.path, parent, parentPropName, callback\n );\n if (Array.isArray(tmp)) {\n ret[t] = tmp[0];\n const tl = tmp.length;\n for (let tt = 1; tt < tl; tt++) {\n t++;\n ret.splice(t, 0, tmp[tt]);\n }\n } else {\n ret[t] = tmp;\n }\n }\n }\n }\n return ret;\n};\n\nJSONPath.prototype._walk = function (\n loc, expr, val, path, parent, parentPropName, callback, f\n) {\n if (Array.isArray(val)) {\n const n = val.length;\n for (let i = 0; i < n; i++) {\n f(i, loc, expr, val, path, parent, parentPropName, callback);\n }\n } else if (typeof val === 'object') {\n for (const m in val) {\n if (hasOwnProp.call(val, m)) {\n f(m, loc, expr, val, path, parent, parentPropName, callback);\n }\n }\n }\n};\n\nJSONPath.prototype._slice = function (\n loc, expr, val, path, parent, parentPropName, callback\n) {\n if (!Array.isArray(val)) { return undefined; }\n const len = val.length, parts = loc.split(':'),\n step = (parts[2] && parseInt(parts[2])) || 1;\n let start = (parts[0] && parseInt(parts[0])) || 0,\n end = (parts[1] && parseInt(parts[1])) || len;\n start = (start < 0) ? Math.max(0, start + len) : Math.min(len, start);\n end = (end < 0) ? Math.max(0, end + len) : Math.min(len, end);\n const ret = [];\n for (let i = start; i < end; i += step) {\n const tmp = this._trace(\n unshift(i, expr), val, path, parent, parentPropName, callback\n );\n if (Array.isArray(tmp)) {\n // This was causing excessive stack size in Node (with or\n // without Babel) against our performance test: `ret.push(...tmp);`\n tmp.forEach((t) => {\n ret.push(t);\n });\n } else {\n ret.push(tmp);\n }\n }\n return ret;\n};\n\nJSONPath.prototype._eval = function (\n code, _v, _vname, path, parent, parentPropName\n) {\n if (!this._obj || !_v) { return false; }\n if (code.includes('@parentProperty')) {\n this.currSandbox._$_parentProperty = parentPropName;\n code = code.replace(/@parentProperty/gu, '_$_parentProperty');\n }\n if (code.includes('@parent')) {\n this.currSandbox._$_parent = parent;\n code = code.replace(/@parent/gu, '_$_parent');\n }\n if (code.includes('@property')) {\n this.currSandbox._$_property = _vname;\n code = code.replace(/@property/gu, '_$_property');\n }\n if (code.includes('@path')) {\n this.currSandbox._$_path = JSONPath.toPathString(path.concat([_vname]));\n code = code.replace(/@path/gu, '_$_path');\n }\n if (code.includes('@root')) {\n this.currSandbox._$_root = this.json;\n code = code.replace(/@root/gu, '_$_root');\n }\n if (code.match(/@([.\\s)[])/u)) {\n this.currSandbox._$_v = _v;\n code = code.replace(/@([.\\s)[])/gu, '_$_v$1');\n }\n try {\n return vm.runInNewContext(code, this.currSandbox);\n } catch (e) {\n // eslint-disable-next-line no-console\n console.log(e);\n throw new Error('jsonPath: ' + e.message + ': ' + code);\n }\n};\n\n// PUBLIC CLASS PROPERTIES AND METHODS\n\n// Could store the cache object itself\nJSONPath.cache = {};\n\n/**\n * @param {string[]} pathArr Array to convert\n * @returns {string} The path string\n */\nJSONPath.toPathString = function (pathArr) {\n const x = pathArr, n = x.length;\n let p = '$';\n for (let i = 1; i < n; i++) {\n if (!(/^(~|\\^|@.*?\\(\\))$/u).test(x[i])) {\n p += (/^[0-9*]+$/u).test(x[i]) ? ('[' + x[i] + ']') : (\"['\" + x[i] + \"']\");\n }\n }\n return p;\n};\n\n/**\n * @param {string} pointer JSON Path\n * @returns {string} JSON Pointer\n */\nJSONPath.toPointer = function (pointer) {\n const x = pointer, n = x.length;\n let p = '';\n for (let i = 1; i < n; i++) {\n if (!(/^(~|\\^|@.*?\\(\\))$/u).test(x[i])) {\n p += '/' + x[i].toString()\n .replace(/~/gu, '~0')\n .replace(/\\//gu, '~1');\n }\n }\n return p;\n};\n\n/**\n * @param {string} expr Expression to convert\n * @returns {string[]}\n */\nJSONPath.toPathArray = function (expr) {\n const {cache} = JSONPath;\n if (cache[expr]) { return cache[expr].concat(); }\n const subx = [];\n const normalized = expr\n // Properties\n .replace(\n /@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\\(\\)/gu,\n ';$&;'\n )\n // Parenthetical evaluations (filtering and otherwise), directly\n // within brackets or single quotes\n .replace(/[['](\\??\\(.*?\\))[\\]']/gu, function ($0, $1) {\n return '[#' + (subx.push($1) - 1) + ']';\n })\n // Escape periods and tildes within properties\n .replace(/\\['([^'\\]]*)'\\]/gu, function ($0, prop) {\n return \"['\" + prop\n .replace(/\\./gu, '%@%')\n .replace(/~/gu, '%%@@%%') +\n \"']\";\n })\n // Properties operator\n .replace(/~/gu, ';~;')\n // Split by property boundaries\n .replace(/'?\\.'?(?![^[]*\\])|\\['?/gu, ';')\n // Reinsert periods within properties\n .replace(/%@%/gu, '.')\n // Reinsert tildes within properties\n .replace(/%%@@%%/gu, '~')\n // Parent\n .replace(/(?:;)?(\\^+)(?:;)?/gu, function ($0, ups) {\n return ';' + ups.split('').join(';') + ';';\n })\n // Descendents\n .replace(/;;;|;;/gu, ';..;')\n // Remove trailing\n .replace(/;$|'?\\]|'$/gu, '');\n\n const exprList = normalized.split(';').map(function (exp) {\n const match = exp.match(/#(\\d+)/u);\n return !match || !match[1] ? exp : subx[match[1]];\n });\n cache[expr] = exprList;\n return cache[expr];\n};\n\nexport {JSONPath};\n"],"names":["allowedResultTypes","hasOwnProp","Object","prototype","hasOwnProperty","vm","toString","call","global","process","e","supportsNodeVM","require","runInNewContext","expr","context","keys","funcs","source","target","conditionCb","il","length","i","push","splice","moveToAnotherArray","key","values","map","vr","reduce","s","func","fString","exec","match","includes","lastStatementEnd","replace","lastIndexOf","code","slice","_construct","Function","arr","item","unshift","NewError","value","avoidNew","name","Error","JSONPath","opts","obj","callback","otherTypeCallback","this","optObj","_typeof","json","path","resultType","toLowerCase","flatten","wrap","sandbox","preventEval","parent","parentProperty","TypeError","autostart","args","ret","evaluate","that","currParent","currParentProperty","currResultType","currPreventEval","currSandbox","currOtherTypeCallback","Array","isArray","toPathString","_obj","exprList","toPathArray","shift","_hasParentSelector","result","_trace","filter","ea","isParentSelector","rslt","valOrPath","_getPreferredOutput","concat","undefined","pointer","toPointer","_handleCallback","fullRetObj","type","preferredOutput","val","parentPropName","literalPriority","retObj","loc","x","addRet","elems","forEach","t","_walk","m","l","_x","v","p","par","pr","cb","test","_slice","indexOf","_eval","addType","valueType","isFinite","Number","locProp","parts","split","part","rett","tmp","tl","tt","f","n","len","step","parseInt","start","end","Math","max","min","_v","_vname","_$_parentProperty","_$_parent","_$_property","_$_path","_$_root","_$_v","console","log","message","cache","pathArr","subx","$0","$1","prop","ups","join","exp"],"mappings":"mkEAGA,IASMA,EAAqB,CACvB,QAAS,OAAQ,UAAW,SAAU,iBAAkB,OAErCC,EAAcC,OAAOC,UAArCC,eA8BDC,EA1CiB,qBAIT,qBAFCH,OAAOC,UAAUG,SAASC,KAC7BC,OAAOC,SAEb,MAAOC,UACE,GAoCJC,GACLC,QAAQ,MACR,CAOEC,yBAAiBC,EAAMC,OACbC,EAAOd,OAAOc,KAAKD,GACnBE,EAAQ,IArBC,SAAUC,EAAQC,EAAQC,WAC3CC,EAAKH,EAAOI,OACTC,EAAI,EAAGA,EAAIF,EAAIE,IAAK,CAErBH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A,QAAQ,KAAO,UAChB,QAGPA,QAAQ,KAAO,OAEfA,QAAQ,8JAA4B,KAEpCA,QAAQ,OAAS,KAEjBA,QAAQ,UAAY,KAEpBA,QAAQ,sBAAuB,SAAU+H,EAAIG,SACnC,IAAMA,EAAIjC,MAAM,IAAIkC,KAAK,KAAO,OAG1CnI,QAAQ,UAAY,QAEpBA,QAAQ,cAAgB,IAEDiG,MAAM,KAAK3G,KAAI,SAAU8I,OAC3CvI,EAAQuI,EAAIvI,MAAM,oBAChBA,GAAUA,EAAM,GAAWiI,EAAKjI,EAAM,IAAjBuI,YAEjCR,EAAMrJ,GAAQyE,EACP4E,EAAMrJ"} \ No newline at end of file +{"version":3,"file":"index-umd.min.js","sources":["../src/jsonpath.js"],"sourcesContent":["/* eslint-disable prefer-named-capture-group */\n// Disabled `prefer-named-capture-group` due to https://github.com/babel/babel/issues/8951#issuecomment-508045524\n// Only Node.JS has a process variable that is of [[Class]] process\nconst supportsNodeVM = function () {\n try {\n return Object.prototype.toString.call(\n global.process\n ) === '[object process]';\n } catch (e) {\n return false;\n }\n};\nconst allowedResultTypes = [\n 'value', 'path', 'pointer', 'parent', 'parentProperty', 'all'\n];\nconst {hasOwnProperty: hasOwnProp} = Object.prototype;\n\n/**\n* @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject\n*/\n\n/**\n* @callback ConditionCallback\n* @param item\n* @returns {boolean}\n*/\n\n/**\n * Copy items out of one array into another.\n * @param {GenericArray} source Array with items to copy\n * @param {GenericArray} target Array to which to copy\n * @param {ConditionCallback} conditionCb Callback passed the current item;\n * will move item if evaluates to `true`\n * @returns {undefined}\n */\nconst moveToAnotherArray = function (source, target, conditionCb) {\n const il = source.length;\n for (let i = 0; i < il; i++) {\n const item = source[i];\n if (conditionCb(item)) {\n target.push(source.splice(i--, 1)[0]);\n }\n }\n};\n\nconst vm = supportsNodeVM()\n ? require('vm')\n : {\n /**\n * @param {string} expr Expression to evaluate\n * @param {PlainObject} context Object whose items will be added\n * to evaluation\n * @returns {any} Result of evaluated code\n */\n runInNewContext (expr, context) {\n const keys = Object.keys(context);\n const funcs = [];\n moveToAnotherArray(keys, funcs, (key) => {\n return typeof context[key] === 'function';\n });\n // Todo[engine:node@>=8]: Use the next line instead of the\n // succeeding\n // const values = Object.values(context);\n const values = keys.map((vr, i) => {\n return context[vr];\n });\n const funcString = funcs.reduce((s, func) => {\n let fString = context[func].toString();\n if (!(/function/u).exec(fString)) {\n fString = 'function ' + fString;\n }\n return 'var ' + func + '=' + fString + ';' + s;\n }, '');\n\n expr = funcString + expr;\n\n // Mitigate http://perfectionkills.com/global-eval-what-are-the-options/#new_function\n if (!expr.match(/(['\"])use strict\\1/u) &&\n !keys.includes('arguments')\n ) {\n expr = 'var arguments = undefined;' + expr;\n }\n\n // Remove last semi so `return` will be inserted before\n // the previous one instead, allowing for the return\n // of a bare ending expression\n expr = expr.replace(/;\\s*$/u, '');\n\n // Insert `return`\n const lastStatementEnd = expr.lastIndexOf(';');\n const code = (lastStatementEnd > -1\n ? expr.slice(0, lastStatementEnd + 1) +\n ' return ' + expr.slice(lastStatementEnd + 1)\n : ' return ' + expr);\n\n // eslint-disable-next-line no-new-func\n return (new Function(...keys, code))(...values);\n }\n };\n\n/**\n * Copies array and then pushes item into it.\n * @param {GenericArray} arr Array to copy and into which to push\n * @param {any} item Array item to add (to end)\n * @returns {GenericArray} Copy of the original array\n */\nfunction push (arr, item) {\n arr = arr.slice();\n arr.push(item);\n return arr;\n}\n/**\n * Copies array and then unshifts item into it.\n * @param {any} item Array item to add (to beginning)\n * @param {GenericArray} arr Array to copy and into which to unshift\n * @returns {GenericArray} Copy of the original array\n */\nfunction unshift (item, arr) {\n arr = arr.slice();\n arr.unshift(item);\n return arr;\n}\n\n/**\n * Caught when JSONPath is used without `new` but rethrown if with `new`\n * @extends Error\n */\nclass NewError extends Error {\n /**\n * @param {any} value The evaluated scalar value\n */\n constructor (value) {\n super(\n 'JSONPath should not be called with \"new\" (it prevents return ' +\n 'of (unwrapped) scalar values)'\n );\n this.avoidNew = true;\n this.value = value;\n this.name = 'NewError';\n }\n}\n\n/**\n* @typedef {PlainObject} ReturnObject\n* @property {string} path\n* @property {JSONObject} value\n* @property {PlainObject|GenericArray} parent\n* @property {string} parentProperty\n*/\n\n/**\n* @callback JSONPathCallback\n* @param {string|PlainObject} preferredOutput\n* @param {\"value\"|\"property\"} type\n* @param {ReturnObject} fullRetObj\n* @returns {void}\n*/\n\n/**\n* @callback OtherTypeCallback\n* @param {JSONObject} val\n* @param {string} path\n* @param {PlainObject|GenericArray} parent\n* @param {string} parentPropName\n* @returns {boolean}\n*/\n\n/**\n * @typedef {PlainObject} JSONPathOptions\n * @property {JSON} json\n * @property {string|string[]} path\n * @property {\"value\"|\"path\"|\"pointer\"|\"parent\"|\"parentProperty\"|\"all\"}\n * [resultType=\"value\"]\n * @property {boolean} [flatten=false]\n * @property {boolean} [wrap=true]\n * @property {PlainObject} [sandbox={}]\n * @property {boolean} [preventEval=false]\n * @property {PlainObject|GenericArray|null} [parent=null]\n * @property {string|null} [parentProperty=null]\n * @property {JSONPathCallback} [callback]\n * @property {OtherTypeCallback} [otherTypeCallback] Defaults to\n * function which throws on encountering `@other`\n * @property {boolean} [autostart=true]\n */\n\n/**\n * @param {string|JSONPathOptions} opts If a string, will be treated as `expr`\n * @param {string} [expr] JSON path to evaluate\n * @param {JSON} [obj] JSON object to evaluate against\n * @param {JSONPathCallback} [callback] Passed 3 arguments: 1) desired payload\n * per `resultType`, 2) `\"value\"|\"property\"`, 3) Full returned object with\n * all payloads\n * @param {OtherTypeCallback} [otherTypeCallback] If `@other()` is at the end\n * of one's query, this will be invoked with the value of the item, its\n * path, its parent, and its parent's property name, and it should return\n * a boolean indicating whether the supplied value belongs to the \"other\"\n * type or not (or it may handle transformations and return `false`).\n * @returns {JSONPath}\n * @class\n */\nfunction JSONPath (opts, expr, obj, callback, otherTypeCallback) {\n // eslint-disable-next-line no-restricted-syntax\n if (!(this instanceof JSONPath)) {\n try {\n return new JSONPath(opts, expr, obj, callback, otherTypeCallback);\n } catch (e) {\n if (!e.avoidNew) {\n throw e;\n }\n return e.value;\n }\n }\n\n if (typeof opts === 'string') {\n otherTypeCallback = callback;\n callback = obj;\n obj = expr;\n expr = opts;\n opts = null;\n }\n const optObj = opts && typeof opts === 'object';\n opts = opts || {};\n this.json = opts.json || obj;\n this.path = opts.path || expr;\n this.resultType = (opts.resultType && opts.resultType.toLowerCase()) ||\n 'value';\n this.flatten = opts.flatten || false;\n this.wrap = hasOwnProp.call(opts, 'wrap') ? opts.wrap : true;\n this.sandbox = opts.sandbox || {};\n this.preventEval = opts.preventEval || false;\n this.parent = opts.parent || null;\n this.parentProperty = opts.parentProperty || null;\n this.callback = opts.callback || callback || null;\n this.otherTypeCallback = opts.otherTypeCallback ||\n otherTypeCallback ||\n function () {\n throw new TypeError(\n 'You must supply an otherTypeCallback callback option ' +\n 'with the @other() operator.'\n );\n };\n\n if (opts.autostart !== false) {\n const args = {\n path: (optObj ? opts.path : expr)\n };\n if (!optObj) {\n args.json = obj;\n } else if ('json' in opts) {\n args.json = opts.json;\n }\n const ret = this.evaluate(args);\n if (!ret || typeof ret !== 'object') {\n throw new NewError(ret);\n }\n return ret;\n }\n}\n\n// PUBLIC METHODS\nJSONPath.prototype.evaluate = function (\n expr, json, callback, otherTypeCallback\n) {\n const that = this;\n let currParent = this.parent,\n currParentProperty = this.parentProperty;\n let {flatten, wrap} = this;\n\n this.currResultType = this.resultType;\n this.currPreventEval = this.preventEval;\n this.currSandbox = this.sandbox;\n callback = callback || this.callback;\n this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback;\n\n json = json || this.json;\n expr = expr || this.path;\n if (expr && typeof expr === 'object') {\n if (!expr.path) {\n throw new TypeError(\n 'You must supply a \"path\" property when providing an object ' +\n 'argument to JSONPath.evaluate().'\n );\n }\n if (!('json' in expr)) {\n throw new TypeError(\n 'You must supply a \"json\" property when providing an object ' +\n 'argument to JSONPath.evaluate().'\n );\n }\n json = hasOwnProp.call(expr, 'json') ? expr.json : json;\n flatten = hasOwnProp.call(expr, 'flatten') ? expr.flatten : flatten;\n this.currResultType = hasOwnProp.call(expr, 'resultType')\n ? expr.resultType\n : this.currResultType;\n this.currSandbox = hasOwnProp.call(expr, 'sandbox')\n ? expr.sandbox\n : this.currSandbox;\n wrap = hasOwnProp.call(expr, 'wrap') ? expr.wrap : wrap;\n this.currPreventEval = hasOwnProp.call(expr, 'preventEval')\n ? expr.preventEval\n : this.currPreventEval;\n callback = hasOwnProp.call(expr, 'callback') ? expr.callback : callback;\n this.currOtherTypeCallback = hasOwnProp.call(expr, 'otherTypeCallback')\n ? expr.otherTypeCallback\n : this.currOtherTypeCallback;\n currParent = hasOwnProp.call(expr, 'parent') ? expr.parent : currParent;\n currParentProperty = hasOwnProp.call(expr, 'parentProperty')\n ? expr.parentProperty\n : currParentProperty;\n expr = expr.path;\n }\n currParent = currParent || null;\n currParentProperty = currParentProperty || null;\n\n if (Array.isArray(expr)) {\n expr = JSONPath.toPathString(expr);\n }\n if (!expr || !json || !allowedResultTypes.includes(this.currResultType)) {\n return undefined;\n }\n this._obj = json;\n\n const exprList = JSONPath.toPathArray(expr);\n if (exprList[0] === '$' && exprList.length > 1) { exprList.shift(); }\n this._hasParentSelector = null;\n const result = this\n ._trace(exprList, json, ['$'], currParent, currParentProperty, callback)\n .filter(function (ea) { return ea && !ea.isParentSelector; });\n\n if (!result.length) { return wrap ? [] : undefined; }\n if (!wrap && result.length === 1 && !result[0].hasArrExpr) {\n return this._getPreferredOutput(result[0]);\n }\n return result.reduce(function (rslt, ea) {\n const valOrPath = that._getPreferredOutput(ea);\n if (flatten && Array.isArray(valOrPath)) {\n rslt = rslt.concat(valOrPath);\n } else {\n rslt.push(valOrPath);\n }\n return rslt;\n }, []);\n};\n\n// PRIVATE METHODS\n\nJSONPath.prototype._getPreferredOutput = function (ea) {\n const resultType = this.currResultType;\n switch (resultType) {\n default:\n throw new TypeError('Unknown result type');\n case 'all':\n ea.pointer = JSONPath.toPointer(ea.path);\n ea.path = typeof ea.path === 'string'\n ? ea.path\n : JSONPath.toPathString(ea.path);\n return ea;\n case 'value': case 'parent': case 'parentProperty':\n return ea[resultType];\n case 'path':\n return JSONPath.toPathString(ea[resultType]);\n case 'pointer':\n return JSONPath.toPointer(ea.path);\n }\n};\n\nJSONPath.prototype._handleCallback = function (fullRetObj, callback, type) {\n if (callback) {\n const preferredOutput = this._getPreferredOutput(fullRetObj);\n fullRetObj.path = typeof fullRetObj.path === 'string'\n ? fullRetObj.path\n : JSONPath.toPathString(fullRetObj.path);\n // eslint-disable-next-line callback-return\n callback(preferredOutput, type, fullRetObj);\n }\n};\n\n/**\n *\n * @param {string} expr\n * @param {JSONObject} val\n * @param {string} path\n * @param {PlainObject|GenericArray} parent\n * @param {string} parentPropName\n * @param {JSONPathCallback} callback\n * @param {boolean} literalPriority\n * @param {boolean} hasArrExpr\n * @returns {ReturnObject|ReturnObject[]}\n */\nJSONPath.prototype._trace = function (\n expr, val, path, parent, parentPropName, callback, hasArrExpr, literalPriority\n) {\n // No expr to follow? return path and value as the result of\n // this trace branch\n let retObj;\n const that = this;\n if (!expr.length) {\n retObj = {path, value: val, parent, parentProperty: parentPropName, hasArrExpr};\n this._handleCallback(retObj, callback, 'value');\n return retObj;\n }\n\n const loc = expr[0], x = expr.slice(1);\n\n // We need to gather the return value of recursive trace calls in order to\n // do the parent sel computation.\n const ret = [];\n /**\n *\n * @param {ReturnObject|ReturnObject[]} elems\n * @returns {void}\n */\n function addRet (elems) {\n if (Array.isArray(elems)) {\n // This was causing excessive stack size in Node (with or\n // without Babel) against our performance test:\n // `ret.push(...elems);`\n elems.forEach((t) => {\n ret.push(t);\n });\n } else {\n ret.push(elems);\n }\n }\n if ((typeof loc !== 'string' || literalPriority) && val &&\n hasOwnProp.call(val, loc)\n ) { // simple case--directly follow property\n addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr));\n } else if (loc === '*') { // all child properties\n this._walk(\n loc, x, val, path, parent, parentPropName, callback,\n function (m, l, _x, v, p, par, pr, cb) {\n addRet(that._trace(unshift(m, _x), v, p, par, pr, cb, true, true));\n }\n );\n } else if (loc === '..') { // all descendent parent properties\n // Check remaining expression with val's immediate children\n addRet(\n this._trace(x, val, path, parent, parentPropName, callback, hasArrExpr)\n );\n this._walk(\n loc, x, val, path, parent, parentPropName, callback,\n function (m, l, _x, v, p, par, pr, cb) {\n // We don't join m and x here because we only want parents,\n // not scalar values\n if (typeof v[m] === 'object') {\n // Keep going with recursive descent on val's\n // object children\n addRet(that._trace(\n unshift(l, _x), v[m], push(p, m), v, m, cb, true\n ));\n }\n }\n );\n // The parent sel computation is handled in the frame above using the\n // ancestor object of val\n } else if (loc === '^') {\n // This is not a final endpoint, so we do not invoke the callback here\n this._hasParentSelector = true;\n return path.length\n ? {\n path: path.slice(0, -1),\n expr: x,\n isParentSelector: true\n }\n : [];\n } else if (loc === '~') { // property name\n retObj = {\n path: push(path, loc),\n value: parentPropName,\n parent,\n parentProperty: null\n };\n this._handleCallback(retObj, callback, 'property');\n return retObj;\n } else if (loc === '$') { // root only\n addRet(this._trace(x, val, path, null, null, callback, hasArrExpr));\n } else if ((/^(-?\\d*):(-?\\d*):?(\\d*)$/u).test(loc)) { // [start:end:step] Python slice syntax\n addRet(\n this._slice(loc, x, val, path, parent, parentPropName, callback)\n );\n } else if (loc.indexOf('?(') === 0) { // [?(expr)] (filtering)\n if (this.currPreventEval) {\n throw new Error('Eval [?(expr)] prevented in JSONPath expression.');\n }\n this._walk(\n loc, x, val, path, parent, parentPropName, callback,\n function (m, l, _x, v, p, par, pr, cb) {\n if (that._eval(l.replace(/^\\?\\((.*?)\\)$/u, '$1'), v[m], m, p, par, pr)) {\n addRet(that._trace(unshift(m, _x), v, p, par, pr, cb, true));\n }\n }\n );\n } else if (loc[0] === '(') { // [(expr)] (dynamic property/index)\n if (this.currPreventEval) {\n throw new Error('Eval [(expr)] prevented in JSONPath expression.');\n }\n // As this will resolve to a property name (but we don't know it\n // yet), property and parent information is relative to the\n // parent of the property to which this expression will resolve\n addRet(this._trace(unshift(\n this._eval(\n loc, val, path[path.length - 1],\n path.slice(0, -1), parent, parentPropName\n ),\n x\n ), val, path, parent, parentPropName, callback, hasArrExpr));\n } else if (loc[0] === '@') { // value type: @boolean(), etc.\n let addType = false;\n const valueType = loc.slice(1, -2);\n switch (valueType) {\n default:\n throw new TypeError('Unknown value type ' + valueType);\n case 'scalar':\n if (!val || !(['object', 'function'].includes(typeof val))) {\n addType = true;\n }\n break;\n case 'boolean': case 'string': case 'undefined': case 'function':\n // eslint-disable-next-line valid-typeof\n if (typeof val === valueType) {\n addType = true;\n }\n break;\n case 'number':\n // eslint-disable-next-line valid-typeof\n if (typeof val === valueType && isFinite(val)) {\n addType = true;\n }\n break;\n case 'nonFinite':\n if (typeof val === 'number' && !isFinite(val)) {\n addType = true;\n }\n break;\n case 'object':\n // eslint-disable-next-line valid-typeof\n if (val && typeof val === valueType) {\n addType = true;\n }\n break;\n case 'array':\n if (Array.isArray(val)) {\n addType = true;\n }\n break;\n case 'other':\n addType = this.currOtherTypeCallback(\n val, path, parent, parentPropName\n );\n break;\n case 'integer':\n if (val === Number(val) && isFinite(val) && !(val % 1)) {\n addType = true;\n }\n break;\n case 'null':\n if (val === null) {\n addType = true;\n }\n break;\n }\n if (addType) {\n retObj = {path, value: val, parent, parentProperty: parentPropName};\n this._handleCallback(retObj, callback, 'value');\n return retObj;\n }\n // `-escaped property\n } else if (loc[0] === '`' && val && hasOwnProp.call(val, loc.slice(1))) {\n const locProp = loc.slice(1);\n addRet(this._trace(\n x, val[locProp], push(path, locProp), val, locProp, callback, hasArrExpr, true\n ));\n } else if (loc.includes(',')) { // [name1,name2,...]\n const parts = loc.split(',');\n for (const part of parts) {\n addRet(this._trace(\n unshift(part, x), val, path, parent, parentPropName, callback, true\n ));\n }\n // simple case--directly follow property\n } else if (!literalPriority && val && hasOwnProp.call(val, loc)) {\n addRet(\n this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr, true)\n );\n }\n\n // We check the resulting values for parent selections. For parent\n // selections we discard the value object and continue the trace with the\n // current val object\n if (this._hasParentSelector) {\n for (let t = 0; t < ret.length; t++) {\n const rett = ret[t];\n if (rett.isParentSelector) {\n const tmp = that._trace(\n rett.expr, val, rett.path, parent, parentPropName, callback, hasArrExpr\n );\n if (Array.isArray(tmp)) {\n ret[t] = tmp[0];\n const tl = tmp.length;\n for (let tt = 1; tt < tl; tt++) {\n t++;\n ret.splice(t, 0, tmp[tt]);\n }\n } else {\n ret[t] = tmp;\n }\n }\n }\n }\n return ret;\n};\n\nJSONPath.prototype._walk = function (\n loc, expr, val, path, parent, parentPropName, callback, f\n) {\n if (Array.isArray(val)) {\n const n = val.length;\n for (let i = 0; i < n; i++) {\n f(i, loc, expr, val, path, parent, parentPropName, callback);\n }\n } else if (typeof val === 'object') {\n for (const m in val) {\n if (hasOwnProp.call(val, m)) {\n f(m, loc, expr, val, path, parent, parentPropName, callback);\n }\n }\n }\n};\n\nJSONPath.prototype._slice = function (\n loc, expr, val, path, parent, parentPropName, callback\n) {\n if (!Array.isArray(val)) { return undefined; }\n const len = val.length, parts = loc.split(':'),\n step = (parts[2] && parseInt(parts[2])) || 1;\n let start = (parts[0] && parseInt(parts[0])) || 0,\n end = (parts[1] && parseInt(parts[1])) || len;\n start = (start < 0) ? Math.max(0, start + len) : Math.min(len, start);\n end = (end < 0) ? Math.max(0, end + len) : Math.min(len, end);\n const ret = [];\n for (let i = start; i < end; i += step) {\n const tmp = this._trace(\n unshift(i, expr), val, path, parent, parentPropName, callback, true\n );\n if (Array.isArray(tmp)) {\n // This was causing excessive stack size in Node (with or\n // without Babel) against our performance test: `ret.push(...tmp);`\n tmp.forEach((t) => {\n ret.push(t);\n });\n } else {\n ret.push(tmp);\n }\n }\n return ret;\n};\n\nJSONPath.prototype._eval = function (\n code, _v, _vname, path, parent, parentPropName\n) {\n if (!this._obj || !_v) { return false; }\n if (code.includes('@parentProperty')) {\n this.currSandbox._$_parentProperty = parentPropName;\n code = code.replace(/@parentProperty/gu, '_$_parentProperty');\n }\n if (code.includes('@parent')) {\n this.currSandbox._$_parent = parent;\n code = code.replace(/@parent/gu, '_$_parent');\n }\n if (code.includes('@property')) {\n this.currSandbox._$_property = _vname;\n code = code.replace(/@property/gu, '_$_property');\n }\n if (code.includes('@path')) {\n this.currSandbox._$_path = JSONPath.toPathString(path.concat([_vname]));\n code = code.replace(/@path/gu, '_$_path');\n }\n if (code.includes('@root')) {\n this.currSandbox._$_root = this.json;\n code = code.replace(/@root/gu, '_$_root');\n }\n if (code.match(/@([.\\s)[])/u)) {\n this.currSandbox._$_v = _v;\n code = code.replace(/@([.\\s)[])/gu, '_$_v$1');\n }\n try {\n return vm.runInNewContext(code, this.currSandbox);\n } catch (e) {\n // eslint-disable-next-line no-console\n console.log(e);\n throw new Error('jsonPath: ' + e.message + ': ' + code);\n }\n};\n\n// PUBLIC CLASS PROPERTIES AND METHODS\n\n// Could store the cache object itself\nJSONPath.cache = {};\n\n/**\n * @param {string[]} pathArr Array to convert\n * @returns {string} The path string\n */\nJSONPath.toPathString = function (pathArr) {\n const x = pathArr, n = x.length;\n let p = '$';\n for (let i = 1; i < n; i++) {\n if (!(/^(~|\\^|@.*?\\(\\))$/u).test(x[i])) {\n p += (/^[0-9*]+$/u).test(x[i]) ? ('[' + x[i] + ']') : (\"['\" + x[i] + \"']\");\n }\n }\n return p;\n};\n\n/**\n * @param {string} pointer JSON Path\n * @returns {string} JSON Pointer\n */\nJSONPath.toPointer = function (pointer) {\n const x = pointer, n = x.length;\n let p = '';\n for (let i = 1; i < n; i++) {\n if (!(/^(~|\\^|@.*?\\(\\))$/u).test(x[i])) {\n p += '/' + x[i].toString()\n .replace(/~/gu, '~0')\n .replace(/\\//gu, '~1');\n }\n }\n return p;\n};\n\n/**\n * @param {string} expr Expression to convert\n * @returns {string[]}\n */\nJSONPath.toPathArray = function (expr) {\n const {cache} = JSONPath;\n if (cache[expr]) { return cache[expr].concat(); }\n const subx = [];\n const normalized = expr\n // Properties\n .replace(\n /@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\\(\\)/gu,\n ';$&;'\n )\n // Parenthetical evaluations (filtering and otherwise), directly\n // within brackets or single quotes\n .replace(/[['](\\??\\(.*?\\))[\\]']/gu, function ($0, $1) {\n return '[#' + (subx.push($1) - 1) + ']';\n })\n // Escape periods and tildes within properties\n .replace(/\\['([^'\\]]*)'\\]/gu, function ($0, prop) {\n return \"['\" + prop\n .replace(/\\./gu, '%@%')\n .replace(/~/gu, '%%@@%%') +\n \"']\";\n })\n // Properties operator\n .replace(/~/gu, ';~;')\n // Split by property boundaries\n .replace(/'?\\.'?(?![^[]*\\])|\\['?/gu, ';')\n // Reinsert periods within properties\n .replace(/%@%/gu, '.')\n // Reinsert tildes within properties\n .replace(/%%@@%%/gu, '~')\n // Parent\n .replace(/(?:;)?(\\^+)(?:;)?/gu, function ($0, ups) {\n return ';' + ups.split('').join(';') + ';';\n })\n // Descendents\n .replace(/;;;|;;/gu, ';..;')\n // Remove trailing\n .replace(/;$|'?\\]|'$/gu, '');\n\n const exprList = normalized.split(';').map(function (exp) {\n const match = exp.match(/#(\\d+)/u);\n return !match || !match[1] ? exp : subx[match[1]];\n });\n cache[expr] = exprList;\n return cache[expr];\n};\n\nexport {JSONPath};\n"],"names":["allowedResultTypes","hasOwnProp","Object","prototype","hasOwnProperty","vm","toString","call","global","process","e","supportsNodeVM","require","runInNewContext","expr","context","keys","funcs","source","target","conditionCb","il","length","i","push","splice","moveToAnotherArray","key","values","map","vr","reduce","s","func","fString","exec","match","includes","lastStatementEnd","replace","lastIndexOf","code","slice","_construct","Function","arr","item","unshift","NewError","value","avoidNew","name","Error","JSONPath","opts","obj","callback","otherTypeCallback","this","optObj","_typeof","json","path","resultType","toLowerCase","flatten","wrap","sandbox","preventEval","parent","parentProperty","TypeError","autostart","args","ret","evaluate","that","currParent","currParentProperty","currResultType","currPreventEval","currSandbox","currOtherTypeCallback","Array","isArray","toPathString","_obj","exprList","toPathArray","shift","_hasParentSelector","result","_trace","filter","ea","isParentSelector","hasArrExpr","rslt","valOrPath","_getPreferredOutput","concat","undefined","pointer","toPointer","_handleCallback","fullRetObj","type","preferredOutput","val","parentPropName","literalPriority","retObj","loc","x","addRet","elems","forEach","t","_walk","m","l","_x","v","p","par","pr","cb","test","_slice","indexOf","_eval","addType","valueType","isFinite","Number","locProp","parts","split","part","rett","tmp","tl","tt","f","n","len","step","parseInt","start","end","Math","max","min","_v","_vname","_$_parentProperty","_$_parent","_$_property","_$_path","_$_root","_$_v","console","log","message","cache","pathArr","subx","$0","$1","prop","ups","join","exp"],"mappings":"mkEAGA,IASMA,EAAqB,CACvB,QAAS,OAAQ,UAAW,SAAU,iBAAkB,OAErCC,EAAcC,OAAOC,UAArCC,eA8BDC,EA1CiB,qBAIT,qBAFCH,OAAOC,UAAUG,SAASC,KAC7BC,OAAOC,SAEb,MAAOC,UACE,GAoCJC,GACLC,QAAQ,MACR,CAOEC,yBAAiBC,EAAMC,OACbC,EAAOd,OAAOc,KAAKD,GACnBE,EAAQ,IArBC,SAAUC,EAAQC,EAAQC,WAC3CC,EAAKH,EAAOI,OACTC,EAAI,EAAGA,EAAIF,EAAIE,IAAK,CAErBH,EADSF,EAAOK,KAEhBJ,EAAOK,KAAKN,EAAOO,OAAOF,IAAK,GAAG,KAiBlCG,CAAmBV,EAAMC,GAAO,SAACU,SACE,mBAAjBZ,EAAQY,UAKpBC,EAASZ,EAAKa,KAAI,SAACC,EAAIP,UAClBR,EAAQe,OAUnBhB,EARmBG,EAAMc,QAAO,SAACC,EAAGC,OAC5BC,EAAUnB,EAAQkB,GAAM3B,iBACtB,WAAa6B,KAAKD,KACpBA,EAAU,YAAcA,GAErB,OAASD,EAAO,IAAMC,EAAU,IAAMF,IAC9C,IAEiBlB,GAGVsB,MAAM,uBACXpB,EAAKqB,SAAS,eAEfvB,EAAO,6BAA+BA,OASpCwB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,GAAWkI,EAAKlI,EAAM,IAAjBwI,YAEjCR,EAAMtJ,GAAQyE,EACP6E,EAAMtJ"} \ No newline at end of file diff --git a/src/jsonpath.js b/src/jsonpath.js index 168fb23..6e3e98d 100644 --- a/src/jsonpath.js +++ b/src/jsonpath.js @@ -328,7 +328,7 @@ JSONPath.prototype.evaluate = function ( .filter(function (ea) { return ea && !ea.isParentSelector; }); if (!result.length) { return wrap ? [] : undefined; } - if (result.length === 1 && !wrap && !Array.isArray(result[0].value)) { + if (!wrap && result.length === 1 && !result[0].hasArrExpr) { return this._getPreferredOutput(result[0]); } return result.reduce(function (rslt, ea) { @@ -383,18 +383,26 @@ JSONPath.prototype._handleCallback = function (fullRetObj, callback, type) { * @param {PlainObject|GenericArray} parent * @param {string} parentPropName * @param {JSONPathCallback} callback + * @param {boolean} hasArrExpr * @param {boolean} literalPriority * @returns {ReturnObject|ReturnObject[]} */ JSONPath.prototype._trace = function ( - expr, val, path, parent, parentPropName, callback, literalPriority + expr, val, path, parent, parentPropName, callback, hasArrExpr, + literalPriority ) { // No expr to follow? return path and value as the result of // this trace branch let retObj; const that = this; if (!expr.length) { - retObj = {path, value: val, parent, parentProperty: parentPropName}; + retObj = { + path, + value: val, + parent, + parentProperty: parentPropName, + hasArrExpr + }; this._handleCallback(retObj, callback, 'value'); return retObj; } @@ -421,22 +429,24 @@ JSONPath.prototype._trace = function ( ret.push(elems); } } - if ((typeof loc !== 'string' || literalPriority) && val && hasOwnProp.call(val, loc) ) { // simple case--directly follow property - addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback)); + addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, + hasArrExpr)); } else if (loc === '*') { // all child properties this._walk( loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) { - addRet(that._trace(unshift(m, _x), v, p, par, pr, cb, true)); + addRet(that._trace(unshift(m, _x), v, p, par, pr, cb, + true, true)); } ); } else if (loc === '..') { // all descendent parent properties // Check remaining expression with val's immediate children addRet( - this._trace(x, val, path, parent, parentPropName, callback) + this._trace(x, val, path, parent, parentPropName, callback, + hasArrExpr) ); this._walk( loc, x, val, path, parent, parentPropName, callback, @@ -447,7 +457,7 @@ JSONPath.prototype._trace = function ( // Keep going with recursive descent on val's // object children addRet(that._trace( - unshift(l, _x), v[m], push(p, m), v, m, cb + unshift(l, _x), v[m], push(p, m), v, m, cb, true )); } } @@ -474,7 +484,7 @@ JSONPath.prototype._trace = function ( this._handleCallback(retObj, callback, 'property'); return retObj; } else if (loc === '$') { // root only - addRet(this._trace(x, val, path, null, null, callback)); + addRet(this._trace(x, val, path, null, null, callback, hasArrExpr)); } else if ((/^(-?\d*):(-?\d*):?(\d*)$/u).test(loc)) { // [start:end:step] Python slice syntax addRet( this._slice(loc, x, val, path, parent, parentPropName, callback) @@ -487,7 +497,8 @@ JSONPath.prototype._trace = function ( loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) { if (that._eval(l.replace(/^\?\((.*?)\)$/u, '$1'), v[m], m, p, par, pr)) { - addRet(that._trace(unshift(m, _x), v, p, par, pr, cb)); + addRet(that._trace(unshift(m, _x), v, p, par, pr, cb, + true)); } } ); @@ -504,7 +515,7 @@ JSONPath.prototype._trace = function ( path.slice(0, -1), parent, parentPropName ), x - ), val, path, parent, parentPropName, callback)); + ), val, path, parent, parentPropName, callback, hasArrExpr)); } else if (loc[0] === '@') { // value type: @boolean(), etc. let addType = false; const valueType = loc.slice(1, -2); @@ -569,19 +580,22 @@ JSONPath.prototype._trace = function ( } else if (loc[0] === '`' && val && hasOwnProp.call(val, loc.slice(1))) { const locProp = loc.slice(1); addRet(this._trace( - x, val[locProp], push(path, locProp), val, locProp, callback, true + x, val[locProp], push(path, locProp), val, locProp, callback, + hasArrExpr, true )); } else if (loc.includes(',')) { // [name1,name2,...] const parts = loc.split(','); for (const part of parts) { addRet(this._trace( - unshift(part, x), val, path, parent, parentPropName, callback + unshift(part, x), val, path, parent, parentPropName, callback, + true )); } // simple case--directly follow property } else if (!literalPriority && val && hasOwnProp.call(val, loc)) { addRet( - this._trace(x, val[loc], push(path, loc), val, loc, callback, true) + this._trace(x, val[loc], push(path, loc), val, loc, callback, + hasArrExpr, true) ); } @@ -593,7 +607,8 @@ JSONPath.prototype._trace = function ( const rett = ret[t]; if (rett.isParentSelector) { const tmp = that._trace( - rett.expr, val, rett.path, parent, parentPropName, callback + rett.expr, val, rett.path, parent, parentPropName, callback, + hasArrExpr ); if (Array.isArray(tmp)) { ret[t] = tmp[0]; @@ -641,7 +656,7 @@ JSONPath.prototype._slice = function ( const ret = []; for (let i = start; i < end; i += step) { const tmp = this._trace( - unshift(i, expr), val, path, parent, parentPropName, callback + unshift(i, expr), val, path, parent, parentPropName, callback, true ); if (Array.isArray(tmp)) { // This was causing excessive stack size in Node (with or diff --git a/test/test.all.js b/test/test.all.js index 911be92..7ea8a55 100644 --- a/test/test.all.js +++ b/test/test.all.js @@ -12,24 +12,24 @@ describe('JSONPath - All', function () { it('simple parent selection, return both path and value', () => { const result = jsonpath({json, path: '$.children[0]^', resultType: 'all'}); - assert.deepEqual([{path: "$['children']", value: json.children, parent: json, parentProperty: 'children', pointer: '/children'}], result); + assert.deepEqual([{path: "$['children']", value: json.children, parent: json, parentProperty: 'children', pointer: '/children', hasArrExpr: undefined}], result); }); it('parent selection with multiple matches, return both path and value', () => { - const expectedOne = {path: "$['children']", value: json.children, parent: json, parentProperty: 'children', pointer: '/children'}; + const expectedOne = {path: "$['children']", value: json.children, parent: json, parentProperty: 'children', pointer: '/children', hasArrExpr: true}; const expected = [expectedOne, expectedOne]; const result = jsonpath({json, path: '$.children[1:3]^', resultType: 'all'}); assert.deepEqual(expected, result); }); it('select sibling via parent, return both path and value', () => { - const expected = [{path: "$['children'][2]['children'][1]", value: {name: 'child3_2'}, parent: json.children[2].children, parentProperty: 1, pointer: '/children/2/children/1'}]; + const expected = [{path: "$['children'][2]['children'][1]", value: {name: 'child3_2'}, parent: json.children[2].children, parentProperty: 1, pointer: '/children/2/children/1', hasArrExpr: true}]; const result = jsonpath({json, path: '$..[?(@.name && @.name.match(/3_1$/))]^[?(@.name.match(/_2$/))]', resultType: 'all'}); assert.deepEqual(expected, result); }); it('parent parent parent, return both path and value', () => { - const expected = [{path: "$['children'][0]['children']", value: json.children[0].children, parent: json.children[0], parentProperty: 'children', pointer: '/children/0/children'}]; + const expected = [{path: "$['children'][0]['children']", value: json.children[0].children, parent: json.children[0], parentProperty: 'children', pointer: '/children/0/children', hasArrExpr: true}]; const result = jsonpath({json, path: '$..[?(@.name && @.name.match(/1_1$/))].name^^', resultType: 'all'}); assert.deepEqual(expected, result); }); diff --git a/test/test.arr.js b/test/test.arr.js index 2909fea..57476e4 100644 --- a/test/test.arr.js +++ b/test/test.arr.js @@ -29,4 +29,30 @@ describe('JSONPath - Array', function () { const result = jsonpath({json, path: 'store.books', flatten: true, wrap: false}); assert.deepEqual(expected, result); }); + + it('query single element arr w/scalar value', () => { + const expected = [json.store.books[0].author]; + const result = jsonpath({json, path: 'store.books[*].author', wrap: false}); + assert.deepEqual(expected, result); + }); + + it('query single element arr w/array value', () => { + const authors = ['Dickens', 'Lancaster']; + const input = { + books: [{authors}] + }; + const expected = authors; + const result = jsonpath({json: input, path: '$.books[0].authors', wrap: false}); + assert.deepEqual(expected, result); + }); + + it('query multi element arr w/array value', () => { + const authors = ['Dickens', 'Lancaster']; + const input = { + books: [{authors}, {authors}] + }; + const expected = [authors, authors]; + const result = jsonpath({json: input, path: '$.books[*].authors', wrap: false}); + assert.deepEqual(expected, result); + }); }); diff --git a/test/test.callback.js b/test/test.callback.js index 6ef67ac..5a3ed8d 100644 --- a/test/test.callback.js +++ b/test/test.callback.js @@ -37,7 +37,7 @@ describe('JSONPath - Callback', function () { }; it('Callback', () => { - const expected = ['value', json.store.bicycle, {path: "$['store']['bicycle']", value: json.store.bicycle, parent: json.store, parentProperty: 'bicycle'}]; + const expected = ['value', json.store.bicycle, {path: "$['store']['bicycle']", value: json.store.bicycle, parent: json.store, parentProperty: 'bicycle', hasArrExpr: undefined}]; let result; /** * diff --git a/test/test.eval.js b/test/test.eval.js index b32d829..74b0c0d 100644 --- a/test/test.eval.js +++ b/test/test.eval.js @@ -25,7 +25,7 @@ describe('JSONPath - Eval', function () { }; it('multi statement eval', () => { - const expected = json.store.books[0]; + const expected = [json.store.books[0]]; const selector = '$..[?(' + 'var sum = @.price && @.price[0]+@.price[1];' + 'sum > 20;)]'; @@ -34,13 +34,13 @@ describe('JSONPath - Eval', function () { }); it('accessing current path', () => { - const expected = json.store.books[1]; + const expected = [json.store.books[1]]; const result = jsonpath({json, path: "$..[?(@path==\"$['store']['books'][1]\")]", wrap: false}); assert.deepEqual(expected, result); }); it('sandbox', () => { - const expected = json.store.book; + const expected = [json.store.book]; const result = jsonpath({ json, sandbox: {category: 'reference'}, @@ -50,7 +50,7 @@ describe('JSONPath - Eval', function () { }); it('sandbox (with parsing function)', () => { - const expected = json.store.book; + const expected = [json.store.book]; const result = jsonpath({ json, sandbox: { diff --git a/test/test.examples.js b/test/test.examples.js index 6f5b6a3..b1bfa94 100644 --- a/test/test.examples.js +++ b/test/test.examples.js @@ -93,6 +93,17 @@ describe('JSONPath - Examples', function () { assert.deepEqual(expected, result); }); + it('range of property of entire tree w/ single element result', () => { + const book = json.store.book[0]; + const input = {books: [book]}; + const expected = [book]; + let result = jsonpath({json: input, path: '$.books[0,1]', wrap: false}); + assert.deepEqual(expected, result); + + result = jsonpath({json: input, path: '$.books[:1]', wrap: false}); + assert.deepEqual(expected, result); + }); + it('categories and authors of all books', () => { const expected = ['reference', 'Nigel Rees']; const result = jsonpath({json, path: '$..book[0][category,author]'}); @@ -106,6 +117,14 @@ describe('JSONPath - Examples', function () { assert.deepEqual(expected, result); }); + it('filter all properties if sub property exists, of single element array', () => { + const book = json.store.book[3]; + const input = {books: [book]}; + const expected = [book]; + const result = jsonpath({json: input, path: '$.books[?(@.isbn)]', wrap: false}); + assert.deepEqual(expected, result); + }); + it('filter all properties if sub property greater than of entire tree', () => { const books = json.store.book; const expected = [books[0], books[2]]; diff --git a/test/test.intermixed.arr.js b/test/test.intermixed.arr.js index dd0ce62..e38ce1a 100644 --- a/test/test.intermixed.arr.js +++ b/test/test.intermixed.arr.js @@ -46,4 +46,12 @@ describe('JSONPath - Intermixed Array', function () { const result = jsonpath({json, path: '$.store..price', flatten: true}); assert.deepEqual(expected, result); }); + + it('all sub properties of single element arr', () => { + const book = json.store.book[0]; + const input = {book}; + const expected = [book.title]; + const result = jsonpath({json: input, path: '$..title', flatten: true, wrap: false}); + assert.deepEqual(expected, result); + }); }); diff --git a/test/test.properties.js b/test/test.properties.js index e8f720d..b832bd7 100644 --- a/test/test.properties.js +++ b/test/test.properties.js @@ -24,9 +24,9 @@ describe('JSONPath - Properties', function () { it('At signs within properties', () => { let result = jsonpath({json, path: "$.datafield[?(@.tag=='035')]", wrap: false}); - assert.deepEqual(json.datafield[0], result); + assert.deepEqual([json.datafield[0]], result); result = jsonpath({json, path: "$.datafield[?(@['@tag']=='042')]", wrap: false}); - assert.deepEqual(json.datafield[1], result); + assert.deepEqual([json.datafield[1]], result); result = jsonpath({json, path: "$.datafield[2][(@['@tag'])]", wrap: false}); assert.deepEqual(json.datafield[2]['045'], result); });