jsonpath-plus
Advanced tools
Comparing version 6.0.1 to 7.0.0
# CHANGES for jsonpath-plus | ||
## 7.0.0 | ||
- Breaking change: Bump `engines` to 12 | ||
- fix: remove `console.log` when error is thrown (@sh33dafi) | ||
- chore: update devDeps. | ||
## 6.0.1 (2021-07-07) | ||
@@ -4,0 +10,0 @@ |
function _typeof(obj) { | ||
"@babel/helpers - typeof"; | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
return _typeof(obj); | ||
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}, _typeof(obj); | ||
} | ||
@@ -23,2 +17,21 @@ | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
} | ||
function _inherits(subClass, superClass) { | ||
@@ -36,2 +49,5 @@ if (typeof superClass !== "function" && superClass !== null) { | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
@@ -41,3 +57,3 @@ } | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
@@ -49,7 +65,6 @@ }; | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
@@ -73,3 +88,3 @@ } | ||
if (_isNativeReflectConstruct()) { | ||
_construct = Reflect.construct; | ||
_construct = Reflect.construct.bind(); | ||
} else { | ||
@@ -138,2 +153,4 @@ _construct = function _construct(Parent, args, Class) { | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
@@ -255,9 +272,17 @@ | ||
/** | ||
* @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject | ||
*/ | ||
* @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject | ||
*/ | ||
/** | ||
* @typedef {any} AnyItem | ||
*/ | ||
/** | ||
* @typedef {any} AnyResult | ||
*/ | ||
/** | ||
* Copies array and then pushes item into it. | ||
* @param {GenericArray} arr Array to copy and into which to push | ||
* @param {any} item Array item to add (to end) | ||
* @param {AnyItem} item Array item to add (to end) | ||
* @returns {GenericArray} Copy of the original array | ||
@@ -273,3 +298,3 @@ */ | ||
* Copies array and then unshifts item into it. | ||
* @param {any} item Array item to add (to beginning) | ||
* @param {AnyItem} item Array item to add (to beginning) | ||
* @param {GenericArray} arr Array to copy and into which to unshift | ||
@@ -297,3 +322,3 @@ * @returns {GenericArray} Copy of the original array | ||
/** | ||
* @param {any} value The evaluated scalar value | ||
* @param {AnyResult} value The evaluated scalar value | ||
*/ | ||
@@ -312,3 +337,3 @@ function NewError(value) { | ||
return NewError; | ||
return _createClass(NewError); | ||
}( /*#__PURE__*/_wrapNativeSuper(Error)); | ||
@@ -554,3 +579,3 @@ /** | ||
fullRetObj.path = typeof fullRetObj.path === 'string' ? fullRetObj.path : JSONPath.toPathString(fullRetObj.path); // eslint-disable-next-line node/callback-return | ||
fullRetObj.path = typeof fullRetObj.path === 'string' ? fullRetObj.path : JSONPath.toPathString(fullRetObj.path); // eslint-disable-next-line n/callback-return | ||
@@ -911,4 +936,2 @@ callback(preferredOutput, type, fullRetObj); | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.log(e); | ||
throw new Error('jsonPath: ' + e.message + ': ' + code); | ||
@@ -999,8 +1022,16 @@ } | ||
/** | ||
* @callback ConditionCallback | ||
* @param {any} item | ||
* @returns {boolean} | ||
*/ | ||
* @typedef {any} ContextItem | ||
*/ | ||
/** | ||
* @typedef {any} EvaluatedResult | ||
*/ | ||
/** | ||
* @callback ConditionCallback | ||
* @param {ContextItem} item | ||
* @returns {boolean} | ||
*/ | ||
/** | ||
* Copy items out of one array into another. | ||
@@ -1031,3 +1062,3 @@ * @param {GenericArray} source Array with items to copy | ||
* to evaluation | ||
* @returns {any} Result of evaluated code | ||
* @returns {EvaluatedResult} Result of evaluated code | ||
*/ | ||
@@ -1034,0 +1065,0 @@ runInNewContext: function runInNewContext(expr, context) { |
@@ -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&&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}; | ||
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},t(r)}function r(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function e(t){return e=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},e(t)}function n(t,r){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t},n(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.bind():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},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)},u(t)}function i(t,r){if(r&&("object"==typeof r||"function"==typeof r))return r;if(void 0!==r)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 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 h(t,r){return(t=t.slice()).push(r),t}function f(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}}),Object.defineProperty(t,"prototype",{writable:!1}),r&&n(t,r)}(f,u(Error));var o,c,l,s,p,h=(o=f,c=a(),function(){var t,r=e(o);if(c){var n=e(this).constructor;t=Reflect.construct(r,arguments,n)}else t=r.apply(this,arguments);return i(this,t)});function f(t){var r;return function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}(this,f),(r=h.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=f,s&&r(l.prototype,s),p&&r(l,p),Object.defineProperty(l,"prototype",{writable:!1}),l}();function b(r,e,n,a,o){if(!(this instanceof b))try{return new b(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=!p.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 y(c);return c}}b.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(!p.call(r,"json"))throw new TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');e=r.json,c=p.call(r,"flatten")?r.flatten:c,this.currResultType=p.call(r,"resultType")?r.resultType:this.currResultType,this.currSandbox=p.call(r,"sandbox")?r.sandbox:this.currSandbox,l=p.call(r,"wrap")?r.wrap:l,this.currPreventEval=p.call(r,"preventEval")?r.preventEval:this.currPreventEval,n=p.call(r,"callback")?r.callback:n,this.currOtherTypeCallback=p.call(r,"otherTypeCallback")?r.otherTypeCallback:this.currOtherTypeCallback,u=p.call(r,"parent")?r.parent:u,i=p.call(r,"parentProperty")?r.parentProperty:i,r=r.path}if(u=u||null,i=i||null,Array.isArray(r)&&(r=b.toPathString(r)),(r||""===r)&&e){var s=b.toPathArray(r);"$"===s[0]&&s.length>1&&s.shift(),this._hasParentSelector=null;var h=this._trace(s,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}},b.prototype._getPreferredOutput=function(t){var r=this.currResultType;switch(r){case"all":var e=Array.isArray(t.path)?t.path:b.toPathArray(t.path);return t.pointer=b.toPointer(e),t.path="string"==typeof t.path?t.path:b.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[r];case"path":return b.toPathString(t[r]);case"pointer":return b.toPointer(t.path);default:throw new TypeError("Unknown result type")}},b.prototype._handleCallback=function(t,r,e){if(r){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:b.toPathString(t.path),r(n,e,t)}},b.prototype._trace=function(r,e,n,a,o,u,i,c){var s,y=this;if(!r.length)return s={path:n,value:e,parent:a,parentProperty:o,hasArrExpr:i},this._handleCallback(s,u,"value"),s;var b=r[0],v=r.slice(1),F=[];function d(t){Array.isArray(t)?t.forEach((function(t){F.push(t)})):F.push(t)}if(("string"!=typeof b||c)&&e&&p.call(e,b))d(this._trace(v,e[b],h(n,b),e,b,u,i));else if("*"===b)this._walk(b,v,e,n,a,o,u,(function(t,r,e,n,a,o,u,i){d(y._trace(f(t,e),n,a,o,u,i,!0,!0))}));else if(".."===b)d(this._trace(v,e,n,a,o,u,i)),this._walk(b,v,e,n,a,o,u,(function(r,e,n,a,o,u,i,c){"object"===t(a[r])&&d(y._trace(f(e,n),a[r],h(o,r),a,r,c,!0))}));else{if("^"===b)return this._hasParentSelector=!0,{path:n.slice(0,-1),expr:v,isParentSelector:!0};if("~"===b)return s={path:h(n,b),value:o,parent:a,parentProperty:null},this._handleCallback(s,u,"property"),s;if("$"===b)d(this._trace(v,e,n,null,null,u,i));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(b))d(this._slice(b,v,e,n,a,o,u));else if(0===b.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");this._walk(b,v,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(f(t,e),n,a,o,u,i,!0))}))}else if("("===b[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");d(this._trace(f(this._eval(b,e,n[n.length-1],n.slice(0,-1),a,o),v),e,n,a,o,u,i))}else if("@"===b[0]){var g=!1,w=b.slice(1,-2);switch(w){case"scalar":e&&["object","function"].includes(t(e))||(g=!0);break;case"boolean":case"string":case"undefined":case"function":t(e)===w&&(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)===w&&(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 "+w)}if(g)return s={path:n,value:e,parent:a,parentProperty:o},this._handleCallback(s,u,"value"),s}else if("`"===b[0]&&e&&p.call(e,b.slice(1))){var _=b.slice(1);d(this._trace(v,e[_],h(n,_),e,_,u,i,!0))}else if(b.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}}}}(b.split(","));try{for(P.s();!(m=P.n()).done;){var D=m.value;d(this._trace(f(D,v),e,n,a,o,u,!0))}}catch(t){P.e(t)}finally{P.f()}}else!c&&e&&p.call(e,b)&&d(this._trace(v,e[b],h(n,b),e,b,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 j=E.length,A=1;A<j;A++)x++,F.splice(x,0,E[A])}else F[x]=E}}return F},b.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)}))},b.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 h=[],y=s;y<p;y+=l){this._trace(f(y,r),e,n,a,o,u,!0).forEach((function(t){h.push(t)}))}return h}},b.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=b.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 new Error("jsonPath: "+r.message+": "+t)}},b.cache={},b.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},b.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},b.toPathArray=function(t){var r=b.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()};b.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))}};export{b as JSONPath}; | ||
//# sourceMappingURL=index-browser-esm.min.js.map |
@@ -7,9 +7,17 @@ import vm from 'vm'; | ||
/** | ||
* @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject | ||
*/ | ||
* @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject | ||
*/ | ||
/** | ||
* @typedef {any} AnyItem | ||
*/ | ||
/** | ||
* @typedef {any} AnyResult | ||
*/ | ||
/** | ||
* Copies array and then pushes item into it. | ||
* @param {GenericArray} arr Array to copy and into which to push | ||
* @param {any} item Array item to add (to end) | ||
* @param {AnyItem} item Array item to add (to end) | ||
* @returns {GenericArray} Copy of the original array | ||
@@ -25,3 +33,3 @@ */ | ||
* Copies array and then unshifts item into it. | ||
* @param {any} item Array item to add (to beginning) | ||
* @param {AnyItem} item Array item to add (to beginning) | ||
* @param {GenericArray} arr Array to copy and into which to unshift | ||
@@ -45,3 +53,3 @@ * @returns {GenericArray} Copy of the original array | ||
/** | ||
* @param {any} value The evaluated scalar value | ||
* @param {AnyResult} value The evaluated scalar value | ||
*/ | ||
@@ -296,3 +304,3 @@ constructor(value) { | ||
fullRetObj.path = typeof fullRetObj.path === 'string' ? fullRetObj.path : JSONPath.toPathString(fullRetObj.path); // eslint-disable-next-line node/callback-return | ||
fullRetObj.path = typeof fullRetObj.path === 'string' ? fullRetObj.path : JSONPath.toPathString(fullRetObj.path); // eslint-disable-next-line n/callback-return | ||
@@ -641,4 +649,2 @@ callback(preferredOutput, type, fullRetObj); | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.log(e); | ||
throw new Error('jsonPath: ' + e.message + ': ' + code); | ||
@@ -645,0 +651,0 @@ } |
296
package.json
{ | ||
"author": "Stefan Goessner", | ||
"name": "jsonpath-plus", | ||
"version": "6.0.1", | ||
"type": "module", | ||
"main": "dist/index-node-cjs.cjs", | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": { | ||
"browser": "./dist/index-browser-esm.js", | ||
"umd": "./dist/index-browser-umd.cjs", | ||
"import": "./dist/index-node-esm.js", | ||
"require": "./dist/index-node-cjs.cjs", | ||
"default": "./dist/index-browser-esm.js" | ||
} | ||
}, | ||
"module": "dist/index-node-esm.js", | ||
"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 | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.14.6", | ||
"@babel/preset-env": "^7.14.7", | ||
"@brettz9/eslint-plugin": "^1.0.3", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
"c8": "^7.7.3", | ||
"chai": "^4.3.4", | ||
"core-js-bundle": "^3.15.2", | ||
"coveradge": "^0.7.0", | ||
"eslint": "^7.30.0", | ||
"eslint-config-ash-nazg": "^30.1.0", | ||
"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.1", | ||
"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-sonarjs": "^0.9.1", | ||
"eslint-plugin-standard": "^4.1.0", | ||
"eslint-plugin-unicorn": "^34.0.1", | ||
"http-server": "^0.12.3", | ||
"license-badger": "^0.19.0", | ||
"mocha": "^9.0.2", | ||
"mocha-badge-generator": "^0.9.0", | ||
"mocha-multi-reporters": "^1.5.1", | ||
"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.7", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"typedoc": "^0.21.2", | ||
"typescript": "^4.3.5" | ||
}, | ||
"keywords": [ | ||
"json", | ||
"jsonpath" | ||
], | ||
"browserslist": [ | ||
"cover 100%" | ||
], | ||
"c8": { | ||
"reporter": [ | ||
"text", | ||
"html", | ||
"json-summary" | ||
], | ||
"exclude": [ | ||
".mocharc.cjs", | ||
".eslintrc.cjs", | ||
"src/jsonpath.d.ts", | ||
"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 test-helpers/node-env.js --reporter-options configFile=mocha-multi-reporters.json test", | ||
"c8": "rm -Rf ./coverage && rm -Rf ./node_modules/.cache && c8 --all npm run mocha && npm run coverage-badge", | ||
"rollup": "rollup -c", | ||
"eslint": "eslint --ext js,cjs,md,html .", | ||
"lint": "npm run eslint", | ||
"test": "npm run eslint && npm run rollup && npm run c8 && 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": "7.0.0", | ||
"type": "module", | ||
"main": "dist/index-node-cjs.cjs", | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": { | ||
"browser": "./dist/index-browser-esm.js", | ||
"umd": "./dist/index-browser-umd.cjs", | ||
"import": "./dist/index-node-esm.js", | ||
"require": "./dist/index-node-cjs.cjs", | ||
"default": "./dist/index-browser-esm.js" | ||
} | ||
}, | ||
"module": "dist/index-node-esm.js", | ||
"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": ">=12.0.0" | ||
}, | ||
"react-native": { | ||
"vm": false | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.18.5", | ||
"@babel/preset-env": "^7.18.2", | ||
"@brettz9/eslint-plugin": "^1.0.4", | ||
"@rollup/plugin-babel": "^5.3.1", | ||
"c8": "^7.11.3", | ||
"chai": "^4.3.6", | ||
"core-js-bundle": "^3.23.1", | ||
"coveradge": "^0.8.1", | ||
"eslint": "^8.17.0", | ||
"eslint-config-ash-nazg": "^33.1.0", | ||
"eslint-config-standard": "^17.0.0", | ||
"eslint-plugin-array-func": "^3.1.7", | ||
"eslint-plugin-chai-expect": "^3.0.0", | ||
"eslint-plugin-chai-friendly": "^0.7.2", | ||
"eslint-plugin-compat": "^4.0.2", | ||
"eslint-plugin-eslint-comments": "^3.2.0", | ||
"eslint-plugin-html": "^6.2.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-jsdoc": "^39.3.2", | ||
"eslint-plugin-markdown": "^2.2.1", | ||
"eslint-plugin-n": "^15.2.3", | ||
"eslint-plugin-no-unsanitized": "^4.0.1", | ||
"eslint-plugin-no-use-extend-native": "^0.5.0", | ||
"eslint-plugin-promise": "^6.0.0", | ||
"eslint-plugin-sonarjs": "^0.13.0", | ||
"eslint-plugin-standard": "^4.1.0", | ||
"eslint-plugin-unicorn": "^42.0.0", | ||
"http-server": "^14.1.1", | ||
"license-badger": "^0.19.0", | ||
"mocha": "^10.0.0", | ||
"mocha-badge-generator": "^0.9.0", | ||
"mocha-multi-reporters": "^1.5.1", | ||
"open-cli": "^7.0.1", | ||
"rollup": "2.75.6", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"typedoc": "^0.22.17", | ||
"typescript": "^4.7.3" | ||
}, | ||
"keywords": [ | ||
"json", | ||
"jsonpath" | ||
], | ||
"browserslist": [ | ||
"cover 100%" | ||
], | ||
"c8": { | ||
"reporter": [ | ||
"text", | ||
"html", | ||
"json-summary" | ||
], | ||
"exclude": [ | ||
".mocharc.cjs", | ||
".eslintrc.cjs", | ||
"src/jsonpath.d.ts", | ||
"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", | ||
"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 test-helpers/node-env.js --reporter-options configFile=mocha-multi-reporters.json test", | ||
"c8": "rm -Rf ./coverage && rm -Rf ./node_modules/.cache && c8 --all npm run mocha && npm run coverage-badge", | ||
"rollup": "rollup -c", | ||
"eslint": "eslint --ext js,cjs,md,html .", | ||
"lint": "npm run eslint", | ||
"test": "npm run eslint && npm run rollup && npm run c8 && npm run typescript", | ||
"browser-test": "npm run eslint && npm run rollup && open-cli http://localhost:8084/test/ && npm start" | ||
} | ||
} |
import {JSONPath} from './jsonpath.js'; | ||
/** | ||
* @callback ConditionCallback | ||
* @param {any} item | ||
* @returns {boolean} | ||
*/ | ||
* @typedef {any} ContextItem | ||
*/ | ||
/** | ||
* @typedef {any} EvaluatedResult | ||
*/ | ||
/** | ||
* @callback ConditionCallback | ||
* @param {ContextItem} item | ||
* @returns {boolean} | ||
*/ | ||
/** | ||
* Copy items out of one array into another. | ||
@@ -32,3 +40,3 @@ * @param {GenericArray} source Array with items to copy | ||
* to evaluation | ||
* @returns {any} Result of evaluated code | ||
* @returns {EvaluatedResult} Result of evaluated code | ||
*/ | ||
@@ -35,0 +43,0 @@ runInNewContext (expr, context) { |
const {hasOwnProperty: hasOwnProp} = Object.prototype; | ||
/** | ||
* @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject | ||
*/ | ||
* @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject | ||
*/ | ||
/** | ||
* @typedef {any} AnyItem | ||
*/ | ||
/** | ||
* @typedef {any} AnyResult | ||
*/ | ||
/** | ||
* Copies array and then pushes item into it. | ||
* @param {GenericArray} arr Array to copy and into which to push | ||
* @param {any} item Array item to add (to end) | ||
* @param {AnyItem} item Array item to add (to end) | ||
* @returns {GenericArray} Copy of the original array | ||
@@ -20,3 +28,3 @@ */ | ||
* Copies array and then unshifts item into it. | ||
* @param {any} item Array item to add (to beginning) | ||
* @param {AnyItem} item Array item to add (to beginning) | ||
* @param {GenericArray} arr Array to copy and into which to unshift | ||
@@ -37,3 +45,3 @@ * @returns {GenericArray} Copy of the original array | ||
/** | ||
* @param {any} value The evaluated scalar value | ||
* @param {AnyResult} value The evaluated scalar value | ||
*/ | ||
@@ -284,3 +292,3 @@ constructor (value) { | ||
: JSONPath.toPathString(fullRetObj.path); | ||
// eslint-disable-next-line node/callback-return | ||
// eslint-disable-next-line n/callback-return | ||
callback(preferredOutput, type, fullRetObj); | ||
@@ -613,4 +621,2 @@ } | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.log(e); | ||
throw new Error('jsonPath: ' + e.message + ': ' + code); | ||
@@ -617,0 +623,0 @@ } |
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
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
302501
37
4259