Skip to content

Commit 0f8ff1a

Browse files
committed
- Enhancement: jsdoc/typescript type for better clarity and specificty
1 parent 8a9f1b2 commit 0f8ff1a

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

src/jsonpath.d.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@
33
*/
44
declare module 'jsonpath-plus' {
55
type JSONPathCallback = (
6-
payload: any, payloadType: any, fullPayload: any
7-
) => any
6+
payload: any, payloadType: "value"|"property", fullPayload: any
7+
) => void
88

9-
type JSONPathOtherTypeCallback = (...args: any[]) => void
9+
type JSONPathOtherTypeCallback = (...args: any[]) => boolean
10+
11+
type JSON = null|boolean|number|string|{[key: string]: JSON}|JSON[]
1012

1113
interface JSONPathOptions {
1214
/**
1315
* The JSONPath expression as a (normalized or unnormalized) string or
1416
* array.
1517
*/
16-
path: string | any[]
18+
path?: string | string[]
1719
/**
1820
* The JSON object to evaluate (whether of null, boolean, number,
1921
* string, object, or array type).
2022
*/
21-
json: null | boolean | number | string | object | any[]
23+
json?: JSON|any
2224
/**
2325
* If this is supplied as false, one may call the evaluate method
2426
* manually.
@@ -54,7 +56,7 @@ declare module 'jsonpath-plus' {
5456
* (Note that the current path and value will also be available to those
5557
* expressions; see the Syntax section for details.)
5658
*/
57-
sandbox?: Map<string, any>
59+
sandbox?: { [k: string]: any }
5860
/**
5961
* Whether or not to wrap the results in an array.
6062
*
@@ -95,7 +97,7 @@ declare module 'jsonpath-plus' {
9597
*
9698
* @default null
9799
*/
98-
parentProperty?: null | any
100+
parentProperty?: null | string
99101
/**
100102
* If supplied, a callback will be called immediately upon retrieval of
101103
* an end point value.
@@ -146,7 +148,9 @@ declare module 'jsonpath-plus' {
146148
* Exposes the cache object for those who wish to preserve and reuse
147149
* it for optimization purposes.
148150
*/
149-
cache: any
151+
cache: {
152+
[key: string]: string[]
153+
}
150154

151155
/**
152156
* Accepts a normalized or unnormalized path as string and
@@ -174,20 +178,15 @@ declare module 'jsonpath-plus' {
174178
* The JSONPath terminal constructions `~` and `^` and type operators
175179
* like `@string()` are silently stripped.
176180
*/
177-
toPointer(path: string[]): any
181+
toPointer(path: string[]): string
178182

179183
evaluate(
180184
path: JSONPathOptions['path'],
181185
json: JSONPathOptions['json'],
182186
callback: JSONPathOptions['callback'],
183187
otherTypeCallback: JSONPathOptions['otherTypeCallback']
184188
): any
185-
evaluate(options: {
186-
path: JSONPathOptions['path'],
187-
json: JSONPathOptions['json'],
188-
callback: JSONPathOptions['callback'],
189-
otherTypeCallback: JSONPathOptions['otherTypeCallback']
190-
}): any
189+
evaluate(options?: JSONPathOptions): any
191190
}
192191

193192
type JSONPathType = JSONPathCallable & JSONPathClass

src/jsonpath.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const {hasOwnProperty: hasOwnProp} = Object.prototype;
22

33
/**
4-
* @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject
4+
* @typedef {null|boolean|number|string|object<string, JSON>|JSON[]} JSON
55
*/
66

77
/**
@@ -49,7 +49,7 @@ class NewError extends Error {
4949
/**
5050
* @typedef {PlainObject} ReturnObject
5151
* @property {string} path
52-
* @property {JSONObject} value
52+
* @property {JSON} value
5353
* @property {PlainObject|GenericArray} parent
5454
* @property {string} parentProperty
5555
*/
@@ -64,7 +64,7 @@ class NewError extends Error {
6464

6565
/**
6666
* @callback OtherTypeCallback
67-
* @param {JSONObject} val
67+
* @param {JSON} val
6868
* @param {string} path
6969
* @param {PlainObject|GenericArray} parent
7070
* @param {string} parentPropName
@@ -287,7 +287,7 @@ JSONPath.prototype._handleCallback = function (fullRetObj, callback, type) {
287287
/**
288288
*
289289
* @param {string} expr
290-
* @param {JSONObject} val
290+
* @param {JSON} val
291291
* @param {string} path
292292
* @param {PlainObject|GenericArray} parent
293293
* @param {string} parentPropName

0 commit comments

Comments
 (0)