forked from JSONPath-Plus/JSONPath
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index-browser-umd.min.cjs
2 lines (2 loc) · 13.8 KB
/
index-browser-umd.min.cjs
1
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},e(t)}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){for(var r=0;r<e.length;r ){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function a(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(t){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},o(t)}function u(t,e){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},u(t,e)}function i(){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 c(t,e,r){return c=i()?Reflect.construct.bind():function(t,e,r){var n=[null];n.push.apply(n,e);var a=new(Function.bind.apply(t,n));return r&&u(a,r.prototype),a},c.apply(null,arguments)}function l(t){var e="function"==typeof Map?new Map:void 0;return l=function(t){if(null===t||(r=t,-1===Function.toString.call(r).indexOf("[native code]")))return t;var r;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,n)}function n(){return c(t,arguments,o(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),u(n,t)},l(t)}function s(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function p(t){return function(t){if(Array.isArray(t))return h(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||f(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 f(t,e){if(t){if("string"==typeof t)return h(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)?h(t,e):void 0}}function h(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 y=Object.prototype.hasOwnProperty;function v(t,e){return(t=t.slice()).push(e),t}function b(t,e){return(e=e.slice()).unshift(t),e}var F=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}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&u(t,e)}(l,t);var e,n,c=(e=l,n=i(),function(){var t,r=o(e);if(n){var a=o(this).constructor;t=Reflect.construct(r,arguments,a)}else t=r.apply(this,arguments);return s(this,t)});function l(t){var e;return r(this,l),(e=c.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 a(l)}(l(Error));function d(t,r,n,a,o){if(!(this instanceof d))try{return new d(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=!y.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 F(c);return c}}d.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(!y.call(t,"json"))throw new TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');r=t.json,c=y.call(t,"flatten")?t.flatten:c,this.currResultType=y.call(t,"resultType")?t.resultType:this.currResultType,this.currSandbox=y.call(t,"sandbox")?t.sandbox:this.currSandbox,l=y.call(t,"wrap")?t.wrap:l,this.currPreventEval=y.call(t,"preventEval")?t.preventEval:this.currPreventEval,n=y.call(t,"callback")?t.callback:n,this.currOtherTypeCallback=y.call(t,"otherTypeCallback")?t.otherTypeCallback:this.currOtherTypeCallback,u=y.call(t,"parent")?t.parent:u,i=y.call(t,"parentProperty")?t.parentProperty:i,t=t.path}if(u=u||null,i=i||null,Array.isArray(t)&&(t=d.toPathString(t)),(t||""===t)&&r){var s=d.toPathArray(t);"$"===s[0]&&s.length>1&&s.shift(),this._hasParentSelector=null;var p=this._trace(s,r,["$"],u,i,n).filter((function(t){return t&&!t.isParentSelector}));return p.length?l||1!==p.length||p[0].hasArrExpr?p.reduce((function(t,e){var r=o._getPreferredOutput(e);return c&&Array.isArray(r)?t=t.concat(r):t.push(r),t}),[]):this._getPreferredOutput(p[0]):l?[]:void 0}},d.prototype._getPreferredOutput=function(t){var e=this.currResultType;switch(e){case"all":var r=Array.isArray(t.path)?t.path:d.toPathArray(t.path);return t.pointer=d.toPointer(r),t.path="string"==typeof t.path?t.path:d.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[e];case"path":return d.toPathString(t[e]);case"pointer":return d.toPointer(t.path);default:throw new TypeError("Unknown result type")}},d.prototype._handleCallback=function(t,e,r){if(e){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:d.toPathString(t.path),e(n,r,t)}},d.prototype._trace=function(t,r,n,a,o,u,i,c){var l,s=this;if(!t.length)return l={path:n,value:r,parent:a,parentProperty:o,hasArrExpr:i},this._handleCallback(l,u,"value"),l;var p=t[0],h=t.slice(1),F=[];function d(t){Array.isArray(t)?t.forEach((function(t){F.push(t)})):F.push(t)}if(("string"!=typeof p||c)&&r&&y.call(r,p))d(this._trace(h,r[p],v(n,p),r,p,u,i));else if("*"===p)this._walk(r,(function(t){d(s._trace(h,r[t],v(n,t),r,t,u,!0,!0))}));else if(".."===p)d(this._trace(h,r,n,a,o,u,i)),this._walk(r,(function(a){"object"===e(r[a])&&d(s._trace(t.slice(),r[a],v(n,a),r,a,u,!0))}));else{if("^"===p)return this._hasParentSelector=!0,{path:n.slice(0,-1),expr:h,isParentSelector:!0};if("~"===p)return l={path:v(n,p),value:o,parent:a,parentProperty:null},this._handleCallback(l,u,"property"),l;if("$"===p)d(this._trace(h,r,n,null,null,u,i));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(p))d(this._slice(p,h,r,n,a,o,u));else if(0===p.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");var g=p.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/,"$1");this._walk(r,(function(t){s._eval(g,r[t],t,n,a,o)&&d(s._trace(h,r[t],v(n,t),r,t,u,!0))}))}else if("("===p[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");d(this._trace(b(this._eval(p,r,n[n.length-1],n.slice(0,-1),a,o),h),r,n,a,o,u,i))}else if("@"===p[0]){var w=!1,_=p.slice(1,-2);switch(_){case"scalar":r&&["object","function"].includes(e(r))||(w=!0);break;case"boolean":case"string":case"undefined":case"function":e(r)===_&&(w=!0);break;case"integer":!Number.isFinite(r)||r%1||(w=!0);break;case"number":Number.isFinite(r)&&(w=!0);break;case"nonFinite":"number"!=typeof r||Number.isFinite(r)||(w=!0);break;case"object":r&&e(r)===_&&(w=!0);break;case"array":Array.isArray(r)&&(w=!0);break;case"other":w=this.currOtherTypeCallback(r,n,a,o);break;case"null":null===r&&(w=!0);break;default:throw new TypeError("Unknown value type " _)}if(w)return l={path:n,value:r,parent:a,parentProperty:o},this._handleCallback(l,u,"value"),l}else if("`"===p[0]&&r&&y.call(r,p.slice(1))){var m=p.slice(1);d(this._trace(h,r[m],v(n,m),r,m,u,i,!0))}else if(p.includes(",")){var P,D=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=f(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=r.call(t)},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}}}}(p.split(","));try{for(D.s();!(P=D.n()).done;){var S=P.value;d(this._trace(b(S,h),r,n,a,o,u,!0))}}catch(t){D.e(t)}finally{D.f()}}else!c&&r&&y.call(r,p)&&d(this._trace(h,r[p],v(n,p),r,p,u,i,!0))}if(this._hasParentSelector)for(var x=0;x<F.length;x ){var j=F[x];if(j&&j.isParentSelector){var E=this._trace(j.expr,r,j.path,a,o,u,i);if(Array.isArray(E)){F[x]=E[0];for(var O=E.length,A=1;A<O;A )x ,F.splice(x,0,E[A])}else F[x]=E}}return F},d.prototype._walk=function(t,r){if(Array.isArray(t))for(var n=t.length,a=0;a<n;a )r(a);else t&&"object"===e(t)&&Object.keys(t).forEach((function(t){r(t)}))},d.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=[],h=s;h<p;h =l){this._trace(b(h,e),r,n,a,o,u,!0).forEach((function(t){f.push(t)}))}return f}},d.prototype._eval=function(t,e,r,n,a,o){this.currSandbox._$_parentProperty=o,this.currSandbox._$_parent=a,this.currSandbox._$_property=r,this.currSandbox._$_root=this.json,this.currSandbox._$_v=e;var u=t.includes("@path");u&&(this.currSandbox._$_path=d.toPathString(n.concat([r])));var i="script:" t;if(!d.cache[i]){var c=t.replace(/@parentProperty/g,"_$_parentProperty").replace(/@parent/g,"_$_parent").replace(/@property/g,"_$_property").replace(/@root/g,"_$_root").replace(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/g,"_$_v$1");u&&(c=c.replace(/@path/g,"_$_path")),d.cache[i]=new this.vm.Script(c)}try{return d.cache[i].runInNewContext(this.currSandbox)}catch(e){throw new Error("jsonPath: " e.message ": " t)}},d.cache={},d.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},d.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},d.toPathArray=function(t){var e=d.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()};var g=function(){function t(e){r(this,t),this.code=e}return a(t,[{key:"runInNewContext",value:function(t){var e=this.code,r=Object.keys(t),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(e){return"function"==typeof t[e]}));var a=r.map((function(e,r){return t[e]})),o=n.reduce((function(e,r){var n=t[r].toString();return/function/.test(n)||(n="function " n),"var " r "=" n ";" e}),"");/(["'])use strict\1/.test(e=o e)||r.includes("arguments")||(e="var arguments = undefined;" e);var u=(e=e.replace(/;[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*$/,"")).lastIndexOf(";"),i=u>-1?e.slice(0,u 1) " return " e.slice(u 1):" return " e;return c(Function,r.concat([i])).apply(void 0,p(a))}}]),t}();d.prototype.vm={Script:g},t.JSONPath=d,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=index-browser-umd.min.cjs.map