Socket
Socket
Sign inDemoInstall

jsonpath-plus

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonpath-plus - npm Package Compare versions

Comparing version 0.20.1 to 1.0.0

.idea/ts-testing.js

10

.eslintrc.js

@@ -57,3 +57,5 @@ module.exports = {

"import/unambiguous": 0,
"quotes": 0
"quotes": 0,
// Todo: Reenable
"max-len": 0
}

@@ -66,6 +68,6 @@ }

"quote-props": 0,
"require-unicode-regexp": 0,
"max-len": 0,
"require-jsdoc": 0
"require-jsdoc": 0,
// Reenable when no longer having problems
"unicorn/no-unsafe-regex": 0
}
};

4

CHANGES.md
# CHANGES for jsonpath-plus
## 1.0.0 (August 7, 2019)
- Add TypeScript declaration
## 0.20.1 (June 12, 2019)

@@ -4,0 +8,0 @@

@@ -136,7 +136,14 @@ function _typeof(obj) {

/* eslint-disable no-eval, jsdoc/check-types */
// Todo: Reenable jsdoc/check-types once PR merged: https://github.com/gajus/eslint-plugin-jsdoc/pull/270
var globalEval = eval; // eslint-disable-next-line import/no-commonjs
/* eslint-disable no-eval, prefer-named-capture-group */
// Disabled `prefer-named-capture-group` due to https://github.com/babel/babel/issues/8951#issuecomment-508045524
var globalEval = eval; // Only Node.JS has a process variable that is of [[Class]] process
var supportsNodeVM = typeof module !== 'undefined' && Boolean(module.exports) && !(typeof navigator !== 'undefined' && navigator.product === 'ReactNative');
var supportsNodeVM = function supportsNodeVM() {
try {
return Object.prototype.toString.call(global.process) === '[object process]';
} catch (e) {
return false;
}
};
var allowedResultTypes = ['value', 'path', 'pointer', 'parent', 'parentProperty', 'all'];

@@ -156,6 +163,6 @@ var hasOwnProp = Object.prototype.hasOwnProperty;

* Copy items out of one array into another.
* @param {Array} source Array with items to copy
* @param {Array} target Array to which to copy
* @param {ConditionCallback} conditionCb Callback passed the current item; will move
* item if evaluates to `true`
* @param {GenericArray} source Array with items to copy
* @param {GenericArray} target Array to which to copy
* @param {ConditionCallback} conditionCb Callback passed the current item;
* will move item if evaluates to `true`
* @returns {undefined}

@@ -176,7 +183,8 @@ */

var vm = supportsNodeVM ? require('vm') : {
var vm = supportsNodeVM() ? require('vm') : {
/**
* @param {string} expr Expression to evaluate
* @param {PlainObject} context Object whose items will be added to evaluation
* @returns {Any} Result of evaluated code
* @param {PlainObject} context Object whose items will be added
* to evaluation
* @returns {any} Result of evaluated code
*/

@@ -208,5 +216,5 @@ runInNewContext: function runInNewContext(expr, context) {

* Copies array and then pushes item into it.
* @param {Array} arr Array to copy and into which to push
* @param {Any} item Array item to add (to end)
* @returns {Array} Copy of the original array
* @param {GenericArray} arr Array to copy and into which to push
* @param {any} item Array item to add (to end)
* @returns {GenericArray} Copy of the original array
*/

@@ -221,5 +229,5 @@

* Copies array and then unshifts item into it.
* @param {Any} item Array item to add (to beginning)
* @param {Array} arr Array to copy and into which to unshift
* @returns {Array} Copy of the original array
* @param {any} item Array item to add (to beginning)
* @param {GenericArray} arr Array to copy and into which to unshift
* @returns {GenericArray} Copy of the original array
*/

@@ -245,3 +253,3 @@

/**
* @param {Any} value The evaluated scalar value
* @param {any} value The evaluated scalar value
*/

@@ -253,3 +261,3 @@ function NewError(value) {

_this = _possibleConstructorReturn(this, _getPrototypeOf(NewError).call(this, 'JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)'));
_this = _possibleConstructorReturn(this, _getPrototypeOf(NewError).call(this, 'JSONPath should not be called with "new" (it prevents return ' + 'of (unwrapped) scalar values)'));
_this.avoidNew = true;

@@ -290,8 +298,10 @@ _this.value = value;

* @param {JSON} obj JSON object to evaluate against
* @param {JSONPathCallback} callback Passed 3 arguments: 1) desired payload per `resultType`,
* 2) `"value"|"property"`, 3) Full returned object with all payloads
* @param {OtherTypeCallback} otherTypeCallback If `@other()` is at the end of one's query, this
* will be invoked with the value of the item, its path, its parent, and its parent's
* property name, and it should return a boolean indicating whether the supplied value
* belongs to the "other" type or not (or it may handle transformations and return `false`).
* @param {JSONPathCallback} callback Passed 3 arguments: 1) desired payload
* per `resultType`, 2) `"value"|"property"`, 3) Full returned object with
* all payloads
* @param {OtherTypeCallback} otherTypeCallback If `@other()` is at the end
* of one's query, this will be invoked with the value of the item, its
* path, its parent, and its parent's property name, and it should return
* a boolean indicating whether the supplied value belongs to the "other"
* type or not (or it may handle transformations and return `false`).
* @returns {JSONPath}

@@ -338,3 +348,3 @@ * @class

this.otherTypeCallback = opts.otherTypeCallback || otherTypeCallback || function () {
throw new Error('You must supply an otherTypeCallback callback option with the @other() operator.');
throw new Error('You must supply an otherTypeCallback callback option ' + 'with the @other() operator.');
};

@@ -373,3 +383,3 @@

if (!expr.path) {
throw new Error('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');
throw new Error('You must supply a "path" property when providing an object ' + 'argument to JSONPath.evaluate().');
}

@@ -484,3 +494,4 @@

JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, callback, literalPriority) {
// No expr to follow? return path and value as the result of this trace branch
// No expr to follow? return path and value as the result of
// this trace branch
var retObj;

@@ -515,3 +526,5 @@ var that = this;

if (Array.isArray(elems)) {
// This was causing excessive stack size in Node (with or without Babel) against our performance test: `ret.push(...elems);`
// This was causing excessive stack size in Node (with or
// without Babel) against our performance test:
// `ret.push(...elems);`
elems.forEach(function (t) {

@@ -530,16 +543,17 @@ ret.push(t);

// all child properties
// eslint-disable-next-line no-shadow
this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, x, v, p, par, pr, cb) {
addRet(that._trace(unshift(m, x), v, p, par, pr, cb, true));
this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) {
addRet(that._trace(unshift(m, _x), v, p, par, pr, cb, true));
});
} else if (loc === '..') {
// all descendent parent properties
addRet(this._trace(x, val, path, parent, parentPropName, callback)); // Check remaining expression with val's immediate children
// eslint-disable-next-line no-shadow
// Check remaining expression with val's immediate children
addRet(this._trace(x, val, path, parent, parentPropName, callback));
this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, x, v, p, par, pr, cb) {
// We don't join m and x here because we only want parents, not scalar values
this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) {
// We don't join m and x here because we only want parents,
// not scalar values
if (_typeof(v[m]) === 'object') {
// Keep going with recursive descent on val's object children
addRet(that._trace(unshift(l, x), v[m], push(p, m), v, m, cb));
// Keep going with recursive descent on val's
// object children
addRet(that._trace(unshift(l, _x), v[m], push(p, m), v, m, cb));
}

@@ -572,3 +586,3 @@ }); // The parent sel computation is handled in the frame above using the

addRet(this._trace(x, val, path, null, null, callback));
} else if (/^(-?\d*):(-?\d*):?(\d*)$/.test(loc)) {
} else if (/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(loc)) {
// [start:end:step] Python slice syntax

@@ -580,8 +594,7 @@ addRet(this._slice(loc, x, val, path, parent, parentPropName, callback));

throw new Error('Eval [?(expr)] prevented in JSONPath expression.');
} // eslint-disable-next-line no-shadow
}
this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, x, v, p, par, pr, cb) {
if (that._eval(l.replace(/^\?\((.*?)\)$/, '$1'), v[m], m, p, par, pr)) {
addRet(that._trace(unshift(m, x), v, p, par, pr, cb));
this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) {
if (that._eval(l.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/, '$1'), v[m], m, p, par, pr)) {
addRet(that._trace(unshift(m, _x), v, p, par, pr, cb));
}

@@ -593,3 +606,5 @@ });

throw new Error('Eval [(expr)] prevented in JSONPath expression.');
} // As this will resolve to a property name (but we don't know it yet), property and parent information is relative to the parent of the property to which this expression will resolve
} // As this will resolve to a property name (but we don't know it
// yet), property and parent information is relative to the
// parent of the property to which this expression will resolve

@@ -618,4 +633,4 @@

case 'function':
// eslint-disable-next-line valid-typeof
if (_typeof(val) === valueType) {
// eslint-disable-line valid-typeof
addType = true;

@@ -627,4 +642,4 @@ }

case 'number':
// eslint-disable-next-line valid-typeof
if (_typeof(val) === valueType && isFinite(val)) {
// eslint-disable-line valid-typeof
addType = true;

@@ -643,4 +658,4 @@ }

case 'object':
// eslint-disable-next-line valid-typeof
if (val && _typeof(val) === valueType) {
// eslint-disable-line valid-typeof
addType = true;

@@ -688,5 +703,5 @@ }

return retObj;
}
} // `-escaped property
} else if (loc[0] === '`' && val && hasOwnProp.call(val, loc.slice(1))) {
// `-escaped property
var locProp = loc.slice(1);

@@ -705,3 +720,4 @@ addRet(this._trace(x, val[locProp], push(path, locProp), val, locProp, callback, true));

addRet(this._trace(unshift(part, x), val, path, parent, parentPropName, callback));
}
} // simple case--directly follow property
} catch (err) {

@@ -722,3 +738,2 @@ _didIteratorError = true;

} else if (!literalPriority && val && hasOwnProp.call(val, loc)) {
// simple case--directly follow property
addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, true));

@@ -789,3 +804,4 @@ } // We check the resulting values for parent selections. For parent

if (Array.isArray(tmp)) {
// This was causing excessive stack size in Node (with or without Babel) against our performance test: `ret.push(...tmp);`
// This was causing excessive stack size in Node (with or
// without Babel) against our performance test: `ret.push(...tmp);`
tmp.forEach(function (t) {

@@ -827,5 +843,5 @@ ret.push(t);

if (code.match(/@([.\s)[])/)) {
if (code.match(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/)) {
this.currSandbox._$_v = _v;
code = code.replace(/@([.\s)[])/g, '_$_v$1');
code = code.replace(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/g, '_$_v$1');
}

@@ -856,4 +872,4 @@

for (var i = 1; i < n; i++) {
if (!/^(~|\^|@.*?\(\))$/.test(x[i])) {
p += /^[0-9*]+$/.test(x[i]) ? '[' + x[i] + ']' : "['" + x[i] + "']";
if (!/^(~|\^|@(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\(\))$/.test(x[i])) {
p += /^[\*0-9]+$/.test(x[i]) ? '[' + x[i] + ']' : "['" + x[i] + "']";
}

@@ -876,3 +892,3 @@ }

for (var i = 1; i < n; i++) {
if (!/^(~|\^|@.*?\(\))$/.test(x[i])) {
if (!/^(~|\^|@(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\(\))$/.test(x[i])) {
p += '/' + x[i].toString().replace(/~/g, '~0').replace(/\//g, '~1');

@@ -901,10 +917,10 @@ }

// within brackets or single quotes
.replace(/[['](\??\(.*?\))[\]']/g, function ($0, $1) {
.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 ($0, $1) {
return '[#' + (subx.push($1) - 1) + ']';
}) // Escape periods and tildes within properties
.replace(/\['([^'\]]*)'\]/g, function ($0, prop) {
.replace(/\['((?:[\0-&\(-\\\^-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)'\]/g, function ($0, prop) {
return "['" + prop.replace(/\./g, '%@%').replace(/~/g, '%%@@%%') + "']";
}) // Properties operator
.replace(/~/g, ';~;') // Split by property boundaries
.replace(/'?\.'?(?![^[]*\])|\['?/g, ';') // Reinsert periods within properties
.replace(/'?\.'?(?!(?:[\0-Z\\-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*\])|\['?/g, ';') // Reinsert periods within properties
.replace(/%@%/g, '.') // Reinsert tildes within properties

@@ -918,3 +934,3 @@ .replace(/%%@@%%/g, '~') // Parent

var exprList = normalized.split(';').map(function (exp) {
var match = exp.match(/#(\d+)/);
var match = exp.match(/#([0-9]+)/);
return !match || !match[1] ? exp : subx[match[1]];

@@ -921,0 +937,0 @@ });

@@ -1,2 +0,2 @@

function t(e){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})(e)}function e(t){return(e=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function r(t,e){return(r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function n(t,e,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,e,n){var a=[null];a.push.apply(a,e);var o=new(Function.bind.apply(t,a));return n&&r(o,n.prototype),o}).apply(null,arguments)}function a(t){var o="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!==o){if(o.has(t))return o.get(t);o.set(t,i)}function i(){return n(t,arguments,e(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),r(i,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,l="undefined"!=typeof module&&Boolean(module.exports)&&!("undefined"!=typeof navigator&&"ReactNative"===navigator.product),c=["value","path","pointer","parent","parentProperty","all"],u=Object.prototype.hasOwnProperty,p=l?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 n(t){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n),(r=o(this,e(n).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 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&&r(t,e)}(n,a(Error)),n}();function y(e,r,n,a,o){if(!(this instanceof y))try{return new y(e,r,n,a,o)}catch(t){if(!t.avoidNew)throw t;return t.value}"string"==typeof e&&(o=a,a=n,n=r,r=e,e={}),e=e||{};var i=u.call(e,"json")&&u.call(e,"path");if(this.json=e.json||n,this.path=e.path||r,this.resultType=e.resultType&&e.resultType.toLowerCase()||"value",this.flatten=e.flatten||!1,this.wrap=!u.call(e,"wrap")||e.wrap,this.sandbox=e.sandbox||{},this.preventEval=e.preventEval||!1,this.parent=e.parent||null,this.parentProperty=e.parentProperty||null,this.callback=e.callback||a||null,this.otherTypeCallback=e.otherTypeCallback||o||function(){throw new Error("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==e.autostart){var l=this.evaluate({path:i?e.path:r,json:i?e.json:n});if(!l||"object"!==t(l))throw new f(l);return l}}y.prototype.evaluate=function(e,r,n,a){var o=this,i=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,r=r||this.json,(e=e||this.path)&&"object"===t(e)){if(!e.path)throw new Error('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');r=u.call(e,"json")?e.json:r,p=u.call(e,"flatten")?e.flatten:p,this.currResultType=u.call(e,"resultType")?e.resultType:this.currResultType,this.currSandbox=u.call(e,"sandbox")?e.sandbox:this.currSandbox,s=u.call(e,"wrap")?e.wrap:s,this.currPreventEval=u.call(e,"preventEval")?e.preventEval:this.currPreventEval,n=u.call(e,"callback")?e.callback:n,this.currOtherTypeCallback=u.call(e,"otherTypeCallback")?e.otherTypeCallback:this.currOtherTypeCallback,i=u.call(e,"parent")?e.parent:i,l=u.call(e,"parentProperty")?e.parentProperty:l,e=e.path}if(i=i||null,l=l||null,Array.isArray(e)&&(e=y.toPathString(e)),e&&r&&c.includes(this.currResultType)){this._obj=r;var h=y.toPathArray(e);"$"===h[0]&&h.length>1&&h.shift(),this._hasParentSelector=null;var f=this._trace(h,r,["$"],i,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,e){var r=o._getPreferredOutput(e);return p&&Array.isArray(r)?t=t.concat(r):t.push(r),t},[]):this._getPreferredOutput(f[0]):s?[]:void 0}},y.prototype._getPreferredOutput=function(t){var e=this.currResultType;switch(e){default:throw new TypeError("Unknown result type");case"all":return t.pointer=y.toPointer(t.path),t.path="string"==typeof t.path?t.path:y.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[e];case"path":return y.toPathString(t[e]);case"pointer":return y.toPointer(t.path)}},y.prototype._handleCallback=function(t,e,r){if(e){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:y.toPathString(t.path),e(n,r,t)}},y.prototype._trace=function(e,r,n,a,o,i,l){var c,p=this;if(!e.length)return c={path:n,value:r,parent:a,parentProperty:o},this._handleCallback(c,i,"value"),c;var f=e[0],y=e.slice(1),v=[];function b(t){Array.isArray(t)?t.forEach(function(t){v.push(t)}):v.push(t)}if(("string"!=typeof f||l)&&r&&u.call(r,f))b(this._trace(y,r[f],s(n,f),r,f,i));else if("*"===f)this._walk(f,y,r,n,a,o,i,function(t,e,r,n,a,o,i,l){b(p._trace(h(t,r),n,a,o,i,l,!0))});else if(".."===f)b(this._trace(y,r,n,a,o,i)),this._walk(f,y,r,n,a,o,i,function(e,r,n,a,o,i,l,c){"object"===t(a[e])&&b(p._trace(h(r,n),a[e],s(o,e),a,e,c))});else{if("^"===f)return this._hasParentSelector=!0,n.length?{path:n.slice(0,-1),expr:y,isParentSelector:!0}:[];if("~"===f)return c={path:s(n,f),value:o,parent:a,parentProperty:null},this._handleCallback(c,i,"property"),c;if("$"===f)b(this._trace(y,r,n,null,null,i));else if(/^(-?\d*):(-?\d*):?(\d*)$/.test(f))b(this._slice(f,y,r,n,a,o,i));else if(0===f.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");this._walk(f,y,r,n,a,o,i,function(t,e,r,n,a,o,i,l){p._eval(e.replace(/^\?\((.*?)\)$/,"$1"),n[t],t,a,o,i)&&b(p._trace(h(t,r),n,a,o,i,l))})}else if("("===f[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");b(this._trace(h(this._eval(f,r,n[n.length-1],n.slice(0,-1),a,o),y),r,n,a,o,i))}else if("@"===f[0]){var d=!1,g=f.slice(1,-2);switch(g){default:throw new TypeError("Unknown value type "+g);case"scalar":r&&["object","function"].includes(t(r))||(d=!0);break;case"boolean":case"string":case"undefined":case"function":t(r)===g&&(d=!0);break;case"number":t(r)===g&&isFinite(r)&&(d=!0);break;case"nonFinite":"number"!=typeof r||isFinite(r)||(d=!0);break;case"object":r&&t(r)===g&&(d=!0);break;case"array":Array.isArray(r)&&(d=!0);break;case"other":d=this.currOtherTypeCallback(r,n,a,o);break;case"integer":r!==Number(r)||!isFinite(r)||r%1||(d=!0);break;case"null":null===r&&(d=!0)}if(d)return c={path:n,value:r,parent:a,parentProperty:o},this._handleCallback(c,i,"value"),c}else if("`"===f[0]&&r&&u.call(r,f.slice(1))){var _=f.slice(1);b(this._trace(y,r[_],s(n,_),r,_,i,!0))}else if(f.includes(",")){var w=f.split(","),P=!0,S=!1,k=void 0;try{for(var x,m=w[Symbol.iterator]();!(P=(x=m.next()).done);P=!0){var j=x.value;b(this._trace(h(j,y),r,n,a,o,i))}}catch(t){S=!0,k=t}finally{try{P||null==m.return||m.return()}finally{if(S)throw k}}}else!l&&r&&u.call(r,f)&&b(this._trace(y,r[f],s(n,f),r,f,i,!0))}if(this._hasParentSelector)for(var O=0;O<v.length;O++){var E=v[O];if(E.isParentSelector){var T=p._trace(E.expr,r,E.path,a,o,i);if(Array.isArray(T)){v[O]=T[0];for(var $=T.length,A=1;A<$;A++)O++,v.splice(O,0,T[A])}else v[O]=T}}return v},y.prototype._walk=function(e,r,n,a,o,i,l,c){if(Array.isArray(n))for(var p=n.length,s=0;s<p;s++)c(s,e,r,n,a,o,i,l);else if("object"===t(n))for(var h in n)u.call(n,h)&&c(h,e,r,n,a,o,i,l)},y.prototype._slice=function(t,e,r,n,a,o,i){if(Array.isArray(r)){var l=r.length,c=t.split(":"),u=c[2]&&parseInt(c[2])||1,p=c[0]&&parseInt(c[0])||0,s=c[1]&&parseInt(c[1])||l;p=p<0?Math.max(0,p+l):Math.min(l,p),s=s<0?Math.max(0,s+l):Math.min(l,s);for(var f=[],y=p;y<s;y+=u){var v=this._trace(h(y,e),r,n,a,o,i);Array.isArray(v)?v.forEach(function(t){f.push(t)}):f.push(v)}return f}},y.prototype._eval=function(t,e,r,n,a,o){if(!this._obj||!e)return!1;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=r,t=t.replace(/@property/g,"_$_property")),t.includes("@path")&&(this.currSandbox._$_path=y.toPathString(n.concat([r])),t=t.replace(/@path/g,"_$_path")),t.match(/@([.\s)[])/)&&(this.currSandbox._$_v=e,t=t.replace(/@([.\s)[])/g,"_$_v$1"));try{return p.runInNewContext(t,this.currSandbox)}catch(e){throw console.log(e),new Error("jsonPath: "+e.message+": "+t)}},y.cache={},y.toPathString=function(t){for(var e=t,r=e.length,n="$",a=1;a<r;a++)/^(~|\^|@.*?\(\))$/.test(e[a])||(n+=/^[0-9*]+$/.test(e[a])?"["+e[a]+"]":"['"+e[a]+"']");return n},y.toPointer=function(t){for(var e=t,r=e.length,n="",a=1;a<r;a++)/^(~|\^|@.*?\(\))$/.test(e[a])||(n+="/"+e[a].toString().replace(/~/g,"~0").replace(/\//g,"~1"));return n},y.toPathArray=function(t){var e=y.cache;if(e[t])return e[t].concat();var r=[],n=t.replace(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/g,";$&;").replace(/[['](\??\(.*?\))[\]']/g,function(t,e){return"[#"+(r.push(e)-1)+"]"}).replace(/\['([^'\]]*)'\]/g,function(t,e){return"['"+e.replace(/\./g,"%@%").replace(/~/g,"%%@@%%")+"']"}).replace(/~/g,";~;").replace(/'?\.'?(?![^[]*\])|\['?/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(/#(\d+)/);return e&&e[1]?r[e[1]]:t});return e[t]=n,e[t]};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})(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

@@ -142,7 +142,14 @@ (function (global, factory) {

/* eslint-disable no-eval, jsdoc/check-types */
// Todo: Reenable jsdoc/check-types once PR merged: https://github.com/gajus/eslint-plugin-jsdoc/pull/270
var globalEval = eval; // eslint-disable-next-line import/no-commonjs
/* eslint-disable no-eval, prefer-named-capture-group */
// Disabled `prefer-named-capture-group` due to https://github.com/babel/babel/issues/8951#issuecomment-508045524
var globalEval = eval; // Only Node.JS has a process variable that is of [[Class]] process
var supportsNodeVM = typeof module !== 'undefined' && Boolean(module.exports) && !(typeof navigator !== 'undefined' && navigator.product === 'ReactNative');
var supportsNodeVM = function supportsNodeVM() {
try {
return Object.prototype.toString.call(global.process) === '[object process]';
} catch (e) {
return false;
}
};
var allowedResultTypes = ['value', 'path', 'pointer', 'parent', 'parentProperty', 'all'];

@@ -162,6 +169,6 @@ var hasOwnProp = Object.prototype.hasOwnProperty;

* Copy items out of one array into another.
* @param {Array} source Array with items to copy
* @param {Array} target Array to which to copy
* @param {ConditionCallback} conditionCb Callback passed the current item; will move
* item if evaluates to `true`
* @param {GenericArray} source Array with items to copy
* @param {GenericArray} target Array to which to copy
* @param {ConditionCallback} conditionCb Callback passed the current item;
* will move item if evaluates to `true`
* @returns {undefined}

@@ -182,7 +189,8 @@ */

var vm = supportsNodeVM ? require('vm') : {
var vm = supportsNodeVM() ? require('vm') : {
/**
* @param {string} expr Expression to evaluate
* @param {PlainObject} context Object whose items will be added to evaluation
* @returns {Any} Result of evaluated code
* @param {PlainObject} context Object whose items will be added
* to evaluation
* @returns {any} Result of evaluated code
*/

@@ -214,5 +222,5 @@ runInNewContext: function runInNewContext(expr, context) {

* Copies array and then pushes item into it.
* @param {Array} arr Array to copy and into which to push
* @param {Any} item Array item to add (to end)
* @returns {Array} Copy of the original array
* @param {GenericArray} arr Array to copy and into which to push
* @param {any} item Array item to add (to end)
* @returns {GenericArray} Copy of the original array
*/

@@ -227,5 +235,5 @@

* Copies array and then unshifts item into it.
* @param {Any} item Array item to add (to beginning)
* @param {Array} arr Array to copy and into which to unshift
* @returns {Array} Copy of the original array
* @param {any} item Array item to add (to beginning)
* @param {GenericArray} arr Array to copy and into which to unshift
* @returns {GenericArray} Copy of the original array
*/

@@ -251,3 +259,3 @@

/**
* @param {Any} value The evaluated scalar value
* @param {any} value The evaluated scalar value
*/

@@ -259,3 +267,3 @@ function NewError(value) {

_this = _possibleConstructorReturn(this, _getPrototypeOf(NewError).call(this, 'JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)'));
_this = _possibleConstructorReturn(this, _getPrototypeOf(NewError).call(this, 'JSONPath should not be called with "new" (it prevents return ' + 'of (unwrapped) scalar values)'));
_this.avoidNew = true;

@@ -296,8 +304,10 @@ _this.value = value;

* @param {JSON} obj JSON object to evaluate against
* @param {JSONPathCallback} callback Passed 3 arguments: 1) desired payload per `resultType`,
* 2) `"value"|"property"`, 3) Full returned object with all payloads
* @param {OtherTypeCallback} otherTypeCallback If `@other()` is at the end of one's query, this
* will be invoked with the value of the item, its path, its parent, and its parent's
* property name, and it should return a boolean indicating whether the supplied value
* belongs to the "other" type or not (or it may handle transformations and return `false`).
* @param {JSONPathCallback} callback Passed 3 arguments: 1) desired payload
* per `resultType`, 2) `"value"|"property"`, 3) Full returned object with
* all payloads
* @param {OtherTypeCallback} otherTypeCallback If `@other()` is at the end
* of one's query, this will be invoked with the value of the item, its
* path, its parent, and its parent's property name, and it should return
* a boolean indicating whether the supplied value belongs to the "other"
* type or not (or it may handle transformations and return `false`).
* @returns {JSONPath}

@@ -344,3 +354,3 @@ * @class

this.otherTypeCallback = opts.otherTypeCallback || otherTypeCallback || function () {
throw new Error('You must supply an otherTypeCallback callback option with the @other() operator.');
throw new Error('You must supply an otherTypeCallback callback option ' + 'with the @other() operator.');
};

@@ -379,3 +389,3 @@

if (!expr.path) {
throw new Error('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');
throw new Error('You must supply a "path" property when providing an object ' + 'argument to JSONPath.evaluate().');
}

@@ -490,3 +500,4 @@

JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, callback, literalPriority) {
// No expr to follow? return path and value as the result of this trace branch
// No expr to follow? return path and value as the result of
// this trace branch
var retObj;

@@ -521,3 +532,5 @@ var that = this;

if (Array.isArray(elems)) {
// This was causing excessive stack size in Node (with or without Babel) against our performance test: `ret.push(...elems);`
// This was causing excessive stack size in Node (with or
// without Babel) against our performance test:
// `ret.push(...elems);`
elems.forEach(function (t) {

@@ -536,16 +549,17 @@ ret.push(t);

// all child properties
// eslint-disable-next-line no-shadow
this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, x, v, p, par, pr, cb) {
addRet(that._trace(unshift(m, x), v, p, par, pr, cb, true));
this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) {
addRet(that._trace(unshift(m, _x), v, p, par, pr, cb, true));
});
} else if (loc === '..') {
// all descendent parent properties
addRet(this._trace(x, val, path, parent, parentPropName, callback)); // Check remaining expression with val's immediate children
// eslint-disable-next-line no-shadow
// Check remaining expression with val's immediate children
addRet(this._trace(x, val, path, parent, parentPropName, callback));
this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, x, v, p, par, pr, cb) {
// We don't join m and x here because we only want parents, not scalar values
this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) {
// We don't join m and x here because we only want parents,
// not scalar values
if (_typeof(v[m]) === 'object') {
// Keep going with recursive descent on val's object children
addRet(that._trace(unshift(l, x), v[m], push(p, m), v, m, cb));
// Keep going with recursive descent on val's
// object children
addRet(that._trace(unshift(l, _x), v[m], push(p, m), v, m, cb));
}

@@ -578,3 +592,3 @@ }); // The parent sel computation is handled in the frame above using the

addRet(this._trace(x, val, path, null, null, callback));
} else if (/^(-?\d*):(-?\d*):?(\d*)$/.test(loc)) {
} else if (/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(loc)) {
// [start:end:step] Python slice syntax

@@ -586,8 +600,7 @@ addRet(this._slice(loc, x, val, path, parent, parentPropName, callback));

throw new Error('Eval [?(expr)] prevented in JSONPath expression.');
} // eslint-disable-next-line no-shadow
}
this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, x, v, p, par, pr, cb) {
if (that._eval(l.replace(/^\?\((.*?)\)$/, '$1'), v[m], m, p, par, pr)) {
addRet(that._trace(unshift(m, x), v, p, par, pr, cb));
this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, _x, v, p, par, pr, cb) {
if (that._eval(l.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/, '$1'), v[m], m, p, par, pr)) {
addRet(that._trace(unshift(m, _x), v, p, par, pr, cb));
}

@@ -599,3 +612,5 @@ });

throw new Error('Eval [(expr)] prevented in JSONPath expression.');
} // As this will resolve to a property name (but we don't know it yet), property and parent information is relative to the parent of the property to which this expression will resolve
} // As this will resolve to a property name (but we don't know it
// yet), property and parent information is relative to the
// parent of the property to which this expression will resolve

@@ -624,4 +639,4 @@

case 'function':
// eslint-disable-next-line valid-typeof
if (_typeof(val) === valueType) {
// eslint-disable-line valid-typeof
addType = true;

@@ -633,4 +648,4 @@ }

case 'number':
// eslint-disable-next-line valid-typeof
if (_typeof(val) === valueType && isFinite(val)) {
// eslint-disable-line valid-typeof
addType = true;

@@ -649,4 +664,4 @@ }

case 'object':
// eslint-disable-next-line valid-typeof
if (val && _typeof(val) === valueType) {
// eslint-disable-line valid-typeof
addType = true;

@@ -694,5 +709,5 @@ }

return retObj;
}
} // `-escaped property
} else if (loc[0] === '`' && val && hasOwnProp.call(val, loc.slice(1))) {
// `-escaped property
var locProp = loc.slice(1);

@@ -711,3 +726,4 @@ addRet(this._trace(x, val[locProp], push(path, locProp), val, locProp, callback, true));

addRet(this._trace(unshift(part, x), val, path, parent, parentPropName, callback));
}
} // simple case--directly follow property
} catch (err) {

@@ -728,3 +744,2 @@ _didIteratorError = true;

} else if (!literalPriority && val && hasOwnProp.call(val, loc)) {
// simple case--directly follow property
addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, true));

@@ -795,3 +810,4 @@ } // We check the resulting values for parent selections. For parent

if (Array.isArray(tmp)) {
// This was causing excessive stack size in Node (with or without Babel) against our performance test: `ret.push(...tmp);`
// This was causing excessive stack size in Node (with or
// without Babel) against our performance test: `ret.push(...tmp);`
tmp.forEach(function (t) {

@@ -833,5 +849,5 @@ ret.push(t);

if (code.match(/@([.\s)[])/)) {
if (code.match(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/)) {
this.currSandbox._$_v = _v;
code = code.replace(/@([.\s)[])/g, '_$_v$1');
code = code.replace(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/g, '_$_v$1');
}

@@ -862,4 +878,4 @@

for (var i = 1; i < n; i++) {
if (!/^(~|\^|@.*?\(\))$/.test(x[i])) {
p += /^[0-9*]+$/.test(x[i]) ? '[' + x[i] + ']' : "['" + x[i] + "']";
if (!/^(~|\^|@(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\(\))$/.test(x[i])) {
p += /^[\*0-9]+$/.test(x[i]) ? '[' + x[i] + ']' : "['" + x[i] + "']";
}

@@ -882,3 +898,3 @@ }

for (var i = 1; i < n; i++) {
if (!/^(~|\^|@.*?\(\))$/.test(x[i])) {
if (!/^(~|\^|@(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\(\))$/.test(x[i])) {
p += '/' + x[i].toString().replace(/~/g, '~0').replace(/\//g, '~1');

@@ -907,10 +923,10 @@ }

// within brackets or single quotes
.replace(/[['](\??\(.*?\))[\]']/g, function ($0, $1) {
.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 ($0, $1) {
return '[#' + (subx.push($1) - 1) + ']';
}) // Escape periods and tildes within properties
.replace(/\['([^'\]]*)'\]/g, function ($0, prop) {
.replace(/\['((?:[\0-&\(-\\\^-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)'\]/g, function ($0, prop) {
return "['" + prop.replace(/\./g, '%@%').replace(/~/g, '%%@@%%') + "']";
}) // Properties operator
.replace(/~/g, ';~;') // Split by property boundaries
.replace(/'?\.'?(?![^[]*\])|\['?/g, ';') // Reinsert periods within properties
.replace(/'?\.'?(?!(?:[\0-Z\\-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*\])|\['?/g, ';') // Reinsert periods within properties
.replace(/%@%/g, '.') // Reinsert tildes within properties

@@ -924,3 +940,3 @@ .replace(/%%@@%%/g, '~') // Parent

var exprList = normalized.split(';').map(function (exp) {
var match = exp.match(/#(\d+)/);
var match = exp.match(/#([0-9]+)/);
return !match || !match[1] ? exp : subx[match[1]];

@@ -927,0 +943,0 @@ });

@@ -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 o=new(Function.bind.apply(t,a));return r&&n(o,r.prototype),o}).apply(null,arguments)}function o(t){var e="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!==e){if(e.has(t))return e.get(t);e.set(t,i)}function i(){return a(t,arguments,r(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),n(i,t)})(t)}function i(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}var l=eval,c="undefined"!=typeof module&&Boolean(module.exports)&&!("undefined"!=typeof navigator&&"ReactNative"===navigator.product),u=["value","path","pointer","parent","parentProperty","all"],p=Object.prototype.hasOwnProperty,s=c?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 l(a)}};function h(t,e){return(t=t.slice()).push(e),t}function f(t,e){return(e=e.slice()).unshift(t),e}var y=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=i(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,o(Error)),e}();function v(t,r,n,a,o){if(!(this instanceof v))try{return new v(t,r,n,a,o)}catch(t){if(!t.avoidNew)throw t;return t.value}"string"==typeof t&&(o=a,a=n,n=r,r=t,t={}),t=t||{};var i=p.call(t,"json")&&p.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=!p.call(t,"wrap")||t.wrap,this.sandbox=t.sandbox||{},this.preventEval=t.preventEval||!1,this.parent=t.parent||null,this.parentProperty=t.parentProperty||null,this.callback=t.callback||a||null,this.otherTypeCallback=t.otherTypeCallback||o||function(){throw new Error("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==t.autostart){var l=this.evaluate({path:i?t.path:r,json:i?t.json:n});if(!l||"object"!==e(l))throw new y(l);return l}}v.prototype.evaluate=function(t,r,n,a){var o=this,i=this.parent,l=this.parentProperty,c=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=p.call(t,"json")?t.json:r,c=p.call(t,"flatten")?t.flatten:c,this.currResultType=p.call(t,"resultType")?t.resultType:this.currResultType,this.currSandbox=p.call(t,"sandbox")?t.sandbox:this.currSandbox,s=p.call(t,"wrap")?t.wrap:s,this.currPreventEval=p.call(t,"preventEval")?t.preventEval:this.currPreventEval,n=p.call(t,"callback")?t.callback:n,this.currOtherTypeCallback=p.call(t,"otherTypeCallback")?t.otherTypeCallback:this.currOtherTypeCallback,i=p.call(t,"parent")?t.parent:i,l=p.call(t,"parentProperty")?t.parentProperty:l,t=t.path}if(i=i||null,l=l||null,Array.isArray(t)&&(t=v.toPathString(t)),t&&r&&u.includes(this.currResultType)){this._obj=r;var h=v.toPathArray(t);"$"===h[0]&&h.length>1&&h.shift(),this._hasParentSelector=null;var f=this._trace(h,r,["$"],i,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,e){var r=o._getPreferredOutput(e);return c&&Array.isArray(r)?t=t.concat(r):t.push(r),t},[]):this._getPreferredOutput(f[0]):s?[]:void 0}},v.prototype._getPreferredOutput=function(t){var e=this.currResultType;switch(e){default:throw new TypeError("Unknown result type");case"all":return t.pointer=v.toPointer(t.path),t.path="string"==typeof t.path?t.path:v.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[e];case"path":return v.toPathString(t[e]);case"pointer":return v.toPointer(t.path)}},v.prototype._handleCallback=function(t,e,r){if(e){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:v.toPathString(t.path),e(n,r,t)}},v.prototype._trace=function(t,r,n,a,o,i,l){var c,u=this;if(!t.length)return c={path:n,value:r,parent:a,parentProperty:o},this._handleCallback(c,i,"value"),c;var s=t[0],y=t.slice(1),v=[];function b(t){Array.isArray(t)?t.forEach(function(t){v.push(t)}):v.push(t)}if(("string"!=typeof s||l)&&r&&p.call(r,s))b(this._trace(y,r[s],h(n,s),r,s,i));else if("*"===s)this._walk(s,y,r,n,a,o,i,function(t,e,r,n,a,o,i,l){b(u._trace(f(t,r),n,a,o,i,l,!0))});else if(".."===s)b(this._trace(y,r,n,a,o,i)),this._walk(s,y,r,n,a,o,i,function(t,r,n,a,o,i,l,c){"object"===e(a[t])&&b(u._trace(f(r,n),a[t],h(o,t),a,t,c))});else{if("^"===s)return this._hasParentSelector=!0,n.length?{path:n.slice(0,-1),expr:y,isParentSelector:!0}:[];if("~"===s)return c={path:h(n,s),value:o,parent:a,parentProperty:null},this._handleCallback(c,i,"property"),c;if("$"===s)b(this._trace(y,r,n,null,null,i));else if(/^(-?\d*):(-?\d*):?(\d*)$/.test(s))b(this._slice(s,y,r,n,a,o,i));else if(0===s.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");this._walk(s,y,r,n,a,o,i,function(t,e,r,n,a,o,i,l){u._eval(e.replace(/^\?\((.*?)\)$/,"$1"),n[t],t,a,o,i)&&b(u._trace(f(t,r),n,a,o,i,l))})}else if("("===s[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");b(this._trace(f(this._eval(s,r,n[n.length-1],n.slice(0,-1),a,o),y),r,n,a,o,i))}else if("@"===s[0]){var d=!1,g=s.slice(1,-2);switch(g){default:throw new TypeError("Unknown value type "+g);case"scalar":r&&["object","function"].includes(e(r))||(d=!0);break;case"boolean":case"string":case"undefined":case"function":e(r)===g&&(d=!0);break;case"number":e(r)===g&&isFinite(r)&&(d=!0);break;case"nonFinite":"number"!=typeof r||isFinite(r)||(d=!0);break;case"object":r&&e(r)===g&&(d=!0);break;case"array":Array.isArray(r)&&(d=!0);break;case"other":d=this.currOtherTypeCallback(r,n,a,o);break;case"integer":r!==Number(r)||!isFinite(r)||r%1||(d=!0);break;case"null":null===r&&(d=!0)}if(d)return c={path:n,value:r,parent:a,parentProperty:o},this._handleCallback(c,i,"value"),c}else if("`"===s[0]&&r&&p.call(r,s.slice(1))){var _=s.slice(1);b(this._trace(y,r[_],h(n,_),r,_,i,!0))}else if(s.includes(",")){var w=s.split(","),P=!0,S=!1,k=void 0;try{for(var x,m=w[Symbol.iterator]();!(P=(x=m.next()).done);P=!0){var j=x.value;b(this._trace(f(j,y),r,n,a,o,i))}}catch(t){S=!0,k=t}finally{try{P||null==m.return||m.return()}finally{if(S)throw k}}}else!l&&r&&p.call(r,s)&&b(this._trace(y,r[s],h(n,s),r,s,i,!0))}if(this._hasParentSelector)for(var O=0;O<v.length;O++){var E=v[O];if(E.isParentSelector){var T=u._trace(E.expr,r,E.path,a,o,i);if(Array.isArray(T)){v[O]=T[0];for(var $=T.length,A=1;A<$;A++)O++,v.splice(O,0,T[A])}else v[O]=T}}return v},v.prototype._walk=function(t,r,n,a,o,i,l,c){if(Array.isArray(n))for(var u=n.length,s=0;s<u;s++)c(s,t,r,n,a,o,i,l);else if("object"===e(n))for(var h in n)p.call(n,h)&&c(h,t,r,n,a,o,i,l)},v.prototype._slice=function(t,e,r,n,a,o,i){if(Array.isArray(r)){var l=r.length,c=t.split(":"),u=c[2]&&parseInt(c[2])||1,p=c[0]&&parseInt(c[0])||0,s=c[1]&&parseInt(c[1])||l;p=p<0?Math.max(0,p+l):Math.min(l,p),s=s<0?Math.max(0,s+l):Math.min(l,s);for(var h=[],y=p;y<s;y+=u){var v=this._trace(f(y,e),r,n,a,o,i);Array.isArray(v)?v.forEach(function(t){h.push(t)}):h.push(v)}return h}},v.prototype._eval=function(t,e,r,n,a,o){if(!this._obj||!e)return!1;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=r,t=t.replace(/@property/g,"_$_property")),t.includes("@path")&&(this.currSandbox._$_path=v.toPathString(n.concat([r])),t=t.replace(/@path/g,"_$_path")),t.match(/@([.\s)[])/)&&(this.currSandbox._$_v=e,t=t.replace(/@([.\s)[])/g,"_$_v$1"));try{return s.runInNewContext(t,this.currSandbox)}catch(e){throw console.log(e),new Error("jsonPath: "+e.message+": "+t)}},v.cache={},v.toPathString=function(t){for(var e=t,r=e.length,n="$",a=1;a<r;a++)/^(~|\^|@.*?\(\))$/.test(e[a])||(n+=/^[0-9*]+$/.test(e[a])?"["+e[a]+"]":"['"+e[a]+"']");return n},v.toPointer=function(t){for(var e=t,r=e.length,n="",a=1;a<r;a++)/^(~|\^|@.*?\(\))$/.test(e[a])||(n+="/"+e[a].toString().replace(/~/g,"~0").replace(/\//g,"~1"));return n},v.toPathArray=function(t){var e=v.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(/[['](\??\(.*?\))[\]']/g,function(t,e){return"[#"+(r.push(e)-1)+"]"}).replace(/\['([^'\]]*)'\]/g,function(t,e){return"['"+e.replace(/\./g,"%@%").replace(/~/g,"%%@@%%")+"']"}).replace(/~/g,";~;").replace(/'?\.'?(?![^[]*\])|\['?/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(/#(\d+)/);return e&&e[1]?r[e[1]]:t});return e[t]=n,e[t]},t.JSONPath=v,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,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})});
//# sourceMappingURL=index-umd.min.js.map
{
"author": "Stefan Goessner",
"name": "jsonpath-plus",
"version": "0.20.1",
"version": "1.0.0",
"main": "dist/index-umd.js",
"module": "dist/index-es.js",
"types": "./src/jsonpath.d.ts",
"description": "A JS implementation of JSONPath with some additional operators",

@@ -49,30 +50,34 @@ "contributors": [

"devDependencies": {
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"@mysticatea/eslint-plugin": "^10.0.3",
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@mysticatea/eslint-plugin": "^11.0.0",
"chai": "^4.2.0",
"core-js-bundle": "^3.1.3",
"eslint": "^5.16.0",
"eslint-config-ash-nazg": "^6.1.1",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-compat": "^3.1.1",
"eslint-plugin-eslint-comments": "^3.1.1",
"eslint-plugin-import": "^2.17.3",
"eslint-plugin-jsdoc": "^7.2.3",
"core-js-bundle": "^3.1.4",
"eslint": "^6.1.0",
"eslint-config-ash-nazg": "^8.5.2",
"eslint-config-standard": "^13.0.1",
"eslint-plugin-array-func": "^3.1.3",
"eslint-plugin-compat": "^3.3.0",
"eslint-plugin-eslint-comments": "^3.1.2",
"eslint-plugin-html": "^6.0.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsdoc": "^15.8.0",
"eslint-plugin-markdown": "^1.0.0",
"eslint-plugin-no-use-extend-native": "^0.4.0",
"eslint-plugin-no-use-extend-native": "^0.4.1",
"eslint-plugin-node": "^9.1.0",
"eslint-plugin-promise": "^4.1.1",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-sonarjs": "^0.4.0",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-unicorn": "^9.0.0",
"mocha": "^6.1.4",
"eslint-plugin-unicorn": "^10.0.0",
"mocha": "^6.2.0",
"node-static": "^0.7.11",
"open-cli": "^5.0.0",
"remark-cli": "^6.0.1",
"remark-lint-code-block-style": "^1.0.2",
"remark-lint-ordered-list-marker-value": "^1.0.2",
"rollup": "1.13.1",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-terser": "^5.0.0",
"typescript": "^3.5.1"
"remark-cli": "^7.0.0",
"remark-lint-code-block-style": "^1.0.3",
"remark-lint-ordered-list-marker-value": "^1.0.3",
"rollup": "1.19.4",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-terser": "^5.1.1",
"typedoc": "^0.15.0",
"typescript": "^3.5.3"
},

@@ -88,9 +93,12 @@ "keywords": [

"remark": "remark -q -f .",
"rollup": "rollup -c",
"eslint": "eslint --ext js,md .",
"typescript": "tsc src/jsonpath.d.ts",
"build-docs": "typedoc --out docs/ts src --includeDeclarations",
"open-docs": "open-cli http://localhost:8084/docs/ts/ && npm start",
"mocha": "mocha --require test-helpers/node-env.js test",
"test": "npm run eslint && npm run rollup && npm run mocha",
"browser-test": "npm run eslint && npm run rollup && open-cli http://localhost:8084/test/ && static -p 8084",
"start": "npm run browser-test"
"start": "static -p 8084",
"rollup": "rollup -c",
"eslint": "eslint --ext js,md,html .",
"browser-test": "npm run eslint && npm run rollup && open-cli http://localhost:8084/test/ && npm start"
}
}

@@ -80,3 +80,3 @@ # JSONPath Plus [![build status](https://secure.travis-ci.org/s3u/JSONPath.png)](http://travis-ci.org/s3u/JSONPath)

<script type="module">
import JSONPath from './node_modules/jsonpath-plus/dist/index-es.js';
import {JSONPath} from './node_modules/jsonpath-plus/dist/index-es.js';
const result = JSONPath({path: '...', json: ...});

@@ -91,3 +91,3 @@ </script>

```js
import JSONPath from 'jsonpath-plus';
import {JSONPath} from 'jsonpath-plus';

@@ -202,3 +202,3 @@ const result = JSONPath({path: '...', json});

converts to a [JSON Pointer](http://www.rfc-base.org/txt/rfc-6901.txt).
The string will be in a form like: `'/aProperty/anotherProperty/0`
The string will be in a form like: `/aProperty/anotherProperty/0`
(with any `~` and `/` internal characters escaped as per the JSON

@@ -205,0 +205,0 @@ Pointer spec). The JSONPath terminal constructions `~` and `^` and

@@ -1,9 +0,17 @@

/* eslint-disable no-eval, jsdoc/check-types */
// Todo: Reenable jsdoc/check-types once PR merged: https://github.com/gajus/eslint-plugin-jsdoc/pull/270
/* eslint-disable no-eval, prefer-named-capture-group */
// Disabled `prefer-named-capture-group` due to https://github.com/babel/babel/issues/8951#issuecomment-508045524
const globalEval = eval;
// eslint-disable-next-line import/no-commonjs
const supportsNodeVM = typeof module !== 'undefined' && Boolean(module.exports) &&
!(typeof navigator !== 'undefined' && navigator.product === 'ReactNative');
const allowedResultTypes = ['value', 'path', 'pointer', 'parent', 'parentProperty', 'all'];
// Only Node.JS has a process variable that is of [[Class]] process
const supportsNodeVM = function () {
try {
return Object.prototype.toString.call(
global.process
) === '[object process]';
} catch (e) {
return false;
}
};
const allowedResultTypes = [
'value', 'path', 'pointer', 'parent', 'parentProperty', 'all'
];
const {hasOwnProperty: hasOwnProp} = Object.prototype;

@@ -23,6 +31,6 @@

* Copy items out of one array into another.
* @param {Array} source Array with items to copy
* @param {Array} target Array to which to copy
* @param {ConditionCallback} conditionCb Callback passed the current item; will move
* item if evaluates to `true`
* @param {GenericArray} source Array with items to copy
* @param {GenericArray} target Array to which to copy
* @param {ConditionCallback} conditionCb Callback passed the current item;
* will move item if evaluates to `true`
* @returns {undefined}

@@ -40,3 +48,3 @@ */

const vm = supportsNodeVM
const vm = supportsNodeVM()
? require('vm')

@@ -46,4 +54,5 @@ : {

* @param {string} expr Expression to evaluate
* @param {PlainObject} context Object whose items will be added to evaluation
* @returns {Any} Result of evaluated code
* @param {PlainObject} context Object whose items will be added
* to evaluation
* @returns {any} Result of evaluated code
*/

@@ -58,3 +67,3 @@ runInNewContext (expr, context) {

let fString = context[func].toString();
if (!(/function/).exec(fString)) {
if (!(/function/u).exec(fString)) {
fString = 'function ' + fString;

@@ -66,3 +75,3 @@ }

// http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/
/\u2028|\u2029/g, (m) => {
/\u2028|\u2029/gu, (m) => {
return '\\u202' + (m === '\u2028' ? '8' : '9');

@@ -78,5 +87,5 @@ }

* Copies array and then pushes item into it.
* @param {Array} arr Array to copy and into which to push
* @param {Any} item Array item to add (to end)
* @returns {Array} Copy of the original array
* @param {GenericArray} arr Array to copy and into which to push
* @param {any} item Array item to add (to end)
* @returns {GenericArray} Copy of the original array
*/

@@ -90,5 +99,5 @@ function push (arr, item) {

* Copies array and then unshifts item into it.
* @param {Any} item Array item to add (to beginning)
* @param {Array} arr Array to copy and into which to unshift
* @returns {Array} Copy of the original array
* @param {any} item Array item to add (to beginning)
* @param {GenericArray} arr Array to copy and into which to unshift
* @returns {GenericArray} Copy of the original array
*/

@@ -107,6 +116,9 @@ function unshift (item, arr) {

/**
* @param {Any} value The evaluated scalar value
* @param {any} value The evaluated scalar value
*/
constructor (value) {
super('JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)');
super(
'JSONPath should not be called with "new" (it prevents return ' +
'of (unwrapped) scalar values)'
);
this.avoidNew = true;

@@ -145,8 +157,10 @@ this.value = value;

* @param {JSON} obj JSON object to evaluate against
* @param {JSONPathCallback} callback Passed 3 arguments: 1) desired payload per `resultType`,
* 2) `"value"|"property"`, 3) Full returned object with all payloads
* @param {OtherTypeCallback} otherTypeCallback If `@other()` is at the end of one's query, this
* will be invoked with the value of the item, its path, its parent, and its parent's
* property name, and it should return a boolean indicating whether the supplied value
* belongs to the "other" type or not (or it may handle transformations and return `false`).
* @param {JSONPathCallback} callback Passed 3 arguments: 1) desired payload
* per `resultType`, 2) `"value"|"property"`, 3) Full returned object with
* all payloads
* @param {OtherTypeCallback} otherTypeCallback If `@other()` is at the end
* of one's query, this will be invoked with the value of the item, its
* path, its parent, and its parent's property name, and it should return
* a boolean indicating whether the supplied value belongs to the "other"
* type or not (or it may handle transformations and return `false`).
* @returns {JSONPath}

@@ -176,6 +190,8 @@ * @class

opts = opts || {};
const objArgs = hasOwnProp.call(opts, 'json') && hasOwnProp.call(opts, 'path');
const objArgs = hasOwnProp.call(opts, 'json') &&
hasOwnProp.call(opts, 'path');
this.json = opts.json || obj;
this.path = opts.path || expr;
this.resultType = (opts.resultType && opts.resultType.toLowerCase()) || 'value';
this.resultType = (opts.resultType && opts.resultType.toLowerCase()) ||
'value';
this.flatten = opts.flatten || false;

@@ -188,5 +204,10 @@ this.wrap = hasOwnProp.call(opts, 'wrap') ? opts.wrap : true;

this.callback = opts.callback || callback || null;
this.otherTypeCallback = opts.otherTypeCallback || otherTypeCallback || function () {
throw new Error('You must supply an otherTypeCallback callback option with the @other() operator.');
};
this.otherTypeCallback = opts.otherTypeCallback ||
otherTypeCallback ||
function () {
throw new Error(
'You must supply an otherTypeCallback callback option ' +
'with the @other() operator.'
);
};

@@ -206,3 +227,5 @@ if (opts.autostart !== false) {

// PUBLIC METHODS
JSONPath.prototype.evaluate = function (expr, json, callback, otherTypeCallback) {
JSONPath.prototype.evaluate = function (
expr, json, callback, otherTypeCallback
) {
const that = this;

@@ -223,14 +246,27 @@ let currParent = this.parent,

if (!expr.path) {
throw new Error('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');
throw new Error(
'You must supply a "path" property when providing an object ' +
'argument to JSONPath.evaluate().'
);
}
json = hasOwnProp.call(expr, 'json') ? expr.json : json;
flatten = hasOwnProp.call(expr, 'flatten') ? expr.flatten : flatten;
this.currResultType = hasOwnProp.call(expr, 'resultType') ? expr.resultType : this.currResultType;
this.currSandbox = hasOwnProp.call(expr, 'sandbox') ? expr.sandbox : this.currSandbox;
this.currResultType = hasOwnProp.call(expr, 'resultType')
? expr.resultType
: this.currResultType;
this.currSandbox = hasOwnProp.call(expr, 'sandbox')
? expr.sandbox
: this.currSandbox;
wrap = hasOwnProp.call(expr, 'wrap') ? expr.wrap : wrap;
this.currPreventEval = hasOwnProp.call(expr, 'preventEval') ? expr.preventEval : this.currPreventEval;
this.currPreventEval = hasOwnProp.call(expr, 'preventEval')
? expr.preventEval
: this.currPreventEval;
callback = hasOwnProp.call(expr, 'callback') ? expr.callback : callback;
this.currOtherTypeCallback = hasOwnProp.call(expr, 'otherTypeCallback') ? expr.otherTypeCallback : this.currOtherTypeCallback;
this.currOtherTypeCallback = hasOwnProp.call(expr, 'otherTypeCallback')
? expr.otherTypeCallback
: this.currOtherTypeCallback;
currParent = hasOwnProp.call(expr, 'parent') ? expr.parent : currParent;
currParentProperty = hasOwnProp.call(expr, 'parentProperty') ? expr.parentProperty : currParentProperty;
currParentProperty = hasOwnProp.call(expr, 'parentProperty')
? expr.parentProperty
: currParentProperty;
expr = expr.path;

@@ -280,3 +316,5 @@ }

ea.pointer = JSONPath.toPointer(ea.path);
ea.path = typeof ea.path === 'string' ? ea.path : JSONPath.toPathString(ea.path);
ea.path = typeof ea.path === 'string'
? ea.path
: JSONPath.toPathString(ea.path);
return ea;

@@ -317,3 +355,4 @@ case 'value': case 'parent': case 'parentProperty':

) {
// No expr to follow? return path and value as the result of this trace branch
// No expr to follow? return path and value as the result of
// this trace branch
let retObj;

@@ -339,3 +378,5 @@ const that = this;

if (Array.isArray(elems)) {
// This was causing excessive stack size in Node (with or without Babel) against our performance test: `ret.push(...elems);`
// This was causing excessive stack size in Node (with or
// without Babel) against our performance test:
// `ret.push(...elems);`
elems.forEach((t) => {

@@ -354,15 +395,27 @@ ret.push(t);

} else if (loc === '*') { // all child properties
// eslint-disable-next-line no-shadow
this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, x, v, p, par, pr, cb) {
addRet(that._trace(unshift(m, x), v, p, par, pr, cb, true));
});
this._walk(
loc, x, val, path, parent, parentPropName, callback,
function (m, l, _x, v, p, par, pr, cb) {
addRet(that._trace(unshift(m, _x), v, p, par, pr, cb, true));
}
);
} else if (loc === '..') { // all descendent parent properties
addRet(this._trace(x, val, path, parent, parentPropName, callback)); // Check remaining expression with val's immediate children
// eslint-disable-next-line no-shadow
this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, x, v, p, par, pr, cb) {
// We don't join m and x here because we only want parents, not scalar values
if (typeof v[m] === 'object') { // Keep going with recursive descent on val's object children
addRet(that._trace(unshift(l, x), v[m], push(p, m), v, m, cb));
// Check remaining expression with val's immediate children
addRet(
this._trace(x, val, path, parent, parentPropName, callback)
);
this._walk(
loc, x, val, path, parent, parentPropName, callback,
function (m, l, _x, v, p, par, pr, cb) {
// We don't join m and x here because we only want parents,
// not scalar values
if (typeof v[m] === 'object') {
// Keep going with recursive descent on val's
// object children
addRet(that._trace(
unshift(l, _x), v[m], push(p, m), v, m, cb
));
}
}
});
);
// The parent sel computation is handled in the frame above using the

@@ -381,3 +434,8 @@ // ancestor object of val

} else if (loc === '~') { // property name
retObj = {path: push(path, loc), value: parentPropName, parent, parentProperty: null};
retObj = {
path: push(path, loc),
value: parentPropName,
parent,
parentProperty: null
};
this._handleCallback(retObj, callback, 'property');

@@ -387,4 +445,6 @@ return retObj;

addRet(this._trace(x, val, path, null, null, callback));
} else if ((/^(-?\d*):(-?\d*):?(\d*)$/).test(loc)) { // [start:end:step] Python slice syntax
addRet(this._slice(loc, x, val, path, parent, parentPropName, callback));
} else if ((/^(-?\d*):(-?\d*):?(\d*)$/u).test(loc)) { // [start:end:step] Python slice syntax
addRet(
this._slice(loc, x, val, path, parent, parentPropName, callback)
);
} else if (loc.indexOf('?(') === 0) { // [?(expr)] (filtering)

@@ -394,8 +454,10 @@ if (this.currPreventEval) {

}
// eslint-disable-next-line no-shadow
this._walk(loc, x, val, path, parent, parentPropName, callback, function (m, l, x, v, p, par, pr, cb) {
if (that._eval(l.replace(/^\?\((.*?)\)$/, '$1'), v[m], m, p, par, pr)) {
addRet(that._trace(unshift(m, x), v, p, par, pr, cb));
this._walk(
loc, x, val, path, parent, parentPropName, callback,
function (m, l, _x, v, p, par, pr, cb) {
if (that._eval(l.replace(/^\?\((.*?)\)$/u, '$1'), v[m], m, p, par, pr)) {
addRet(that._trace(unshift(m, _x), v, p, par, pr, cb));
}
}
});
);
} else if (loc[0] === '(') { // [(expr)] (dynamic property/index)

@@ -405,5 +467,10 @@ if (this.currPreventEval) {

}
// As this will resolve to a property name (but we don't know it yet), property and parent information is relative to the parent of the property to which this expression will resolve
// As this will resolve to a property name (but we don't know it
// yet), property and parent information is relative to the
// parent of the property to which this expression will resolve
addRet(this._trace(unshift(
this._eval(loc, val, path[path.length - 1], path.slice(0, -1), parent, parentPropName),
this._eval(
loc, val, path[path.length - 1],
path.slice(0, -1), parent, parentPropName
),
x

@@ -423,3 +490,4 @@ ), val, path, parent, parentPropName, callback));

case 'boolean': case 'string': case 'undefined': case 'function':
if (typeof val === valueType) { // eslint-disable-line valid-typeof
// eslint-disable-next-line valid-typeof
if (typeof val === valueType) {
addType = true;

@@ -429,3 +497,4 @@ }

case 'number':
if (typeof val === valueType && isFinite(val)) { // eslint-disable-line valid-typeof
// eslint-disable-next-line valid-typeof
if (typeof val === valueType && isFinite(val)) {
addType = true;

@@ -440,3 +509,4 @@ }

case 'object':
if (val && typeof val === valueType) { // eslint-disable-line valid-typeof
// eslint-disable-next-line valid-typeof
if (val && typeof val === valueType) {
addType = true;

@@ -451,3 +521,5 @@ }

case 'other':
addType = this.currOtherTypeCallback(val, path, parent, parentPropName);
addType = this.currOtherTypeCallback(
val, path, parent, parentPropName
);
break;

@@ -470,12 +542,20 @@ case 'integer':

}
} else if (loc[0] === '`' && val && hasOwnProp.call(val, loc.slice(1))) { // `-escaped property
// `-escaped property
} else if (loc[0] === '`' && val && hasOwnProp.call(val, loc.slice(1))) {
const locProp = loc.slice(1);
addRet(this._trace(x, val[locProp], push(path, locProp), val, locProp, callback, true));
addRet(this._trace(
x, val[locProp], push(path, locProp), val, locProp, callback, true
));
} else if (loc.includes(',')) { // [name1,name2,...]
const parts = loc.split(',');
for (const part of parts) {
addRet(this._trace(unshift(part, x), val, path, parent, parentPropName, callback));
addRet(this._trace(
unshift(part, x), val, path, parent, parentPropName, callback
));
}
} else if (!literalPriority && val && hasOwnProp.call(val, loc)) { // simple case--directly follow property
addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, true));
// simple case--directly follow property
} else if (!literalPriority && val && hasOwnProp.call(val, loc)) {
addRet(
this._trace(x, val[loc], push(path, loc), val, loc, callback, true)
);
}

@@ -509,3 +589,5 @@

JSONPath.prototype._walk = function (loc, expr, val, path, parent, parentPropName, callback, f) {
JSONPath.prototype._walk = function (
loc, expr, val, path, parent, parentPropName, callback, f
) {
if (Array.isArray(val)) {

@@ -525,3 +607,5 @@ const n = val.length;

JSONPath.prototype._slice = function (loc, expr, val, path, parent, parentPropName, callback) {
JSONPath.prototype._slice = function (
loc, expr, val, path, parent, parentPropName, callback
) {
if (!Array.isArray(val)) { return undefined; }

@@ -536,5 +620,8 @@ const len = val.length, parts = loc.split(':'),

for (let i = start; i < end; i += step) {
const tmp = this._trace(unshift(i, expr), val, path, parent, parentPropName, callback);
const tmp = this._trace(
unshift(i, expr), val, path, parent, parentPropName, callback
);
if (Array.isArray(tmp)) {
// This was causing excessive stack size in Node (with or without Babel) against our performance test: `ret.push(...tmp);`
// This was causing excessive stack size in Node (with or
// without Babel) against our performance test: `ret.push(...tmp);`
tmp.forEach((t) => {

@@ -550,23 +637,25 @@ ret.push(t);

JSONPath.prototype._eval = function (code, _v, _vname, path, parent, parentPropName) {
JSONPath.prototype._eval = function (
code, _v, _vname, path, parent, parentPropName
) {
if (!this._obj || !_v) { return false; }
if (code.includes('@parentProperty')) {
this.currSandbox._$_parentProperty = parentPropName;
code = code.replace(/@parentProperty/g, '_$_parentProperty');
code = code.replace(/@parentProperty/gu, '_$_parentProperty');
}
if (code.includes('@parent')) {
this.currSandbox._$_parent = parent;
code = code.replace(/@parent/g, '_$_parent');
code = code.replace(/@parent/gu, '_$_parent');
}
if (code.includes('@property')) {
this.currSandbox._$_property = _vname;
code = code.replace(/@property/g, '_$_property');
code = code.replace(/@property/gu, '_$_property');
}
if (code.includes('@path')) {
this.currSandbox._$_path = JSONPath.toPathString(path.concat([_vname]));
code = code.replace(/@path/g, '_$_path');
code = code.replace(/@path/gu, '_$_path');
}
if (code.match(/@([.\s)[])/)) {
if (code.match(/@([.\s)[])/u)) {
this.currSandbox._$_v = _v;
code = code.replace(/@([.\s)[])/g, '_$_v$1');
code = code.replace(/@([.\s)[])/gu, '_$_v$1');
}

@@ -595,4 +684,4 @@ try {

for (let i = 1; i < n; i++) {
if (!(/^(~|\^|@.*?\(\))$/).test(x[i])) {
p += (/^[0-9*]+$/).test(x[i]) ? ('[' + x[i] + ']') : ("['" + x[i] + "']");
if (!(/^(~|\^|@.*?\(\))$/u).test(x[i])) {
p += (/^[0-9*]+$/u).test(x[i]) ? ('[' + x[i] + ']') : ("['" + x[i] + "']");
}

@@ -611,6 +700,6 @@ }

for (let i = 1; i < n; i++) {
if (!(/^(~|\^|@.*?\(\))$/).test(x[i])) {
if (!(/^(~|\^|@.*?\(\))$/u).test(x[i])) {
p += '/' + x[i].toString()
.replace(/~/g, '~0')
.replace(/\//g, '~1');
.replace(/~/gu, '~0')
.replace(/\//gu, '~1');
}

@@ -632,3 +721,3 @@ }

.replace(
/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/g,
/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/gu,
';$&;'

@@ -638,31 +727,31 @@ )

// within brackets or single quotes
.replace(/[['](\??\(.*?\))[\]']/g, function ($0, $1) {
.replace(/[['](\??\(.*?\))[\]']/gu, function ($0, $1) {
return '[#' + (subx.push($1) - 1) + ']';
})
// Escape periods and tildes within properties
.replace(/\['([^'\]]*)'\]/g, function ($0, prop) {
.replace(/\['([^'\]]*)'\]/gu, function ($0, prop) {
return "['" + prop
.replace(/\./g, '%@%')
.replace(/~/g, '%%@@%%') +
.replace(/\./gu, '%@%')
.replace(/~/gu, '%%@@%%') +
"']";
})
// Properties operator
.replace(/~/g, ';~;')
.replace(/~/gu, ';~;')
// Split by property boundaries
.replace(/'?\.'?(?![^[]*\])|\['?/g, ';')
.replace(/'?\.'?(?![^[]*\])|\['?/gu, ';')
// Reinsert periods within properties
.replace(/%@%/g, '.')
.replace(/%@%/gu, '.')
// Reinsert tildes within properties
.replace(/%%@@%%/g, '~')
.replace(/%%@@%%/gu, '~')
// Parent
.replace(/(?:;)?(\^+)(?:;)?/g, function ($0, ups) {
.replace(/(?:;)?(\^+)(?:;)?/gu, function ($0, ups) {
return ';' + ups.split('').join(';') + ';';
})
// Descendents
.replace(/;;;|;;/g, ';..;')
.replace(/;;;|;;/gu, ';..;')
// Remove trailing
.replace(/;$|'?\]|'$/g, '');
.replace(/;$|'?\]|'$/gu, '');
const exprList = normalized.split(';').map(function (exp) {
const match = exp.match(/#(\d+)/);
const match = exp.match(/#(\d+)/u);
return !match || !match[1] ? exp : subx[match[1]];

@@ -669,0 +758,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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc