forked from JSONPath-Plus/JSONPath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex-umd.min.js
More file actions
2 lines (2 loc) · 13 KB
/
index-umd.min.js
File metadata and controls
2 lines (2 loc) · 13 KB
1
2
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).JSONPath={})}(this,(function(t){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function r(t){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function n(t,e){return(n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function a(t,e,r){return(a=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}()?Reflect.construct:function(t,e,r){var a=[null];a.push.apply(a,e);var u=new(Function.bind.apply(t,a));return r&&n(u,r.prototype),u}).apply(null,arguments)}function u(t){var e="function"==typeof Map?new Map:void 0;return(u=function(t){if(null===t||(u=t,-1===Function.toString.call(u).indexOf("[native code]")))return t;var u;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,o)}function o(){return a(t,arguments,r(this).constructor)}return o.prototype=Object.create(t.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),n(o,t)})(t)}function o(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function i(t){return function(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e<t.length;e++)r[e]=t[e];return r}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var c=["value","path","pointer","parent","parentProperty","all"],l=Object.prototype.hasOwnProperty,s=function(){try{return"[object process]"===Object.prototype.toString.call(global.process)}catch(t){return!1}}()?require("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 u=r.map((function(t,r){return e[t]}));(t=n.reduce((function(t,r){var n=e[r].toString();return/function/.exec(n)||(n="function "+n),"var "+r+"="+n+";"+t}),"")+t).match(/(["'])use strict\1/)||r.includes("arguments")||(t="var arguments = undefined;"+t);var o=(t=t.replace(/;[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*$/,"")).lastIndexOf(";"),c=o>-1?t.slice(0,o+1)+" return "+t.slice(o+1):" return "+t;return a(Function,i(r).concat([c])).apply(void 0,i(u))}};function p(t,e){return(t=t.slice()).push(e),t}function h(t,e){return(e=e.slice()).unshift(t),e}var f=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=o(this,r(e).call(this,'JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)'))).avoidNew=!0,n.value=t,n.name="NewError",n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&n(t,e)}(e,t),e}(u(Error));function y(t,r,n,a,u){if(!(this instanceof y))try{return new y(t,r,n,a,u)}catch(t){if(!t.avoidNew)throw t;return t.value}"string"==typeof t&&(u=a,a=n,n=r,r=t,t=null);var o=t&&"object"===e(t);if(t=t||{},this.json=t.json||n,this.path=t.path||r,this.resultType=t.resultType&&t.resultType.toLowerCase()||"value",this.flatten=t.flatten||!1,this.wrap=!l.call(t,"wrap")||t.wrap,this.sandbox=t.sandbox||{},this.preventEval=t.preventEval||!1,this.parent=t.parent||null,this.parentProperty=t.parentProperty||null,this.callback=t.callback||a||null,this.otherTypeCallback=t.otherTypeCallback||u||function(){throw new TypeError("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==t.autostart){var i={path:o?t.path:r};o?"json"in t&&(i.json=t.json):i.json=n;var c=this.evaluate(i);if(!c||"object"!==e(c))throw new f(c);return c}}y.prototype.evaluate=function(t,r,n,a){var u=this,o=this.parent,i=this.parentProperty,s=this.flatten,p=this.wrap;if(this.currResultType=this.resultType,this.currPreventEval=this.preventEval,this.currSandbox=this.sandbox,n=n||this.callback,this.currOtherTypeCallback=a||this.otherTypeCallback,r=r||this.json,(t=t||this.path)&&"object"===e(t)){if(!t.path)throw new TypeError('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');if(!("json"in t))throw new TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');r=l.call(t,"json")?t.json:r,s=l.call(t,"flatten")?t.flatten:s,this.currResultType=l.call(t,"resultType")?t.resultType:this.currResultType,this.currSandbox=l.call(t,"sandbox")?t.sandbox:this.currSandbox,p=l.call(t,"wrap")?t.wrap:p,this.currPreventEval=l.call(t,"preventEval")?t.preventEval:this.currPreventEval,n=l.call(t,"callback")?t.callback:n,this.currOtherTypeCallback=l.call(t,"otherTypeCallback")?t.otherTypeCallback:this.currOtherTypeCallback,o=l.call(t,"parent")?t.parent:o,i=l.call(t,"parentProperty")?t.parentProperty:i,t=t.path}if(o=o||null,i=i||null,Array.isArray(t)&&(t=y.toPathString(t)),t&&r&&c.includes(this.currResultType)){this._obj=r;var h=y.toPathArray(t);"$"===h[0]&&h.length>1&&h.shift(),this._hasParentSelector=null;var f=this._trace(h,r,["$"],o,i,n).filter((function(t){return t&&!t.isParentSelector}));return f.length?!p&&this.isSingularResult(f,h)?this._getPreferredOutput(f[0]):f.reduce((function(t,e){var r=u._getPreferredOutput(e);return s&&Array.isArray(r)?t=t.concat(r):t.push(r),t}),[]):p?[]:void 0}},y.prototype._getPreferredOutput=function(t){var e=this.currResultType;switch(e){default:throw new TypeError("Unknown result type");case"all":return t.pointer=y.toPointer(t.path),t.path="string"==typeof t.path?t.path:y.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[e];case"path":return y.toPathString(t[e]);case"pointer":return y.toPointer(t.path)}},y.prototype.isFilterExpr=function(t){return 0===t.indexOf("?(")},y.prototype.isSingularResult=function(t,e){var r=this;return 1===t.length&&!e.includes("*")&&!e.includes("..")&&e.every((function(t){return!r.isFilterExpr(t)}))&&e.every((function(t){return!t.includes(",")}))&&e.every((function(t){return!t.includes(":")}))},y.prototype._handleCallback=function(t,e,r){if(e){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:y.toPathString(t.path),e(n,r,t)}},y.prototype._trace=function(t,r,n,a,u,o,i){var c,s=this;if(!t.length)return c={path:n,value:r,parent:a,parentProperty:u},this._handleCallback(c,o,"value"),c;var f=t[0],y=t.slice(1),F=[];function v(t){Array.isArray(t)?t.forEach((function(t){F.push(t)})):F.push(t)}if(("string"!=typeof f||i)&&r&&l.call(r,f))v(this._trace(y,r[f],p(n,f),r,f,o));else if("*"===f)this._walk(f,y,r,n,a,u,o,(function(t,e,r,n,a,u,o,i){v(s._trace(h(t,r),n,a,u,o,i,!0))}));else if(".."===f)v(this._trace(y,r,n,a,u,o)),this._walk(f,y,r,n,a,u,o,(function(t,r,n,a,u,o,i,c){"object"===e(a[t])&&v(s._trace(h(r,n),a[t],p(u,t),a,t,c))}));else{if("^"===f)return this._hasParentSelector=!0,n.length?{path:n.slice(0,-1),expr:y,isParentSelector:!0}:[];if("~"===f)return c={path:p(n,f),value:u,parent:a,parentProperty:null},this._handleCallback(c,o,"property"),c;if("$"===f)v(this._trace(y,r,n,null,null,o));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(f))v(this._slice(f,y,r,n,a,u,o));else if(this.isFilterExpr(f)){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");this._walk(f,y,r,n,a,u,o,(function(t,e,r,n,a,u,o,i){s._eval(e.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/,"$1"),n[t],t,a,u,o)&&v(s._trace(h(t,r),n,a,u,o,i))}))}else if("("===f[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");v(this._trace(h(this._eval(f,r,n[n.length-1],n.slice(0,-1),a,u),y),r,n,a,u,o))}else if("@"===f[0]){var b=!1,d=f.slice(1,-2);switch(d){default:throw new TypeError("Unknown value type "+d);case"scalar":r&&["object","function"].includes(e(r))||(b=!0);break;case"boolean":case"string":case"undefined":case"function":e(r)===d&&(b=!0);break;case"number":e(r)===d&&isFinite(r)&&(b=!0);break;case"nonFinite":"number"!=typeof r||isFinite(r)||(b=!0);break;case"object":r&&e(r)===d&&(b=!0);break;case"array":Array.isArray(r)&&(b=!0);break;case"other":b=this.currOtherTypeCallback(r,n,a,u);break;case"integer":r!==Number(r)||!isFinite(r)||r%1||(b=!0);break;case"null":null===r&&(b=!0)}if(b)return c={path:n,value:r,parent:a,parentProperty:u},this._handleCallback(c,o,"value"),c}else if("`"===f[0]&&r&&l.call(r,f.slice(1))){var D=f.slice(1);v(this._trace(y,r[D],p(n,D),r,D,o,!0))}else if(f.includes(",")){var g=f.split(","),_=!0,w=!1,P=void 0;try{for(var x,S=g[Symbol.iterator]();!(_=(x=S.next()).done);_=!0){var E=x.value;v(this._trace(h(E,y),r,n,a,u,o))}}catch(t){w=!0,P=t}finally{try{_||null==S.return||S.return()}finally{if(w)throw P}}}else!i&&r&&l.call(r,f)&&v(this._trace(y,r[f],p(n,f),r,f,o,!0))}if(this._hasParentSelector)for(var j=0;j<F.length;j++){var m=F[j];if(m.isParentSelector){var C=s._trace(m.expr,r,m.path,a,u,o);if(Array.isArray(C)){F[j]=C[0];for(var k=C.length,O=1;O<k;O++)j++,F.splice(j,0,C[O])}else F[j]=C}}return F},y.prototype._walk=function(t,r,n,a,u,o,i,c){if(Array.isArray(n))for(var s=n.length,p=0;p<s;p++)c(p,t,r,n,a,u,o,i);else if("object"===e(n))for(var h in n)l.call(n,h)&&c(h,t,r,n,a,u,o,i)},y.prototype._slice=function(t,e,r,n,a,u,o){if(Array.isArray(r)){var i=r.length,c=t.split(":"),l=c[2]&&parseInt(c[2])||1,s=c[0]&&parseInt(c[0])||0,p=c[1]&&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){var F=this._trace(h(y,e),r,n,a,u,o);Array.isArray(F)?F.forEach((function(t){f.push(t)})):f.push(F)}return f}},y.prototype._eval=function(t,e,r,n,a,u){if(!this._obj||!e)return!1;t.includes("@parentProperty")&&(this.currSandbox._$_parentProperty=u,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=y.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.match(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/)&&(this.currSandbox._$_v=e,t=t.replace(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/g,"_$_v$1"));try{return s.runInNewContext(t,this.currSandbox)}catch(e){throw console.log(e),new Error("jsonPath: "+e.message+": "+t)}},y.cache={},y.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},y.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},y.toPathArray=function(t){var e=y.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(/\['((?:[\0-&\(-\\\^-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)'\]/g,(function(t,e){return"['"+e.replace(/\./g,"%@%").replace(/~/g,"%%@@%%")+"']"})).replace(/~/g,";~;").replace(/'?\.'?(?!(?:[\0-Z\\-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*\])|\['?/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]},t.JSONPath=y,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=index-umd.min.js.map