Skip to content

Commit 9873841

Browse files
committed
- Enhancement: jsdoc/typescript type for better clarity and specificty
1 parent a585dc8 commit 9873841

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/jsonpath.d.ts

Lines changed: 13 additions & 9 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?: {}
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-
static cache: any
151+
static cache: {
152+
[key: string]: string[]
153+
}
150154

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

179183
evaluate(
180184
path: JSONPathOptions['path'],

src/jsonpath.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const supportsNodeVM = function () {
1414
const {hasOwnProperty: hasOwnProp} = Object.prototype;
1515

1616
/**
17-
* @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject
17+
* @typedef {null|boolean|number|string|object<string, JSON>|JSON[]} JSON
1818
*/
1919

2020
/**
@@ -141,7 +141,7 @@ class NewError extends Error {
141141
/**
142142
* @typedef {PlainObject} ReturnObject
143143
* @property {string} path
144-
* @property {JSONObject} value
144+
* @property {JSON} value
145145
* @property {PlainObject|GenericArray} parent
146146
* @property {string} parentProperty
147147
*/
@@ -156,7 +156,7 @@ class NewError extends Error {
156156

157157
/**
158158
* @callback OtherTypeCallback
159-
* @param {JSONObject} val
159+
* @param {JSON} val
160160
* @param {string} path
161161
* @param {PlainObject|GenericArray} parent
162162
* @param {string} parentPropName
@@ -379,7 +379,7 @@ JSONPath.prototype._handleCallback = function (fullRetObj, callback, type) {
379379
/**
380380
*
381381
* @param {string} expr
382-
* @param {JSONObject} val
382+
* @param {JSON} val
383383
* @param {string} path
384384
* @param {PlainObject|GenericArray} parent
385385
* @param {string} parentPropName

0 commit comments

Comments
 (0)