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 7.2.0 to 8.0.0

LICENSE

7

CHANGES.md
# CHANGES for jsonpath-plus
## 8.0.0
- Breaking change: Bump Node `engines` to 14
- feat: add support for nested filter expressions (@carlosingles)
- docs: update README and license (@akirataguchi115)
- docs: github workflow badge (@dsanch3z)
## 7.2.0

@@ -4,0 +11,0 @@

2

demo/index.js

@@ -34,3 +34,3 @@ /* globals JSONPath */

}
const result = JSONPath.JSONPath({
const result = new JSONPath.JSONPath({
path: $('#jsonpath').value,

@@ -37,0 +37,0 @@ json

@@ -1,4 +0,4 @@

import {JSONPath} from '../dist/index-node-esm.js';
import {JSONPath as jsonpath} from '../dist/index-node-esm.js';
/* eslint-disable quotes, quote-props */
/* eslint-disable @stylistic/quotes, @stylistic/quote-props */
const json = {

@@ -38,5 +38,5 @@ "store": {

};
/* eslint-enable quotes, quote-props */
/* eslint-enable @stylistic/quotes, @stylistic/quote-props */
const result = JSONPath({
const result = jsonpath({
json,

@@ -43,0 +43,0 @@ path: '$.store.book[*].author'

@@ -1,11 +0,42 @@

function _typeof(obj) {
function _callSuper(t, o, e) {
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
}
function _construct(t, e, r) {
if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
var o = [null];
o.push.apply(o, e);
var p = new (t.bind.apply(t, o))();
return r && _setPrototypeOf(p, r.prototype), p;
}
function _isNativeReflectConstruct() {
try {
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
} catch (t) {}
return (_isNativeReflectConstruct = function () {
return !!t;
})();
}
function _toPrimitive(t, r) {
if ("object" != typeof t || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != typeof i) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == typeof i ? i : String(i);
}
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
}, _typeof(obj);
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
function _classCallCheck(instance, Constructor) {

@@ -16,3 +47,2 @@ if (!(instance instanceof Constructor)) {

}
function _defineProperties(target, props) {

@@ -24,6 +54,5 @@ for (var i = 0; i < props.length; i++) {

if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {

@@ -37,3 +66,2 @@ if (protoProps) _defineProperties(Constructor.prototype, protoProps);

}
function _inherits(subClass, superClass) {

@@ -43,3 +71,2 @@ if (typeof superClass !== "function" && superClass !== null) {

}
subClass.prototype = Object.create(superClass && superClass.prototype, {

@@ -57,3 +84,2 @@ constructor: {

}
function _getPrototypeOf(o) {

@@ -65,3 +91,2 @@ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {

}
function _setPrototypeOf(o, p) {

@@ -74,57 +99,23 @@ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {

}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
function _isNativeFunction(fn) {
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
return Function.toString.call(fn).indexOf("[native code]") !== -1;
} catch (e) {
return false;
return typeof fn === "function";
}
}
function _construct(Parent, args, Class) {
if (_isNativeReflectConstruct()) {
_construct = Reflect.construct.bind();
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) _setPrototypeOf(instance, Class.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
function _isNativeFunction(fn) {
return Function.toString.call(fn).indexOf("[native code]") !== -1;
}
function _wrapNativeSuper(Class) {
var _cache = typeof Map === "function" ? new Map() : undefined;
_wrapNativeSuper = function _wrapNativeSuper(Class) {
if (Class === null || !_isNativeFunction(Class)) return Class;
if (typeof Class !== "function") {
throw new TypeError("Super expression must either be null or a function");
}
if (typeof _cache !== "undefined") {
if (_cache.has(Class)) return _cache.get(Class);
_cache.set(Class, Wrapper);
}
function Wrapper() {
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
}
Wrapper.prototype = Object.create(Class.prototype, {

@@ -140,6 +131,4 @@ constructor: {

};
return _wrapNativeSuper(Class);
}
function _assertThisInitialized(self) {

@@ -149,6 +138,4 @@ if (self === void 0) {

}
return self;
}
function _possibleConstructorReturn(self, call) {

@@ -160,37 +147,13 @@ if (call && (typeof call === "object" || typeof call === "function")) {

}
return _assertThisInitialized(self);
}
function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {

@@ -204,18 +167,12 @@ if (!o) return;

}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _createForOfIteratorHelper(o, allowArrayLike) {
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
if (!it) {

@@ -225,5 +182,3 @@ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {

var i = 0;
var F = function () {};
return {

@@ -246,9 +201,7 @@ s: F,

}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var normalCompletion = true,
didErr = false,
err;
didErr = false,
err;
return {

@@ -277,3 +230,6 @@ s: function () {

/* eslint-disable camelcase, unicorn/prefer-string-replace-all,
unicorn/prefer-at */
var hasOwnProp = Object.prototype.hasOwnProperty;
/**

@@ -297,3 +253,2 @@ * @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject

*/
function push(arr, item) {

@@ -310,4 +265,2 @@ arr = arr.slice();

*/
function unshift(item, arr) {

@@ -318,2 +271,3 @@ arr = arr.slice();

}
/**

@@ -323,9 +277,4 @@ * Caught when JSONPath is used without `new` but rethrown if with `new`

*/
var NewError = /*#__PURE__*/function (_Error) {
_inherits(NewError, _Error);
var _super = _createSuper(NewError);
/**

@@ -336,6 +285,4 @@ * @param {AnyResult} value The evaluated scalar value

var _this;
_classCallCheck(this, NewError);
_this = _super.call(this, 'JSONPath should not be called with "new" (it prevents return ' + 'of (unwrapped) scalar values)');
_this = _callSuper(this, NewError, ['JSONPath should not be called with "new" (it prevents return ' + 'of (unwrapped) scalar values)']);
_this.avoidNew = true;

@@ -346,3 +293,2 @@ _this.value = value;

}
return _createClass(NewError);

@@ -357,3 +303,2 @@ }( /*#__PURE__*/_wrapNativeSuper(Error));

*/
/**

@@ -366,3 +311,2 @@ * @callback JSONPathCallback

*/
/**

@@ -376,5 +320,3 @@ * @callback OtherTypeCallback

*/
/* eslint-disable max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */
/* eslint-disable @stylistic/max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */
/**

@@ -396,5 +338,3 @@ * @typedef {PlainObject} JSONPathOptions

*/
/* eslint-enable max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */
/* eslint-enable @stylistic/max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */
/**

@@ -415,4 +355,2 @@ * @param {string|JSONPathOptions} opts If a string, will be treated as `expr`

*/
function JSONPath(opts, expr, obj, callback, otherTypeCallback) {

@@ -427,7 +365,5 @@ // eslint-disable-next-line no-restricted-syntax

}
return e.value;
}
}
if (typeof opts === 'string') {

@@ -440,3 +376,2 @@ otherTypeCallback = callback;

}
var optObj = opts && _typeof(opts) === 'object';

@@ -454,7 +389,5 @@ opts = opts || {};

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

@@ -464,3 +397,2 @@ var args = {

};
if (!optObj) {

@@ -471,21 +403,17 @@ args.json = obj;

}
var ret = this.evaluate(args);
if (!ret || _typeof(ret) !== 'object') {
throw new NewError(ret);
}
return ret;
}
} // PUBLIC METHODS
}
// PUBLIC METHODS
JSONPath.prototype.evaluate = function (expr, json, callback, otherTypeCallback) {
var _this2 = this;
var currParent = this.parent,
currParentProperty = this.parentProperty;
currParentProperty = this.parentProperty;
var flatten = this.flatten,
wrap = this.wrap;
wrap = this.wrap;
this.currResultType = this.resultType;

@@ -498,3 +426,2 @@ this.currPreventEval = this.preventEval;

expr = expr || this.path;
if (expr && _typeof(expr) === 'object' && !Array.isArray(expr)) {

@@ -504,7 +431,5 @@ if (!expr.path && expr.path !== '') {

}
if (!hasOwnProp.call(expr, 'json')) {
throw new TypeError('You must supply a "json" property when providing an object ' + 'argument to JSONPath.evaluate().');
}
var _expr = expr;

@@ -523,37 +448,26 @@ json = _expr.json;

}
currParent = currParent || null;
currParentProperty = currParentProperty || null;
if (Array.isArray(expr)) {
expr = JSONPath.toPathString(expr);
}
if (!expr && expr !== '' || !json) {
return undefined;
}
var exprList = JSONPath.toPathArray(expr);
if (exprList[0] === '$' && exprList.length > 1) {
exprList.shift();
}
this._hasParentSelector = null;
var result = this._trace(exprList, json, ['$'], currParent, currParentProperty, callback).filter(function (ea) {
return ea && !ea.isParentSelector;
});
if (!result.length) {
return wrap ? [] : undefined;
}
if (!wrap && result.length === 1 && !result[0].hasArrExpr) {
return this._getPreferredOutput(result[0]);
}
return result.reduce(function (rslt, ea) {
var valOrPath = _this2._getPreferredOutput(ea);
if (flatten && Array.isArray(valOrPath)) {

@@ -564,11 +478,10 @@ rslt = rslt.concat(valOrPath);

}
return rslt;
}, []);
}; // PRIVATE METHODS
};
// PRIVATE METHODS
JSONPath.prototype._getPreferredOutput = function (ea) {
var resultType = this.currResultType;
switch (resultType) {

@@ -582,3 +495,2 @@ case 'all':

}
case 'value':

@@ -588,9 +500,6 @@ case 'parent':

return ea[resultType];
case 'path':
return JSONPath.toPathString(ea[resultType]);
case 'pointer':
return JSONPath.toPointer(ea.path);
default:

@@ -600,12 +509,11 @@ throw new TypeError('Unknown result type');

};
JSONPath.prototype._handleCallback = function (fullRetObj, callback, type) {
if (callback) {
var preferredOutput = this._getPreferredOutput(fullRetObj);
fullRetObj.path = typeof fullRetObj.path === 'string' ? fullRetObj.path : JSONPath.toPathString(fullRetObj.path); // eslint-disable-next-line n/callback-return
fullRetObj.path = typeof fullRetObj.path === 'string' ? fullRetObj.path : JSONPath.toPathString(fullRetObj.path);
// eslint-disable-next-line n/callback-return
callback(preferredOutput, type, fullRetObj);
}
};
/**

@@ -623,11 +531,7 @@ *

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

@@ -641,12 +545,10 @@ retObj = {

};
this._handleCallback(retObj, callback, 'value');
return retObj;
}
var loc = expr[0],
x = expr.slice(1);
var loc = expr[0],
x = expr.slice(1); // We need to gather the return value of recursive trace calls in order to
// We need to gather the return value of recursive trace calls in order to
// do the parent sel computation.
var ret = [];

@@ -658,3 +560,2 @@ /**

*/
function addRet(elems) {

@@ -672,6 +573,6 @@ if (Array.isArray(elems)) {

}
if ((typeof loc !== 'string' || literalPriority) && val && hasOwnProp.call(val, loc)) {
// simple case--directly follow property
addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr)); // eslint-disable-next-line unicorn/prefer-switch -- Part of larger `if`
addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr));
// eslint-disable-next-line unicorn/prefer-switch -- Part of larger `if`
} else if (loc === '*') {

@@ -686,3 +587,2 @@ // all child properties

addRet(this._trace(x, val, path, parent, parentPropName, callback, hasArrExpr));
this._walk(val, function (m) {

@@ -696,5 +596,5 @@ // We don't join m and x here because we only want parents,

}
}); // The parent sel computation is handled in the frame above using the
});
// The parent sel computation is handled in the frame above using the
// ancestor object of val
} else if (loc === '^') {

@@ -716,5 +616,3 @@ // This is not a final endpoint, so we do not invoke the callback here

};
this._handleCallback(retObj, callback, 'property');
return retObj;

@@ -732,10 +630,23 @@ } else if (loc === '$') {

}
var safeLoc = loc.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/, '$1');
this._walk(val, function (m) {
if (_this3._eval(safeLoc, val[m], m, path, parent, parentPropName)) {
addRet(_this3._trace(x, val[m], push(path, m), val, m, callback, true));
}
});
// check for a nested filter expression
var nested = /@(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])?((?:[\0->@-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)['\[](\??\((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\))(?!(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])\)\])['\]]/g.exec(safeLoc);
if (nested) {
// find if there are matches in the nested expression
// add them to the result set if there is at least one match
this._walk(val, function (m) {
var npath = [nested[2]];
var nvalue = nested[1] ? val[m][nested[1]] : val[m];
var filterResults = _this3._trace(npath, nvalue, path, parent, parentPropName, callback, true);
if (filterResults.length > 0) {
addRet(_this3._trace(x, val[m], push(path, m), val, m, callback, true));
}
});
} else {
this._walk(val, function (m) {
if (_this3._eval(safeLoc, val[m], m, path, parent, parentPropName)) {
addRet(_this3._trace(x, val[m], push(path, m), val, m, callback, true));
}
});
}
} else if (loc[0] === '(') {

@@ -745,7 +656,6 @@ // [(expr)] (dynamic property/index)

throw new Error('Eval [(expr)] prevented in JSONPath expression.');
} // As this will resolve to a property name (but we don't know it
}
// 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), x), val, path, parent, parentPropName, callback, hasArrExpr));

@@ -756,3 +666,2 @@ } else if (loc[0] === '@') {

var valueType = loc.slice(1, -2);
switch (valueType) {

@@ -763,5 +672,3 @@ case 'scalar':

}
break;
case 'boolean':

@@ -771,9 +678,6 @@ case 'string':

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

@@ -783,5 +687,3 @@ if (Number.isFinite(val) && !(val % 1)) {

}
break;
case 'number':

@@ -791,5 +693,3 @@ if (Number.isFinite(val)) {

}
break;
case 'nonFinite':

@@ -799,13 +699,8 @@ if (typeof val === 'number' && !Number.isFinite(val)) {

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

@@ -815,9 +710,6 @@ if (Array.isArray(val)) {

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

@@ -827,11 +719,7 @@ if (val === null) {

}
break;
/* c8 ignore next 2 */
default:
throw new TypeError('Unknown value type ' + valueType);
}
if (addType) {

@@ -844,8 +732,6 @@ retObj = {

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

@@ -857,6 +743,4 @@ var locProp = loc.slice(1);

var parts = loc.split(',');
var _iterator = _createForOfIteratorHelper(parts),
_step;
_step;
try {

@@ -866,4 +750,4 @@ for (_iterator.s(); !(_step = _iterator.n()).done;) {

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

@@ -876,18 +760,15 @@ _iterator.e(err);

addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr, true));
} // We check the resulting values for parent selections. For parent
}
// We check the resulting values for parent selections. For parent
// selections we discard the value object and continue the trace with the
// current val object
if (this._hasParentSelector) {
for (var t = 0; t < ret.length; t++) {
var rett = ret[t];
if (rett && rett.isParentSelector) {
var tmp = this._trace(rett.expr, val, rett.path, parent, parentPropName, callback, hasArrExpr);
if (Array.isArray(tmp)) {
ret[t] = tmp[0];
var tl = tmp.length;
for (var tt = 1; tt < tl; tt++) {

@@ -903,10 +784,7 @@ t++;

}
return ret;
};
JSONPath.prototype._walk = function (val, f) {
if (Array.isArray(val)) {
var n = val.length;
for (var i = 0; i < n; i++) {

@@ -921,3 +799,2 @@ f(i);

};
JSONPath.prototype._slice = function (loc, expr, val, path, parent, parentPropName, callback) {

@@ -927,14 +804,13 @@ if (!Array.isArray(val)) {

}
var len = val.length,
parts = loc.split(':'),
step = parts[2] && Number.parseInt(parts[2]) || 1;
parts = loc.split(':'),
step = parts[2] && Number.parseInt(parts[2]) || 1;
var start = parts[0] && Number.parseInt(parts[0]) || 0,
end = parts[1] && Number.parseInt(parts[1]) || len;
end = parts[1] && Number.parseInt(parts[1]) || len;
start = start < 0 ? Math.max(0, start + len) : Math.min(len, start);
end = end < 0 ? Math.max(0, end + len) : Math.min(len, end);
var ret = [];
for (var i = start; i < end; i += step) {
var tmp = this._trace(unshift(i, expr), val, path, parent, parentPropName, callback, true); // Should only be possible to be an array here since first part of
var tmp = this._trace(unshift(i, expr), val, path, parent, parentPropName, callback, true);
// Should only be possible to be an array here since first part of
// ``unshift(i, expr)` passed in above would not be empty, nor `~`,

@@ -944,4 +820,2 @@ // nor begin with `@` (as could return objects)

// without Babel) against our performance test: `ret.push(...tmp);`
tmp.forEach(function (t) {

@@ -951,6 +825,4 @@ ret.push(t);

}
return ret;
};
JSONPath.prototype._eval = function (code, _v, _vname, path, parent, parentPropName) {

@@ -963,19 +835,13 @@ this.currSandbox._$_parentProperty = parentPropName;

var containsPath = code.includes('@path');
if (containsPath) {
this.currSandbox._$_path = JSONPath.toPathString(path.concat([_vname]));
}
var scriptCacheKey = 'script:' + code;
if (!JSONPath.cache[scriptCacheKey]) {
var script = code.replace(/@parentProperty/g, '_$_parentProperty').replace(/@parent/g, '_$_parent').replace(/@property/g, '_$_property').replace(/@root/g, '_$_root').replace(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/g, '_$_v$1');
if (containsPath) {
script = script.replace(/@path/g, '_$_path');
}
JSONPath.cache[scriptCacheKey] = new this.vm.Script(script);
}
try {

@@ -986,7 +852,9 @@ return JSONPath.cache[scriptCacheKey].runInNewContext(this.currSandbox);

}
}; // PUBLIC CLASS PROPERTIES AND METHODS
// Could store the cache object itself
};
// PUBLIC CLASS PROPERTIES AND METHODS
// Could store the cache object itself
JSONPath.cache = {};
/**

@@ -996,8 +864,6 @@ * @param {string[]} pathArr Array to convert

*/
JSONPath.toPathString = function (pathArr) {
var x = pathArr,
n = x.length;
n = x.length;
var p = '$';
for (var i = 1; i < n; i++) {

@@ -1008,5 +874,5 @@ 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])) {

}
return p;
};
/**

@@ -1016,9 +882,6 @@ * @param {string} pointer JSON Path

*/
JSONPath.toPointer = function (pointer) {
var x = pointer,
n = x.length;
n = x.length;
var p = '';
for (var i = 1; i < n; i++) {

@@ -1029,5 +892,5 @@ 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])) {

}
return p;
};
/**

@@ -1037,29 +900,35 @@ * @param {string} expr Expression to convert

*/
JSONPath.toPathArray = function (expr) {
var cache = JSONPath.cache;
if (cache[expr]) {
return cache[expr].concat();
}
var subx = [];
var normalized = expr // Properties
.replace(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/g, ';$&;') // Parenthetical evaluations (filtering and otherwise), directly
var normalized = expr
// Properties
.replace(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/g, ';$&;')
// Parenthetical evaluations (filtering and otherwise), directly
// within brackets or single quotes
.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) {
.replace(/['\[](\??\((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\))['\]](?!(?:[\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(/\[["']((?:(?!['\]])[\s\S])*)["']\]/g, function ($0, prop) {
})
// Escape periods and tildes within properties
.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(/["']?\.["']?(?!(?:(?!\[)[\s\S])*\])|\[["']?/g, ';') // Reinsert periods within properties
.replace(/%@%/g, '.') // Reinsert tildes within properties
.replace(/%%@@%%/g, '~') // Parent
})
// Properties operator
.replace(/~/g, ';~;')
// Split by property boundaries
.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
.replace(/%%@@%%/g, '~')
// Parent
.replace(/(?:;)?(\^+)(?:;)?/g, function ($0, ups) {
return ';' + ups.split('').join(';') + ';';
}) // Descendents
.replace(/;;;|;;/g, ';..;') // Remove trailing
})
// Descendents
.replace(/;;;|;;/g, ';..;')
// Remove trailing
.replace(/;$|'?\]|'$/g, '');

@@ -1096,9 +965,6 @@ var exprList = normalized.split(';').map(function (exp) {

*/
var moveToAnotherArray = function moveToAnotherArray(source, target, conditionCb) {
var il = source.length;
for (var i = 0; i < il; i++) {
var item = source[i];
if (conditionCb(item)) {

@@ -1109,7 +975,6 @@ target.push(source.splice(i--, 1)[0]);

};
/**
* In-browser replacement for NodeJS' VM.Script.
*/
var Script = /*#__PURE__*/function () {

@@ -1121,5 +986,5 @@ /**

_classCallCheck(this, Script);
this.code = expr;
}
/**

@@ -1130,4 +995,2 @@ * @param {PlainObject} context Object whose items will be added

*/
_createClass(Script, [{

@@ -1142,3 +1005,3 @@ key: "runInNewContext",

});
var values = keys.map(function (vr, i) {
var values = keys.map(function (vr) {
return context[vr];

@@ -1148,30 +1011,29 @@ });

var fString = context[func].toString();
if (!/function/.test(fString)) {
fString = 'function ' + fString;
}
return 'var ' + func + '=' + fString + ';' + s;
}, '');
expr = funcString + expr; // Mitigate http://perfectionkills.com/global-eval-what-are-the-options/#new_function
expr = funcString + expr;
// Mitigate http://perfectionkills.com/global-eval-what-are-the-options/#new_function
if (!/(["'])use strict\1/.test(expr) && !keys.includes('arguments')) {
expr = 'var arguments = undefined;' + expr;
} // Remove last semi so `return` will be inserted before
}
// Remove last semi so `return` will be inserted before
// the previous one instead, allowing for the return
// of a bare ending expression
expr = expr.replace(/;[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*$/, '');
expr = expr.replace(/;[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*$/, ''); // Insert `return`
// Insert `return`
var lastStatementEnd = expr.lastIndexOf(';');
var code = lastStatementEnd > -1 ? expr.slice(0, lastStatementEnd + 1) + ' return ' + expr.slice(lastStatementEnd + 1) : ' return ' + expr; // eslint-disable-next-line no-new-func
var code = lastStatementEnd > -1 ? expr.slice(0, lastStatementEnd + 1) + ' return ' + expr.slice(lastStatementEnd + 1) : ' return ' + expr;
// eslint-disable-next-line no-new-func
return _construct(Function, keys.concat([code])).apply(void 0, _toConsumableArray(values));
}
}]);
return Script;
}();
JSONPath.prototype.vm = {

@@ -1178,0 +1040,0 @@ Script: Script

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

function t(r){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(r)}function r(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}function e(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function n(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function a(t){return a=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},a(t)}function o(t,r){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t},o(t,r)}function u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function i(t,r,e){return i=u()?Reflect.construct.bind():function(t,r,e){var n=[null];n.push.apply(n,r);var a=new(Function.bind.apply(t,n));return e&&o(a,e.prototype),a},i.apply(null,arguments)}function c(t){var r="function"==typeof Map?new Map:void 0;return c=function(t){if(null===t||(e=t,-1===Function.toString.call(e).indexOf("[native code]")))return t;var e;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,n)}function n(){return i(t,arguments,a(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),o(n,t)},c(t)}function l(t,r){if(r&&("object"==typeof r||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function s(t){return function(t){if(Array.isArray(t))return h(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||p(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function p(t,r){if(t){if("string"==typeof t)return h(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?h(t,r):void 0}}function h(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}var f=Object.prototype.hasOwnProperty;function y(t,r){return(t=t.slice()).push(r),t}function v(t,r){return(r=r.slice()).unshift(t),r}var b=function(t){!function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),r&&o(t,r)}(p,c(Error));var e,i,s=(e=p,i=u(),function(){var t,r=a(e);if(i){var n=a(this).constructor;t=Reflect.construct(r,arguments,n)}else t=r.apply(this,arguments);return l(this,t)});function p(t){var e;return r(this,p),(e=s.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 n(p)}();function F(r,e,n,a,o){if(!(this instanceof F))try{return new F(r,e,n,a,o)}catch(t){if(!t.avoidNew)throw t;return t.value}"string"==typeof r&&(o=a,a=n,n=e,e=r,r=null);var u=r&&"object"===t(r);if(r=r||{},this.json=r.json||n,this.path=r.path||e,this.resultType=r.resultType||"value",this.flatten=r.flatten||!1,this.wrap=!f.call(r,"wrap")||r.wrap,this.sandbox=r.sandbox||{},this.preventEval=r.preventEval||!1,this.parent=r.parent||null,this.parentProperty=r.parentProperty||null,this.callback=r.callback||a||null,this.otherTypeCallback=r.otherTypeCallback||o||function(){throw new TypeError("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==r.autostart){var i={path:u?r.path:e};u?"json"in r&&(i.json=r.json):i.json=n;var c=this.evaluate(i);if(!c||"object"!==t(c))throw new b(c);return c}}F.prototype.evaluate=function(r,e,n,a){var o=this,u=this.parent,i=this.parentProperty,c=this.flatten,l=this.wrap;if(this.currResultType=this.resultType,this.currPreventEval=this.preventEval,this.currSandbox=this.sandbox,n=n||this.callback,this.currOtherTypeCallback=a||this.otherTypeCallback,e=e||this.json,(r=r||this.path)&&"object"===t(r)&&!Array.isArray(r)){if(!r.path&&""!==r.path)throw new TypeError('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');if(!f.call(r,"json"))throw new TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');e=r.json,c=f.call(r,"flatten")?r.flatten:c,this.currResultType=f.call(r,"resultType")?r.resultType:this.currResultType,this.currSandbox=f.call(r,"sandbox")?r.sandbox:this.currSandbox,l=f.call(r,"wrap")?r.wrap:l,this.currPreventEval=f.call(r,"preventEval")?r.preventEval:this.currPreventEval,n=f.call(r,"callback")?r.callback:n,this.currOtherTypeCallback=f.call(r,"otherTypeCallback")?r.otherTypeCallback:this.currOtherTypeCallback,u=f.call(r,"parent")?r.parent:u,i=f.call(r,"parentProperty")?r.parentProperty:i,r=r.path}if(u=u||null,i=i||null,Array.isArray(r)&&(r=F.toPathString(r)),(r||""===r)&&e){var s=F.toPathArray(r);"$"===s[0]&&s.length>1&&s.shift(),this._hasParentSelector=null;var p=this._trace(s,e,["$"],u,i,n).filter((function(t){return t&&!t.isParentSelector}));return p.length?l||1!==p.length||p[0].hasArrExpr?p.reduce((function(t,r){var e=o._getPreferredOutput(r);return c&&Array.isArray(e)?t=t.concat(e):t.push(e),t}),[]):this._getPreferredOutput(p[0]):l?[]:void 0}},F.prototype._getPreferredOutput=function(t){var r=this.currResultType;switch(r){case"all":var e=Array.isArray(t.path)?t.path:F.toPathArray(t.path);return t.pointer=F.toPointer(e),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);default:throw new TypeError("Unknown result type")}},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,o,u,i,c){var l,s=this;if(!r.length)return l={path:n,value:e,parent:a,parentProperty:o,hasArrExpr:i},this._handleCallback(l,u,"value"),l;var h=r[0],b=r.slice(1),F=[];function d(t){Array.isArray(t)?t.forEach((function(t){F.push(t)})):F.push(t)}if(("string"!=typeof h||c)&&e&&f.call(e,h))d(this._trace(b,e[h],y(n,h),e,h,u,i));else if("*"===h)this._walk(e,(function(t){d(s._trace(b,e[t],y(n,t),e,t,u,!0,!0))}));else if(".."===h)d(this._trace(b,e,n,a,o,u,i)),this._walk(e,(function(a){"object"===t(e[a])&&d(s._trace(r.slice(),e[a],y(n,a),e,a,u,!0))}));else{if("^"===h)return this._hasParentSelector=!0,{path:n.slice(0,-1),expr:b,isParentSelector:!0};if("~"===h)return l={path:y(n,h),value:o,parent:a,parentProperty:null},this._handleCallback(l,u,"property"),l;if("$"===h)d(this._trace(b,e,n,null,null,u,i));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(h))d(this._slice(h,b,e,n,a,o,u));else if(0===h.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");var g=h.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/,"$1");this._walk(e,(function(t){s._eval(g,e[t],t,n,a,o)&&d(s._trace(b,e[t],y(n,t),e,t,u,!0))}))}else if("("===h[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");d(this._trace(v(this._eval(h,e,n[n.length-1],n.slice(0,-1),a,o),b),e,n,a,o,u,i))}else if("@"===h[0]){var w=!1,_=h.slice(1,-2);switch(_){case"scalar":e&&["object","function"].includes(t(e))||(w=!0);break;case"boolean":case"string":case"undefined":case"function":t(e)===_&&(w=!0);break;case"integer":!Number.isFinite(e)||e%1||(w=!0);break;case"number":Number.isFinite(e)&&(w=!0);break;case"nonFinite":"number"!=typeof e||Number.isFinite(e)||(w=!0);break;case"object":e&&t(e)===_&&(w=!0);break;case"array":Array.isArray(e)&&(w=!0);break;case"other":w=this.currOtherTypeCallback(e,n,a,o);break;case"null":null===e&&(w=!0);break;default:throw new TypeError("Unknown value type "+_)}if(w)return l={path:n,value:e,parent:a,parentProperty:o},this._handleCallback(l,u,"value"),l}else if("`"===h[0]&&e&&f.call(e,h.slice(1))){var m=h.slice(1);d(this._trace(b,e[m],y(n,m),e,m,u,i,!0))}else if(h.includes(",")){var D,P=function(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=p(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0,a=function(){};return{s:a,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,u=!0,i=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return u=t.done,t},e:function(t){i=!0,o=t},f:function(){try{u||null==e.return||e.return()}finally{if(i)throw o}}}}(h.split(","));try{for(P.s();!(D=P.n()).done;){var S=D.value;d(this._trace(v(S,b),e,n,a,o,u,!0))}}catch(t){P.e(t)}finally{P.f()}}else!c&&e&&f.call(e,h)&&d(this._trace(b,e[h],y(n,h),e,h,u,i,!0))}if(this._hasParentSelector)for(var x=0;x<F.length;x++){var E=F[x];if(E&&E.isParentSelector){var j=this._trace(E.expr,e,E.path,a,o,u,i);if(Array.isArray(j)){F[x]=j[0];for(var A=j.length,k=1;k<A;k++)x++,F.splice(x,0,j[k])}else F[x]=j}}return F},F.prototype._walk=function(r,e){if(Array.isArray(r))for(var n=r.length,a=0;a<n;a++)e(a);else r&&"object"===t(r)&&Object.keys(r).forEach((function(t){e(t)}))},F.prototype._slice=function(t,r,e,n,a,o,u){if(Array.isArray(e)){var i=e.length,c=t.split(":"),l=c[2]&&Number.parseInt(c[2])||1,s=c[0]&&Number.parseInt(c[0])||0,p=c[1]&&Number.parseInt(c[1])||i;s=s<0?Math.max(0,s+i):Math.min(i,s),p=p<0?Math.max(0,p+i):Math.min(i,p);for(var h=[],f=s;f<p;f+=l){this._trace(v(f,r),e,n,a,o,u,!0).forEach((function(t){h.push(t)}))}return h}},F.prototype._eval=function(t,r,e,n,a,o){this.currSandbox._$_parentProperty=o,this.currSandbox._$_parent=a,this.currSandbox._$_property=e,this.currSandbox._$_root=this.json,this.currSandbox._$_v=r;var u=t.includes("@path");u&&(this.currSandbox._$_path=F.toPathString(n.concat([e])));var i="script:"+t;if(!F.cache[i]){var c=t.replace(/@parentProperty/g,"_$_parentProperty").replace(/@parent/g,"_$_parent").replace(/@property/g,"_$_property").replace(/@root/g,"_$_root").replace(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/g,"_$_v$1");u&&(c=c.replace(/@path/g,"_$_path")),F.cache[i]=new this.vm.Script(c)}try{return F.cache[i].runInNewContext(this.currSandbox)}catch(r){throw 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(/\[["']((?:(?!['\]])[\s\S])*)["']\]/g,(function(t,r){return"['"+r.replace(/\./g,"%@%").replace(/~/g,"%%@@%%")+"']"})).replace(/~/g,";~;").replace(/["']?\.["']?(?!(?:(?!\[)[\s\S])*\])|\[["']?/g,";").replace(/%@%/g,".").replace(/%%@@%%/g,"~").replace(/(?:;)?(\^+)(?:;)?/g,(function(t,r){return";"+r.split("").join(";")+";"})).replace(/;;;|;;/g,";..;").replace(/;$|'?\]|'$/g,"").split(";").map((function(t){var r=t.match(/#([0-9]+)/);return r&&r[1]?e[r[1]]:t}));return r[t]=n,r[t].concat()};var d=function(){function t(e){r(this,t),this.code=e}return n(t,[{key:"runInNewContext",value:function(t){var r=this.code,e=Object.keys(t),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(r){return"function"==typeof t[r]}));var a=e.map((function(r,e){return t[r]})),o=n.reduce((function(r,e){var n=t[e].toString();return/function/.test(n)||(n="function "+n),"var "+e+"="+n+";"+r}),"");/(["'])use strict\1/.test(r=o+r)||e.includes("arguments")||(r="var arguments = undefined;"+r);var u=(r=r.replace(/;[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*$/,"")).lastIndexOf(";"),c=u>-1?r.slice(0,u+1)+" return "+r.slice(u+1):" return "+r;return i(Function,e.concat([c])).apply(void 0,s(a))}}]),t}();F.prototype.vm={Script:d};export{F as JSONPath};
function t(t,r,n){return r=c(r),function(t,r){if(r&&("object"==typeof r||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,e()?Reflect.construct(r,n||[],c(t).constructor):r.apply(t,n))}function r(t,r,n){if(e())return Reflect.construct.apply(null,arguments);var u=[null];u.push.apply(u,r);var a=new(t.bind.apply(t,u));return n&&l(a,n.prototype),a}function e(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(e=function(){return!!t})()}function n(t){var r=function(t,r){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==typeof r?r:String(r)}function u(t){return u="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},u(t)}function a(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}function o(t,r){for(var e=0;e<r.length;e++){var u=r[e];u.enumerable=u.enumerable||!1,u.configurable=!0,"value"in u&&(u.writable=!0),Object.defineProperty(t,n(u.key),u)}}function i(t,r,e){return r&&o(t.prototype,r),e&&o(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function c(t){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},c(t)}function l(t,r){return l=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t},l(t,r)}function p(t){var e="function"==typeof Map?new Map:void 0;return p=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(r){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return r(t,arguments,c(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),l(n,t)},p(t)}function s(t){return function(t){if(Array.isArray(t))return f(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||F(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function F(t,r){if(t){if("string"==typeof t)return f(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?f(t,r):void 0}}function f(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}var h=Object.prototype.hasOwnProperty;function y(t,r){return(t=t.slice()).push(r),t}function D(t,r){return(r=r.slice()).unshift(t),r}var v=function(r){function e(r){var n;return a(this,e),(n=t(this,e,['JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)'])).avoidNew=!0,n.value=r,n.name="NewError",n}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}}),Object.defineProperty(t,"prototype",{writable:!1}),r&&l(t,r)}(e,p(Error)),i(e)}();function b(t,r,e,n,a){if(!(this instanceof b))try{return new b(t,r,e,n,a)}catch(t){if(!t.avoidNew)throw t;return t.value}"string"==typeof t&&(a=n,n=e,e=r,r=t,t=null);var o=t&&"object"===u(t);if(t=t||{},this.json=t.json||e,this.path=t.path||r,this.resultType=t.resultType||"value",this.flatten=t.flatten||!1,this.wrap=!h.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||n||null,this.otherTypeCallback=t.otherTypeCallback||a||function(){throw new TypeError("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==t.autostart){var i={path:o?t.path:r};o?"json"in t&&(i.json=t.json):i.json=e;var c=this.evaluate(i);if(!c||"object"!==u(c))throw new v(c);return c}}b.prototype.evaluate=function(t,r,e,n){var a=this,o=this.parent,i=this.parentProperty,c=this.flatten,l=this.wrap;if(this.currResultType=this.resultType,this.currPreventEval=this.preventEval,this.currSandbox=this.sandbox,e=e||this.callback,this.currOtherTypeCallback=n||this.otherTypeCallback,r=r||this.json,(t=t||this.path)&&"object"===u(t)&&!Array.isArray(t)){if(!t.path&&""!==t.path)throw new TypeError('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');if(!h.call(t,"json"))throw new TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');r=t.json,c=h.call(t,"flatten")?t.flatten:c,this.currResultType=h.call(t,"resultType")?t.resultType:this.currResultType,this.currSandbox=h.call(t,"sandbox")?t.sandbox:this.currSandbox,l=h.call(t,"wrap")?t.wrap:l,this.currPreventEval=h.call(t,"preventEval")?t.preventEval:this.currPreventEval,e=h.call(t,"callback")?t.callback:e,this.currOtherTypeCallback=h.call(t,"otherTypeCallback")?t.otherTypeCallback:this.currOtherTypeCallback,o=h.call(t,"parent")?t.parent:o,i=h.call(t,"parentProperty")?t.parentProperty:i,t=t.path}if(o=o||null,i=i||null,Array.isArray(t)&&(t=b.toPathString(t)),(t||""===t)&&r){var p=b.toPathArray(t);"$"===p[0]&&p.length>1&&p.shift(),this._hasParentSelector=null;var s=this._trace(p,r,["$"],o,i,e).filter((function(t){return t&&!t.isParentSelector}));return s.length?l||1!==s.length||s[0].hasArrExpr?s.reduce((function(t,r){var e=a._getPreferredOutput(r);return c&&Array.isArray(e)?t=t.concat(e):t.push(e),t}),[]):this._getPreferredOutput(s[0]):l?[]:void 0}},b.prototype._getPreferredOutput=function(t){var r=this.currResultType;switch(r){case"all":var e=Array.isArray(t.path)?t.path:b.toPathArray(t.path);return t.pointer=b.toPointer(e),t.path="string"==typeof t.path?t.path:b.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[r];case"path":return b.toPathString(t[r]);case"pointer":return b.toPointer(t.path);default:throw new TypeError("Unknown result type")}},b.prototype._handleCallback=function(t,r,e){if(r){var n=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:b.toPathString(t.path),r(n,e,t)}},b.prototype._trace=function(t,r,e,n,a,o,i,c){var l,p=this;if(!t.length)return l={path:e,value:r,parent:n,parentProperty:a,hasArrExpr:i},this._handleCallback(l,o,"value"),l;var s=t[0],f=t.slice(1),v=[];function b(t){Array.isArray(t)?t.forEach((function(t){v.push(t)})):v.push(t)}if(("string"!=typeof s||c)&&r&&h.call(r,s))b(this._trace(f,r[s],y(e,s),r,s,o,i));else if("*"===s)this._walk(r,(function(t){b(p._trace(f,r[t],y(e,t),r,t,o,!0,!0))}));else if(".."===s)b(this._trace(f,r,e,n,a,o,i)),this._walk(r,(function(n){"object"===u(r[n])&&b(p._trace(t.slice(),r[n],y(e,n),r,n,o,!0))}));else{if("^"===s)return this._hasParentSelector=!0,{path:e.slice(0,-1),expr:f,isParentSelector:!0};if("~"===s)return l={path:y(e,s),value:a,parent:n,parentProperty:null},this._handleCallback(l,o,"property"),l;if("$"===s)b(this._trace(f,r,e,null,null,o,i));else if(/^(\x2D?[0-9]*):(\x2D?[0-9]*):?([0-9]*)$/.test(s))b(this._slice(s,f,r,e,n,a,o));else if(0===s.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");var d=s.replace(/^\?\(((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?)\)$/,"$1"),g=/@(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])?((?:[\0->@-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)['\[](\??\((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\))(?!(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])\)\])['\]]/g.exec(d);g?this._walk(r,(function(t){var u=[g[2]],i=g[1]?r[t][g[1]]:r[t];p._trace(u,i,e,n,a,o,!0).length>0&&b(p._trace(f,r[t],y(e,t),r,t,o,!0))})):this._walk(r,(function(t){p._eval(d,r[t],t,e,n,a)&&b(p._trace(f,r[t],y(e,t),r,t,o,!0))}))}else if("("===s[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");b(this._trace(D(this._eval(s,r,e[e.length-1],e.slice(0,-1),n,a),f),r,e,n,a,o,i))}else if("@"===s[0]){var w=!1,_=s.slice(1,-2);switch(_){case"scalar":r&&["object","function"].includes(u(r))||(w=!0);break;case"boolean":case"string":case"undefined":case"function":u(r)===_&&(w=!0);break;case"integer":!Number.isFinite(r)||r%1||(w=!0);break;case"number":Number.isFinite(r)&&(w=!0);break;case"nonFinite":"number"!=typeof r||Number.isFinite(r)||(w=!0);break;case"object":r&&u(r)===_&&(w=!0);break;case"array":Array.isArray(r)&&(w=!0);break;case"other":w=this.currOtherTypeCallback(r,e,n,a);break;case"null":null===r&&(w=!0);break;default:throw new TypeError("Unknown value type "+_)}if(w)return l={path:e,value:r,parent:n,parentProperty:a},this._handleCallback(l,o,"value"),l}else if("`"===s[0]&&r&&h.call(r,s.slice(1))){var m=s.slice(1);b(this._trace(f,r[m],y(e,m),r,m,o,i,!0))}else if(s.includes(",")){var E,P=function(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=F(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0,u=function(){};return{s:u,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:u}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,i=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return o=t.done,t},e:function(t){i=!0,a=t},f:function(){try{o||null==e.return||e.return()}finally{if(i)throw a}}}}(s.split(","));try{for(P.s();!(E=P.n()).done;){var x=E.value;b(this._trace(D(x,f),r,e,n,a,o,!0))}}catch(t){P.e(t)}finally{P.f()}}else!c&&r&&h.call(r,s)&&b(this._trace(f,r[s],y(e,s),r,s,o,i,!0))}if(this._hasParentSelector)for(var C=0;C<v.length;C++){var S=v[C];if(S&&S.isParentSelector){var j=this._trace(S.expr,r,S.path,n,a,o,i);if(Array.isArray(j)){v[C]=j[0];for(var A=j.length,B=1;B<A;B++)C++,v.splice(C,0,j[B])}else v[C]=j}}return v},b.prototype._walk=function(t,r){if(Array.isArray(t))for(var e=t.length,n=0;n<e;n++)r(n);else t&&"object"===u(t)&&Object.keys(t).forEach((function(t){r(t)}))},b.prototype._slice=function(t,r,e,n,u,a,o){if(Array.isArray(e)){var i=e.length,c=t.split(":"),l=c[2]&&Number.parseInt(c[2])||1,p=c[0]&&Number.parseInt(c[0])||0,s=c[1]&&Number.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){this._trace(D(f,r),e,n,u,a,o,!0).forEach((function(t){F.push(t)}))}return F}},b.prototype._eval=function(t,r,e,n,u,a){this.currSandbox._$_parentProperty=a,this.currSandbox._$_parent=u,this.currSandbox._$_property=e,this.currSandbox._$_root=this.json,this.currSandbox._$_v=r;var o=t.includes("@path");o&&(this.currSandbox._$_path=b.toPathString(n.concat([e])));var i="script:"+t;if(!b.cache[i]){var c=t.replace(/@parentProperty/g,"_$_parentProperty").replace(/@parent/g,"_$_parent").replace(/@property/g,"_$_property").replace(/@root/g,"_$_root").replace(/@([\t-\r \)\.\[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])/g,"_$_v$1");o&&(c=c.replace(/@path/g,"_$_path")),b.cache[i]=new this.vm.Script(c)}try{return b.cache[i].runInNewContext(this.currSandbox)}catch(r){throw new Error("jsonPath: "+r.message+": "+t)}},b.cache={},b.toPathString=function(t){for(var r=t,e=r.length,n="$",u=1;u<e;u++)/^(~|\^|@(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\(\))$/.test(r[u])||(n+=/^[\*0-9]+$/.test(r[u])?"["+r[u]+"]":"['"+r[u]+"']");return n},b.toPointer=function(t){for(var r=t,e=r.length,n="",u=1;u<e;u++)/^(~|\^|@(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\(\))$/.test(r[u])||(n+="/"+r[u].toString().replace(/~/g,"~0").replace(/\//g,"~1"));return n},b.toPathArray=function(t){var r=b.cache;if(r[t])return r[t].concat();var e=[],n=t.replace(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/g,";$&;").replace(/['\[](\??\((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*?\))['\]](?!(?:[\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].concat()};var d=function(){function t(r){a(this,t),this.code=r}return i(t,[{key:"runInNewContext",value:function(t){var e=this.code,n=Object.keys(t),u=[];!function(t,r,e){for(var n=t.length,u=0;u<n;u++)e(t[u])&&r.push(t.splice(u--,1)[0])}(n,u,(function(r){return"function"==typeof t[r]}));var a=n.map((function(r){return t[r]})),o=u.reduce((function(r,e){var n=t[e].toString();return/function/.test(n)||(n="function "+n),"var "+e+"="+n+";"+r}),"");/(["'])use strict\1/.test(e=o+e)||n.includes("arguments")||(e="var arguments = undefined;"+e);var i=(e=e.replace(/;[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*$/,"")).lastIndexOf(";"),c=i>-1?e.slice(0,i+1)+" return "+e.slice(i+1):" return "+e;return r(Function,n.concat([c])).apply(void 0,s(a))}}]),t}();b.prototype.vm={Script:d};export{b as JSONPath};
//# sourceMappingURL=index-browser-esm.min.js.map
import vm from 'vm';
/* eslint-disable camelcase, unicorn/prefer-string-replace-all,
unicorn/prefer-at */
const {
hasOwnProperty: hasOwnProp
} = Object.prototype;
/**

@@ -24,3 +27,2 @@ * @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject

*/
function push(arr, item) {

@@ -37,4 +39,2 @@ arr = arr.slice();

*/
function unshift(item, arr) {

@@ -45,2 +45,3 @@ arr = arr.slice();

}
/**

@@ -50,4 +51,2 @@ * Caught when JSONPath is used without `new` but rethrown if with `new`

*/
class NewError extends Error {

@@ -63,4 +62,4 @@ /**

}
}
}
/**

@@ -91,4 +90,3 @@ * @typedef {PlainObject} ReturnObject

/* eslint-disable max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */
/* eslint-disable @stylistic/max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */
/**

@@ -110,5 +108,4 @@ * @typedef {PlainObject} JSONPathOptions

*/
/* eslint-enable @stylistic/max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */
/* eslint-enable max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */
/**

@@ -129,4 +126,2 @@ * @param {string|JSONPathOptions} opts If a string, will be treated as `expr`

*/
function JSONPath(opts, expr, obj, callback, otherTypeCallback) {

@@ -141,7 +136,5 @@ // eslint-disable-next-line no-restricted-syntax

}
return e.value;
}
}
if (typeof opts === 'string') {

@@ -154,3 +147,2 @@ otherTypeCallback = callback;

}
const optObj = opts && typeof opts === 'object';

@@ -168,7 +160,5 @@ opts = opts || {};

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

@@ -178,3 +168,2 @@ const args = {

};
if (!optObj) {

@@ -185,17 +174,14 @@ args.json = obj;

}
const ret = this.evaluate(args);
if (!ret || typeof ret !== 'object') {
throw new NewError(ret);
}
return ret;
}
} // PUBLIC METHODS
}
// PUBLIC METHODS
JSONPath.prototype.evaluate = function (expr, json, callback, otherTypeCallback) {
let currParent = this.parent,
currParentProperty = this.parentProperty;
currParentProperty = this.parentProperty;
let {

@@ -212,3 +198,2 @@ flatten,

expr = expr || this.path;
if (expr && typeof expr === 'object' && !Array.isArray(expr)) {

@@ -218,7 +203,5 @@ if (!expr.path && expr.path !== '') {

}
if (!hasOwnProp.call(expr, 'json')) {
throw new TypeError('You must supply a "json" property when providing an object ' + 'argument to JSONPath.evaluate().');
}
({

@@ -238,37 +221,26 @@ json

}
currParent = currParent || null;
currParentProperty = currParentProperty || null;
if (Array.isArray(expr)) {
expr = JSONPath.toPathString(expr);
}
if (!expr && expr !== '' || !json) {
return undefined;
}
const exprList = JSONPath.toPathArray(expr);
if (exprList[0] === '$' && exprList.length > 1) {
exprList.shift();
}
this._hasParentSelector = null;
const result = this._trace(exprList, json, ['$'], currParent, currParentProperty, callback).filter(function (ea) {
return ea && !ea.isParentSelector;
});
if (!result.length) {
return wrap ? [] : undefined;
}
if (!wrap && result.length === 1 && !result[0].hasArrExpr) {
return this._getPreferredOutput(result[0]);
}
return result.reduce((rslt, ea) => {
const valOrPath = this._getPreferredOutput(ea);
if (flatten && Array.isArray(valOrPath)) {

@@ -279,11 +251,10 @@ rslt = rslt.concat(valOrPath);

}
return rslt;
}, []);
}; // PRIVATE METHODS
};
// PRIVATE METHODS
JSONPath.prototype._getPreferredOutput = function (ea) {
const resultType = this.currResultType;
switch (resultType) {

@@ -297,3 +268,2 @@ case 'all':

}
case 'value':

@@ -303,9 +273,6 @@ case 'parent':

return ea[resultType];
case 'path':
return JSONPath.toPathString(ea[resultType]);
case 'pointer':
return JSONPath.toPointer(ea.path);
default:

@@ -315,12 +282,11 @@ throw new TypeError('Unknown result type');

};
JSONPath.prototype._handleCallback = function (fullRetObj, callback, type) {
if (callback) {
const preferredOutput = this._getPreferredOutput(fullRetObj);
fullRetObj.path = typeof fullRetObj.path === 'string' ? fullRetObj.path : JSONPath.toPathString(fullRetObj.path); // eslint-disable-next-line n/callback-return
fullRetObj.path = typeof fullRetObj.path === 'string' ? fullRetObj.path : JSONPath.toPathString(fullRetObj.path);
// eslint-disable-next-line n/callback-return
callback(preferredOutput, type, fullRetObj);
}
};
/**

@@ -338,4 +304,2 @@ *

*/
JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, callback, hasArrExpr, literalPriority) {

@@ -345,3 +309,2 @@ // No expr to follow? return path and value as the result of

let retObj;
if (!expr.length) {

@@ -355,12 +318,10 @@ retObj = {

};
this._handleCallback(retObj, callback, 'value');
return retObj;
}
const loc = expr[0],
x = expr.slice(1);
const loc = expr[0],
x = expr.slice(1); // We need to gather the return value of recursive trace calls in order to
// We need to gather the return value of recursive trace calls in order to
// do the parent sel computation.
const ret = [];

@@ -372,3 +333,2 @@ /**

*/
function addRet(elems) {

@@ -386,6 +346,6 @@ if (Array.isArray(elems)) {

}
if ((typeof loc !== 'string' || literalPriority) && val && hasOwnProp.call(val, loc)) {
// simple case--directly follow property
addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr)); // eslint-disable-next-line unicorn/prefer-switch -- Part of larger `if`
addRet(this._trace(x, val[loc], push(path, loc), val, loc, callback, hasArrExpr));
// eslint-disable-next-line unicorn/prefer-switch -- Part of larger `if`
} else if (loc === '*') {

@@ -400,3 +360,2 @@ // all child properties

addRet(this._trace(x, val, path, parent, parentPropName, callback, hasArrExpr));
this._walk(val, m => {

@@ -410,5 +369,5 @@ // We don't join m and x here because we only want parents,

}
}); // The parent sel computation is handled in the frame above using the
});
// The parent sel computation is handled in the frame above using the
// ancestor object of val
} else if (loc === '^') {

@@ -430,5 +389,3 @@ // This is not a final endpoint, so we do not invoke the callback here

};
this._handleCallback(retObj, callback, 'property');
return retObj;

@@ -446,10 +403,23 @@ } else if (loc === '$') {

}
const safeLoc = loc.replace(/^\?\((.*?)\)$/u, '$1');
this._walk(val, m => {
if (this._eval(safeLoc, val[m], m, path, parent, parentPropName)) {
addRet(this._trace(x, val[m], push(path, m), val, m, callback, true));
}
});
// check for a nested filter expression
const nested = /@.?([^?]*)[['](\??\(.*?\))(?!.\)\])[\]']/gu.exec(safeLoc);
if (nested) {
// find if there are matches in the nested expression
// add them to the result set if there is at least one match
this._walk(val, m => {
const npath = [nested[2]];
const nvalue = nested[1] ? val[m][nested[1]] : val[m];
const filterResults = this._trace(npath, nvalue, path, parent, parentPropName, callback, true);
if (filterResults.length > 0) {
addRet(this._trace(x, val[m], push(path, m), val, m, callback, true));
}
});
} else {
this._walk(val, m => {
if (this._eval(safeLoc, val[m], m, path, parent, parentPropName)) {
addRet(this._trace(x, val[m], push(path, m), val, m, callback, true));
}
});
}
} else if (loc[0] === '(') {

@@ -459,7 +429,6 @@ // [(expr)] (dynamic property/index)

throw new Error('Eval [(expr)] prevented in JSONPath expression.');
} // As this will resolve to a property name (but we don't know it
}
// 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), x), val, path, parent, parentPropName, callback, hasArrExpr));

@@ -470,3 +439,2 @@ } else if (loc[0] === '@') {

const valueType = loc.slice(1, -2);
switch (valueType) {

@@ -477,5 +445,3 @@ case 'scalar':

}
break;
case 'boolean':

@@ -485,9 +451,6 @@ case 'string':

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

@@ -497,5 +460,3 @@ if (Number.isFinite(val) && !(val % 1)) {

}
break;
case 'number':

@@ -505,5 +466,3 @@ if (Number.isFinite(val)) {

}
break;
case 'nonFinite':

@@ -513,13 +472,8 @@ if (typeof val === 'number' && !Number.isFinite(val)) {

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

@@ -529,9 +483,6 @@ if (Array.isArray(val)) {

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

@@ -541,11 +492,7 @@ if (val === null) {

}
break;
/* c8 ignore next 2 */
default:
throw new TypeError('Unknown value type ' + valueType);
}
if (addType) {

@@ -558,8 +505,6 @@ retObj = {

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

@@ -571,25 +516,21 @@ const locProp = loc.slice(1);

const parts = loc.split(',');
for (const part of parts) {
addRet(this._trace(unshift(part, x), val, path, parent, parentPropName, callback, true));
} // simple case--directly follow property
}
// 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, hasArrExpr, true));
} // We check the resulting values for parent selections. For parent
}
// We check the resulting values for parent selections. For parent
// selections we discard the value object and continue the trace with the
// current val object
if (this._hasParentSelector) {
for (let t = 0; t < ret.length; t++) {
const rett = ret[t];
if (rett && rett.isParentSelector) {
const tmp = this._trace(rett.expr, val, rett.path, parent, parentPropName, callback, hasArrExpr);
if (Array.isArray(tmp)) {
ret[t] = tmp[0];
const tl = tmp.length;
for (let tt = 1; tt < tl; tt++) {

@@ -605,10 +546,7 @@ t++;

}
return ret;
};
JSONPath.prototype._walk = function (val, f) {
if (Array.isArray(val)) {
const n = val.length;
for (let i = 0; i < n; i++) {

@@ -623,3 +561,2 @@ f(i);

};
JSONPath.prototype._slice = function (loc, expr, val, path, parent, parentPropName, callback) {

@@ -629,14 +566,13 @@ if (!Array.isArray(val)) {

}
const len = val.length,
parts = loc.split(':'),
step = parts[2] && Number.parseInt(parts[2]) || 1;
parts = loc.split(':'),
step = parts[2] && Number.parseInt(parts[2]) || 1;
let start = parts[0] && Number.parseInt(parts[0]) || 0,
end = parts[1] && Number.parseInt(parts[1]) || len;
end = parts[1] && Number.parseInt(parts[1]) || len;
start = start < 0 ? Math.max(0, start + len) : Math.min(len, start);
end = end < 0 ? Math.max(0, end + len) : Math.min(len, end);
const ret = [];
for (let i = start; i < end; i += step) {
const tmp = this._trace(unshift(i, expr), val, path, parent, parentPropName, callback, true); // Should only be possible to be an array here since first part of
const tmp = this._trace(unshift(i, expr), val, path, parent, parentPropName, callback, true);
// Should only be possible to be an array here since first part of
// ``unshift(i, expr)` passed in above would not be empty, nor `~`,

@@ -646,4 +582,2 @@ // nor begin with `@` (as could return objects)

// without Babel) against our performance test: `ret.push(...tmp);`
tmp.forEach(t => {

@@ -653,6 +587,4 @@ ret.push(t);

}
return ret;
};
JSONPath.prototype._eval = function (code, _v, _vname, path, parent, parentPropName) {

@@ -665,19 +597,13 @@ this.currSandbox._$_parentProperty = parentPropName;

const containsPath = code.includes('@path');
if (containsPath) {
this.currSandbox._$_path = JSONPath.toPathString(path.concat([_vname]));
}
const scriptCacheKey = 'script:' + code;
if (!JSONPath.cache[scriptCacheKey]) {
let script = code.replace(/@parentProperty/gu, '_$_parentProperty').replace(/@parent/gu, '_$_parent').replace(/@property/gu, '_$_property').replace(/@root/gu, '_$_root').replace(/@([.\s)[])/gu, '_$_v$1');
if (containsPath) {
script = script.replace(/@path/gu, '_$_path');
}
JSONPath.cache[scriptCacheKey] = new this.vm.Script(script);
}
try {

@@ -688,7 +614,9 @@ return JSONPath.cache[scriptCacheKey].runInNewContext(this.currSandbox);

}
}; // PUBLIC CLASS PROPERTIES AND METHODS
// Could store the cache object itself
};
// PUBLIC CLASS PROPERTIES AND METHODS
// Could store the cache object itself
JSONPath.cache = {};
/**

@@ -698,8 +626,6 @@ * @param {string[]} pathArr Array to convert

*/
JSONPath.toPathString = function (pathArr) {
const x = pathArr,
n = x.length;
n = x.length;
let p = '$';
for (let i = 1; i < n; i++) {

@@ -710,5 +636,5 @@ if (!/^(~|\^|@.*?\(\))$/u.test(x[i])) {

}
return p;
};
/**

@@ -718,9 +644,6 @@ * @param {string} pointer JSON Path

*/
JSONPath.toPointer = function (pointer) {
const x = pointer,
n = x.length;
n = x.length;
let p = '';
for (let i = 1; i < n; i++) {

@@ -731,5 +654,5 @@ if (!/^(~|\^|@.*?\(\))$/u.test(x[i])) {

}
return p;
};
/**

@@ -739,4 +662,2 @@ * @param {string} expr Expression to convert

*/
JSONPath.toPathArray = function (expr) {

@@ -746,25 +667,33 @@ const {

} = JSONPath;
if (cache[expr]) {
return cache[expr].concat();
}
const subx = [];
const normalized = expr // Properties
.replace(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/gu, ';$&;') // Parenthetical evaluations (filtering and otherwise), directly
const normalized = expr
// Properties
.replace(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/gu, ';$&;')
// Parenthetical evaluations (filtering and otherwise), directly
// within brackets or single quotes
.replace(/[['](\??\(.*?\))[\]']/gu, function ($0, $1) {
.replace(/[['](\??\(.*?\))[\]'](?!.\])/gu, function ($0, $1) {
return '[#' + (subx.push($1) - 1) + ']';
}) // Escape periods and tildes within properties
})
// Escape periods and tildes within properties
.replace(/\[['"]([^'\]]*)['"]\]/gu, function ($0, prop) {
return "['" + prop.replace(/\./gu, '%@%').replace(/~/gu, '%%@@%%') + "']";
}) // Properties operator
.replace(/~/gu, ';~;') // Split by property boundaries
.replace(/['"]?\.['"]?(?![^[]*\])|\[['"]?/gu, ';') // Reinsert periods within properties
.replace(/%@%/gu, '.') // Reinsert tildes within properties
.replace(/%%@@%%/gu, '~') // Parent
})
// Properties operator
.replace(/~/gu, ';~;')
// Split by property boundaries
.replace(/['"]?\.['"]?(?![^[]*\])|\[['"]?/gu, ';')
// Reinsert periods within properties
.replace(/%@%/gu, '.')
// Reinsert tildes within properties
.replace(/%%@@%%/gu, '~')
// Parent
.replace(/(?:;)?(\^+)(?:;)?/gu, function ($0, ups) {
return ';' + ups.split('').join(';') + ';';
}) // Descendents
.replace(/;;;|;;/gu, ';..;') // Remove trailing
})
// Descendents
.replace(/;;;|;;/gu, ';..;')
// Remove trailing
.replace(/;$|'?\]|'$/gu, '');

@@ -771,0 +700,0 @@ const exprList = normalized.split(';').map(function (exp) {

{
"author": "Stefan Goessner",
"name": "jsonpath-plus",
"version": "7.2.0",
"version": "8.0.0",
"type": "module",

@@ -56,3 +56,3 @@ "main": "dist/index-node-cjs.cjs",

"engines": {
"node": ">=12.0.0"
"node": ">=14.0.0"
},

@@ -62,41 +62,40 @@ "react-native": {

},
"dependencies": {},
"devDependencies": {
"@babel/core": "^7.18.13",
"@babel/preset-env": "^7.18.10",
"@babel/core": "^7.23.7",
"@babel/preset-env": "^7.23.8",
"@brettz9/eslint-plugin": "^1.0.4",
"@rollup/plugin-babel": "^5.3.1",
"c8": "^7.12.0",
"chai": "^4.3.6",
"core-js-bundle": "^3.25.0",
"coveradge": "^0.8.1",
"eslint": "^8.23.0",
"eslint-config-ash-nazg": "^34.1.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-array-func": "^3.1.7",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-terser": "^0.4.4",
"c8": "^9.1.0",
"chai": "^4.4.1",
"core-js-bundle": "^3.35.0",
"coveradge": "^0.8.2",
"eslint": "^8.56.0",
"eslint-config-ash-nazg": "^35.3.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-array-func": "^4.0.0",
"eslint-plugin-chai-expect": "^3.0.0",
"eslint-plugin-chai-friendly": "^0.7.2",
"eslint-plugin-compat": "^4.0.2",
"eslint-plugin-chai-friendly": "^0.7.4",
"eslint-plugin-compat": "^4.2.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsdoc": "^39.3.6",
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-n": "^15.2.5",
"eslint-plugin-no-unsanitized": "^4.0.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsdoc": "^48.0.2",
"eslint-plugin-markdown": "^3.0.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-no-unsanitized": "^4.0.2",
"eslint-plugin-no-use-extend-native": "^0.5.0",
"eslint-plugin-promise": "^6.0.1",
"eslint-plugin-sonarjs": "^0.15.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-sonarjs": "^0.23.0",
"eslint-plugin-standard": "^4.1.0",
"eslint-plugin-unicorn": "^43.0.2",
"eslint-plugin-unicorn": "^50.0.1",
"http-server": "^14.1.1",
"license-badger": "^0.19.0",
"mocha": "^10.0.0",
"mocha-badge-generator": "^0.9.0",
"license-badger": "^0.21.1",
"mocha": "^10.2.0",
"mocha-badge-generator": "^0.11.0",
"mocha-multi-reporters": "^1.5.1",
"open-cli": "^7.0.1",
"rollup": "2.79.0",
"rollup-plugin-terser": "^7.0.2",
"typedoc": "^0.23.13",
"typescript": "^4.8.2"
"open-cli": "^8.0.0",
"rollup": "4.9.5",
"typedoc": "^0.25.7",
"typescript": "^5.3.3"
},

@@ -103,0 +102,0 @@ "keywords": [

[![npm](https://img.shields.io/npm/v/jsonpath-plus.svg)](https://www.npmjs.com/package/jsonpath-plus)
[![Dependencies](https://img.shields.io/david/s3u/JSONPath.svg)](https://david-dm.org/s3u/JSONPath)
[![devDependencies](https://img.shields.io/david/dev/s3u/JSONPath.svg)](https://david-dm.org/s3u/JSONPath?type=dev)

@@ -9,4 +7,2 @@ [![testing badge](https://raw.githubusercontent.com/s3u/JSONPath/master/badges/tests-badge.svg?sanitize=true)](badges/tests-badge.svg)

[![Known Vulnerabilities](https://snyk.io/test/github/s3u/JSONPath/badge.svg)](https://snyk.io/test/github/s3u/JSONPath)
[![Total Alerts](https://img.shields.io/lgtm/alerts/g/s3u/JSONPath.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/s3u/JSONPath/alerts)
[![Code Quality: Javascript](https://img.shields.io/lgtm/grade/javascript/g/s3u/JSONPath.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/s3u/JSONPath/context:javascript)

@@ -16,5 +12,7 @@ <!--[![License](https://img.shields.io/npm/l/JSONPath.svg)](LICENSE-MIT.txt)-->

[![Node.js CI status](https://github.com/JSONPath-Plus/JSONPath/actions/workflows/node.js.yml/badge.svg)](https://github.com/JSONPath-Plus/JSONPath/actions/workflows/node.js.yml)
<small>(see also [licenses for dev. deps.](https://raw.githubusercontent.com/s3u/JSONPath/master/badges/licenses-badge-dev.svg?sanitize=true))</small>
# JSONPath Plus [![Node.js CI status](https://github.com/git://github.com/s3u/JSONPath.git/workflows/Node.js%20CI/badge.svg)](https://github.com/git://github.com/s3u/JSONPath.git/actions)
# JSONPath Plus

@@ -402,2 +400,2 @@ Analyse, transform, and selectively extract data from JSON

[MIT License](http://www.opensource.org/licenses/mit-license.php).
[MIT License](https://opensource.org/license/mit/).

@@ -58,3 +58,3 @@ import {JSONPath} from './jsonpath.js';

});
const values = keys.map((vr, i) => {
const values = keys.map((vr) => {
return context[vr];

@@ -61,0 +61,0 @@ });

@@ -0,1 +1,3 @@

/* eslint-disable camelcase, unicorn/prefer-string-replace-all,
unicorn/prefer-at */
const {hasOwnProperty: hasOwnProp} = Object.prototype;

@@ -82,3 +84,3 @@

/* eslint-disable max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */
/* eslint-disable @stylistic/max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */
/**

@@ -100,3 +102,3 @@ * @typedef {PlainObject} JSONPathOptions

*/
/* eslint-enable max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */
/* eslint-enable @stylistic/max-len -- Can make multiline type after https://github.com/syavorsky/comment-parser/issues/109 */

@@ -238,3 +240,5 @@ /**

const exprList = JSONPath.toPathArray(expr);
if (exprList[0] === '$' && exprList.length > 1) { exprList.shift(); }
if (exprList[0] === '$' && exprList.length > 1) {
exprList.shift();
}
this._hasParentSelector = null;

@@ -245,5 +249,9 @@ const result = this

)
.filter(function (ea) { return ea && !ea.isParentSelector; });
.filter(function (ea) {
return ea && !ea.isParentSelector;
});
if (!result.length) { return wrap ? [] : undefined; }
if (!result.length) {
return wrap ? [] : undefined;
}
if (!wrap && result.length === 1 && !result[0].hasArrExpr) {

@@ -411,8 +419,28 @@ return this._getPreferredOutput(result[0]);

const safeLoc = loc.replace(/^\?\((.*?)\)$/u, '$1');
this._walk(val, (m) => {
if (this._eval(safeLoc, val[m], m, path, parent, parentPropName)) {
addRet(this._trace(x, val[m], push(path, m), val, m, callback,
true));
}
});
// check for a nested filter expression
const nested = (/@.?([^?]*)[['](\??\(.*?\))(?!.\)\])[\]']/gu).exec(safeLoc);
if (nested) {
// find if there are matches in the nested expression
// add them to the result set if there is at least one match
this._walk(val, (m) => {
const npath = [nested[2]];
const nvalue = nested[1]
? val[m][nested[1]]
: val[m];
const filterResults = this._trace(npath, nvalue, path,
parent, parentPropName, callback, true);
if (filterResults.length > 0) {
addRet(this._trace(x, val[m], push(path, m), val,
m, callback, true));
}
});
} else {
this._walk(val, (m) => {
if (this._eval(safeLoc, val[m], m, path, parent,
parentPropName)) {
addRet(this._trace(x, val[m], push(path, m), val, m,
callback, true));
}
});
}
} else if (loc[0] === '(') { // [(expr)] (dynamic property/index)

@@ -442,3 +470,2 @@ if (this.currPreventEval) {

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

@@ -464,3 +491,2 @@ addType = true;

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

@@ -562,3 +588,5 @@ addType = true;

) {
if (!Array.isArray(val)) { return undefined; }
if (!Array.isArray(val)) {
return undefined;
}
const len = val.length, parts = loc.split(':'),

@@ -666,3 +694,5 @@ step = (parts[2] && Number.parseInt(parts[2])) || 1;

const {cache} = JSONPath;
if (cache[expr]) { return cache[expr].concat(); }
if (cache[expr]) {
return cache[expr].concat();
}
const subx = [];

@@ -677,3 +707,3 @@ const normalized = expr

// within brackets or single quotes
.replace(/[['](\??\(.*?\))[\]']/gu, function ($0, $1) {
.replace(/[['](\??\(.*?\))[\]'](?!.\])/gu, function ($0, $1) {
return '[#' + (subx.push($1) - 1) + ']';

@@ -680,0 +710,0 @@ })

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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