Skip to content

Commit dfa3ea0

Browse files
committed
chore: update devDeps and build/doc files
1 parent c859500 commit dfa3ea0

52 files changed

Lines changed: 924 additions & 817 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGES.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGES for jsonpath-plus
22

3+
## 11.3.0
4+
5+
- feat(slice): support negative steps like `[::-1]` (@simonkundrik)
6+
37
## 11.2.2
48

59
- fix: leave @root, @parent, @property, @parentProperty and @path inside literals intact (@youdie006)

‎badges/tests-badge.svg‎

Lines changed: 1 addition & 1 deletion
Loading

‎dist/index-browser-esm.js‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,7 +2132,7 @@ class JSONPathClass {
21322132
} else if (loc === '$') {
21332133
// root only
21342134
addRet(this._trace(x, val, path, null, null, callback, hasArrExpr));
2135-
} else if (/^(-?\d*):(-?\d*):?(\d*)$/v.test(loc)) {
2135+
} else if (/^(-?\d*):(-?\d*):?(-?\d*)$/v.test(loc)) {
21362136
// [start:end:step] Python slice syntax
21372137
const sliceResult = this._slice(loc, x, val, path, parent, parentPropName, callback);
21382138
if (sliceResult) {
@@ -2344,14 +2344,25 @@ class JSONPathClass {
23442344
}
23452345
const len = val.length,
23462346
parts = loc.split(':'),
2347-
step = parts[2] && Number(parts[2]) || 1;
2348-
let start = parts[0] && Number(parts[0]) || 0,
2349-
end = parts[1] ? Number(parts[1]) : len;
2350-
start = start < 0 ? Math.max(0, start + len) : Math.min(len, start);
2351-
end = end < 0 ? Math.max(0, end + len) : Math.min(len, end);
2347+
step = parts[2] ? Number(parts[2]) : 1;
23522348
/** @type {ReturnObject[]} */
23532349
const ret = [];
2354-
for (let i = start; i < end; i += step) {
2350+
// A step of zero selects nothing (RFC 9535 section 2.3.4.2.2)
2351+
if (step === 0) {
2352+
return ret;
2353+
}
2354+
/**
2355+
* @param {number} index
2356+
* @returns {number}
2357+
*/
2358+
const normalize = index => index < 0 ? index + len : index;
2359+
// With a negative step the defaults run backwards: from the last
2360+
// item to (and including) the first
2361+
const start = normalize(parts[0] ? Number(parts[0]) : step > 0 ? 0 : len - 1),
2362+
end = normalize(parts[1] ? Number(parts[1]) : step > 0 ? len : -len - 1);
2363+
// The first and last positions to visit, whichever way we are going
2364+
const [from, to] = step > 0 ? [Math.min(Math.max(start, 0), len), Math.min(Math.max(end, 0), len)] : [Math.min(Math.max(start, -1), len - 1), Math.min(Math.max(end, -1), len - 1)];
2365+
for (let i = from; step > 0 ? i < to : i > to; i += step) {
23552366
const tmp = this._trace(unshift(i, expr), val, path, parent, parentPropName, callback, true);
23562367
// Should only be possible to be an array here since first part of
23572368
// ``unshift(i, expr)` passed in above would not be empty,

‎dist/index-browser-esm.min.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/index-browser-esm.min.js.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/index-browser-umd.cjs‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,7 +2138,7 @@
21382138
} else if (loc === '$') {
21392139
// root only
21402140
addRet(this._trace(x, val, path, null, null, callback, hasArrExpr));
2141-
} else if (/^(-?\d*):(-?\d*):?(\d*)$/v.test(loc)) {
2141+
} else if (/^(-?\d*):(-?\d*):?(-?\d*)$/v.test(loc)) {
21422142
// [start:end:step] Python slice syntax
21432143
const sliceResult = this._slice(loc, x, val, path, parent, parentPropName, callback);
21442144
if (sliceResult) {
@@ -2350,14 +2350,25 @@
23502350
}
23512351
const len = val.length,
23522352
parts = loc.split(':'),
2353-
step = parts[2] && Number(parts[2]) || 1;
2354-
let start = parts[0] && Number(parts[0]) || 0,
2355-
end = parts[1] ? Number(parts[1]) : len;
2356-
start = start < 0 ? Math.max(0, start + len) : Math.min(len, start);
2357-
end = end < 0 ? Math.max(0, end + len) : Math.min(len, end);
2353+
step = parts[2] ? Number(parts[2]) : 1;
23582354
/** @type {ReturnObject[]} */
23592355
const ret = [];
2360-
for (let i = start; i < end; i += step) {
2356+
// A step of zero selects nothing (RFC 9535 section 2.3.4.2.2)
2357+
if (step === 0) {
2358+
return ret;
2359+
}
2360+
/**
2361+
* @param {number} index
2362+
* @returns {number}
2363+
*/
2364+
const normalize = index => index < 0 ? index + len : index;
2365+
// With a negative step the defaults run backwards: from the last
2366+
// item to (and including) the first
2367+
const start = normalize(parts[0] ? Number(parts[0]) : step > 0 ? 0 : len - 1),
2368+
end = normalize(parts[1] ? Number(parts[1]) : step > 0 ? len : -len - 1);
2369+
// The first and last positions to visit, whichever way we are going
2370+
const [from, to] = step > 0 ? [Math.min(Math.max(start, 0), len), Math.min(Math.max(end, 0), len)] : [Math.min(Math.max(start, -1), len - 1), Math.min(Math.max(end, -1), len - 1)];
2371+
for (let i = from; step > 0 ? i < to : i > to; i += step) {
23612372
const tmp = this._trace(unshift(i, expr), val, path, parent, parentPropName, callback, true);
23622373
// Should only be possible to be an array here since first part of
23632374
// ``unshift(i, expr)` passed in above would not be empty,

‎dist/index-browser-umd.min.cjs‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎dist/index-browser-umd.min.cjs.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/index-node-cjs.cjs‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,7 @@ class JSONPathClass {
21362136
} else if (loc === '$') {
21372137
// root only
21382138
addRet(this._trace(x, val, path, null, null, callback, hasArrExpr));
2139-
} else if (/^(-?\d*):(-?\d*):?(\d*)$/v.test(loc)) {
2139+
} else if (/^(-?\d*):(-?\d*):?(-?\d*)$/v.test(loc)) {
21402140
// [start:end:step] Python slice syntax
21412141
const sliceResult = this._slice(loc, x, val, path, parent, parentPropName, callback);
21422142
if (sliceResult) {
@@ -2348,14 +2348,25 @@ class JSONPathClass {
23482348
}
23492349
const len = val.length,
23502350
parts = loc.split(':'),
2351-
step = parts[2] && Number(parts[2]) || 1;
2352-
let start = parts[0] && Number(parts[0]) || 0,
2353-
end = parts[1] ? Number(parts[1]) : len;
2354-
start = start < 0 ? Math.max(0, start + len) : Math.min(len, start);
2355-
end = end < 0 ? Math.max(0, end + len) : Math.min(len, end);
2351+
step = parts[2] ? Number(parts[2]) : 1;
23562352
/** @type {ReturnObject[]} */
23572353
const ret = [];
2358-
for (let i = start; i < end; i += step) {
2354+
// A step of zero selects nothing (RFC 9535 section 2.3.4.2.2)
2355+
if (step === 0) {
2356+
return ret;
2357+
}
2358+
/**
2359+
* @param {number} index
2360+
* @returns {number}
2361+
*/
2362+
const normalize = index => index < 0 ? index + len : index;
2363+
// With a negative step the defaults run backwards: from the last
2364+
// item to (and including) the first
2365+
const start = normalize(parts[0] ? Number(parts[0]) : step > 0 ? 0 : len - 1),
2366+
end = normalize(parts[1] ? Number(parts[1]) : step > 0 ? len : -len - 1);
2367+
// The first and last positions to visit, whichever way we are going
2368+
const [from, to] = step > 0 ? [Math.min(Math.max(start, 0), len), Math.min(Math.max(end, 0), len)] : [Math.min(Math.max(start, -1), len - 1), Math.min(Math.max(end, -1), len - 1)];
2369+
for (let i = from; step > 0 ? i < to : i > to; i += step) {
23592370
const tmp = this._trace(unshift(i, expr), val, path, parent, parentPropName, callback, true);
23602371
// Should only be possible to be an array here since first part of
23612372
// ``unshift(i, expr)` passed in above would not be empty,

‎dist/index-node-esm.js‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,7 @@ class JSONPathClass {
21342134
} else if (loc === '$') {
21352135
// root only
21362136
addRet(this._trace(x, val, path, null, null, callback, hasArrExpr));
2137-
} else if (/^(-?\d*):(-?\d*):?(\d*)$/v.test(loc)) {
2137+
} else if (/^(-?\d*):(-?\d*):?(-?\d*)$/v.test(loc)) {
21382138
// [start:end:step] Python slice syntax
21392139
const sliceResult = this._slice(loc, x, val, path, parent, parentPropName, callback);
21402140
if (sliceResult) {
@@ -2346,14 +2346,25 @@ class JSONPathClass {
23462346
}
23472347
const len = val.length,
23482348
parts = loc.split(':'),
2349-
step = parts[2] && Number(parts[2]) || 1;
2350-
let start = parts[0] && Number(parts[0]) || 0,
2351-
end = parts[1] ? Number(parts[1]) : len;
2352-
start = start < 0 ? Math.max(0, start + len) : Math.min(len, start);
2353-
end = end < 0 ? Math.max(0, end + len) : Math.min(len, end);
2349+
step = parts[2] ? Number(parts[2]) : 1;
23542350
/** @type {ReturnObject[]} */
23552351
const ret = [];
2356-
for (let i = start; i < end; i += step) {
2352+
// A step of zero selects nothing (RFC 9535 section 2.3.4.2.2)
2353+
if (step === 0) {
2354+
return ret;
2355+
}
2356+
/**
2357+
* @param {number} index
2358+
* @returns {number}
2359+
*/
2360+
const normalize = index => index < 0 ? index + len : index;
2361+
// With a negative step the defaults run backwards: from the last
2362+
// item to (and including) the first
2363+
const start = normalize(parts[0] ? Number(parts[0]) : step > 0 ? 0 : len - 1),
2364+
end = normalize(parts[1] ? Number(parts[1]) : step > 0 ? len : -len - 1);
2365+
// The first and last positions to visit, whichever way we are going
2366+
const [from, to] = step > 0 ? [Math.min(Math.max(start, 0), len), Math.min(Math.max(end, 0), len)] : [Math.min(Math.max(start, -1), len - 1), Math.min(Math.max(end, -1), len - 1)];
2367+
for (let i = from; step > 0 ? i < to : i > to; i += step) {
23572368
const tmp = this._trace(unshift(i, expr), val, path, parent, parentPropName, callback, true);
23582369
// Should only be possible to be an array here since first part of
23592370
// ``unshift(i, expr)` passed in above would not be empty,

0 commit comments

Comments
 (0)