!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);r1&&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-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})})); //# sourceMappingURL=index-browser-umd.min.js.map