jsonpath-plus
Advanced tools
Comparing version 1.0.0 to 1.1.0
# CHANGES for jsonpath-plus | ||
## 1.1.0 (September 26, 2019) | ||
- Enhancement: Add explicit 'any' to `evaluate()` declaration (for use | ||
with `noImplicitAny` TypeScript option) | ||
- Build: Update minified build files | ||
- Travis: Update to check Node 6, 10, 12 | ||
- npm: Ignore `.idea`/`.remarkrc` files | ||
- npm: Update devDeps (Babel, linting, Rollup, TypeScript related) | ||
- npm: Avoid eslint script within test script | ||
- npm: Ignore typescript docs | ||
## 1.0.0 (August 7, 2019) | ||
@@ -4,0 +15,0 @@ |
@@ -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(t,r,a){return(n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}()?Reflect.construct:function(t,r,n){var a=[null];a.push.apply(a,r);var u=new(Function.bind.apply(t,a));return n&&e(u,n.prototype),u}).apply(null,arguments)}function a(t){var u="function"==typeof Map?new Map:void 0;return(a=function(t){if(null===t||(a=t,-1===Function.toString.call(a).indexOf("[native code]")))return t;var a;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==u){if(u.has(t))return u.get(t);u.set(t,o)}function o(){return n(t,arguments,r(this).constructor)}return o.prototype=Object.create(t.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),e(o,t)})(t)}function u(t,r){return!r||"object"!=typeof r&&"function"!=typeof r?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):r}var o=eval,i=["value","path","pointer","parent","parentProperty","all"],c=Object.prototype.hasOwnProperty,l=function(){try{return"[object process]"===Object.prototype.toString.call(global.process)}catch(t){return!1}}()?require("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=n.reduce(function(t,e){var n=r[e].toString();return/function/.exec(n)||(n="function "+n),"var "+e+"="+n+";"+t},"")+e.reduce(function(t,e){return"var "+e+"="+JSON.stringify(r[e]).replace(/\u2028|\u2029/g,function(t){return"\\u202"+("\u2028"===t?"8":"9")})+";"+t},t);return o(a)}};function p(t,r){return(t=t.slice()).push(r),t}function s(t,r){return(r=r.slice()).unshift(t),r}var h=function(t){function n(t){var e;return function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,n),(e=u(this,r(n).call(this,'JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)'))).avoidNew=!0,e.value=t,e.name="NewError",e}return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),r&&e(t,r)}(n,a(Error)),n}();function f(r,e,n,a,u){if(!(this instanceof f))try{return new f(r,e,n,a,u)}catch(t){if(!t.avoidNew)throw t;return t.value}"string"==typeof r&&(u=a,a=n,n=e,e=r,r={}),r=r||{};var o=c.call(r,"json")&&c.call(r,"path");if(this.json=r.json||n,this.path=r.path||e,this.resultType=r.resultType&&r.resultType.toLowerCase()||"value",this.flatten=r.flatten||!1,this.wrap=!c.call(r,"wrap")||r.wrap,this.sandbox=r.sandbox||{},this.preventEval=r.preventEval||!1,this.parent=r.parent||null,this.parentProperty=r.parentProperty||null,this.callback=r.callback||a||null,this.otherTypeCallback=r.otherTypeCallback||u||function(){throw new Error("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==r.autostart){var i=this.evaluate({path:o?r.path:e,json:o?r.json:n});if(!i||"object"!==t(i))throw new h(i);return i}}f.prototype.evaluate=function(r,e,n,a){var u=this,o=this.parent,l=this.parentProperty,p=this.flatten,s=this.wrap;if(this.currResultType=this.resultType,this.currPreventEval=this.preventEval,this.currSandbox=this.sandbox,n=n||this.callback,this.currOtherTypeCallback=a||this.otherTypeCallback,e=e||this.json,(r=r||this.path)&&"object"===t(r)){if(!r.path)throw new Error('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');e=c.call(r,"json")?r.json:e,p=c.call(r,"flatten")?r.flatten:p,this.currResultType=c.call(r,"resultType")?r.resultType:this.currResultType,this.currSandbox=c.call(r,"sandbox")?r.sandbox:this.currSandbox,s=c.call(r,"wrap")?r.wrap:s,this.currPreventEval=c.call(r,"preventEval")?r.preventEval:this.currPreventEval,n=c.call(r,"callback")?r.callback:n,this.currOtherTypeCallback=c.call(r,"otherTypeCallback")?r.otherTypeCallback:this.currOtherTypeCallback,o=c.call(r,"parent")?r.parent:o,l=c.call(r,"parentProperty")?r.parentProperty:l,r=r.path}if(o=o||null,l=l||null,Array.isArray(r)&&(r=f.toPathString(r)),r&&e&&i.includes(this.currResultType)){this._obj=e;var h=f.toPathArray(r);"$"===h[0]&&h.length>1&&h.shift(),this._hasParentSelector=null;var F=this._trace(h,e,["$"],o,l,n).filter(function(t){return t&&!t.isParentSelector});return F.length?1!==F.length||s||Array.isArray(F[0].value)?F.reduce(function(t,r){var e=u._getPreferredOutput(r);return p&&Array.isArray(e)?t=t.concat(e):t.push(e),t},[]):this._getPreferredOutput(F[0]):s?[]:void 0}},f.prototype._getPreferredOutput=function(t){var r=this.currResultType;switch(r){default:throw new TypeError("Unknown result type");case"all":return t.pointer=f.toPointer(t.path),t.path="string"==typeof t.path?t.path:f.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[r];case"path":return f.toPathString(t[r]);case"pointer":return f.toPointer(t.path)}},f.prototype._handleCallback=function(t,r,e){if(r){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:f.toPathString(t.path),r(n,e,t)}},f.prototype._trace=function(r,e,n,a,u,o,i){var l,h=this;if(!r.length)return l={path:n,value:e,parent:a,parentProperty:u},this._handleCallback(l,o,"value"),l;var f=r[0],F=r.slice(1),y=[];function v(t){Array.isArray(t)?t.forEach(function(t){y.push(t)}):y.push(t)}if(("string"!=typeof f||i)&&e&&c.call(e,f))v(this._trace(F,e[f],p(n,f),e,f,o));else if("*"===f)this._walk(f,F,e,n,a,u,o,function(t,r,e,n,a,u,o,i){v(h._trace(s(t,e),n,a,u,o,i,!0))});else if(".."===f)v(this._trace(F,e,n,a,u,o)),this._walk(f,F,e,n,a,u,o,function(r,e,n,a,u,o,i,c){"object"===t(a[r])&&v(h._trace(s(e,n),a[r],p(u,r),a,r,c))});else{if("^"===f)return this._hasParentSelector=!0,n.length?{path:n.slice(0,-1),expr:F,isParentSelector:!0}:[];if("~"===f)return l={path:p(n,f),value:u,parent:a,parentProperty:null},this._handleCallback(l,o,"property"),l;if("$"===f)v(this._trace(F,e,n,null,null,o));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(f))v(this._slice(f,F,e,n,a,u,o));else if(0===f.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");this._walk(f,F,e,n,a,u,o,function(t,r,e,n,a,u,o,i){h._eval(r.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/,"$1"),n[t],t,a,u,o)&&v(h._trace(s(t,e),n,a,u,o,i))})}else if("("===f[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");v(this._trace(s(this._eval(f,e,n[n.length-1],n.slice(0,-1),a,u),F),e,n,a,u,o))}else if("@"===f[0]){var b=!1,D=f.slice(1,-2);switch(D){default:throw new TypeError("Unknown value type "+D);case"scalar":e&&["object","function"].includes(t(e))||(b=!0);break;case"boolean":case"string":case"undefined":case"function":t(e)===D&&(b=!0);break;case"number":t(e)===D&&isFinite(e)&&(b=!0);break;case"nonFinite":"number"!=typeof e||isFinite(e)||(b=!0);break;case"object":e&&t(e)===D&&(b=!0);break;case"array":Array.isArray(e)&&(b=!0);break;case"other":b=this.currOtherTypeCallback(e,n,a,u);break;case"integer":e!==Number(e)||!isFinite(e)||e%1||(b=!0);break;case"null":null===e&&(b=!0)}if(b)return l={path:n,value:e,parent:a,parentProperty:u},this._handleCallback(l,o,"value"),l}else if("`"===f[0]&&e&&c.call(e,f.slice(1))){var g=f.slice(1);v(this._trace(F,e[g],p(n,g),e,g,o,!0))}else if(f.includes(",")){var _=f.split(","),d=!0,w=!1,P=void 0;try{for(var x,E=_[Symbol.iterator]();!(d=(x=E.next()).done);d=!0){var S=x.value;v(this._trace(s(S,F),e,n,a,u,o))}}catch(t){w=!0,P=t}finally{try{d||null==E.return||E.return()}finally{if(w)throw P}}}else!i&&e&&c.call(e,f)&&v(this._trace(F,e[f],p(n,f),e,f,o,!0))}if(this._hasParentSelector)for(var C=0;C<y.length;C++){var k=y[C];if(k.isParentSelector){var j=h._trace(k.expr,e,k.path,a,u,o);if(Array.isArray(j)){y[C]=j[0];for(var m=j.length,O=1;O<m;O++)C++,y.splice(C,0,j[O])}else y[C]=j}}return y},f.prototype._walk=function(r,e,n,a,u,o,i,l){if(Array.isArray(n))for(var p=n.length,s=0;s<p;s++)l(s,r,e,n,a,u,o,i);else if("object"===t(n))for(var h in n)c.call(n,h)&&l(h,r,e,n,a,u,o,i)},f.prototype._slice=function(t,r,e,n,a,u,o){if(Array.isArray(e)){var i=e.length,c=t.split(":"),l=c[2]&&parseInt(c[2])||1,p=c[0]&&parseInt(c[0])||0,h=c[1]&&parseInt(c[1])||i;p=p<0?Math.max(0,p+i):Math.min(i,p),h=h<0?Math.max(0,h+i):Math.min(i,h);for(var f=[],F=p;F<h;F+=l){var y=this._trace(s(F,r),e,n,a,u,o);Array.isArray(y)?y.forEach(function(t){f.push(t)}):f.push(y)}return f}},f.prototype._eval=function(t,r,e,n,a,u){if(!this._obj||!r)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=e,t=t.replace(/@property/g,"_$_property")),t.includes("@path")&&(this.currSandbox._$_path=f.toPathString(n.concat([e])),t=t.replace(/@path/g,"_$_path")),t.match(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/)&&(this.currSandbox._$_v=r,t=t.replace(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/g,"_$_v$1"));try{return l.runInNewContext(t,this.currSandbox)}catch(r){throw console.log(r),new Error("jsonPath: "+r.message+": "+t)}},f.cache={},f.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},f.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},f.toPathArray=function(t){var r=f.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(/\['((?:[\0-&\(-\\\^-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)'\]/g,function(t,r){return"['"+r.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,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]};export{f 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(t,r,a){return(n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}()?Reflect.construct:function(t,r,n){var a=[null];a.push.apply(a,r);var u=new(Function.bind.apply(t,a));return n&&e(u,n.prototype),u}).apply(null,arguments)}function a(t){var u="function"==typeof Map?new Map:void 0;return(a=function(t){if(null===t||(a=t,-1===Function.toString.call(a).indexOf("[native code]")))return t;var a;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==u){if(u.has(t))return u.get(t);u.set(t,o)}function o(){return n(t,arguments,r(this).constructor)}return o.prototype=Object.create(t.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),e(o,t)})(t)}function u(t,r){return!r||"object"!=typeof r&&"function"!=typeof r?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):r}var o=eval,i=["value","path","pointer","parent","parentProperty","all"],c=Object.prototype.hasOwnProperty,l=function(){try{return"[object process]"===Object.prototype.toString.call(global.process)}catch(t){return!1}}()?require("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=n.reduce((function(t,e){var n=r[e].toString();return/function/.exec(n)||(n="function "+n),"var "+e+"="+n+";"+t}),"")+e.reduce((function(t,e){return"var "+e+"="+JSON.stringify(r[e]).replace(/\u2028|\u2029/g,(function(t){return"\\u202"+("\u2028"===t?"8":"9")}))+";"+t}),t);return o(a)}};function p(t,r){return(t=t.slice()).push(r),t}function s(t,r){return(r=r.slice()).unshift(t),r}var h=function(t){function n(t){var e;return function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,n),(e=u(this,r(n).call(this,'JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)'))).avoidNew=!0,e.value=t,e.name="NewError",e}return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),r&&e(t,r)}(n,a(Error)),n}();function f(r,e,n,a,u){if(!(this instanceof f))try{return new f(r,e,n,a,u)}catch(t){if(!t.avoidNew)throw t;return t.value}"string"==typeof r&&(u=a,a=n,n=e,e=r,r={}),r=r||{};var o=c.call(r,"json")&&c.call(r,"path");if(this.json=r.json||n,this.path=r.path||e,this.resultType=r.resultType&&r.resultType.toLowerCase()||"value",this.flatten=r.flatten||!1,this.wrap=!c.call(r,"wrap")||r.wrap,this.sandbox=r.sandbox||{},this.preventEval=r.preventEval||!1,this.parent=r.parent||null,this.parentProperty=r.parentProperty||null,this.callback=r.callback||a||null,this.otherTypeCallback=r.otherTypeCallback||u||function(){throw new Error("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==r.autostart){var i=this.evaluate({path:o?r.path:e,json:o?r.json:n});if(!i||"object"!==t(i))throw new h(i);return i}}f.prototype.evaluate=function(r,e,n,a){var u=this,o=this.parent,l=this.parentProperty,p=this.flatten,s=this.wrap;if(this.currResultType=this.resultType,this.currPreventEval=this.preventEval,this.currSandbox=this.sandbox,n=n||this.callback,this.currOtherTypeCallback=a||this.otherTypeCallback,e=e||this.json,(r=r||this.path)&&"object"===t(r)){if(!r.path)throw new Error('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');e=c.call(r,"json")?r.json:e,p=c.call(r,"flatten")?r.flatten:p,this.currResultType=c.call(r,"resultType")?r.resultType:this.currResultType,this.currSandbox=c.call(r,"sandbox")?r.sandbox:this.currSandbox,s=c.call(r,"wrap")?r.wrap:s,this.currPreventEval=c.call(r,"preventEval")?r.preventEval:this.currPreventEval,n=c.call(r,"callback")?r.callback:n,this.currOtherTypeCallback=c.call(r,"otherTypeCallback")?r.otherTypeCallback:this.currOtherTypeCallback,o=c.call(r,"parent")?r.parent:o,l=c.call(r,"parentProperty")?r.parentProperty:l,r=r.path}if(o=o||null,l=l||null,Array.isArray(r)&&(r=f.toPathString(r)),r&&e&&i.includes(this.currResultType)){this._obj=e;var h=f.toPathArray(r);"$"===h[0]&&h.length>1&&h.shift(),this._hasParentSelector=null;var F=this._trace(h,e,["$"],o,l,n).filter((function(t){return t&&!t.isParentSelector}));return F.length?1!==F.length||s||Array.isArray(F[0].value)?F.reduce((function(t,r){var e=u._getPreferredOutput(r);return p&&Array.isArray(e)?t=t.concat(e):t.push(e),t}),[]):this._getPreferredOutput(F[0]):s?[]:void 0}},f.prototype._getPreferredOutput=function(t){var r=this.currResultType;switch(r){default:throw new TypeError("Unknown result type");case"all":return t.pointer=f.toPointer(t.path),t.path="string"==typeof t.path?t.path:f.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[r];case"path":return f.toPathString(t[r]);case"pointer":return f.toPointer(t.path)}},f.prototype._handleCallback=function(t,r,e){if(r){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:f.toPathString(t.path),r(n,e,t)}},f.prototype._trace=function(r,e,n,a,u,o,i){var l,h=this;if(!r.length)return l={path:n,value:e,parent:a,parentProperty:u},this._handleCallback(l,o,"value"),l;var f=r[0],F=r.slice(1),y=[];function v(t){Array.isArray(t)?t.forEach((function(t){y.push(t)})):y.push(t)}if(("string"!=typeof f||i)&&e&&c.call(e,f))v(this._trace(F,e[f],p(n,f),e,f,o));else if("*"===f)this._walk(f,F,e,n,a,u,o,(function(t,r,e,n,a,u,o,i){v(h._trace(s(t,e),n,a,u,o,i,!0))}));else if(".."===f)v(this._trace(F,e,n,a,u,o)),this._walk(f,F,e,n,a,u,o,(function(r,e,n,a,u,o,i,c){"object"===t(a[r])&&v(h._trace(s(e,n),a[r],p(u,r),a,r,c))}));else{if("^"===f)return this._hasParentSelector=!0,n.length?{path:n.slice(0,-1),expr:F,isParentSelector:!0}:[];if("~"===f)return l={path:p(n,f),value:u,parent:a,parentProperty:null},this._handleCallback(l,o,"property"),l;if("$"===f)v(this._trace(F,e,n,null,null,o));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(f))v(this._slice(f,F,e,n,a,u,o));else if(0===f.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");this._walk(f,F,e,n,a,u,o,(function(t,r,e,n,a,u,o,i){h._eval(r.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/,"$1"),n[t],t,a,u,o)&&v(h._trace(s(t,e),n,a,u,o,i))}))}else if("("===f[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");v(this._trace(s(this._eval(f,e,n[n.length-1],n.slice(0,-1),a,u),F),e,n,a,u,o))}else if("@"===f[0]){var b=!1,D=f.slice(1,-2);switch(D){default:throw new TypeError("Unknown value type "+D);case"scalar":e&&["object","function"].includes(t(e))||(b=!0);break;case"boolean":case"string":case"undefined":case"function":t(e)===D&&(b=!0);break;case"number":t(e)===D&&isFinite(e)&&(b=!0);break;case"nonFinite":"number"!=typeof e||isFinite(e)||(b=!0);break;case"object":e&&t(e)===D&&(b=!0);break;case"array":Array.isArray(e)&&(b=!0);break;case"other":b=this.currOtherTypeCallback(e,n,a,u);break;case"integer":e!==Number(e)||!isFinite(e)||e%1||(b=!0);break;case"null":null===e&&(b=!0)}if(b)return l={path:n,value:e,parent:a,parentProperty:u},this._handleCallback(l,o,"value"),l}else if("`"===f[0]&&e&&c.call(e,f.slice(1))){var g=f.slice(1);v(this._trace(F,e[g],p(n,g),e,g,o,!0))}else if(f.includes(",")){var _=f.split(","),d=!0,w=!1,P=void 0;try{for(var x,E=_[Symbol.iterator]();!(d=(x=E.next()).done);d=!0){var S=x.value;v(this._trace(s(S,F),e,n,a,u,o))}}catch(t){w=!0,P=t}finally{try{d||null==E.return||E.return()}finally{if(w)throw P}}}else!i&&e&&c.call(e,f)&&v(this._trace(F,e[f],p(n,f),e,f,o,!0))}if(this._hasParentSelector)for(var C=0;C<y.length;C++){var k=y[C];if(k.isParentSelector){var j=h._trace(k.expr,e,k.path,a,u,o);if(Array.isArray(j)){y[C]=j[0];for(var m=j.length,O=1;O<m;O++)C++,y.splice(C,0,j[O])}else y[C]=j}}return y},f.prototype._walk=function(r,e,n,a,u,o,i,l){if(Array.isArray(n))for(var p=n.length,s=0;s<p;s++)l(s,r,e,n,a,u,o,i);else if("object"===t(n))for(var h in n)c.call(n,h)&&l(h,r,e,n,a,u,o,i)},f.prototype._slice=function(t,r,e,n,a,u,o){if(Array.isArray(e)){var i=e.length,c=t.split(":"),l=c[2]&&parseInt(c[2])||1,p=c[0]&&parseInt(c[0])||0,h=c[1]&&parseInt(c[1])||i;p=p<0?Math.max(0,p+i):Math.min(i,p),h=h<0?Math.max(0,h+i):Math.min(i,h);for(var f=[],F=p;F<h;F+=l){var y=this._trace(s(F,r),e,n,a,u,o);Array.isArray(y)?y.forEach((function(t){f.push(t)})):f.push(y)}return f}},f.prototype._eval=function(t,r,e,n,a,u){if(!this._obj||!r)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=e,t=t.replace(/@property/g,"_$_property")),t.includes("@path")&&(this.currSandbox._$_path=f.toPathString(n.concat([e])),t=t.replace(/@path/g,"_$_path")),t.match(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/)&&(this.currSandbox._$_v=r,t=t.replace(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/g,"_$_v$1"));try{return l.runInNewContext(t,this.currSandbox)}catch(r){throw console.log(r),new Error("jsonPath: "+r.message+": "+t)}},f.cache={},f.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},f.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},f.toPathArray=function(t){var r=f.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(/\['((?:[\0-&\(-\\\^-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)'\]/g,(function(t,r){return"['"+r.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,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]};export{f as JSONPath}; | ||
//# sourceMappingURL=index-es.min.js.map |
@@ -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=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}var i=eval,c=["value","path","pointer","parent","parentProperty","all"],l=Object.prototype.hasOwnProperty,p=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 a=n.reduce(function(t,r){var n=e[r].toString();return/function/.exec(n)||(n="function "+n),"var "+r+"="+n+";"+t},"")+r.reduce(function(t,r){return"var "+r+"="+JSON.stringify(e[r]).replace(/\u2028|\u2029/g,function(t){return"\\u202"+("\u2028"===t?"8":"9")})+";"+t},t);return i(a)}};function s(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,u(Error)),e}();function F(t,r,n,a,u){if(!(this instanceof F))try{return new F(t,r,n,a,u)}catch(t){if(!t.avoidNew)throw t;return t.value}"string"==typeof t&&(u=a,a=n,n=r,r=t,t={}),t=t||{};var o=l.call(t,"json")&&l.call(t,"path");if(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 Error("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==t.autostart){var i=this.evaluate({path:o?t.path:r,json:o?t.json:n});if(!i||"object"!==e(i))throw new f(i);return i}}F.prototype.evaluate=function(t,r,n,a){var u=this,o=this.parent,i=this.parentProperty,p=this.flatten,s=this.wrap;if(this.currResultType=this.resultType,this.currPreventEval=this.preventEval,this.currSandbox=this.sandbox,n=n||this.callback,this.currOtherTypeCallback=a||this.otherTypeCallback,r=r||this.json,(t=t||this.path)&&"object"===e(t)){if(!t.path)throw new Error('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');r=l.call(t,"json")?t.json:r,p=l.call(t,"flatten")?t.flatten:p,this.currResultType=l.call(t,"resultType")?t.resultType:this.currResultType,this.currSandbox=l.call(t,"sandbox")?t.sandbox:this.currSandbox,s=l.call(t,"wrap")?t.wrap:s,this.currPreventEval=l.call(t,"preventEval")?t.preventEval:this.currPreventEval,n=l.call(t,"callback")?t.callback:n,this.currOtherTypeCallback=l.call(t,"otherTypeCallback")?t.otherTypeCallback:this.currOtherTypeCallback,o=l.call(t,"parent")?t.parent:o,i=l.call(t,"parentProperty")?t.parentProperty:i,t=t.path}if(o=o||null,i=i||null,Array.isArray(t)&&(t=F.toPathString(t)),t&&r&&c.includes(this.currResultType)){this._obj=r;var h=F.toPathArray(t);"$"===h[0]&&h.length>1&&h.shift(),this._hasParentSelector=null;var f=this._trace(h,r,["$"],o,i,n).filter(function(t){return t&&!t.isParentSelector});return f.length?1!==f.length||s||Array.isArray(f[0].value)?f.reduce(function(t,e){var r=u._getPreferredOutput(e);return p&&Array.isArray(r)?t=t.concat(r):t.push(r),t},[]):this._getPreferredOutput(f[0]):s?[]:void 0}},F.prototype._getPreferredOutput=function(t){var e=this.currResultType;switch(e){default:throw new TypeError("Unknown result type");case"all":return t.pointer=F.toPointer(t.path),t.path="string"==typeof t.path?t.path:F.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[e];case"path":return F.toPathString(t[e]);case"pointer":return F.toPointer(t.path)}},F.prototype._handleCallback=function(t,e,r){if(e){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:F.toPathString(t.path),e(n,r,t)}},F.prototype._trace=function(t,r,n,a,u,o,i){var c,p=this;if(!t.length)return c={path:n,value:r,parent:a,parentProperty:u},this._handleCallback(c,o,"value"),c;var f=t[0],F=t.slice(1),y=[];function v(t){Array.isArray(t)?t.forEach(function(t){y.push(t)}):y.push(t)}if(("string"!=typeof f||i)&&r&&l.call(r,f))v(this._trace(F,r[f],s(n,f),r,f,o));else if("*"===f)this._walk(f,F,r,n,a,u,o,function(t,e,r,n,a,u,o,i){v(p._trace(h(t,r),n,a,u,o,i,!0))});else if(".."===f)v(this._trace(F,r,n,a,u,o)),this._walk(f,F,r,n,a,u,o,function(t,r,n,a,u,o,i,c){"object"===e(a[t])&&v(p._trace(h(r,n),a[t],s(u,t),a,t,c))});else{if("^"===f)return this._hasParentSelector=!0,n.length?{path:n.slice(0,-1),expr:F,isParentSelector:!0}:[];if("~"===f)return c={path:s(n,f),value:u,parent:a,parentProperty:null},this._handleCallback(c,o,"property"),c;if("$"===f)v(this._trace(F,r,n,null,null,o));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(f))v(this._slice(f,F,r,n,a,u,o));else if(0===f.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");this._walk(f,F,r,n,a,u,o,function(t,e,r,n,a,u,o,i){p._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(p._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),F),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(F,r[d],s(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,F),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(F,r[f],s(n,f),r,f,o,!0))}if(this._hasParentSelector)for(var C=0;C<y.length;C++){var k=y[C];if(k.isParentSelector){var j=p._trace(k.expr,r,k.path,a,u,o);if(Array.isArray(j)){y[C]=j[0];for(var O=j.length,m=1;m<O;m++)C++,y.splice(C,0,j[m])}else y[C]=j}}return y},F.prototype._walk=function(t,r,n,a,u,o,i,c){if(Array.isArray(n))for(var p=n.length,s=0;s<p;s++)c(s,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)},F.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,p=c[0]&&parseInt(c[0])||0,s=c[1]&&parseInt(c[1])||i;p=p<0?Math.max(0,p+i):Math.min(i,p),s=s<0?Math.max(0,s+i):Math.min(i,s);for(var f=[],F=p;F<s;F+=l){var y=this._trace(h(F,e),r,n,a,u,o);Array.isArray(y)?y.forEach(function(t){f.push(t)}):f.push(y)}return f}},F.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=F.toPathString(n.concat([r])),t=t.replace(/@path/g,"_$_path")),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 p.runInNewContext(t,this.currSandbox)}catch(e){throw console.log(e),new Error("jsonPath: "+e.message+": "+t)}},F.cache={},F.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},F.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},F.toPathArray=function(t){var e=F.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=F,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!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}var i=eval,c=["value","path","pointer","parent","parentProperty","all"],l=Object.prototype.hasOwnProperty,p=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 a=n.reduce((function(t,r){var n=e[r].toString();return/function/.exec(n)||(n="function "+n),"var "+r+"="+n+";"+t}),"")+r.reduce((function(t,r){return"var "+r+"="+JSON.stringify(e[r]).replace(/\u2028|\u2029/g,(function(t){return"\\u202"+("\u2028"===t?"8":"9")}))+";"+t}),t);return i(a)}};function s(t,e){return(t=t.slice()).push(e),t}function h(t,e){return(e=e.slice()).unshift(t),e}var f=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=o(this,r(e).call(this,'JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)'))).avoidNew=!0,n.value=t,n.name="NewError",n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&n(t,e)}(e,t),e}(u(Error));function F(t,r,n,a,u){if(!(this instanceof F))try{return new F(t,r,n,a,u)}catch(t){if(!t.avoidNew)throw t;return t.value}"string"==typeof t&&(u=a,a=n,n=r,r=t,t={}),t=t||{};var o=l.call(t,"json")&&l.call(t,"path");if(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 Error("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==t.autostart){var i=this.evaluate({path:o?t.path:r,json:o?t.json:n});if(!i||"object"!==e(i))throw new f(i);return i}}F.prototype.evaluate=function(t,r,n,a){var u=this,o=this.parent,i=this.parentProperty,p=this.flatten,s=this.wrap;if(this.currResultType=this.resultType,this.currPreventEval=this.preventEval,this.currSandbox=this.sandbox,n=n||this.callback,this.currOtherTypeCallback=a||this.otherTypeCallback,r=r||this.json,(t=t||this.path)&&"object"===e(t)){if(!t.path)throw new Error('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');r=l.call(t,"json")?t.json:r,p=l.call(t,"flatten")?t.flatten:p,this.currResultType=l.call(t,"resultType")?t.resultType:this.currResultType,this.currSandbox=l.call(t,"sandbox")?t.sandbox:this.currSandbox,s=l.call(t,"wrap")?t.wrap:s,this.currPreventEval=l.call(t,"preventEval")?t.preventEval:this.currPreventEval,n=l.call(t,"callback")?t.callback:n,this.currOtherTypeCallback=l.call(t,"otherTypeCallback")?t.otherTypeCallback:this.currOtherTypeCallback,o=l.call(t,"parent")?t.parent:o,i=l.call(t,"parentProperty")?t.parentProperty:i,t=t.path}if(o=o||null,i=i||null,Array.isArray(t)&&(t=F.toPathString(t)),t&&r&&c.includes(this.currResultType)){this._obj=r;var h=F.toPathArray(t);"$"===h[0]&&h.length>1&&h.shift(),this._hasParentSelector=null;var f=this._trace(h,r,["$"],o,i,n).filter((function(t){return t&&!t.isParentSelector}));return f.length?1!==f.length||s||Array.isArray(f[0].value)?f.reduce((function(t,e){var r=u._getPreferredOutput(e);return p&&Array.isArray(r)?t=t.concat(r):t.push(r),t}),[]):this._getPreferredOutput(f[0]):s?[]:void 0}},F.prototype._getPreferredOutput=function(t){var e=this.currResultType;switch(e){default:throw new TypeError("Unknown result type");case"all":return t.pointer=F.toPointer(t.path),t.path="string"==typeof t.path?t.path:F.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[e];case"path":return F.toPathString(t[e]);case"pointer":return F.toPointer(t.path)}},F.prototype._handleCallback=function(t,e,r){if(e){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:F.toPathString(t.path),e(n,r,t)}},F.prototype._trace=function(t,r,n,a,u,o,i){var c,p=this;if(!t.length)return c={path:n,value:r,parent:a,parentProperty:u},this._handleCallback(c,o,"value"),c;var f=t[0],F=t.slice(1),y=[];function v(t){Array.isArray(t)?t.forEach((function(t){y.push(t)})):y.push(t)}if(("string"!=typeof f||i)&&r&&l.call(r,f))v(this._trace(F,r[f],s(n,f),r,f,o));else if("*"===f)this._walk(f,F,r,n,a,u,o,(function(t,e,r,n,a,u,o,i){v(p._trace(h(t,r),n,a,u,o,i,!0))}));else if(".."===f)v(this._trace(F,r,n,a,u,o)),this._walk(f,F,r,n,a,u,o,(function(t,r,n,a,u,o,i,c){"object"===e(a[t])&&v(p._trace(h(r,n),a[t],s(u,t),a,t,c))}));else{if("^"===f)return this._hasParentSelector=!0,n.length?{path:n.slice(0,-1),expr:F,isParentSelector:!0}:[];if("~"===f)return c={path:s(n,f),value:u,parent:a,parentProperty:null},this._handleCallback(c,o,"property"),c;if("$"===f)v(this._trace(F,r,n,null,null,o));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(f))v(this._slice(f,F,r,n,a,u,o));else if(0===f.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");this._walk(f,F,r,n,a,u,o,(function(t,e,r,n,a,u,o,i){p._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(p._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),F),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(F,r[d],s(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,F),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(F,r[f],s(n,f),r,f,o,!0))}if(this._hasParentSelector)for(var C=0;C<y.length;C++){var k=y[C];if(k.isParentSelector){var j=p._trace(k.expr,r,k.path,a,u,o);if(Array.isArray(j)){y[C]=j[0];for(var O=j.length,m=1;m<O;m++)C++,y.splice(C,0,j[m])}else y[C]=j}}return y},F.prototype._walk=function(t,r,n,a,u,o,i,c){if(Array.isArray(n))for(var p=n.length,s=0;s<p;s++)c(s,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)},F.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,p=c[0]&&parseInt(c[0])||0,s=c[1]&&parseInt(c[1])||i;p=p<0?Math.max(0,p+i):Math.min(i,p),s=s<0?Math.max(0,s+i):Math.min(i,s);for(var f=[],F=p;F<s;F+=l){var y=this._trace(h(F,e),r,n,a,u,o);Array.isArray(y)?y.forEach((function(t){f.push(t)})):f.push(y)}return f}},F.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=F.toPathString(n.concat([r])),t=t.replace(/@path/g,"_$_path")),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 p.runInNewContext(t,this.currSandbox)}catch(e){throw console.log(e),new Error("jsonPath: "+e.message+": "+t)}},F.cache={},F.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},F.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},F.toPathArray=function(t){var e=F.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=F,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index-umd.min.js.map |
{ | ||
"author": "Stefan Goessner", | ||
"name": "jsonpath-plus", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"main": "dist/index-umd.js", | ||
@@ -50,10 +50,10 @@ "module": "dist/index-es.js", | ||
"devDependencies": { | ||
"@babel/core": "^7.5.5", | ||
"@babel/preset-env": "^7.5.5", | ||
"@mysticatea/eslint-plugin": "^11.0.0", | ||
"@babel/core": "^7.6.2", | ||
"@babel/preset-env": "^7.6.2", | ||
"@mysticatea/eslint-plugin": "^12.0.0", | ||
"chai": "^4.2.0", | ||
"core-js-bundle": "^3.1.4", | ||
"eslint": "^6.1.0", | ||
"eslint-config-ash-nazg": "^8.5.2", | ||
"eslint-config-standard": "^13.0.1", | ||
"core-js-bundle": "^3.2.1", | ||
"eslint": "^6.4.0", | ||
"eslint-config-ash-nazg": "^10.0.0", | ||
"eslint-config-standard": "^14.1.0", | ||
"eslint-plugin-array-func": "^3.1.3", | ||
@@ -64,10 +64,10 @@ "eslint-plugin-compat": "^3.3.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-jsdoc": "^15.8.0", | ||
"eslint-plugin-jsdoc": "^15.9.2", | ||
"eslint-plugin-markdown": "^1.0.0", | ||
"eslint-plugin-no-use-extend-native": "^0.4.1", | ||
"eslint-plugin-node": "^9.1.0", | ||
"eslint-plugin-node": "^10.0.0", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"eslint-plugin-sonarjs": "^0.4.0", | ||
"eslint-plugin-standard": "^4.0.0", | ||
"eslint-plugin-unicorn": "^10.0.0", | ||
"eslint-plugin-standard": "^4.0.1", | ||
"eslint-plugin-unicorn": "^12.0.0", | ||
"mocha": "^6.2.0", | ||
@@ -79,7 +79,7 @@ "node-static": "^0.7.11", | ||
"remark-lint-ordered-list-marker-value": "^1.0.3", | ||
"rollup": "1.19.4", | ||
"rollup": "1.21.4", | ||
"rollup-plugin-babel": "^4.3.3", | ||
"rollup-plugin-terser": "^5.1.1", | ||
"rollup-plugin-terser": "^5.1.2", | ||
"typedoc": "^0.15.0", | ||
"typescript": "^3.5.3" | ||
"typescript": "^3.6.3" | ||
}, | ||
@@ -99,3 +99,3 @@ "keywords": [ | ||
"mocha": "mocha --require test-helpers/node-env.js test", | ||
"test": "npm run eslint && npm run rollup && npm run mocha", | ||
"test": "npm run rollup && npm run mocha", | ||
"start": "static -p 8084", | ||
@@ -102,0 +102,0 @@ "rollup": "rollup -c", |
@@ -184,3 +184,3 @@ /** | ||
otherTypeCallback: JSONPathOptions['otherTypeCallback'] | ||
) | ||
): any | ||
evaluate(options: { | ||
@@ -191,3 +191,3 @@ path: JSONPathOptions['path'], | ||
otherTypeCallback: JSONPathOptions['otherTypeCallback'] | ||
}) | ||
}): any | ||
} | ||
@@ -194,0 +194,0 @@ |
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
219486
14
2565