Skip to content

Commit b35922b

Browse files
committed
- Build: Add browserslist for Babel builds
- Linting: Conform to ESLint updates (jsdoc) - Testing: Switch from end-of-lifed nodeunit to Mocha - Testing: Add performance test to browser, but bump duration - npm: Update devDeps; add core-js-bundle to peerDependencies - npm: Bump to 0.20.0
1 parent d96e607 commit b35922b

31 files changed

+1092
-2267
lines changed

.eslintrc.json renamed to .eslintrc.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1-
{
1+
module.exports = {
22
"extends": ["ash-nazg/sauron-node"],
3+
"settings": {
4+
"polyfills": [
5+
"Array.isArray",
6+
"console",
7+
"Date.now",
8+
"document.head",
9+
"JSON",
10+
"Object.keys",
11+
"XMLHttpRequest"
12+
]
13+
},
314
"overrides": [
415
{
5-
"files": "src/jsonpath.js",
16+
"files": ["src/jsonpath.js", "test-helpers/node-env.js"],
17+
// Apparent bug with `overrides` necessitating this
618
"globals": {
719
"require": "readonly",
820
"module": "readonly"
@@ -29,28 +41,21 @@
2941
{
3042
"files": ["test/**"],
3143
"globals": {
44+
"assert": "readonly",
45+
"jsonpath": "readonly",
3246
"require": "readonly",
3347
"module": "readonly"
3448
},
3549
"parserOptions": {
3650
"sourceType": "script"
3751
},
52+
"env": {"mocha": true},
3853
"rules": {
3954
"strict": ["error", "global"],
4055
"import/no-commonjs": 0,
4156
"import/unambiguous": 0,
4257
"quotes": 0
4358
}
44-
},
45-
{
46-
"files": ["test-helpers/testLoading.js"],
47-
"env": {"node": false, "browser": true},
48-
"parserOptions": {
49-
"sourceType": "module"
50-
},
51-
"rules": {
52-
"no-shadow": ["error", {"allow": ["require", "module"]}]
53-
}
5459
}
5560
],
5661
"rules": {
@@ -61,4 +66,4 @@
6166
"max-len": 0,
6267
"require-jsdoc": 0
6368
}
64-
}
69+
};

CHANGES.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
# jsonpath-plus changes
1+
# CHANGES for jsonpath-plus
2+
3+
## 0.20.0 (June 4, 2019)
4+
5+
- Build: Add `browserslist` for Babel builds
6+
- Linting: Conform to ESLint updates (jsdoc)
7+
- Testing: Switch from end-of-lifed nodeunit to Mocha
8+
- Testing: Add performance test to browser, but bump duration
9+
- npm: Update devDeps; add core-js-bundle to peerDependencies
10+
- npm: Ignore some unneeded files
11+
- Bump Node version in Travis to avoid erring with object rest
12+
in eslint-plugin-node routine
213

314
## 0.19.0 (May 16, 2019)
415

dist/index-es.js

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,28 @@ function _possibleConstructorReturn(self, call) {
133133
return _assertThisInitialized(self);
134134
}
135135

136-
/* eslint-disable no-eval */
136+
/* eslint-disable no-eval, jsdoc/check-types */
137+
// Todo: Reenable jsdoc/check-types once PR merged: https://github.com/gajus/eslint-plugin-jsdoc/pull/270
137138
var globalEval = eval; // eslint-disable-next-line import/no-commonjs
138139

139140
var supportsNodeVM = typeof module !== 'undefined' && Boolean(module.exports) && !(typeof navigator !== 'undefined' && navigator.product === 'ReactNative');
140141
var allowedResultTypes = ['value', 'path', 'pointer', 'parent', 'parentProperty', 'all'];
141142
var hasOwnProp = Object.prototype.hasOwnProperty;
143+
/**
144+
* @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject
145+
*/
146+
147+
/**
148+
* @callback ConditionCallback
149+
* @param item
150+
* @returns {boolean}
151+
*/
152+
142153
/**
143154
* Copy items out of one array into another.
144155
* @param {Array} source Array with items to copy
145156
* @param {Array} target Array to which to copy
146-
* @param {Function} conditionCb Callback passed the current item; will move
157+
* @param {ConditionCallback} conditionCb Callback passed the current item; will move
147158
* item if evaluates to `true`
148159
* @returns {undefined}
149160
*/
@@ -163,8 +174,8 @@ var moveToAnotherArray = function moveToAnotherArray(source, target, conditionCb
163174
var vm = supportsNodeVM ? require('vm') : {
164175
/**
165176
* @param {string} expr Expression to evaluate
166-
* @param {Object} context Object whose items will be added to evaluation
167-
* @returns {*} Result of evaluated code
177+
* @param {PlainObject} context Object whose items will be added to evaluation
178+
* @returns {Any} Result of evaluated code
168179
*/
169180
runInNewContext: function runInNewContext(expr, context) {
170181
var keys = Object.keys(context);
@@ -192,7 +203,7 @@ var vm = supportsNodeVM ? require('vm') : {
192203
/**
193204
* Copies array and then pushes item into it.
194205
* @param {Array} arr Array to copy and into which to push
195-
* @param {*} item Array item to add (to end)
206+
* @param {Any} item Array item to add (to end)
196207
* @returns {Array} Copy of the original array
197208
*/
198209

@@ -203,7 +214,7 @@ function push(arr, item) {
203214
}
204215
/**
205216
* Copies array and then unshifts item into it.
206-
* @param {*} item Array item to add (to beginning)
217+
* @param {Any} item Array item to add (to beginning)
207218
* @param {Array} arr Array to copy and into which to unshift
208219
* @returns {Array} Copy of the original array
209220
*/
@@ -226,7 +237,7 @@ function (_Error) {
226237
_inherits(NewError, _Error);
227238

228239
/**
229-
* @param {*} value The evaluated scalar value
240+
* @param {Any} value The evaluated scalar value
230241
*/
231242
function NewError(value) {
232243
var _this;
@@ -243,12 +254,35 @@ function (_Error) {
243254
return NewError;
244255
}(_wrapNativeSuper(Error));
245256
/**
246-
* @param {Object} [opts] If present, must be an object
257+
* @typedef {PlainObject} ReturnObject
258+
* @property {string} path
259+
* @property {JSONObject} value
260+
* @property {PlainObject|GenericArray} parent
261+
* @property {string} parentProperty
262+
*/
263+
264+
/**
265+
* @callback JSONPathCallback
266+
* @param {string|PlainObject} preferredOutput
267+
* @param {"value"|"property"} type
268+
* @param {ReturnObject} fullRetObj
269+
*/
270+
271+
/**
272+
* @callback OtherTypeCallback
273+
* @param {JSONObject} val
274+
* @param {string} path
275+
* @param {PlainObject|GenericArray} parent
276+
* @param {string} parentPropName
277+
*/
278+
279+
/**
280+
* @param {PlainObject} [opts] If present, must be an object
247281
* @param {string} expr JSON path to evaluate
248282
* @param {JSON} obj JSON object to evaluate against
249-
* @param {Function} callback Passed 3 arguments: 1) desired payload per `resultType`,
283+
* @param {JSONPathCallback} callback Passed 3 arguments: 1) desired payload per `resultType`,
250284
* 2) `"value"|"property"`, 3) Full returned object with all payloads
251-
* @param {Function} otherTypeCallback If `@other()` is at the end of one's query, this
285+
* @param {OtherTypeCallback} otherTypeCallback If `@other()` is at the end of one's query, this
252286
* will be invoked with the value of the item, its path, its parent, and its parent's
253287
* property name, and it should return a boolean indicating whether the supplied value
254288
* belongs to the "other" type or not (or it may handle transformations and return `false`).
@@ -423,6 +457,18 @@ JSONPath.prototype._handleCallback = function (fullRetObj, callback, type) {
423457
callback(preferredOutput, type, fullRetObj);
424458
}
425459
};
460+
/**
461+
*
462+
* @param {string} expr
463+
* @param {JSONObject} val
464+
* @param {string} path
465+
* @param {PlainObject|GenericArray} parent
466+
* @param {string} parentPropName
467+
* @param {JSONPathCallback} callback
468+
* @param {boolean} literalPriority
469+
* @returns {ReturnObject|ReturnObject[]}
470+
*/
471+
426472

427473
JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, callback, literalPriority) {
428474
// No expr to follow? return path and value as the result of this trace branch
@@ -447,6 +493,11 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c
447493
// do the parent sel computation.
448494

449495
var ret = [];
496+
/**
497+
*
498+
* @param {ReturnObject|ReturnObject[]} elems
499+
* @returns {void}
500+
*/
450501

451502
function addRet(elems) {
452503
if (Array.isArray(elems)) {
@@ -655,7 +706,6 @@ JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, c
655706

656707

657708
if (this._hasParentSelector) {
658-
// eslint-disable-next-line unicorn/no-for-loop
659709
for (var t = 0; t < ret.length; t++) {
660710
var rett = ret[t];
661711

dist/index-es.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-umd.js

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,28 @@
139139
return _assertThisInitialized(self);
140140
}
141141

142-
/* eslint-disable no-eval */
142+
/* eslint-disable no-eval, jsdoc/check-types */
143+
// Todo: Reenable jsdoc/check-types once PR merged: https://github.com/gajus/eslint-plugin-jsdoc/pull/270
143144
var globalEval = eval; // eslint-disable-next-line import/no-commonjs
144145

145146
var supportsNodeVM = typeof module !== 'undefined' && Boolean(module.exports) && !(typeof navigator !== 'undefined' && navigator.product === 'ReactNative');
146147
var allowedResultTypes = ['value', 'path', 'pointer', 'parent', 'parentProperty', 'all'];
147148
var hasOwnProp = Object.prototype.hasOwnProperty;
149+
/**
150+
* @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject
151+
*/
152+
153+
/**
154+
* @callback ConditionCallback
155+
* @param item
156+
* @returns {boolean}
157+
*/
158+
148159
/**
149160
* Copy items out of one array into another.
150161
* @param {Array} source Array with items to copy
151162
* @param {Array} target Array to which to copy
152-
* @param {Function} conditionCb Callback passed the current item; will move
163+
* @param {ConditionCallback} conditionCb Callback passed the current item; will move
153164
* item if evaluates to `true`
154165
* @returns {undefined}
155166
*/
@@ -169,8 +180,8 @@
169180
var vm = supportsNodeVM ? require('vm') : {
170181
/**
171182
* @param {string} expr Expression to evaluate
172-
* @param {Object} context Object whose items will be added to evaluation
173-
* @returns {*} Result of evaluated code
183+
* @param {PlainObject} context Object whose items will be added to evaluation
184+
* @returns {Any} Result of evaluated code
174185
*/
175186
runInNewContext: function runInNewContext(expr, context) {
176187
var keys = Object.keys(context);
@@ -198,7 +209,7 @@
198209
/**
199210
* Copies array and then pushes item into it.
200211
* @param {Array} arr Array to copy and into which to push
201-
* @param {*} item Array item to add (to end)
212+
* @param {Any} item Array item to add (to end)
202213
* @returns {Array} Copy of the original array
203214
*/
204215

@@ -209,7 +220,7 @@
209220
}
210221
/**
211222
* Copies array and then unshifts item into it.
212-
* @param {*} item Array item to add (to beginning)
223+
* @param {Any} item Array item to add (to beginning)
213224
* @param {Array} arr Array to copy and into which to unshift
214225
* @returns {Array} Copy of the original array
215226
*/
@@ -232,7 +243,7 @@
232243
_inherits(NewError, _Error);
233244

234245
/**
235-
* @param {*} value The evaluated scalar value
246+
* @param {Any} value The evaluated scalar value
236247
*/
237248
function NewError(value) {
238249
var _this;
@@ -249,12 +260,35 @@
249260
return NewError;
250261
}(_wrapNativeSuper(Error));
251262
/**
252-
* @param {Object} [opts] If present, must be an object
263+
* @typedef {PlainObject} ReturnObject
264+
* @property {string} path
265+
* @property {JSONObject} value
266+
* @property {PlainObject|GenericArray} parent
267+
* @property {string} parentProperty
268+
*/
269+
270+
/**
271+
* @callback JSONPathCallback
272+
* @param {string|PlainObject} preferredOutput
273+
* @param {"value"|"property"} type
274+
* @param {ReturnObject} fullRetObj
275+
*/
276+
277+
/**
278+
* @callback OtherTypeCallback
279+
* @param {JSONObject} val
280+
* @param {string} path
281+
* @param {PlainObject|GenericArray} parent
282+
* @param {string} parentPropName
283+
*/
284+
285+
/**
286+
* @param {PlainObject} [opts] If present, must be an object
253287
* @param {string} expr JSON path to evaluate
254288
* @param {JSON} obj JSON object to evaluate against
255-
* @param {Function} callback Passed 3 arguments: 1) desired payload per `resultType`,
289+
* @param {JSONPathCallback} callback Passed 3 arguments: 1) desired payload per `resultType`,
256290
* 2) `"value"|"property"`, 3) Full returned object with all payloads
257-
* @param {Function} otherTypeCallback If `@other()` is at the end of one's query, this
291+
* @param {OtherTypeCallback} otherTypeCallback If `@other()` is at the end of one's query, this
258292
* will be invoked with the value of the item, its path, its parent, and its parent's
259293
* property name, and it should return a boolean indicating whether the supplied value
260294
* belongs to the "other" type or not (or it may handle transformations and return `false`).
@@ -429,6 +463,18 @@
429463
callback(preferredOutput, type, fullRetObj);
430464
}
431465
};
466+
/**
467+
*
468+
* @param {string} expr
469+
* @param {JSONObject} val
470+
* @param {string} path
471+
* @param {PlainObject|GenericArray} parent
472+
* @param {string} parentPropName
473+
* @param {JSONPathCallback} callback
474+
* @param {boolean} literalPriority
475+
* @returns {ReturnObject|ReturnObject[]}
476+
*/
477+
432478

433479
JSONPath.prototype._trace = function (expr, val, path, parent, parentPropName, callback, literalPriority) {
434480
// No expr to follow? return path and value as the result of this trace branch
@@ -453,6 +499,11 @@
453499
// do the parent sel computation.
454500

455501
var ret = [];
502+
/**
503+
*
504+
* @param {ReturnObject|ReturnObject[]} elems
505+
* @returns {void}
506+
*/
456507

457508
function addRet(elems) {
458509
if (Array.isArray(elems)) {
@@ -661,7 +712,6 @@
661712

662713

663714
if (this._hasParentSelector) {
664-
// eslint-disable-next-line unicorn/no-for-loop
665715
for (var t = 0; t < ret.length; t++) {
666716
var rett = ret[t];
667717

dist/index-umd.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.

0 commit comments

Comments
 (0)