jsonpath-plus
Advanced tools
Comparing version 5.0.7 to 5.1.0
@@ -100,2 +100,3 @@ 'use strict'; | ||
'prefer-named-capture-group': 0, | ||
'unicorn/prefer-spread': 0, | ||
@@ -102,0 +103,0 @@ // Reenable when no longer having problems |
# CHANGES for jsonpath-plus | ||
## 5.1.0 (2021-06-24) | ||
- Enhancement: support double-quoted bracket notation | ||
- Linting: As per latest ash-nazg | ||
- npm: Update devDeps. | ||
## 5.0.7 (2021-04-12) | ||
@@ -4,0 +10,0 @@ |
@@ -166,3 +166,3 @@ function _typeof(obj) { | ||
function _iterableToArray(iter) { | ||
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); | ||
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); | ||
} | ||
@@ -192,5 +192,5 @@ | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
var it; | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { | ||
if (!it) { | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
@@ -228,3 +228,3 @@ if (it) o = it; | ||
s: function () { | ||
it = o[Symbol.iterator](); | ||
it = it.call(o); | ||
}, | ||
@@ -613,3 +613,3 @@ n: function () { | ||
// simple case--directly follow property | ||
addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr)); | ||
addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr)); // eslint-disable-next-line unicorn/prefer-switch -- Part of larger `if` | ||
} else if (loc === '*') { | ||
@@ -970,7 +970,7 @@ // all child properties | ||
}) // Escape periods and tildes within properties | ||
.replace(/\['((?:(?!['\]])[\s\S])*)'\]/g, function ($0, prop) { | ||
.replace(/\[["']((?:(?!['\]])[\s\S])*)["']\]/g, function ($0, prop) { | ||
return "['" + prop.replace(/\./g, '%@%').replace(/~/g, '%%@@%%') + "']"; | ||
}) // Properties operator | ||
.replace(/~/g, ';~;') // Split by property boundaries | ||
.replace(/'?\.'?(?!(?:(?!\[)[\s\S])*\])|\['?/g, ';') // Reinsert periods within properties | ||
.replace(/["']?\.["']?(?!(?:(?!\[)[\s\S])*\])|\[["']?/g, ';') // Reinsert periods within properties | ||
.replace(/%@%/g, '.') // Reinsert tildes within properties | ||
@@ -977,0 +977,0 @@ .replace(/%%@@%%/g, '~') // Parent |
@@ -1,2 +0,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(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function a(t,r,o){return(a=n()?Reflect.construct:function(t,r,n){var a=[null];a.push.apply(a,r);var o=new(Function.bind.apply(t,a));return n&&e(o,n.prototype),o}).apply(null,arguments)}function o(t){var n="function"==typeof Map?new Map:void 0;return(o=function(t){if(null===t||(o=t,-1===Function.toString.call(o).indexOf("[native code]")))return t;var o;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(t))return n.get(t);n.set(t,u)}function u(){return a(t,arguments,r(this).constructor)}return u.prototype=Object.create(t.prototype,{constructor:{value:u,enumerable:!1,writable:!0,configurable:!0}}),e(u,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 i(t){return function(t){if(Array.isArray(t))return l(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||c(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(t,r){if(t){if("string"==typeof t)return l(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?l(t,r):void 0}}function l(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}var s=Object.prototype.hasOwnProperty;function p(t,r){return(t=t.slice()).push(r),t}function h(t,r){return(r=r.slice()).unshift(t),r}var f=function(t){!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)}(l,o(Error));var a,i,c=(a=l,i=n(),function(){var t,e=r(a);if(i){var n=r(this).constructor;t=Reflect.construct(e,arguments,n)}else t=e.apply(this,arguments);return u(this,t)});function l(t){var r;return function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,l),(r=c.call(this,'JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)')).avoidNew=!0,r.value=t,r.name="NewError",r}return l}();function y(r,e,n,a,o){if(!(this instanceof y))try{return new y(r,e,n,a,o)}catch(t){if(!t.avoidNew)throw t;return t.value}"string"==typeof r&&(o=a,a=n,n=e,e=r,r=null);var u=r&&"object"===t(r);if(r=r||{},this.json=r.json||n,this.path=r.path||e,this.resultType=r.resultType||"value",this.flatten=r.flatten||!1,this.wrap=!s.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||o||function(){throw new TypeError("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==r.autostart){var i={path:u?r.path:e};u?"json"in r&&(i.json=r.json):i.json=n;var c=this.evaluate(i);if(!c||"object"!==t(c))throw new f(c);return c}}y.prototype.evaluate=function(r,e,n,a){var o=this,u=this.parent,i=this.parentProperty,c=this.flatten,l=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)&&!Array.isArray(r)){if(!r.path&&""!==r.path)throw new TypeError('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');if(!s.call(r,"json"))throw new TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');e=r.json,c=s.call(r,"flatten")?r.flatten:c,this.currResultType=s.call(r,"resultType")?r.resultType:this.currResultType,this.currSandbox=s.call(r,"sandbox")?r.sandbox:this.currSandbox,l=s.call(r,"wrap")?r.wrap:l,this.currPreventEval=s.call(r,"preventEval")?r.preventEval:this.currPreventEval,n=s.call(r,"callback")?r.callback:n,this.currOtherTypeCallback=s.call(r,"otherTypeCallback")?r.otherTypeCallback:this.currOtherTypeCallback,u=s.call(r,"parent")?r.parent:u,i=s.call(r,"parentProperty")?r.parentProperty:i,r=r.path}if(u=u||null,i=i||null,Array.isArray(r)&&(r=y.toPathString(r)),(r||""===r)&&e){var p=y.toPathArray(r);"$"===p[0]&&p.length>1&&p.shift(),this._hasParentSelector=null;var h=this._trace(p,e,["$"],u,i,n).filter((function(t){return t&&!t.isParentSelector}));return h.length?l||1!==h.length||h[0].hasArrExpr?h.reduce((function(t,r){var e=o._getPreferredOutput(r);return c&&Array.isArray(e)?t=t.concat(e):t.push(e),t}),[]):this._getPreferredOutput(h[0]):l?[]:void 0}},y.prototype._getPreferredOutput=function(t){var r=this.currResultType;switch(r){case"all":var e=Array.isArray(t.path)?t.path:y.toPathArray(t.path);return t.pointer=y.toPointer(e),t.path="string"==typeof t.path?t.path:y.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[r];case"path":return y.toPathString(t[r]);case"pointer":return y.toPointer(t.path);default:throw new TypeError("Unknown result type")}},y.prototype._handleCallback=function(t,r,e){if(r){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:y.toPathString(t.path),r(n,e,t)}},y.prototype._trace=function(r,e,n,a,o,u,i,l){var f,y=this;if(!r.length)return f={path:n,value:e,parent:a,parentProperty:o,hasArrExpr:i},this._handleCallback(f,u,"value"),f;var v=r[0],b=r.slice(1),F=[];function d(t){Array.isArray(t)?t.forEach((function(t){F.push(t)})):F.push(t)}if(("string"!=typeof v||l)&&e&&s.call(e,v))d(this._trace(b,e[v],p(n,v),e,v,u,i));else if("*"===v)this._walk(v,b,e,n,a,o,u,(function(t,r,e,n,a,o,u,i){d(y._trace(h(t,e),n,a,o,u,i,!0,!0))}));else if(".."===v)d(this._trace(b,e,n,a,o,u,i)),this._walk(v,b,e,n,a,o,u,(function(r,e,n,a,o,u,i,c){"object"===t(a[r])&&d(y._trace(h(e,n),a[r],p(o,r),a,r,c,!0))}));else{if("^"===v)return this._hasParentSelector=!0,{path:n.slice(0,-1),expr:b,isParentSelector:!0};if("~"===v)return f={path:p(n,v),value:o,parent:a,parentProperty:null},this._handleCallback(f,u,"property"),f;if("$"===v)d(this._trace(b,e,n,null,null,u,i));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(v))d(this._slice(v,b,e,n,a,o,u));else if(0===v.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");this._walk(v,b,e,n,a,o,u,(function(t,r,e,n,a,o,u,i){y._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,o,u)&&d(y._trace(h(t,e),n,a,o,u,i,!0))}))}else if("("===v[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");d(this._trace(h(this._eval(v,e,n[n.length-1],n.slice(0,-1),a,o),b),e,n,a,o,u,i))}else if("@"===v[0]){var g=!1,_=v.slice(1,-2);switch(_){case"scalar":e&&["object","function"].includes(t(e))||(g=!0);break;case"boolean":case"string":case"undefined":case"function":t(e)===_&&(g=!0);break;case"integer":!Number.isFinite(e)||e%1||(g=!0);break;case"number":Number.isFinite(e)&&(g=!0);break;case"nonFinite":"number"!=typeof e||Number.isFinite(e)||(g=!0);break;case"object":e&&t(e)===_&&(g=!0);break;case"array":Array.isArray(e)&&(g=!0);break;case"other":g=this.currOtherTypeCallback(e,n,a,o);break;case"null":null===e&&(g=!0);break;default:throw new TypeError("Unknown value type "+_)}if(g)return f={path:n,value:e,parent:a,parentProperty:o},this._handleCallback(f,u,"value"),f}else if("`"===v[0]&&e&&s.call(e,v.slice(1))){var w=v.slice(1);d(this._trace(b,e[w],p(n,w),e,w,u,i,!0))}else if(v.includes(",")){var m,D=function(t,r){var e;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(e=c(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0,a=function(){};return{s:a,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,u=!0,i=!1;return{s:function(){e=t[Symbol.iterator]()},n:function(){var t=e.next();return u=t.done,t},e:function(t){i=!0,o=t},f:function(){try{u||null==e.return||e.return()}finally{if(i)throw o}}}}(v.split(","));try{for(D.s();!(m=D.n()).done;){var P=m.value;d(this._trace(h(P,b),e,n,a,o,u,!0))}}catch(t){D.e(t)}finally{D.f()}}else!l&&e&&s.call(e,v)&&d(this._trace(b,e[v],p(n,v),e,v,u,i,!0))}if(this._hasParentSelector)for(var x=0;x<F.length;x++){var S=F[x];if(S&&S.isParentSelector){var E=this._trace(S.expr,e,S.path,a,o,u,i);if(Array.isArray(E)){F[x]=E[0];for(var A=E.length,j=1;j<A;j++)x++,F.splice(x,0,E[j])}else F[x]=E}}return F},y.prototype._walk=function(r,e,n,a,o,u,i,c){if(Array.isArray(n))for(var l=n.length,s=0;s<l;s++)c(s,r,e,n,a,o,u,i);else n&&"object"===t(n)&&Object.keys(n).forEach((function(t){c(t,r,e,n,a,o,u,i)}))},y.prototype._slice=function(t,r,e,n,a,o,u){if(Array.isArray(e)){var i=e.length,c=t.split(":"),l=c[2]&&Number.parseInt(c[2])||1,s=c[0]&&Number.parseInt(c[0])||0,p=c[1]&&Number.parseInt(c[1])||i;s=s<0?Math.max(0,s+i):Math.min(i,s),p=p<0?Math.max(0,p+i):Math.min(i,p);for(var f=[],y=s;y<p;y+=l){this._trace(h(y,r),e,n,a,o,u,!0).forEach((function(t){f.push(t)}))}return f}},y.prototype._eval=function(t,r,e,n,a,o){t.includes("@parentProperty")&&(this.currSandbox._$_parentProperty=o,t=t.replace(/@parentProperty/g,"_$_parentProperty")),t.includes("@parent")&&(this.currSandbox._$_parent=a,t=t.replace(/@parent/g,"_$_parent")),t.includes("@property")&&(this.currSandbox._$_property=e,t=t.replace(/@property/g,"_$_property")),t.includes("@path")&&(this.currSandbox._$_path=y.toPathString(n.concat([e])),t=t.replace(/@path/g,"_$_path")),t.includes("@root")&&(this.currSandbox._$_root=this.json,t=t.replace(/@root/g,"_$_root")),/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/.test(t)&&(this.currSandbox._$_v=r,t=t.replace(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/g,"_$_v$1"));try{return this.vm.runInNewContext(t,this.currSandbox)}catch(r){throw console.log(r),new Error("jsonPath: "+r.message+": "+t)}},y.cache={},y.toPathString=function(t){for(var r=t,e=r.length,n="$",a=1;a<e;a++)/^(~|\^|@(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\(\))$/.test(r[a])||(n+=/^[\*0-9]+$/.test(r[a])?"["+r[a]+"]":"['"+r[a]+"']");return n},y.toPointer=function(t){for(var r=t,e=r.length,n="",a=1;a<e;a++)/^(~|\^|@(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\(\))$/.test(r[a])||(n+="/"+r[a].toString().replace(/~/g,"~0").replace(/\//g,"~1"));return n},y.toPathArray=function(t){var r=y.cache;if(r[t])return r[t].concat();var e=[],n=t.replace(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/g,";$&;").replace(/['\[](\??\((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\))['\]]/g,(function(t,r){return"[#"+(e.push(r)-1)+"]"})).replace(/\['((?:(?!['\]])[\s\S])*)'\]/g,(function(t,r){return"['"+r.replace(/\./g,"%@%").replace(/~/g,"%%@@%%")+"']"})).replace(/~/g,";~;").replace(/'?\.'?(?!(?:(?!\[)[\s\S])*\])|\['?/g,";").replace(/%@%/g,".").replace(/%%@@%%/g,"~").replace(/(?:;)?(\^+)(?:;)?/g,(function(t,r){return";"+r.split("").join(";")+";"})).replace(/;;;|;;/g,";..;").replace(/;$|'?\]|'$/g,"").split(";").map((function(t){var r=t.match(/#([0-9]+)/);return r&&r[1]?e[r[1]]:t}));return r[t]=n,r[t].concat()};y.prototype.vm={runInNewContext:function(t,r){var e=Object.keys(r),n=[];!function(t,r,e){for(var n=t.length,a=0;a<n;a++)e(t[a])&&r.push(t.splice(a--,1)[0])}(e,n,(function(t){return"function"==typeof r[t]}));var o=e.map((function(t,e){return r[t]})),u=n.reduce((function(t,e){var n=r[e].toString();return/function/.test(n)||(n="function "+n),"var "+e+"="+n+";"+t}),"");/(["'])use strict\1/.test(t=u+t)||e.includes("arguments")||(t="var arguments = undefined;"+t);var c=(t=t.replace(/;[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*$/,"")).lastIndexOf(";"),l=c>-1?t.slice(0,c+1)+" return "+t.slice(c+1):" return "+t;return a(Function,i(e).concat([l])).apply(void 0,i(o))}};export{y as JSONPath}; | ||
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(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function a(t,r,o){return(a=n()?Reflect.construct:function(t,r,n){var a=[null];a.push.apply(a,r);var o=new(Function.bind.apply(t,a));return n&&e(o,n.prototype),o}).apply(null,arguments)}function o(t){var n="function"==typeof Map?new Map:void 0;return(o=function(t){if(null===t||(o=t,-1===Function.toString.call(o).indexOf("[native code]")))return t;var o;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(t))return n.get(t);n.set(t,u)}function u(){return a(t,arguments,r(this).constructor)}return u.prototype=Object.create(t.prototype,{constructor:{value:u,enumerable:!1,writable:!0,configurable:!0}}),e(u,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 i(t){return function(t){if(Array.isArray(t))return l(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||c(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(t,r){if(t){if("string"==typeof t)return l(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?l(t,r):void 0}}function l(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}var s=Object.prototype.hasOwnProperty;function p(t,r){return(t=t.slice()).push(r),t}function h(t,r){return(r=r.slice()).unshift(t),r}var f=function(t){!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)}(l,o(Error));var a,i,c=(a=l,i=n(),function(){var t,e=r(a);if(i){var n=r(this).constructor;t=Reflect.construct(e,arguments,n)}else t=e.apply(this,arguments);return u(this,t)});function l(t){var r;return function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,l),(r=c.call(this,'JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)')).avoidNew=!0,r.value=t,r.name="NewError",r}return l}();function y(r,e,n,a,o){if(!(this instanceof y))try{return new y(r,e,n,a,o)}catch(t){if(!t.avoidNew)throw t;return t.value}"string"==typeof r&&(o=a,a=n,n=e,e=r,r=null);var u=r&&"object"===t(r);if(r=r||{},this.json=r.json||n,this.path=r.path||e,this.resultType=r.resultType||"value",this.flatten=r.flatten||!1,this.wrap=!s.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||o||function(){throw new TypeError("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==r.autostart){var i={path:u?r.path:e};u?"json"in r&&(i.json=r.json):i.json=n;var c=this.evaluate(i);if(!c||"object"!==t(c))throw new f(c);return c}}y.prototype.evaluate=function(r,e,n,a){var o=this,u=this.parent,i=this.parentProperty,c=this.flatten,l=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)&&!Array.isArray(r)){if(!r.path&&""!==r.path)throw new TypeError('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');if(!s.call(r,"json"))throw new TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');e=r.json,c=s.call(r,"flatten")?r.flatten:c,this.currResultType=s.call(r,"resultType")?r.resultType:this.currResultType,this.currSandbox=s.call(r,"sandbox")?r.sandbox:this.currSandbox,l=s.call(r,"wrap")?r.wrap:l,this.currPreventEval=s.call(r,"preventEval")?r.preventEval:this.currPreventEval,n=s.call(r,"callback")?r.callback:n,this.currOtherTypeCallback=s.call(r,"otherTypeCallback")?r.otherTypeCallback:this.currOtherTypeCallback,u=s.call(r,"parent")?r.parent:u,i=s.call(r,"parentProperty")?r.parentProperty:i,r=r.path}if(u=u||null,i=i||null,Array.isArray(r)&&(r=y.toPathString(r)),(r||""===r)&&e){var p=y.toPathArray(r);"$"===p[0]&&p.length>1&&p.shift(),this._hasParentSelector=null;var h=this._trace(p,e,["$"],u,i,n).filter((function(t){return t&&!t.isParentSelector}));return h.length?l||1!==h.length||h[0].hasArrExpr?h.reduce((function(t,r){var e=o._getPreferredOutput(r);return c&&Array.isArray(e)?t=t.concat(e):t.push(e),t}),[]):this._getPreferredOutput(h[0]):l?[]:void 0}},y.prototype._getPreferredOutput=function(t){var r=this.currResultType;switch(r){case"all":var e=Array.isArray(t.path)?t.path:y.toPathArray(t.path);return t.pointer=y.toPointer(e),t.path="string"==typeof t.path?t.path:y.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[r];case"path":return y.toPathString(t[r]);case"pointer":return y.toPointer(t.path);default:throw new TypeError("Unknown result type")}},y.prototype._handleCallback=function(t,r,e){if(r){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:y.toPathString(t.path),r(n,e,t)}},y.prototype._trace=function(r,e,n,a,o,u,i,l){var f,y=this;if(!r.length)return f={path:n,value:e,parent:a,parentProperty:o,hasArrExpr:i},this._handleCallback(f,u,"value"),f;var v=r[0],b=r.slice(1),F=[];function d(t){Array.isArray(t)?t.forEach((function(t){F.push(t)})):F.push(t)}if(("string"!=typeof v||l)&&e&&s.call(e,v))d(this._trace(b,e[v],p(n,v),e,v,u,i));else if("*"===v)this._walk(v,b,e,n,a,o,u,(function(t,r,e,n,a,o,u,i){d(y._trace(h(t,e),n,a,o,u,i,!0,!0))}));else if(".."===v)d(this._trace(b,e,n,a,o,u,i)),this._walk(v,b,e,n,a,o,u,(function(r,e,n,a,o,u,i,c){"object"===t(a[r])&&d(y._trace(h(e,n),a[r],p(o,r),a,r,c,!0))}));else{if("^"===v)return this._hasParentSelector=!0,{path:n.slice(0,-1),expr:b,isParentSelector:!0};if("~"===v)return f={path:p(n,v),value:o,parent:a,parentProperty:null},this._handleCallback(f,u,"property"),f;if("$"===v)d(this._trace(b,e,n,null,null,u,i));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(v))d(this._slice(v,b,e,n,a,o,u));else if(0===v.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");this._walk(v,b,e,n,a,o,u,(function(t,r,e,n,a,o,u,i){y._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,o,u)&&d(y._trace(h(t,e),n,a,o,u,i,!0))}))}else if("("===v[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");d(this._trace(h(this._eval(v,e,n[n.length-1],n.slice(0,-1),a,o),b),e,n,a,o,u,i))}else if("@"===v[0]){var g=!1,_=v.slice(1,-2);switch(_){case"scalar":e&&["object","function"].includes(t(e))||(g=!0);break;case"boolean":case"string":case"undefined":case"function":t(e)===_&&(g=!0);break;case"integer":!Number.isFinite(e)||e%1||(g=!0);break;case"number":Number.isFinite(e)&&(g=!0);break;case"nonFinite":"number"!=typeof e||Number.isFinite(e)||(g=!0);break;case"object":e&&t(e)===_&&(g=!0);break;case"array":Array.isArray(e)&&(g=!0);break;case"other":g=this.currOtherTypeCallback(e,n,a,o);break;case"null":null===e&&(g=!0);break;default:throw new TypeError("Unknown value type "+_)}if(g)return f={path:n,value:e,parent:a,parentProperty:o},this._handleCallback(f,u,"value"),f}else if("`"===v[0]&&e&&s.call(e,v.slice(1))){var w=v.slice(1);d(this._trace(b,e[w],p(n,w),e,w,u,i,!0))}else if(v.includes(",")){var m,D=function(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=c(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0,a=function(){};return{s:a,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,u=!0,i=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return u=t.done,t},e:function(t){i=!0,o=t},f:function(){try{u||null==e.return||e.return()}finally{if(i)throw o}}}}(v.split(","));try{for(D.s();!(m=D.n()).done;){var P=m.value;d(this._trace(h(P,b),e,n,a,o,u,!0))}}catch(t){D.e(t)}finally{D.f()}}else!l&&e&&s.call(e,v)&&d(this._trace(b,e[v],p(n,v),e,v,u,i,!0))}if(this._hasParentSelector)for(var x=0;x<F.length;x++){var S=F[x];if(S&&S.isParentSelector){var E=this._trace(S.expr,e,S.path,a,o,u,i);if(Array.isArray(E)){F[x]=E[0];for(var A=E.length,j=1;j<A;j++)x++,F.splice(x,0,E[j])}else F[x]=E}}return F},y.prototype._walk=function(r,e,n,a,o,u,i,c){if(Array.isArray(n))for(var l=n.length,s=0;s<l;s++)c(s,r,e,n,a,o,u,i);else n&&"object"===t(n)&&Object.keys(n).forEach((function(t){c(t,r,e,n,a,o,u,i)}))},y.prototype._slice=function(t,r,e,n,a,o,u){if(Array.isArray(e)){var i=e.length,c=t.split(":"),l=c[2]&&Number.parseInt(c[2])||1,s=c[0]&&Number.parseInt(c[0])||0,p=c[1]&&Number.parseInt(c[1])||i;s=s<0?Math.max(0,s+i):Math.min(i,s),p=p<0?Math.max(0,p+i):Math.min(i,p);for(var f=[],y=s;y<p;y+=l){this._trace(h(y,r),e,n,a,o,u,!0).forEach((function(t){f.push(t)}))}return f}},y.prototype._eval=function(t,r,e,n,a,o){t.includes("@parentProperty")&&(this.currSandbox._$_parentProperty=o,t=t.replace(/@parentProperty/g,"_$_parentProperty")),t.includes("@parent")&&(this.currSandbox._$_parent=a,t=t.replace(/@parent/g,"_$_parent")),t.includes("@property")&&(this.currSandbox._$_property=e,t=t.replace(/@property/g,"_$_property")),t.includes("@path")&&(this.currSandbox._$_path=y.toPathString(n.concat([e])),t=t.replace(/@path/g,"_$_path")),t.includes("@root")&&(this.currSandbox._$_root=this.json,t=t.replace(/@root/g,"_$_root")),/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/.test(t)&&(this.currSandbox._$_v=r,t=t.replace(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/g,"_$_v$1"));try{return this.vm.runInNewContext(t,this.currSandbox)}catch(r){throw console.log(r),new Error("jsonPath: "+r.message+": "+t)}},y.cache={},y.toPathString=function(t){for(var r=t,e=r.length,n="$",a=1;a<e;a++)/^(~|\^|@(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\(\))$/.test(r[a])||(n+=/^[\*0-9]+$/.test(r[a])?"["+r[a]+"]":"['"+r[a]+"']");return n},y.toPointer=function(t){for(var r=t,e=r.length,n="",a=1;a<e;a++)/^(~|\^|@(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\(\))$/.test(r[a])||(n+="/"+r[a].toString().replace(/~/g,"~0").replace(/\//g,"~1"));return n},y.toPathArray=function(t){var r=y.cache;if(r[t])return r[t].concat();var e=[],n=t.replace(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/g,";$&;").replace(/['\[](\??\((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\))['\]]/g,(function(t,r){return"[#"+(e.push(r)-1)+"]"})).replace(/\[["']((?:(?!['\]])[\s\S])*)["']\]/g,(function(t,r){return"['"+r.replace(/\./g,"%@%").replace(/~/g,"%%@@%%")+"']"})).replace(/~/g,";~;").replace(/["']?\.["']?(?!(?:(?!\[)[\s\S])*\])|\[["']?/g,";").replace(/%@%/g,".").replace(/%%@@%%/g,"~").replace(/(?:;)?(\^+)(?:;)?/g,(function(t,r){return";"+r.split("").join(";")+";"})).replace(/;;;|;;/g,";..;").replace(/;$|'?\]|'$/g,"").split(";").map((function(t){var r=t.match(/#([0-9]+)/);return r&&r[1]?e[r[1]]:t}));return r[t]=n,r[t].concat()};y.prototype.vm={runInNewContext:function(t,r){var e=Object.keys(r),n=[];!function(t,r,e){for(var n=t.length,a=0;a<n;a++)e(t[a])&&r.push(t.splice(a--,1)[0])}(e,n,(function(t){return"function"==typeof r[t]}));var o=e.map((function(t,e){return r[t]})),u=n.reduce((function(t,e){var n=r[e].toString();return/function/.test(n)||(n="function "+n),"var "+e+"="+n+";"+t}),"");/(["'])use strict\1/.test(t=u+t)||e.includes("arguments")||(t="var arguments = undefined;"+t);var c=(t=t.replace(/;[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*$/,"")).lastIndexOf(";"),l=c>-1?t.slice(0,c+1)+" return "+t.slice(c+1):" return "+t;return a(Function,i(e).concat([l])).apply(void 0,i(o))}};export{y as JSONPath}; | ||
//# sourceMappingURL=index-browser-esm.min.js.map |
@@ -172,3 +172,3 @@ (function (global, factory) { | ||
function _iterableToArray(iter) { | ||
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); | ||
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); | ||
} | ||
@@ -198,5 +198,5 @@ | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
var it; | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { | ||
if (!it) { | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
@@ -234,3 +234,3 @@ if (it) o = it; | ||
s: function () { | ||
it = o[Symbol.iterator](); | ||
it = it.call(o); | ||
}, | ||
@@ -619,3 +619,3 @@ n: function () { | ||
// simple case--directly follow property | ||
addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr)); | ||
addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr)); // eslint-disable-next-line unicorn/prefer-switch -- Part of larger `if` | ||
} else if (loc === '*') { | ||
@@ -976,7 +976,7 @@ // all child properties | ||
}) // Escape periods and tildes within properties | ||
.replace(/\['((?:(?!['\]])[\s\S])*)'\]/g, function ($0, prop) { | ||
.replace(/\[["']((?:(?!['\]])[\s\S])*)["']\]/g, function ($0, prop) { | ||
return "['" + prop.replace(/\./g, '%@%').replace(/~/g, '%%@@%%') + "']"; | ||
}) // Properties operator | ||
.replace(/~/g, ';~;') // Split by property boundaries | ||
.replace(/'?\.'?(?!(?:(?!\[)[\s\S])*\])|\['?/g, ';') // Reinsert periods within properties | ||
.replace(/["']?\.["']?(?!(?:(?!\[)[\s\S])*\])|\[["']?/g, ';') // Reinsert periods within properties | ||
.replace(/%@%/g, '.') // Reinsert tildes within properties | ||
@@ -983,0 +983,0 @@ .replace(/%%@@%%/g, '~') // Parent |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis: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(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function o(t,e,r){return(o=a()?Reflect.construct:function(t,e,r){var a=[null];a.push.apply(a,e);var o=new(Function.bind.apply(t,a));return r&&n(o,r.prototype),o}).apply(null,arguments)}function u(t){var e="function"==typeof Map?new Map:void 0;return(u=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!==e){if(e.has(t))return e.get(t);e.set(t,u)}function u(){return o(t,arguments,r(this).constructor)}return u.prototype=Object.create(t.prototype,{constructor:{value:u,enumerable:!1,writable:!0,configurable:!0}}),n(u,t)})(t)}function i(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 c(t){return function(t){if(Array.isArray(t))return s(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||l(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(t,e){if(t){if("string"==typeof t)return s(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?s(t,e):void 0}}function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var p=Object.prototype.hasOwnProperty;function f(t,e){return(t=t.slice()).push(e),t}function h(t,e){return(e=e.slice()).unshift(t),e}var y=function(t){!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)}(c,t);var e,o,u=(e=c,o=a(),function(){var t,n=r(e);if(o){var a=r(this).constructor;t=Reflect.construct(n,arguments,a)}else t=n.apply(this,arguments);return i(this,t)});function c(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,c),(e=u.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 c}(u(Error));function v(t,r,n,a,o){if(!(this instanceof v))try{return new v(t,r,n,a,o)}catch(t){if(!t.avoidNew)throw t;return t.value}"string"==typeof t&&(o=a,a=n,n=r,r=t,t=null);var u=t&&"object"===e(t);if(t=t||{},this.json=t.json||n,this.path=t.path||r,this.resultType=t.resultType||"value",this.flatten=t.flatten||!1,this.wrap=!p.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||o||function(){throw new TypeError("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==t.autostart){var i={path:u?t.path:r};u?"json"in t&&(i.json=t.json):i.json=n;var c=this.evaluate(i);if(!c||"object"!==e(c))throw new y(c);return c}}v.prototype.evaluate=function(t,r,n,a){var o=this,u=this.parent,i=this.parentProperty,c=this.flatten,l=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)&&!Array.isArray(t)){if(!t.path&&""!==t.path)throw new TypeError('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');if(!p.call(t,"json"))throw new TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');r=t.json,c=p.call(t,"flatten")?t.flatten:c,this.currResultType=p.call(t,"resultType")?t.resultType:this.currResultType,this.currSandbox=p.call(t,"sandbox")?t.sandbox:this.currSandbox,l=p.call(t,"wrap")?t.wrap:l,this.currPreventEval=p.call(t,"preventEval")?t.preventEval:this.currPreventEval,n=p.call(t,"callback")?t.callback:n,this.currOtherTypeCallback=p.call(t,"otherTypeCallback")?t.otherTypeCallback:this.currOtherTypeCallback,u=p.call(t,"parent")?t.parent:u,i=p.call(t,"parentProperty")?t.parentProperty:i,t=t.path}if(u=u||null,i=i||null,Array.isArray(t)&&(t=v.toPathString(t)),(t||""===t)&&r){var s=v.toPathArray(t);"$"===s[0]&&s.length>1&&s.shift(),this._hasParentSelector=null;var f=this._trace(s,r,["$"],u,i,n).filter((function(t){return t&&!t.isParentSelector}));return f.length?l||1!==f.length||f[0].hasArrExpr?f.reduce((function(t,e){var r=o._getPreferredOutput(e);return c&&Array.isArray(r)?t=t.concat(r):t.push(r),t}),[]):this._getPreferredOutput(f[0]):l?[]:void 0}},v.prototype._getPreferredOutput=function(t){var e=this.currResultType;switch(e){case"all":var r=Array.isArray(t.path)?t.path:v.toPathArray(t.path);return t.pointer=v.toPointer(r),t.path="string"==typeof t.path?t.path:v.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[e];case"path":return v.toPathString(t[e]);case"pointer":return v.toPointer(t.path);default:throw new TypeError("Unknown result type")}},v.prototype._handleCallback=function(t,e,r){if(e){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:v.toPathString(t.path),e(n,r,t)}},v.prototype._trace=function(t,r,n,a,o,u,i,c){var s,y=this;if(!t.length)return s={path:n,value:r,parent:a,parentProperty:o,hasArrExpr:i},this._handleCallback(s,u,"value"),s;var v=t[0],b=t.slice(1),F=[];function d(t){Array.isArray(t)?t.forEach((function(t){F.push(t)})):F.push(t)}if(("string"!=typeof v||c)&&r&&p.call(r,v))d(this._trace(b,r[v],f(n,v),r,v,u,i));else if("*"===v)this._walk(v,b,r,n,a,o,u,(function(t,e,r,n,a,o,u,i){d(y._trace(h(t,r),n,a,o,u,i,!0,!0))}));else if(".."===v)d(this._trace(b,r,n,a,o,u,i)),this._walk(v,b,r,n,a,o,u,(function(t,r,n,a,o,u,i,c){"object"===e(a[t])&&d(y._trace(h(r,n),a[t],f(o,t),a,t,c,!0))}));else{if("^"===v)return this._hasParentSelector=!0,{path:n.slice(0,-1),expr:b,isParentSelector:!0};if("~"===v)return s={path:f(n,v),value:o,parent:a,parentProperty:null},this._handleCallback(s,u,"property"),s;if("$"===v)d(this._trace(b,r,n,null,null,u,i));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(v))d(this._slice(v,b,r,n,a,o,u));else if(0===v.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");this._walk(v,b,r,n,a,o,u,(function(t,e,r,n,a,o,u,i){y._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,o,u)&&d(y._trace(h(t,r),n,a,o,u,i,!0))}))}else if("("===v[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");d(this._trace(h(this._eval(v,r,n[n.length-1],n.slice(0,-1),a,o),b),r,n,a,o,u,i))}else if("@"===v[0]){var g=!1,_=v.slice(1,-2);switch(_){case"scalar":r&&["object","function"].includes(e(r))||(g=!0);break;case"boolean":case"string":case"undefined":case"function":e(r)===_&&(g=!0);break;case"integer":!Number.isFinite(r)||r%1||(g=!0);break;case"number":Number.isFinite(r)&&(g=!0);break;case"nonFinite":"number"!=typeof r||Number.isFinite(r)||(g=!0);break;case"object":r&&e(r)===_&&(g=!0);break;case"array":Array.isArray(r)&&(g=!0);break;case"other":g=this.currOtherTypeCallback(r,n,a,o);break;case"null":null===r&&(g=!0);break;default:throw new TypeError("Unknown value type "+_)}if(g)return s={path:n,value:r,parent:a,parentProperty:o},this._handleCallback(s,u,"value"),s}else if("`"===v[0]&&r&&p.call(r,v.slice(1))){var w=v.slice(1);d(this._trace(b,r[w],f(n,w),r,w,u,i,!0))}else if(v.includes(",")){var m,P=function(t,e){var r;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(r=l(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,a=function(){};return{s:a,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,u=!0,i=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return u=t.done,t},e:function(t){i=!0,o=t},f:function(){try{u||null==r.return||r.return()}finally{if(i)throw o}}}}(v.split(","));try{for(P.s();!(m=P.n()).done;){var D=m.value;d(this._trace(h(D,b),r,n,a,o,u,!0))}}catch(t){P.e(t)}finally{P.f()}}else!c&&r&&p.call(r,v)&&d(this._trace(b,r[v],f(n,v),r,v,u,i,!0))}if(this._hasParentSelector)for(var x=0;x<F.length;x++){var S=F[x];if(S&&S.isParentSelector){var E=this._trace(S.expr,r,S.path,a,o,u,i);if(Array.isArray(E)){F[x]=E[0];for(var A=E.length,j=1;j<A;j++)x++,F.splice(x,0,E[j])}else F[x]=E}}return F},v.prototype._walk=function(t,r,n,a,o,u,i,c){if(Array.isArray(n))for(var l=n.length,s=0;s<l;s++)c(s,t,r,n,a,o,u,i);else n&&"object"===e(n)&&Object.keys(n).forEach((function(e){c(e,t,r,n,a,o,u,i)}))},v.prototype._slice=function(t,e,r,n,a,o,u){if(Array.isArray(r)){var i=r.length,c=t.split(":"),l=c[2]&&Number.parseInt(c[2])||1,s=c[0]&&Number.parseInt(c[0])||0,p=c[1]&&Number.parseInt(c[1])||i;s=s<0?Math.max(0,s+i):Math.min(i,s),p=p<0?Math.max(0,p+i):Math.min(i,p);for(var f=[],y=s;y<p;y+=l){this._trace(h(y,e),r,n,a,o,u,!0).forEach((function(t){f.push(t)}))}return f}},v.prototype._eval=function(t,e,r,n,a,o){t.includes("@parentProperty")&&(this.currSandbox._$_parentProperty=o,t=t.replace(/@parentProperty/g,"_$_parentProperty")),t.includes("@parent")&&(this.currSandbox._$_parent=a,t=t.replace(/@parent/g,"_$_parent")),t.includes("@property")&&(this.currSandbox._$_property=r,t=t.replace(/@property/g,"_$_property")),t.includes("@path")&&(this.currSandbox._$_path=v.toPathString(n.concat([r])),t=t.replace(/@path/g,"_$_path")),t.includes("@root")&&(this.currSandbox._$_root=this.json,t=t.replace(/@root/g,"_$_root")),/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/.test(t)&&(this.currSandbox._$_v=e,t=t.replace(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/g,"_$_v$1"));try{return this.vm.runInNewContext(t,this.currSandbox)}catch(e){throw console.log(e),new Error("jsonPath: "+e.message+": "+t)}},v.cache={},v.toPathString=function(t){for(var e=t,r=e.length,n="$",a=1;a<r;a++)/^(~|\^|@(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\(\))$/.test(e[a])||(n+=/^[\*0-9]+$/.test(e[a])?"["+e[a]+"]":"['"+e[a]+"']");return n},v.toPointer=function(t){for(var e=t,r=e.length,n="",a=1;a<r;a++)/^(~|\^|@(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\(\))$/.test(e[a])||(n+="/"+e[a].toString().replace(/~/g,"~0").replace(/\//g,"~1"));return n},v.toPathArray=function(t){var e=v.cache;if(e[t])return e[t].concat();var r=[],n=t.replace(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/g,";$&;").replace(/['\[](\??\((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\))['\]]/g,(function(t,e){return"[#"+(r.push(e)-1)+"]"})).replace(/\['((?:(?!['\]])[\s\S])*)'\]/g,(function(t,e){return"['"+e.replace(/\./g,"%@%").replace(/~/g,"%%@@%%")+"']"})).replace(/~/g,";~;").replace(/'?\.'?(?!(?:(?!\[)[\s\S])*\])|\['?/g,";").replace(/%@%/g,".").replace(/%%@@%%/g,"~").replace(/(?:;)?(\^+)(?:;)?/g,(function(t,e){return";"+e.split("").join(";")+";"})).replace(/;;;|;;/g,";..;").replace(/;$|'?\]|'$/g,"").split(";").map((function(t){var e=t.match(/#([0-9]+)/);return e&&e[1]?r[e[1]]:t}));return e[t]=n,e[t].concat()};v.prototype.vm={runInNewContext:function(t,e){var r=Object.keys(e),n=[];!function(t,e,r){for(var n=t.length,a=0;a<n;a++)r(t[a])&&e.push(t.splice(a--,1)[0])}(r,n,(function(t){return"function"==typeof e[t]}));var a=r.map((function(t,r){return e[t]})),u=n.reduce((function(t,r){var n=e[r].toString();return/function/.test(n)||(n="function "+n),"var "+r+"="+n+";"+t}),"");/(["'])use strict\1/.test(t=u+t)||r.includes("arguments")||(t="var arguments = undefined;"+t);var i=(t=t.replace(/;[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*$/,"")).lastIndexOf(";"),l=i>-1?t.slice(0,i+1)+" return "+t.slice(i+1):" return "+t;return o(Function,c(r).concat([l])).apply(void 0,c(a))}},t.JSONPath=v,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self).JSONPath={})}(this,(function(t){"use strict";function r(t){return(r="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 e(t){return(e=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function n(t,r){return(n=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t})(t,r)}function a(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function o(t,r,e){return(o=a()?Reflect.construct:function(t,r,e){var a=[null];a.push.apply(a,r);var o=new(Function.bind.apply(t,a));return e&&n(o,e.prototype),o}).apply(null,arguments)}function u(t){var r="function"==typeof Map?new Map:void 0;return(u=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!==r){if(r.has(t))return r.get(t);r.set(t,u)}function u(){return o(t,arguments,e(this).constructor)}return u.prototype=Object.create(t.prototype,{constructor:{value:u,enumerable:!1,writable:!0,configurable:!0}}),n(u,t)})(t)}function i(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 c(t){return function(t){if(Array.isArray(t))return s(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||l(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(t,r){if(t){if("string"==typeof t)return s(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?s(t,r):void 0}}function s(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}var p=Object.prototype.hasOwnProperty;function f(t,r){return(t=t.slice()).push(r),t}function h(t,r){return(r=r.slice()).unshift(t),r}var y=function(t){!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&&n(t,r)}(c,t);var r,o,u=(r=c,o=a(),function(){var t,n=e(r);if(o){var a=e(this).constructor;t=Reflect.construct(n,arguments,a)}else t=n.apply(this,arguments);return i(this,t)});function c(t){var r;return function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,c),(r=u.call(this,'JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)')).avoidNew=!0,r.value=t,r.name="NewError",r}return c}(u(Error));function v(t,e,n,a,o){if(!(this instanceof v))try{return new v(t,e,n,a,o)}catch(t){if(!t.avoidNew)throw t;return t.value}"string"==typeof t&&(o=a,a=n,n=e,e=t,t=null);var u=t&&"object"===r(t);if(t=t||{},this.json=t.json||n,this.path=t.path||e,this.resultType=t.resultType||"value",this.flatten=t.flatten||!1,this.wrap=!p.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||o||function(){throw new TypeError("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==t.autostart){var i={path:u?t.path:e};u?"json"in t&&(i.json=t.json):i.json=n;var c=this.evaluate(i);if(!c||"object"!==r(c))throw new y(c);return c}}v.prototype.evaluate=function(t,e,n,a){var o=this,u=this.parent,i=this.parentProperty,c=this.flatten,l=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,(t=t||this.path)&&"object"===r(t)&&!Array.isArray(t)){if(!t.path&&""!==t.path)throw new TypeError('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');if(!p.call(t,"json"))throw new TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');e=t.json,c=p.call(t,"flatten")?t.flatten:c,this.currResultType=p.call(t,"resultType")?t.resultType:this.currResultType,this.currSandbox=p.call(t,"sandbox")?t.sandbox:this.currSandbox,l=p.call(t,"wrap")?t.wrap:l,this.currPreventEval=p.call(t,"preventEval")?t.preventEval:this.currPreventEval,n=p.call(t,"callback")?t.callback:n,this.currOtherTypeCallback=p.call(t,"otherTypeCallback")?t.otherTypeCallback:this.currOtherTypeCallback,u=p.call(t,"parent")?t.parent:u,i=p.call(t,"parentProperty")?t.parentProperty:i,t=t.path}if(u=u||null,i=i||null,Array.isArray(t)&&(t=v.toPathString(t)),(t||""===t)&&e){var s=v.toPathArray(t);"$"===s[0]&&s.length>1&&s.shift(),this._hasParentSelector=null;var f=this._trace(s,e,["$"],u,i,n).filter((function(t){return t&&!t.isParentSelector}));return f.length?l||1!==f.length||f[0].hasArrExpr?f.reduce((function(t,r){var e=o._getPreferredOutput(r);return c&&Array.isArray(e)?t=t.concat(e):t.push(e),t}),[]):this._getPreferredOutput(f[0]):l?[]:void 0}},v.prototype._getPreferredOutput=function(t){var r=this.currResultType;switch(r){case"all":var e=Array.isArray(t.path)?t.path:v.toPathArray(t.path);return t.pointer=v.toPointer(e),t.path="string"==typeof t.path?t.path:v.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[r];case"path":return v.toPathString(t[r]);case"pointer":return v.toPointer(t.path);default:throw new TypeError("Unknown result type")}},v.prototype._handleCallback=function(t,r,e){if(r){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:v.toPathString(t.path),r(n,e,t)}},v.prototype._trace=function(t,e,n,a,o,u,i,c){var s,y=this;if(!t.length)return s={path:n,value:e,parent:a,parentProperty:o,hasArrExpr:i},this._handleCallback(s,u,"value"),s;var v=t[0],b=t.slice(1),F=[];function d(t){Array.isArray(t)?t.forEach((function(t){F.push(t)})):F.push(t)}if(("string"!=typeof v||c)&&e&&p.call(e,v))d(this._trace(b,e[v],f(n,v),e,v,u,i));else if("*"===v)this._walk(v,b,e,n,a,o,u,(function(t,r,e,n,a,o,u,i){d(y._trace(h(t,e),n,a,o,u,i,!0,!0))}));else if(".."===v)d(this._trace(b,e,n,a,o,u,i)),this._walk(v,b,e,n,a,o,u,(function(t,e,n,a,o,u,i,c){"object"===r(a[t])&&d(y._trace(h(e,n),a[t],f(o,t),a,t,c,!0))}));else{if("^"===v)return this._hasParentSelector=!0,{path:n.slice(0,-1),expr:b,isParentSelector:!0};if("~"===v)return s={path:f(n,v),value:o,parent:a,parentProperty:null},this._handleCallback(s,u,"property"),s;if("$"===v)d(this._trace(b,e,n,null,null,u,i));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(v))d(this._slice(v,b,e,n,a,o,u));else if(0===v.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");this._walk(v,b,e,n,a,o,u,(function(t,r,e,n,a,o,u,i){y._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,o,u)&&d(y._trace(h(t,e),n,a,o,u,i,!0))}))}else if("("===v[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");d(this._trace(h(this._eval(v,e,n[n.length-1],n.slice(0,-1),a,o),b),e,n,a,o,u,i))}else if("@"===v[0]){var g=!1,_=v.slice(1,-2);switch(_){case"scalar":e&&["object","function"].includes(r(e))||(g=!0);break;case"boolean":case"string":case"undefined":case"function":r(e)===_&&(g=!0);break;case"integer":!Number.isFinite(e)||e%1||(g=!0);break;case"number":Number.isFinite(e)&&(g=!0);break;case"nonFinite":"number"!=typeof e||Number.isFinite(e)||(g=!0);break;case"object":e&&r(e)===_&&(g=!0);break;case"array":Array.isArray(e)&&(g=!0);break;case"other":g=this.currOtherTypeCallback(e,n,a,o);break;case"null":null===e&&(g=!0);break;default:throw new TypeError("Unknown value type "+_)}if(g)return s={path:n,value:e,parent:a,parentProperty:o},this._handleCallback(s,u,"value"),s}else if("`"===v[0]&&e&&p.call(e,v.slice(1))){var w=v.slice(1);d(this._trace(b,e[w],f(n,w),e,w,u,i,!0))}else if(v.includes(",")){var m,P=function(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=l(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0,a=function(){};return{s:a,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,u=!0,i=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return u=t.done,t},e:function(t){i=!0,o=t},f:function(){try{u||null==e.return||e.return()}finally{if(i)throw o}}}}(v.split(","));try{for(P.s();!(m=P.n()).done;){var D=m.value;d(this._trace(h(D,b),e,n,a,o,u,!0))}}catch(t){P.e(t)}finally{P.f()}}else!c&&e&&p.call(e,v)&&d(this._trace(b,e[v],f(n,v),e,v,u,i,!0))}if(this._hasParentSelector)for(var x=0;x<F.length;x++){var S=F[x];if(S&&S.isParentSelector){var E=this._trace(S.expr,e,S.path,a,o,u,i);if(Array.isArray(E)){F[x]=E[0];for(var A=E.length,j=1;j<A;j++)x++,F.splice(x,0,E[j])}else F[x]=E}}return F},v.prototype._walk=function(t,e,n,a,o,u,i,c){if(Array.isArray(n))for(var l=n.length,s=0;s<l;s++)c(s,t,e,n,a,o,u,i);else n&&"object"===r(n)&&Object.keys(n).forEach((function(r){c(r,t,e,n,a,o,u,i)}))},v.prototype._slice=function(t,r,e,n,a,o,u){if(Array.isArray(e)){var i=e.length,c=t.split(":"),l=c[2]&&Number.parseInt(c[2])||1,s=c[0]&&Number.parseInt(c[0])||0,p=c[1]&&Number.parseInt(c[1])||i;s=s<0?Math.max(0,s+i):Math.min(i,s),p=p<0?Math.max(0,p+i):Math.min(i,p);for(var f=[],y=s;y<p;y+=l){this._trace(h(y,r),e,n,a,o,u,!0).forEach((function(t){f.push(t)}))}return f}},v.prototype._eval=function(t,r,e,n,a,o){t.includes("@parentProperty")&&(this.currSandbox._$_parentProperty=o,t=t.replace(/@parentProperty/g,"_$_parentProperty")),t.includes("@parent")&&(this.currSandbox._$_parent=a,t=t.replace(/@parent/g,"_$_parent")),t.includes("@property")&&(this.currSandbox._$_property=e,t=t.replace(/@property/g,"_$_property")),t.includes("@path")&&(this.currSandbox._$_path=v.toPathString(n.concat([e])),t=t.replace(/@path/g,"_$_path")),t.includes("@root")&&(this.currSandbox._$_root=this.json,t=t.replace(/@root/g,"_$_root")),/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/.test(t)&&(this.currSandbox._$_v=r,t=t.replace(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/g,"_$_v$1"));try{return this.vm.runInNewContext(t,this.currSandbox)}catch(r){throw console.log(r),new Error("jsonPath: "+r.message+": "+t)}},v.cache={},v.toPathString=function(t){for(var r=t,e=r.length,n="$",a=1;a<e;a++)/^(~|\^|@(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\(\))$/.test(r[a])||(n+=/^[\*0-9]+$/.test(r[a])?"["+r[a]+"]":"['"+r[a]+"']");return n},v.toPointer=function(t){for(var r=t,e=r.length,n="",a=1;a<e;a++)/^(~|\^|@(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\(\))$/.test(r[a])||(n+="/"+r[a].toString().replace(/~/g,"~0").replace(/\//g,"~1"));return n},v.toPathArray=function(t){var r=v.cache;if(r[t])return r[t].concat();var e=[],n=t.replace(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/g,";$&;").replace(/['\[](\??\((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\))['\]]/g,(function(t,r){return"[#"+(e.push(r)-1)+"]"})).replace(/\[["']((?:(?!['\]])[\s\S])*)["']\]/g,(function(t,r){return"['"+r.replace(/\./g,"%@%").replace(/~/g,"%%@@%%")+"']"})).replace(/~/g,";~;").replace(/["']?\.["']?(?!(?:(?!\[)[\s\S])*\])|\[["']?/g,";").replace(/%@%/g,".").replace(/%%@@%%/g,"~").replace(/(?:;)?(\^+)(?:;)?/g,(function(t,r){return";"+r.split("").join(";")+";"})).replace(/;;;|;;/g,";..;").replace(/;$|'?\]|'$/g,"").split(";").map((function(t){var r=t.match(/#([0-9]+)/);return r&&r[1]?e[r[1]]:t}));return r[t]=n,r[t].concat()};v.prototype.vm={runInNewContext:function(t,r){var e=Object.keys(r),n=[];!function(t,r,e){for(var n=t.length,a=0;a<n;a++)e(t[a])&&r.push(t.splice(a--,1)[0])}(e,n,(function(t){return"function"==typeof r[t]}));var a=e.map((function(t,e){return r[t]})),u=n.reduce((function(t,e){var n=r[e].toString();return/function/.test(n)||(n="function "+n),"var "+e+"="+n+";"+t}),"");/(["'])use strict\1/.test(t=u+t)||e.includes("arguments")||(t="var arguments = undefined;"+t);var i=(t=t.replace(/;[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*$/,"")).lastIndexOf(";"),l=i>-1?t.slice(0,i+1)+" return "+t.slice(i+1):" return "+t;return o(Function,c(e).concat([l])).apply(void 0,c(a))}},t.JSONPath=v,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index-browser-umd.min.js.map |
@@ -365,3 +365,3 @@ 'use strict'; | ||
// simple case--directly follow property | ||
addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr)); | ||
addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr)); // eslint-disable-next-line unicorn/prefer-switch -- Part of larger `if` | ||
} else if (loc === '*') { | ||
@@ -714,7 +714,7 @@ // all child properties | ||
}) // Escape periods and tildes within properties | ||
.replace(/\['([^'\]]*)'\]/gu, function ($0, prop) { | ||
.replace(/\[['"]([^'\]]*)['"]\]/gu, function ($0, prop) { | ||
return "['" + prop.replace(/\./gu, '%@%').replace(/~/gu, '%%@@%%') + "']"; | ||
}) // Properties operator | ||
.replace(/~/gu, ';~;') // Split by property boundaries | ||
.replace(/'?\.'?(?![^[]*\])|\['?/gu, ';') // Reinsert periods within properties | ||
.replace(/['"]?\.['"]?(?![^[]*\])|\[['"]?/gu, ';') // Reinsert periods within properties | ||
.replace(/%@%/gu, '.') // Reinsert tildes within properties | ||
@@ -721,0 +721,0 @@ .replace(/%%@@%%/gu, '~') // Parent |
297
package.json
{ | ||
"author": "Stefan Goessner", | ||
"name": "jsonpath-plus", | ||
"version": "5.0.7", | ||
"main": "dist/index-node-cjs.js", | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": { | ||
"browser": "./dist/index-browser-esm.js", | ||
"umd": "./dist/index-browser-umd.js", | ||
"import": "./dist/index-node-esm.mjs", | ||
"require": "./dist/index-node-cjs.js", | ||
"default": "./dist/index-browser-esm.js" | ||
} | ||
}, | ||
"module": "dist/index-node-esm.mjs", | ||
"browser": "dist/index-browser-esm.js", | ||
"types": "./src/jsonpath.d.ts", | ||
"description": "A JS implementation of JSONPath with some additional operators", | ||
"contributors": [ | ||
{ | ||
"name": "Prof. Gössner", | ||
"email": "stefan.goessner@fh-dortmund.de" | ||
}, | ||
{ | ||
"name": "Subbu Allamaraju", | ||
"email": "subbu@subbu.org" | ||
}, | ||
{ | ||
"name": "Mike Brevoort", | ||
"email": "mike@brevoort.com" | ||
}, | ||
{ | ||
"name": "Robert Krahn", | ||
"email": "robert.krahn@gmail.com" | ||
}, | ||
{ | ||
"name": "Brett Zamir", | ||
"email": "brettz9@yahoo.com" | ||
}, | ||
{ | ||
"name": "Richard Schneider", | ||
"email": "makaretu@gmail.com" | ||
} | ||
], | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/s3u/JSONPath.git" | ||
}, | ||
"bugs": "https://github.com/s3u/JSONPath/issues/", | ||
"homepage": "https://github.com/s3u/JSONPath", | ||
"engines": { | ||
"node": ">=10.0.0" | ||
}, | ||
"react-native": { | ||
"vm": false | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@babel/core": "^7.13.15", | ||
"@babel/preset-env": "^7.13.15", | ||
"@brettz9/eslint-plugin": "^1.0.3", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
"chai": "^4.3.4", | ||
"core-js-bundle": "^3.10.1", | ||
"coveradge": "^0.6.0", | ||
"eslint": "^7.23.0", | ||
"eslint-config-ash-nazg": "^29.9.0", | ||
"eslint-config-standard": "^16.0.2", | ||
"eslint-plugin-array-func": "^3.1.7", | ||
"eslint-plugin-chai-expect": "^2.2.0", | ||
"eslint-plugin-chai-friendly": "^0.6.0", | ||
"eslint-plugin-compat": "^3.9.0", | ||
"eslint-plugin-eslint-comments": "^3.2.0", | ||
"eslint-plugin-html": "^6.1.2", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-jsdoc": "^32.3.0", | ||
"eslint-plugin-markdown": "^2.0.1", | ||
"eslint-plugin-no-unsanitized": "^3.1.4", | ||
"eslint-plugin-no-use-extend-native": "^0.5.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^4.3.1", | ||
"eslint-plugin-radar": "^0.2.1", | ||
"eslint-plugin-standard": "^4.1.0", | ||
"eslint-plugin-unicorn": "^29.0.0", | ||
"esm": "^3.2.25", | ||
"http-server": "^0.12.3", | ||
"license-badger": "^0.18.0", | ||
"mocha": "^8.3.2", | ||
"mocha-badge-generator": "^0.9.0", | ||
"mocha-multi-reporters": "^1.5.1", | ||
"nyc": "^15.1.0", | ||
"open-cli": "^6.0.1", | ||
"remark-cli": "^9.0.0", | ||
"remark-lint-code-block-style": "^2.0.1", | ||
"remark-lint-ordered-list-marker-value": "^2.0.1", | ||
"rollup": "2.45.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"typedoc": "^0.20.35", | ||
"typescript": "^4.2.4" | ||
}, | ||
"keywords": [ | ||
"json", | ||
"jsonpath" | ||
], | ||
"browserslist": [ | ||
"cover 100%" | ||
], | ||
"nyc": { | ||
"reporter": [ | ||
"text", | ||
"html", | ||
"json-summary" | ||
], | ||
"exclude": [ | ||
".mocharc.js", | ||
".eslintrc.js", | ||
"rollup.config.js", | ||
".idea", | ||
"coverage", | ||
"dist", | ||
"demo", | ||
"docs", | ||
"ignore", | ||
"test", | ||
"test-helpers" | ||
] | ||
}, | ||
"scripts": { | ||
"prepublishOnly": "pnpm i && echo 'reenable this when may be working for pnpm: npm run license-badges'", | ||
"license-badge": "license-badger --corrections --uncategorizedLicenseTemplate \"\\${license} (\\${name} (\\${version}))\" --filteredTypes=nonempty --textTemplate \"License types\n(project, deps, and bundled devDeps)\" --packageJson --production badges/licenses-badge.svg", | ||
"license-badge-dev": "license-badger --corrections --filteredTypes=nonempty --textTemplate \"License types\n(all devDeps)\" --allDevelopment badges/licenses-badge-dev.svg", | ||
"license-badges": "npm run license-badge && npm run license-badge-dev", | ||
"remark": "remark -q -f .", | ||
"build-docs": "typedoc --out docs/ts src --excludeExternals --tsconfig src/tsconfig.json", | ||
"open-docs": "open-cli http://localhost:8084/docs/ts/ && npm start", | ||
"coverage": "open-cli http://localhost:8084/coverage/ && npm start", | ||
"coverage-badge": "coveradge badges/coverage-badge.svg", | ||
"node-import-test": "node --experimental-modules demo/node-import-test.mjs", | ||
"open": "open-cli http://localhost:8084/demo/ && npm start", | ||
"start": "http-server -p 8084", | ||
"typescript": "tsc -p src", | ||
"mocha": "mocha --require esm --require test-helpers/node-env.js --reporter-options configFile=mocha-multi-reporters.json test", | ||
"nyc": "rm -Rf ./coverage && rm -Rf ./node_modules/.cache && nyc --all npm run mocha && npm run coverage-badge", | ||
"rollup": "rollup -c", | ||
"eslint": "eslint --ext js,md,html .", | ||
"test": "npm run eslint && npm run rollup && npm run nyc && npm run typescript", | ||
"browser-test": "npm run eslint && npm run rollup && open-cli http://localhost:8084/test/ && npm start" | ||
} | ||
"author": "Stefan Goessner", | ||
"name": "jsonpath-plus", | ||
"version": "5.1.0", | ||
"main": "dist/index-node-cjs.js", | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": { | ||
"browser": "./dist/index-browser-esm.js", | ||
"umd": "./dist/index-browser-umd.js", | ||
"import": "./dist/index-node-esm.mjs", | ||
"require": "./dist/index-node-cjs.js", | ||
"default": "./dist/index-browser-esm.js" | ||
} | ||
}, | ||
"module": "dist/index-node-esm.mjs", | ||
"browser": "dist/index-browser-esm.js", | ||
"types": "./src/jsonpath.d.ts", | ||
"description": "A JS implementation of JSONPath with some additional operators", | ||
"contributors": [ | ||
{ | ||
"name": "Prof. Gössner", | ||
"email": "stefan.goessner@fh-dortmund.de" | ||
}, | ||
{ | ||
"name": "Subbu Allamaraju", | ||
"email": "subbu@subbu.org" | ||
}, | ||
{ | ||
"name": "Mike Brevoort", | ||
"email": "mike@brevoort.com" | ||
}, | ||
{ | ||
"name": "Robert Krahn", | ||
"email": "robert.krahn@gmail.com" | ||
}, | ||
{ | ||
"name": "Brett Zamir", | ||
"email": "brettz9@yahoo.com" | ||
}, | ||
{ | ||
"name": "Richard Schneider", | ||
"email": "makaretu@gmail.com" | ||
} | ||
], | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/s3u/JSONPath.git" | ||
}, | ||
"bugs": "https://github.com/s3u/JSONPath/issues/", | ||
"homepage": "https://github.com/s3u/JSONPath", | ||
"engines": { | ||
"node": ">=10.0.0" | ||
}, | ||
"react-native": { | ||
"vm": false | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@babel/core": "^7.14.6", | ||
"@babel/preset-env": "^7.14.7", | ||
"@brettz9/eslint-plugin": "^1.0.3", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
"chai": "^4.3.4", | ||
"core-js-bundle": "^3.15.1", | ||
"coveradge": "^0.7.0", | ||
"eslint": "^7.29.0", | ||
"eslint-config-ash-nazg": "^29.17.1", | ||
"eslint-config-standard": "^16.0.3", | ||
"eslint-plugin-array-func": "^3.1.7", | ||
"eslint-plugin-chai-expect": "^2.2.0", | ||
"eslint-plugin-chai-friendly": "^0.7.1", | ||
"eslint-plugin-compat": "^3.9.0", | ||
"eslint-plugin-eslint-comments": "^3.2.0", | ||
"eslint-plugin-html": "^6.1.2", | ||
"eslint-plugin-import": "^2.23.4", | ||
"eslint-plugin-jsdoc": "^35.4.0", | ||
"eslint-plugin-markdown": "^2.2.0", | ||
"eslint-plugin-no-unsanitized": "^3.1.5", | ||
"eslint-plugin-no-use-extend-native": "^0.5.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^5.1.0", | ||
"eslint-plugin-radar": "^0.2.1", | ||
"eslint-plugin-standard": "^4.1.0", | ||
"eslint-plugin-unicorn": "^33.0.1", | ||
"esm": "^3.2.25", | ||
"http-server": "^0.12.3", | ||
"license-badger": "^0.19.0", | ||
"mocha": "^8.4.0", | ||
"mocha-badge-generator": "^0.9.0", | ||
"mocha-multi-reporters": "^1.5.1", | ||
"nyc": "^15.1.0", | ||
"open-cli": "^7.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-lint-code-block-style": "^2.0.1", | ||
"remark-lint-ordered-list-marker-value": "^2.0.1", | ||
"rollup": "2.52.2", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"typedoc": "^0.21.0", | ||
"typescript": "^4.3.4" | ||
}, | ||
"keywords": [ | ||
"json", | ||
"jsonpath" | ||
], | ||
"browserslist": [ | ||
"cover 100%" | ||
], | ||
"nyc": { | ||
"reporter": [ | ||
"text", | ||
"html", | ||
"json-summary" | ||
], | ||
"exclude": [ | ||
".mocharc.js", | ||
".eslintrc.js", | ||
"rollup.config.js", | ||
".idea", | ||
"coverage", | ||
"dist", | ||
"demo", | ||
"docs", | ||
"ignore", | ||
"test", | ||
"test-helpers" | ||
] | ||
}, | ||
"scripts": { | ||
"license-badge": "license-badger --corrections --uncategorizedLicenseTemplate \"\\${license} (\\${name} (\\${version}))\" --filteredTypes=nonempty --textTemplate \"License types\n(project, deps, and bundled devDeps)\" --packageJson --production badges/licenses-badge.svg", | ||
"license-badge-dev": "license-badger --corrections --filteredTypes=nonempty --textTemplate \"License types\n(all devDeps)\" --allDevelopment badges/licenses-badge-dev.svg", | ||
"license-badges": "npm run license-badge && npm run license-badge-dev", | ||
"remark": "remark -q -f .", | ||
"build-docs": "typedoc --out docs/ts src --excludeExternals --tsconfig src/tsconfig.json", | ||
"open-docs": "open-cli http://localhost:8084/docs/ts/ && npm start", | ||
"coverage": "open-cli http://localhost:8084/coverage/ && npm start", | ||
"coverage-badge": "coveradge badges/coverage-badge.svg", | ||
"node-import-test": "node --experimental-modules demo/node-import-test.mjs", | ||
"open": "open-cli http://localhost:8084/demo/ && npm start", | ||
"start": "http-server -p 8084", | ||
"typescript": "tsc -p src", | ||
"mocha": "mocha --require esm --require test-helpers/node-env.js --reporter-options configFile=mocha-multi-reporters.json test", | ||
"nyc": "rm -Rf ./coverage && rm -Rf ./node_modules/.cache && nyc --all npm run mocha && npm run coverage-badge", | ||
"rollup": "rollup -c", | ||
"eslint": "eslint --ext js,md,html .", | ||
"test": "npm run eslint && npm run rollup && npm run nyc && npm run typescript", | ||
"browser-test": "npm run eslint && npm run rollup && open-cli http://localhost:8084/test/ && npm start" | ||
} | ||
} |
@@ -345,2 +345,3 @@ const {hasOwnProperty: hasOwnProp} = Object.prototype; | ||
hasArrExpr)); | ||
// eslint-disable-next-line unicorn/prefer-switch -- Part of larger `if` | ||
} else if (loc === '*') { // all child properties | ||
@@ -673,3 +674,3 @@ this._walk( | ||
// Escape periods and tildes within properties | ||
.replace(/\['([^'\]]*)'\]/gu, function ($0, prop) { | ||
.replace(/\[['"]([^'\]]*)['"]\]/gu, function ($0, prop) { | ||
return "['" + prop | ||
@@ -683,3 +684,3 @@ .replace(/\./gu, '%@%') | ||
// Split by property boundaries | ||
.replace(/'?\.'?(?![^[]*\])|\['?/gu, ';') | ||
.replace(/['"]?\.['"]?(?![^[]*\])|\[['"]?/gu, ';') | ||
// Reinsert periods within properties | ||
@@ -686,0 +687,0 @@ .replace(/%@%/gu, '.') |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
295684
4184