@prantlf/jsonlint 11.7.0 → 11.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +511 -0
- package/package.json +3 -2
- package/lib/jsonlint.d.ts +0 -119
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
declare module '@prantlf/jsonlint' {
|
|
2
|
+
/**
|
|
3
|
+
* JSON parsing modes, which are a shortcut for setting multiple parsing options.
|
|
4
|
+
*/
|
|
5
|
+
type ParseMode = 'json' | 'cjson' | 'json5'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Can transform the value, which was parsed for a particular object key from the JSON input.
|
|
9
|
+
*
|
|
10
|
+
* See the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#the_reviver_parameter).
|
|
11
|
+
*
|
|
12
|
+
* @param key - a property name
|
|
13
|
+
* @param vaslue - a property value
|
|
14
|
+
* @returns the value to be set in the parsed JSON object
|
|
15
|
+
*/
|
|
16
|
+
type Reviver = (key: string, value: unknown) => unknown
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Options to customize JSON input parsing.
|
|
20
|
+
*/
|
|
21
|
+
interface ParseOptions {
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Ignore the leading BOM in the JSON input, if it is detected.
|
|
25
|
+
*
|
|
26
|
+
* The default is `false`, which will cause the parser to fail, when a BOM is encountered.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
ignoreBOM?: boolean
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Ignore comments in the JSON input (CJSON, JSON5).
|
|
33
|
+
*
|
|
34
|
+
* The default is `false`, which will cause the parser to fail, when a comment is encountered.
|
|
35
|
+
*/
|
|
36
|
+
ignoreComments?: boolean
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Ignore trailing commas after the last item in objects and arrays in the JSON input (JSON5).
|
|
40
|
+
*
|
|
41
|
+
* The default is `false`, which will cause the parser to fail, when a trailing comma is encountered.
|
|
42
|
+
*/
|
|
43
|
+
ignoreTrailingCommas?: boolean
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Allow quotes around strings to be single quotes (JSON5).
|
|
47
|
+
*
|
|
48
|
+
* The default is `false`, which will cause the parser to fail, when a single quote around a string is encountered.
|
|
49
|
+
*/
|
|
50
|
+
allowSingleQuotedStrings?: boolean
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Allow or disallow duplicated keys in objects.
|
|
54
|
+
*
|
|
55
|
+
* The default is `true`, which will allow duplicate keys to occur and return only the last occurrence in the parsed output.
|
|
56
|
+
*/
|
|
57
|
+
allowDuplicateObjectKeys?: boolean
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Set the JSON parsing mode as a shortcut for setting multiple parsing options.
|
|
61
|
+
*
|
|
62
|
+
* Available values: `'json' | 'cjson' | 'json5'`
|
|
63
|
+
*/
|
|
64
|
+
mode?: ParseMode
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Transform the value, which was parsed for a particular object key from the JSON input.
|
|
68
|
+
*
|
|
69
|
+
* See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#the_reviver_parameter.
|
|
70
|
+
*/
|
|
71
|
+
reviver?: Reviver
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Parses a string formatted as JSON to a JSON output (primitive type, object
|
|
76
|
+
* or array). It is compatible with the native `JSON.parse` method.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* import { parse } from '@prantlf/jsonlint'
|
|
81
|
+
* const parsed = parse('string with JSON data')
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @param input - a string input to parse
|
|
85
|
+
* @param reviverOrOptions - either a value reviver or an object
|
|
86
|
+
* with multiple options
|
|
87
|
+
* @returns the parsed result - a primitive value, array or object
|
|
88
|
+
*/
|
|
89
|
+
function parse (input: string, reviverOrOptions?: Reviver | ParseOptions): Record<string, unknown>
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Options to customize JSON input tokenization.
|
|
93
|
+
*/
|
|
94
|
+
interface TokenizeOptions {
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Ignore the leading BOM in the JSON input, if it is detected.
|
|
98
|
+
*
|
|
99
|
+
* The default is `false`, which will cause the parser to fail, when a BOM is encountered.
|
|
100
|
+
*/
|
|
101
|
+
ignoreBOM?: boolean
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Ignore comments in the JSON input (CJSON, JSON5).
|
|
105
|
+
*
|
|
106
|
+
* The default is `false`, which will cause the parser to fail, when a comment is encountered.
|
|
107
|
+
*/
|
|
108
|
+
ignoreComments?: boolean
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Ignore trailing commas after the last item in objects and arrays in the JSON input (JSON5).
|
|
112
|
+
*
|
|
113
|
+
* The default is `false`, which will cause the parser to fail, when a trailing comma is encountered.
|
|
114
|
+
*/
|
|
115
|
+
ignoreTrailingCommas?: boolean
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Allow quotes around strings to be single quotes (JSON5).
|
|
119
|
+
*
|
|
120
|
+
* The default is `false`, which will cause the parser to fail, when a single quote around a string is encountered.
|
|
121
|
+
*/
|
|
122
|
+
allowSingleQuotedStrings?: boolean
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Allow or disallow duplicated keys in objects.
|
|
126
|
+
*
|
|
127
|
+
* The default is `true`, which will allow duplicate keys to occur and return only the last occurrence in the parsed output.
|
|
128
|
+
*/
|
|
129
|
+
allowDuplicateObjectKeys?: boolean
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Set the JSON parsing mode as a shortcut for setting multiple parsing options.
|
|
133
|
+
*
|
|
134
|
+
* Available values: `'json' | 'cjson' | 'json5'`
|
|
135
|
+
*/
|
|
136
|
+
mode?: ParseMode
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Transform the value, which was parsed for a particular object key from the JSON input.
|
|
140
|
+
*
|
|
141
|
+
* See the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#the_reviver_parameter).
|
|
142
|
+
*/
|
|
143
|
+
reviver?: Reviver
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Adds a `raw` property with the original string from the JSON input.
|
|
147
|
+
*/
|
|
148
|
+
rawTokens?: boolean
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Adds a `location` property with start, end and length of the original string from the JSON input.
|
|
152
|
+
*/
|
|
153
|
+
tokenLocations?: boolean
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Adds a `path` property with an array of keys and array indexes "on the way to" the token's value.
|
|
157
|
+
*/
|
|
158
|
+
tokenPaths?: boolean
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Parses a string formatted as JSON to an array of JSON tokens.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* import { tokenize } from '@prantlf/jsonlint'
|
|
167
|
+
* const tokens = tokenize('string with JSON data')
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* @param input - a string input to parse
|
|
171
|
+
* @param reviverOrOptions - either a value reviver or an object
|
|
172
|
+
* with multiple options
|
|
173
|
+
* @returns an array with the tokens
|
|
174
|
+
*/
|
|
175
|
+
function tokenize (input: string, reviverOrOptions?: Reviver | TokenizeOptions): Record<string, unknown>
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
declare module '@prantlf/jsonlint/lib/jsonlint' {
|
|
179
|
+
/**
|
|
180
|
+
* JSON parsing modes, which are a shortcut for setting multiple parsing options.
|
|
181
|
+
*/
|
|
182
|
+
type ParseMode = 'json' | 'cjson' | 'json5'
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Can transform the value, which was parsed for a particular object key from the JSON input.
|
|
186
|
+
*
|
|
187
|
+
* See the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#the_reviver_parameter).
|
|
188
|
+
*
|
|
189
|
+
* @param key - a property name
|
|
190
|
+
* @param vaslue - a property value
|
|
191
|
+
* @returns the value to be set in the parsed JSON object
|
|
192
|
+
*/
|
|
193
|
+
type Reviver = (key: string, value: unknown) => unknown
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Options to customize JSON input parsing.
|
|
197
|
+
*/
|
|
198
|
+
interface ParseOptions {
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Ignore the leading BOM in the JSON input, if it is detected.
|
|
202
|
+
*
|
|
203
|
+
* The default is `false`, which will cause the parser to fail, when a BOM is encountered.
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
ignoreBOM?: boolean
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Ignore comments in the JSON input (CJSON, JSON5).
|
|
210
|
+
*
|
|
211
|
+
* The default is `false`, which will cause the parser to fail, when a comment is encountered.
|
|
212
|
+
*/
|
|
213
|
+
ignoreComments?: boolean
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Ignore trailing commas after the last item in objects and arrays in the JSON input (JSON5).
|
|
217
|
+
*
|
|
218
|
+
* The default is `false`, which will cause the parser to fail, when a trailing comma is encountered.
|
|
219
|
+
*/
|
|
220
|
+
ignoreTrailingCommas?: boolean
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Allow quotes around strings to be single quotes (JSON5).
|
|
224
|
+
*
|
|
225
|
+
* The default is `false`, which will cause the parser to fail, when a single quote around a string is encountered.
|
|
226
|
+
*/
|
|
227
|
+
allowSingleQuotedStrings?: boolean
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Allow or disallow duplicated keys in objects.
|
|
231
|
+
*
|
|
232
|
+
* The default is `true`, which will allow duplicate keys to occur and return only the last occurrence in the parsed output.
|
|
233
|
+
*/
|
|
234
|
+
allowDuplicateObjectKeys?: boolean
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Set the JSON parsing mode as a shortcut for setting multiple parsing options.
|
|
238
|
+
*
|
|
239
|
+
* Available values: `'json' | 'cjson' | 'json5'`
|
|
240
|
+
*/
|
|
241
|
+
mode?: ParseMode
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Transform the value, which was parsed for a particular object key from the JSON input.
|
|
245
|
+
*
|
|
246
|
+
* See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#the_reviver_parameter.
|
|
247
|
+
*/
|
|
248
|
+
reviver?: Reviver
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Parses a string formatted as JSON to a JSON output (primitive type, object
|
|
253
|
+
* or array). It is compatible with the native `JSON.parse` method.
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```ts
|
|
257
|
+
* import { parse } from '@prantlf/jsonlint'
|
|
258
|
+
* const parsed = parse('string with JSON data')
|
|
259
|
+
* ```
|
|
260
|
+
*
|
|
261
|
+
* @param input - a string input to parse
|
|
262
|
+
* @param reviverOrOptions - either a value reviver or an object
|
|
263
|
+
* with multiple options
|
|
264
|
+
* @returns the parsed result - a primitive value, array or object
|
|
265
|
+
*/
|
|
266
|
+
function parse (input: string, reviverOrOptions?: Reviver | ParseOptions): Record<string, unknown>
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Options to customize JSON input tokenization.
|
|
270
|
+
*/
|
|
271
|
+
interface TokenizeOptions {
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Ignore the leading BOM in the JSON input, if it is detected.
|
|
275
|
+
*
|
|
276
|
+
* The default is `false`, which will cause the parser to fail, when a BOM is encountered.
|
|
277
|
+
*/
|
|
278
|
+
ignoreBOM?: boolean
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Ignore comments in the JSON input (CJSON, JSON5).
|
|
282
|
+
*
|
|
283
|
+
* The default is `false`, which will cause the parser to fail, when a comment is encountered.
|
|
284
|
+
*/
|
|
285
|
+
ignoreComments?: boolean
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Ignore trailing commas after the last item in objects and arrays in the JSON input (JSON5).
|
|
289
|
+
*
|
|
290
|
+
* The default is `false`, which will cause the parser to fail, when a trailing comma is encountered.
|
|
291
|
+
*/
|
|
292
|
+
ignoreTrailingCommas?: boolean
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Allow quotes around strings to be single quotes (JSON5).
|
|
296
|
+
*
|
|
297
|
+
* The default is `false`, which will cause the parser to fail, when a single quote around a string is encountered.
|
|
298
|
+
*/
|
|
299
|
+
allowSingleQuotedStrings?: boolean
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Allow or disallow duplicated keys in objects.
|
|
303
|
+
*
|
|
304
|
+
* The default is `true`, which will allow duplicate keys to occur and return only the last occurrence in the parsed output.
|
|
305
|
+
*/
|
|
306
|
+
allowDuplicateObjectKeys?: boolean
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Set the JSON parsing mode as a shortcut for setting multiple parsing options.
|
|
310
|
+
*
|
|
311
|
+
* Available values: `'json' | 'cjson' | 'json5'`
|
|
312
|
+
*/
|
|
313
|
+
mode?: ParseMode
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Transform the value, which was parsed for a particular object key from the JSON input.
|
|
317
|
+
*
|
|
318
|
+
* See the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#the_reviver_parameter).
|
|
319
|
+
*/
|
|
320
|
+
reviver?: Reviver
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Adds a `raw` property with the original string from the JSON input.
|
|
324
|
+
*/
|
|
325
|
+
rawTokens?: boolean
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Adds a `location` property with start, end and length of the original string from the JSON input.
|
|
329
|
+
*/
|
|
330
|
+
tokenLocations?: boolean
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Adds a `path` property with an array of keys and array indexes "on the way to" the token's value.
|
|
334
|
+
*/
|
|
335
|
+
tokenPaths?: boolean
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Parses a string formatted as JSON to an array of JSON tokens.
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```ts
|
|
343
|
+
* import { tokenize } from '@prantlf/jsonlint'
|
|
344
|
+
* const tokens = tokenize('string with JSON data')
|
|
345
|
+
* ```
|
|
346
|
+
*
|
|
347
|
+
* @param input - a string input to parse
|
|
348
|
+
* @param reviverOrOptions - either a value reviver or an object
|
|
349
|
+
* with multiple options
|
|
350
|
+
* @returns an array with the tokens
|
|
351
|
+
*/
|
|
352
|
+
function tokenize (input: string, reviverOrOptions?: Reviver | TokenizeOptions): Record<string, unknown>
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
declare module '@prantlf/jsonlint/lib/validator' {
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* JSON parsing modes, which are a shortcut for setting multiple parsing options.
|
|
359
|
+
*/
|
|
360
|
+
type ParseMode = 'json' | 'cjson' | 'json5'
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Identifiers of supported JSON Schema drafts and JSON Type Definition.
|
|
364
|
+
*/
|
|
365
|
+
type Environment = 'json-schema-draft-04' | 'json-schema-draft-06' | 'json-schema-draft-07'
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Options to customize a JSON Schema validator.
|
|
369
|
+
*/
|
|
370
|
+
interface CompileOptions {
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Ignore the leading BOM in the JSON input, if it is detected.
|
|
374
|
+
*
|
|
375
|
+
* The default is `false`, which will cause the parser to fail, when a BOM is encountered.
|
|
376
|
+
*/
|
|
377
|
+
ignoreBOM?: boolean
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Ignore comments in the JSON input (CJSON, JSON5).
|
|
381
|
+
*
|
|
382
|
+
* The default is `false`, which will cause the parser to fail, when a comment is encountered.
|
|
383
|
+
*/
|
|
384
|
+
ignoreComments?: boolean
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Ignore trailing commas after the last item in objects and arrays in the JSON input (JSON5).
|
|
388
|
+
*
|
|
389
|
+
* The default is `false`, which will cause the parser to fail, when a trailing comma is encountered.
|
|
390
|
+
*/
|
|
391
|
+
ignoreTrailingCommas?: boolean
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Allow quotes around strings to be single quotes (JSON5).
|
|
395
|
+
*
|
|
396
|
+
* The default is `false`, which will cause the parser to fail, when a single quote around a string is encountered.
|
|
397
|
+
*/
|
|
398
|
+
allowSingleQuotedStrings?: boolean
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Allow or disallow duplicated keys in objects.
|
|
402
|
+
*
|
|
403
|
+
* The default is `true`, which will allow duplicate keys to occur and return only the last occurrence in the parsed output.
|
|
404
|
+
*/
|
|
405
|
+
allowDuplicateObjectKeys?: boolean
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Set the JSON parsing mode as a shortcut for setting multiple parsing options.
|
|
409
|
+
*
|
|
410
|
+
* Available values: `'json' | 'cjson' | 'json5'`
|
|
411
|
+
*/
|
|
412
|
+
mode?: ParseMode
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Choose the JSON Schema draft or JSON Type Definition.
|
|
416
|
+
*
|
|
417
|
+
* Available values: `'json-schema-draft-04' | 'json-schema-draft-06' | 'json-schema-draft-07'`
|
|
418
|
+
*/
|
|
419
|
+
environment?: Environment
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* validates JSON input.
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```ts
|
|
427
|
+
* import { compile } from '@prantlf/jsonlint/lib/validator'
|
|
428
|
+
* const validate = compile('string with JSON Schema')
|
|
429
|
+
* const parsed = validate('string with JSON data')
|
|
430
|
+
* ```
|
|
431
|
+
*
|
|
432
|
+
* @param input - a string with the JSON input or a JSON object
|
|
433
|
+
* @returns the valid input as JSON object
|
|
434
|
+
*/
|
|
435
|
+
type Validator = (input: string | Record<string, unknown>) => Record<string, unknown>
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Generates a JSON Schema validator.
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
* ```ts
|
|
442
|
+
* import { compile } from '@prantlf/jsonlint/lib/validator'
|
|
443
|
+
* const validate = compile('string with JSON Schema')
|
|
444
|
+
* const parsed = validate('string with JSON data')
|
|
445
|
+
* ```
|
|
446
|
+
*
|
|
447
|
+
* @param schema - a string with the JSON Schema to validate with
|
|
448
|
+
* @param environmentOrOptions - either a string with the version
|
|
449
|
+
* of the JSON Schema standard or an object
|
|
450
|
+
* with multiple options
|
|
451
|
+
* @returns the validator function
|
|
452
|
+
*/
|
|
453
|
+
function compile (schema: string, environmentOrOptions?: Environment | CompileOptions): Validator
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
declare module '@prantlf/jsonlint/lib/printer' {
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Options to customize printing of JSON tokens to a string.
|
|
460
|
+
*/
|
|
461
|
+
interface PrintOptions {
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Number of spaces to indent objects and arrays with,
|
|
465
|
+
* or a string with the specific whitespace.
|
|
466
|
+
*/
|
|
467
|
+
indent?: number | string
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Omit the comments from the output.
|
|
471
|
+
*/
|
|
472
|
+
pruneComments?: boolean
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Omit quotes around object keys.
|
|
476
|
+
*/
|
|
477
|
+
stripObjectKeys?: boolean
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Enforce all quotes around strings be double quotes.
|
|
481
|
+
*/
|
|
482
|
+
enforceDoubleQuotes?: boolean
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Enforce all quotes around strings be single quotes.
|
|
486
|
+
*/
|
|
487
|
+
enforceSingleQuotes?: boolean
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Remove trailing commas after the last item in objects and arrays.
|
|
491
|
+
*/
|
|
492
|
+
trimTrailingCommas?: boolean
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Pretty-prints an array of JSON tokens parsed from a valid JSON string by `tokenize`.
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
* ```ts
|
|
500
|
+
* import { tokenize } from '@prantlf/jsonlint'
|
|
501
|
+
* import { print } from '@prantlf/jsonlint/lib/printer'
|
|
502
|
+
* const tokens = tokenize('string with JSON data', { rawTokens: true })
|
|
503
|
+
* const outputString = print(tokens, { indent: 2 })
|
|
504
|
+
* ```
|
|
505
|
+
*
|
|
506
|
+
* @param tokens - an array of JSON tokens
|
|
507
|
+
* @param options - an object with multiple options
|
|
508
|
+
* @returns the output string
|
|
509
|
+
*/
|
|
510
|
+
function print (tokens: Array<Record<string, unknown>>, options?: PrintOptions): string
|
|
511
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prantlf/jsonlint",
|
|
3
|
-
"version": "11.7.
|
|
3
|
+
"version": "11.7.2",
|
|
4
4
|
"description": "JSON/CJSON/JSON5 parser, syntax and schema validator and pretty-printer.",
|
|
5
5
|
"author": "Ferdinand Prantl <prantlf@gmail.com> (http://prantl.tk)",
|
|
6
6
|
"contributors": [
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
},
|
|
27
27
|
"preferGlobal": true,
|
|
28
28
|
"main": "lib/jsonlint.js",
|
|
29
|
-
"typings": "lib/
|
|
29
|
+
"typings": "lib/index.d.ts",
|
|
30
|
+
"types": "lib/index.d.ts",
|
|
30
31
|
"bin": {
|
|
31
32
|
"jsonlint": "lib/cli.js"
|
|
32
33
|
},
|
package/lib/jsonlint.d.ts
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
type ParseMode = 'json' | 'cjson' | 'json5'
|
|
2
|
-
|
|
3
|
-
interface ParseOptions {
|
|
4
|
-
ignoreBOM?: boolean
|
|
5
|
-
ignoreComments?: boolean
|
|
6
|
-
ignoreTrailingCommas?: boolean
|
|
7
|
-
allowSingleQuotedStrings?: boolean
|
|
8
|
-
allowDuplicateObjectKeys?: boolean
|
|
9
|
-
mode?: ParseMode
|
|
10
|
-
reviver?: Function
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Parses a string formatted as JSON to a JSON output (primitive type, object
|
|
15
|
-
* or array). It is compatible with the native `JSON.parse` method.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* import { parse } from '@prantlf/jsonlint'
|
|
20
|
-
* const parsed = parse('string with JSON data')
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @param input - a string input to parse
|
|
24
|
-
* @param reviverOrOptions - either a value reviver or an object
|
|
25
|
-
* with multiple options
|
|
26
|
-
* @returns the parsed result - a primitive value, array or object
|
|
27
|
-
*/
|
|
28
|
-
declare function parse (input: string, reviverOrOptions?: Function | ParseOptions): object
|
|
29
|
-
|
|
30
|
-
interface TokenizeOptions {
|
|
31
|
-
ignoreBOM?: boolean
|
|
32
|
-
ignoreComments?: boolean
|
|
33
|
-
ignoreTrailingCommas?: boolean
|
|
34
|
-
allowSingleQuotedStrings?: boolean
|
|
35
|
-
allowDuplicateObjectKeys?: boolean
|
|
36
|
-
mode?: ParseMode
|
|
37
|
-
reviver?: Function
|
|
38
|
-
rawTokens?: boolean
|
|
39
|
-
tokenLocations?: boolean
|
|
40
|
-
tokenPaths?: boolean
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Parses a string formatted as JSON to an array of JSON tokens.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```ts
|
|
48
|
-
* import { tokenize } from '@prantlf/jsonlint'
|
|
49
|
-
* const tokens = tokenize('string with JSON data')
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* @param input - a string input to parse
|
|
53
|
-
* @param reviverOrOptions - either a value reviver or an object
|
|
54
|
-
* with multiple options
|
|
55
|
-
* @returns an array with the tokens
|
|
56
|
-
*/
|
|
57
|
-
declare function tokenize (input: string, reviverOrOptions?: Function | TokenizeOptions): object
|
|
58
|
-
|
|
59
|
-
declare module '@prantlf/jsonlint/lib/validator' {
|
|
60
|
-
type Environment = 'json-schema-draft-04' | 'json-schema-draft-06' | 'json-schema-draft-07'
|
|
61
|
-
|
|
62
|
-
interface CompileOptions {
|
|
63
|
-
ignoreBOM?: boolean
|
|
64
|
-
ignoreComments?: boolean
|
|
65
|
-
ignoreTrailingCommas?: boolean
|
|
66
|
-
allowSingleQuotedStrings?: boolean
|
|
67
|
-
allowDuplicateObjectKeys?: boolean
|
|
68
|
-
environment?: Environment
|
|
69
|
-
mode?: ParseMode
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Generates a JSON Schema validator.
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```ts
|
|
77
|
-
* import { compile } from '@prantlf/jsonlint/lib/validator'
|
|
78
|
-
* const validate = compile('string with JSON schema')
|
|
79
|
-
* const parsed = validate('string with JSON data')
|
|
80
|
-
* ```
|
|
81
|
-
*
|
|
82
|
-
* @param schema - a string with the JSON Schema to validate with
|
|
83
|
-
* @param environmentOrOptions - either a string with the version
|
|
84
|
-
* of the JSON Schema standard or an object
|
|
85
|
-
* with multiple options
|
|
86
|
-
* @returns the validator function
|
|
87
|
-
*/
|
|
88
|
-
function compile (schema: string, environmentOrOptions?: Environment | CompileOptions): Function
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
declare module '@prantlf/jsonlint/lib/printer' {
|
|
92
|
-
interface PrintOptions {
|
|
93
|
-
indent?: number | string
|
|
94
|
-
pruneComments?: boolean
|
|
95
|
-
stripObjectKeys?: boolean
|
|
96
|
-
enforceDoubleQuotes?: boolean
|
|
97
|
-
enforceSingleQuotes?: boolean
|
|
98
|
-
trimTrailingCommas?: boolean
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Pretty-prints an array of JSON tokens parsed from a valid JSON string by `tokenize`.
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* ```ts
|
|
106
|
-
* import { tokenize } from '@prantlf/jsonlint'
|
|
107
|
-
* import { print } from '@prantlf/jsonlint/lib/printer'
|
|
108
|
-
* const tokens = tokenize('string with JSON data', { rawTokens: true })
|
|
109
|
-
* const outputString = print(tokens, { indent: 2 })
|
|
110
|
-
* ```
|
|
111
|
-
*
|
|
112
|
-
* @param tokens - an array of JSON tokens
|
|
113
|
-
* @param options - an object with multiple options
|
|
114
|
-
* @returns the output string
|
|
115
|
-
*/
|
|
116
|
-
function print (tokens: Array<object>, options?: PrintOptions): string
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export { parse, tokenize }
|