@prantlf/jsonlint 15.0.0 → 16.1.0
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/LICENSE +1 -1
- package/README.md +44 -3
- package/lib/cli.js +67 -6
- package/lib/index.d.ts +12 -0
- package/lib/jsonlint.js +10 -10
- package/lib/printer.js +3 -2
- package/lib/sorter.js +4 -3
- package/lib/validator.js +27 -9
- package/package.json +18 -14
- package/web/ajv.min.js +6 -6
- package/web/ajv.min.js.map +1 -1
- package/web/jsonlint.html +12 -5
- package/web/jsonlint.min.js +5 -5
- package/web/jsonlint.min.js.map +2 -2
- package/web/printer.min.js +4 -3
- package/web/printer.min.js.map +3 -3
- package/web/sorter.min.js +1 -1
- package/web/sorter.min.js.map +3 -3
- package/web/validator.min.js +3 -3
- package/web/validator.min.js.map +3 -3
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2012-2018 Zachary Carter
|
|
4
|
-
Copyright (c) 2019-
|
|
4
|
+
Copyright (c) 2019-2026 Ferdinand Prantl
|
|
5
5
|
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -157,12 +157,15 @@ Usage: `jsonlint [options] [--] [<file, directory, pattern> ...]`
|
|
|
157
157
|
-P, --pretty-print-invalid force pretty-printing even for invalid input
|
|
158
158
|
-r, --trailing-newline ensure a line break at the end of the output
|
|
159
159
|
-R, --no-trailing-newline ensure no line break at the end of the output
|
|
160
|
+
--no-strict disable the strict schema validation mode
|
|
160
161
|
--prune-comments omit comments from the prettified output
|
|
161
162
|
--strip-object-keys strip quotes from object keys if possible
|
|
162
163
|
--enforce-double-quotes surrounds all strings with double quotes
|
|
163
164
|
--enforce-single-quotes surrounds all strings with single quotes
|
|
164
165
|
--trim-trailing-commas omit trailing commas from objects and arrays
|
|
166
|
+
--force-crlf makes sure all line breaks are CRLF
|
|
165
167
|
--succeed-with-no-files succeed (exit code 0) if no files were found
|
|
168
|
+
--[no-]color force or disable colourful output of the diff
|
|
166
169
|
-v, --version output the version number
|
|
167
170
|
-h, --help display help for command
|
|
168
171
|
|
|
@@ -177,8 +180,8 @@ for JSON Schema validation are "draft-04", "draft-06", "draft-07",
|
|
|
177
180
|
with "json-schema-". JSON Type Definition can be selected by "rfc8927",
|
|
178
181
|
"json-type-definition" or "jtd". If not specified, it will be "draft-07".
|
|
179
182
|
|
|
180
|
-
If you specify schemas
|
|
181
|
-
|
|
183
|
+
If you specify multiple schemas, either separate them by comma (,) or
|
|
184
|
+
use the "-V" parameter multiple times.
|
|
182
185
|
|
|
183
186
|
### Configuration
|
|
184
187
|
|
|
@@ -222,6 +225,8 @@ The configuration is an object with the following properties, described above, w
|
|
|
222
225
|
| duplicate-keys | duplicateKeys |
|
|
223
226
|
| validate | |
|
|
224
227
|
| environment | |
|
|
228
|
+
| strict | |
|
|
229
|
+
| color | |
|
|
225
230
|
| log-files | logFiles |
|
|
226
231
|
| quiet | |
|
|
227
232
|
| continue | |
|
|
@@ -233,6 +238,7 @@ The configuration is an object with the following properties, described above, w
|
|
|
233
238
|
| enforce-double-quotes | enforceDoubleQuotes |
|
|
234
239
|
| enforce-single-quotes | enforceSingleQuotes |
|
|
235
240
|
| trim-trailing-commas | trimTrailingCommas |
|
|
241
|
+
| force-crlf | forceCrlf |
|
|
236
242
|
|
|
237
243
|
The parameter `config` will be ignored in configuration files. The extra parameter `patterns` can be set to an array of strings with paths or patterns instead of putting them to the command line.
|
|
238
244
|
|
|
@@ -314,6 +320,12 @@ If you use external definitions in multiple schemas, you have to pass an array o
|
|
|
314
320
|
const validate = compile(['string with main schema', 'string with a sub-schema'])
|
|
315
321
|
```
|
|
316
322
|
|
|
323
|
+
The schema is parsed in the *strict mode* by default. It'll fail with unknown schema keywords, string formats, conflicting property definitions, union types etc. You may need to relax the schema compilation by disabling the strict mode under circumstances:
|
|
324
|
+
|
|
325
|
+
```js
|
|
326
|
+
const validate = compile('string with JSON Schema', { environment: 'draft-2020-12', strict: false })
|
|
327
|
+
```
|
|
328
|
+
|
|
317
329
|
### Pretty-Printing
|
|
318
330
|
|
|
319
331
|
You can parse a JSON string to an array of tokens and print it back to a string with some changes applied. It can be unification of whitespace, reformatting or stripping comments, for example. (Raw token values must be enabled when tokenizing the JSON input.)
|
|
@@ -337,6 +349,7 @@ The [`print`](#pretty-printing) method accepts an object `options` as the second
|
|
|
337
349
|
| `enforceDoubleQuotes` | will surround all strings with double quotes |
|
|
338
350
|
| `enforceSingleQuotes` | will surround all strings with single quotes |
|
|
339
351
|
| `trimTrailingCommas` | will omit all trailing commas after the last object entry or array item |
|
|
352
|
+
| `forceCrlf` | makes sure all line breaks are CRLF |
|
|
340
353
|
|
|
341
354
|
```js
|
|
342
355
|
// Just concatenate the tokens to produce the same output as was the input.
|
|
@@ -361,6 +374,34 @@ print(tokens, {
|
|
|
361
374
|
enforceDoubleQuotes: true,
|
|
362
375
|
trimTrailingCommas: true
|
|
363
376
|
})
|
|
377
|
+
// Same as `print(tokens, {})`, but uses \r\n for line breaks.
|
|
378
|
+
print(tokens, { forceCrlf: true })
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
Pretty-printing can be also used to preserve the contents of string literal in the output. For example, the following input:
|
|
382
|
+
|
|
383
|
+
```json
|
|
384
|
+
{ "pattern": "^(?:\\\\x[0-9A-F]{2}|[\u0020-\u007E])+$" }
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
will be validated and printed out by default:
|
|
388
|
+
|
|
389
|
+
```json
|
|
390
|
+
{
|
|
391
|
+
"pattern": "^(?:\\\\x[0-9A-F]{2}|[ -~])+$"
|
|
392
|
+
}
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
As you see, the escape Unicode sequences were replaced by the corresponding UTF-8 characters. While this saves space and is arguably more readable, you may have a coding standard which requires to represent some characters always by the escaped Unicode sequences. Yu can achieve it by enabling pretty-printing, which preserves the string literals in the input form. Apart from the programmatic way above, it's possible on the command line too:
|
|
396
|
+
|
|
397
|
+
jsonlint -p pattern.json
|
|
398
|
+
|
|
399
|
+
resulting in the following output:
|
|
400
|
+
|
|
401
|
+
```json
|
|
402
|
+
{
|
|
403
|
+
"pattern": "^(?:\\\\x[0-9A-F]{2}|[\u0020-\u007E])+$"
|
|
404
|
+
}
|
|
364
405
|
```
|
|
365
406
|
|
|
366
407
|
### Tokenizing
|
|
@@ -445,7 +486,7 @@ ${reason}`)
|
|
|
445
486
|
|
|
446
487
|
## License
|
|
447
488
|
|
|
448
|
-
Copyright (C) 2012-
|
|
489
|
+
Copyright (C) 2012-2026 Zachary Carter, Ferdinand Prantl
|
|
449
490
|
|
|
450
491
|
Licensed under the [MIT License].
|
|
451
492
|
|
package/lib/cli.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const { readdirSync, readFileSync, statSync, writeFileSync } = require('
|
|
4
|
-
const { extname, join } = require('
|
|
3
|
+
const { readdirSync, readFileSync, statSync, writeFileSync } = require('fs')
|
|
4
|
+
const { extname, join } = require('path')
|
|
5
5
|
const { isDynamicPattern, sync } = require('fast-glob')
|
|
6
|
+
const pico = require('picocolors')
|
|
6
7
|
const { parse, tokenize } = require('./jsonlint')
|
|
7
8
|
const { format } = require('./formatter')
|
|
8
9
|
const { print } = require('./printer')
|
|
@@ -54,20 +55,38 @@ Options:
|
|
|
54
55
|
-P, --pretty-print-invalid force pretty-printing even for invalid input
|
|
55
56
|
-r, --trailing-newline ensure a line break at the end of the output
|
|
56
57
|
-R, --no-trailing-newline ensure no line break at the end of the output
|
|
58
|
+
--no-strict disable the strict schema validation mode
|
|
57
59
|
--prune-comments omit comments from the prettified output
|
|
58
60
|
--strip-object-keys strip quotes from object keys if possible
|
|
59
61
|
--enforce-double-quotes surrounds all strings with double quotes
|
|
60
62
|
--enforce-single-quotes surrounds all strings with single quotes
|
|
61
63
|
--trim-trailing-commas omit trailing commas from objects and arrays
|
|
64
|
+
--force-crlf makes sure all line breaks are CRLF
|
|
62
65
|
--succeed-with-no-files succeed (exit code 0) if no files were found
|
|
66
|
+
--[no-]color force or disable colourful output of the diff
|
|
63
67
|
-v, --version output the version number
|
|
64
68
|
-h, --help display help for command
|
|
65
69
|
|
|
70
|
+
You can use BASH patterns for including and excluding files (only files).
|
|
71
|
+
Patterns are case-sensitive and have to use slashes as directory separators.
|
|
72
|
+
A pattern to exclude from processing starts with "!".
|
|
73
|
+
|
|
74
|
+
Parsing mode can be "cjson" or "json5" to enable other flags automatically.
|
|
75
|
+
If no files or directories are specified, stdin will be parsed. Environments
|
|
76
|
+
for JSON Schema validation are "draft-04", "draft-06", "draft-07",
|
|
77
|
+
"draft-2019-09" or "draft-2020-12". The environment may be prefixed
|
|
78
|
+
with "json-schema-". JSON Type Definition can be selected by "rfc8927",
|
|
79
|
+
"json-type-definition" or "jtd". If not specified, it will be "draft-07".
|
|
80
|
+
|
|
81
|
+
If you specify multiple schemas, either separate them by comma (,) or
|
|
82
|
+
use the "-V" parameter multiple times.
|
|
83
|
+
|
|
66
84
|
Examples:
|
|
67
85
|
$ jsonlint myfile.json
|
|
68
86
|
$ jsonlint --in-place --pretty-print mydir
|
|
69
87
|
$ jsonlint --comments --trailing-commas --no-duplicate-keys \\
|
|
70
|
-
--log-files --compact --continue '**/*.json' '!**/node_modules'
|
|
88
|
+
--log-files --compact --continue '**/*.json' '!**/node_modules'
|
|
89
|
+
$ jsonlint --validate openapi-schema.json --environment draft-07 myapi.json`)
|
|
71
90
|
}
|
|
72
91
|
|
|
73
92
|
const { argv } = process
|
|
@@ -174,6 +193,12 @@ for (let i = 2, l = argv.length; i < l; ++i) {
|
|
|
174
193
|
}
|
|
175
194
|
params.environment = arg
|
|
176
195
|
return
|
|
196
|
+
case 'strict':
|
|
197
|
+
params.strict = flag
|
|
198
|
+
return
|
|
199
|
+
case 'color':
|
|
200
|
+
params.color = flag
|
|
201
|
+
return
|
|
177
202
|
case 'x': case 'context':
|
|
178
203
|
arg = match[4] || argv[++i]
|
|
179
204
|
if (Number.isNaN(+arg)) {
|
|
@@ -217,6 +242,9 @@ for (let i = 2, l = argv.length; i < l; ++i) {
|
|
|
217
242
|
case 'trim-trailing-commas':
|
|
218
243
|
params.trimTrailingCommas = flag
|
|
219
244
|
return
|
|
245
|
+
case 'force-crlf':
|
|
246
|
+
params.forceCrlf = flag
|
|
247
|
+
return
|
|
220
248
|
case 'succeed-with-no-files':
|
|
221
249
|
params.succeedWithNoFiles = flag
|
|
222
250
|
return
|
|
@@ -257,6 +285,7 @@ const paramNames = {
|
|
|
257
285
|
'enforce-double-quotes': 'enforceDoubleQuotes',
|
|
258
286
|
'enforce-single-quotes': 'enforceSingleQuotes',
|
|
259
287
|
'trim-trailing-commas': 'trimTrailingCommas',
|
|
288
|
+
'force-crlf': 'forceCrlf',
|
|
260
289
|
'sort-keys': 'sortKeys',
|
|
261
290
|
'sort-keys-ignore-case': 'sortKeysIgnoreCase',
|
|
262
291
|
'sort-keys-locale': 'sortKeysLocale',
|
|
@@ -346,6 +375,7 @@ function processContents (source, file) {
|
|
|
346
375
|
}
|
|
347
376
|
})
|
|
348
377
|
parserOptions.environment = params.environment
|
|
378
|
+
parserOptions.strict = params.strict
|
|
349
379
|
try {
|
|
350
380
|
validate = compile(schemas, parserOptions)
|
|
351
381
|
} catch (error) {
|
|
@@ -365,7 +395,8 @@ function processContents (source, file) {
|
|
|
365
395
|
stripObjectKeys: params.stripObjectKeys,
|
|
366
396
|
enforceDoubleQuotes: params.enforceDoubleQuotes,
|
|
367
397
|
enforceSingleQuotes: params.enforceSingleQuotes,
|
|
368
|
-
trimTrailingCommas: params.trimTrailingCommas
|
|
398
|
+
trimTrailingCommas: params.trimTrailingCommas,
|
|
399
|
+
forceCrlf: params.forceCrlf
|
|
369
400
|
})
|
|
370
401
|
}
|
|
371
402
|
const sortOptions = {}
|
|
@@ -433,11 +464,41 @@ function ensureLineBreak (parsed, source) {
|
|
|
433
464
|
const newLine = !lines[lines.length - 1]
|
|
434
465
|
if (params.trailingNewline === true ||
|
|
435
466
|
(params.trailingNewline !== false && newLine)) {
|
|
436
|
-
parsed +=
|
|
467
|
+
parsed += params.forceCrlf === true ? "\r\n" : "\n"
|
|
437
468
|
}
|
|
438
469
|
return parsed
|
|
439
470
|
}
|
|
440
471
|
|
|
472
|
+
function printDiff (diff) {
|
|
473
|
+
const { env } = process
|
|
474
|
+
const isColorSupported =
|
|
475
|
+
!(env.NO_COLOR || params.color === false || env.CI || env.TERM === 'dumb') &&
|
|
476
|
+
(env.FORCE_COLOR || params.color === true || process.platform === "win32" || process.stdout.isTTY)
|
|
477
|
+
if (isColorSupported) {
|
|
478
|
+
const lines = diff.split(/\r?\n/)
|
|
479
|
+
for (const line of lines) {
|
|
480
|
+
if (/^@@ +-\d+,\d+ +\+\d+,\d+ +@@/.test(line) ||
|
|
481
|
+
/^@@ +-\d+ +\+\d+,\d+ +@@/.test(line) ||
|
|
482
|
+
/^@@ +-\d+,\d+ +\+\d+ +@@/.test(line) ||
|
|
483
|
+
/^@@ +-\d+ +\+\d+ +@@/.test(line)) {
|
|
484
|
+
console.log(pico.blue(line)) // meta
|
|
485
|
+
} else if (/={3,}/.test(line) ||
|
|
486
|
+
/^-{3}/.test(line) ||
|
|
487
|
+
/^\+{3}/.test(line)) {
|
|
488
|
+
console.log(pico.gray(line)) // comment
|
|
489
|
+
} else if (/^\+/.test(line)) {
|
|
490
|
+
console.log(pico.green(line)) // addition
|
|
491
|
+
} else if (/^-/.test(line)) {
|
|
492
|
+
console.log(pico.red(line)) // deletion
|
|
493
|
+
} else {
|
|
494
|
+
console.log(line)
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
} else {
|
|
498
|
+
console.log(diff)
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
441
502
|
function checkContents (file, source, parsed) {
|
|
442
503
|
const { createTwoFilesPatch, structuredPatch } = require('diff')
|
|
443
504
|
const structured = structuredPatch(`${file}.orig`, file, source, parsed, '', '', { context: params.context })
|
|
@@ -454,7 +515,7 @@ function checkContents (file, source, parsed) {
|
|
|
454
515
|
}
|
|
455
516
|
if (!params.quiet) {
|
|
456
517
|
const diff = createTwoFilesPatch(`${file}.orig`, file, source, parsed, '', '', { context: params.context })
|
|
457
|
-
|
|
518
|
+
printDiff(diff)
|
|
458
519
|
}
|
|
459
520
|
if (params.continue) {
|
|
460
521
|
process.exitCode = 1
|
package/lib/index.d.ts
CHANGED
|
@@ -425,6 +425,13 @@ declare module '@prantlf/jsonlint/lib/validator' {
|
|
|
425
425
|
* 'json-type-definition' | 'jtd' | 'rfc8927'`
|
|
426
426
|
*/
|
|
427
427
|
environment?: Environment
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Enable or disable the strict schema validation mode.
|
|
431
|
+
*
|
|
432
|
+
* The default is `true`. You may need to set it to `false` to ignore some schema extensions.
|
|
433
|
+
*/
|
|
434
|
+
strict?: boolean
|
|
428
435
|
}
|
|
429
436
|
|
|
430
437
|
/**
|
|
@@ -499,6 +506,11 @@ declare module '@prantlf/jsonlint/lib/printer' {
|
|
|
499
506
|
* Remove trailing commas after the last item in objects and arrays.
|
|
500
507
|
*/
|
|
501
508
|
trimTrailingCommas?: boolean
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Makes sure all line breaks are CRLF.
|
|
512
|
+
*/
|
|
513
|
+
forceCrlf?: boolean
|
|
502
514
|
}
|
|
503
515
|
|
|
504
516
|
/**
|
package/lib/jsonlint.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// This is autogenerated with esprima tools, see:
|
|
10
10
|
// https://github.com/ariya/esprima/blob/master/esprima.js
|
|
11
11
|
|
|
12
|
-
//
|
|
12
|
+
// biome-ignore lint/correctness/noUnusedVariables: generated code
|
|
13
13
|
const Uni = {
|
|
14
14
|
isWhiteSpace: function isWhiteSpace (x) {
|
|
15
15
|
// section 7.2, table 2
|
|
@@ -103,7 +103,7 @@ const unescapeMap = {
|
|
|
103
103
|
'/': '/'
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
const ownsProperty = Object.
|
|
106
|
+
const ownsProperty = Object.hasOwn
|
|
107
107
|
|
|
108
108
|
const emptyObject = {}
|
|
109
109
|
|
|
@@ -391,7 +391,7 @@ function parseInternal (input, options) {
|
|
|
391
391
|
while (position < inputLength) {
|
|
392
392
|
skipWhiteSpace()
|
|
393
393
|
const key = parseKey()
|
|
394
|
-
if (allowDuplicateObjectKeys === false && ownsProperty
|
|
394
|
+
if (allowDuplicateObjectKeys === false && ownsProperty(result, key)) {
|
|
395
395
|
fail(`Duplicate key: "${key}"`)
|
|
396
396
|
}
|
|
397
397
|
skipWhiteSpace()
|
|
@@ -727,7 +727,7 @@ function parseInternal (input, options) {
|
|
|
727
727
|
}
|
|
728
728
|
}
|
|
729
729
|
|
|
730
|
-
//
|
|
730
|
+
// biome-ignore lint/correctness/noUnusedVariables: concatenated with other files
|
|
731
731
|
function parseCustom (input, options) {
|
|
732
732
|
if (typeof options === 'function') {
|
|
733
733
|
options = {
|
|
@@ -739,7 +739,7 @@ function parseCustom (input, options) {
|
|
|
739
739
|
return parseInternal(input, options)
|
|
740
740
|
}
|
|
741
741
|
|
|
742
|
-
//
|
|
742
|
+
// biome-ignore lint/correctness/noUnusedVariables: concatenated with other files
|
|
743
743
|
function tokenize (input, options) {
|
|
744
744
|
if (!options) {
|
|
745
745
|
options = {}
|
|
@@ -759,7 +759,7 @@ function escapePointerToken (token) {
|
|
|
759
759
|
.replace(/\//g, '~1')
|
|
760
760
|
}
|
|
761
761
|
|
|
762
|
-
//
|
|
762
|
+
// biome-ignore lint/correctness/noUnusedVariables: concatenated with other files
|
|
763
763
|
function pathToPointer (tokens) {
|
|
764
764
|
if (tokens.length === 0) {
|
|
765
765
|
return ''
|
|
@@ -775,7 +775,7 @@ function unescapePointerToken (token) {
|
|
|
775
775
|
.replace(/~0/g, '~')
|
|
776
776
|
}
|
|
777
777
|
|
|
778
|
-
//
|
|
778
|
+
// biome-ignore lint/correctness/noUnusedVariables: concatenated with other files
|
|
779
779
|
function pointerToPath (pointer) {
|
|
780
780
|
if (pointer === '') {
|
|
781
781
|
return []
|
|
@@ -881,7 +881,7 @@ function getLocationOnSpiderMonkey (input, reason) {
|
|
|
881
881
|
if (match) {
|
|
882
882
|
const line = +match[1]
|
|
883
883
|
const column = +match[2]
|
|
884
|
-
const offset = getOffset(input, line, column)
|
|
884
|
+
const offset = getOffset(input, line, column)
|
|
885
885
|
return {
|
|
886
886
|
offset,
|
|
887
887
|
line,
|
|
@@ -942,7 +942,7 @@ function improveNativeError (input, error) {
|
|
|
942
942
|
return error
|
|
943
943
|
}
|
|
944
944
|
|
|
945
|
-
//
|
|
945
|
+
// biome-ignore lint/correctness/noUnusedVariables: concatenated with other files
|
|
946
946
|
function parseNative (input, reviver) {
|
|
947
947
|
try {
|
|
948
948
|
return JSON.parse(input, reviver)
|
|
@@ -974,7 +974,7 @@ function getReviver (options) {
|
|
|
974
974
|
}
|
|
975
975
|
}
|
|
976
976
|
|
|
977
|
-
//
|
|
977
|
+
// biome-ignore lint/correctness/noUnusedVariables: concatenated with other files
|
|
978
978
|
function parse (input, options) {
|
|
979
979
|
options || (options = {})
|
|
980
980
|
return needsCustomParser(options)
|
package/lib/printer.js
CHANGED
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
const enforceDoubleQuotes = options.enforceDoubleQuotes
|
|
49
49
|
const enforceSingleQuotes = options.enforceSingleQuotes
|
|
50
50
|
const trimTrailingCommas = options.trimTrailingCommas
|
|
51
|
+
const newLineChar = options.forceCrlf === true ? "\r\n" : "\n"
|
|
51
52
|
|
|
52
53
|
let outputString = ''
|
|
53
54
|
let foundLineBreak
|
|
@@ -90,7 +91,7 @@
|
|
|
90
91
|
let addDelayedSpaceOrLineBreak
|
|
91
92
|
if (prettyPrint) {
|
|
92
93
|
addLineBreak = function () {
|
|
93
|
-
outputString +=
|
|
94
|
+
outputString += newLineChar
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
addDelayedSpaceOrLineBreak = function () {
|
|
@@ -206,7 +207,7 @@
|
|
|
206
207
|
if (enforceDoubleQuotes && tokenContent[0] !== '"') {
|
|
207
208
|
outputString += JSON.stringify(tokenValue)
|
|
208
209
|
} else if (enforceSingleQuotes && tokenContent[0] !== '\'') {
|
|
209
|
-
outputString +=
|
|
210
|
+
outputString += `'${tokenValue.replace(/'/g, '\\\'')}'`
|
|
210
211
|
} else {
|
|
211
212
|
outputString += tokenContent
|
|
212
213
|
}
|
package/lib/sorter.js
CHANGED
|
@@ -6,18 +6,19 @@
|
|
|
6
6
|
'use strict'
|
|
7
7
|
|
|
8
8
|
// from http://stackoverflow.com/questions/1359761/sorting-a-json-object-in-javascript
|
|
9
|
-
const ownsProperty = Object.
|
|
9
|
+
const ownsProperty = Object.hasOwn
|
|
10
|
+
const formatString = Object.prototype.toString
|
|
10
11
|
function sortObject (o, { ignoreCase, locale, caseFirst, numeric } = {}) {
|
|
11
12
|
if (Array.isArray(o)) {
|
|
12
13
|
return o.map(sortObject)
|
|
13
|
-
}if (
|
|
14
|
+
}if (formatString.call(o) !== '[object Object]') {
|
|
14
15
|
return o
|
|
15
16
|
}
|
|
16
17
|
const sorted = {}
|
|
17
18
|
let key
|
|
18
19
|
const a = []
|
|
19
20
|
for (key in o) {
|
|
20
|
-
if (ownsProperty
|
|
21
|
+
if (ownsProperty(o, key)) {
|
|
21
22
|
a.push(key)
|
|
22
23
|
}
|
|
23
24
|
}
|
package/lib/validator.js
CHANGED
|
@@ -7,7 +7,10 @@
|
|
|
7
7
|
AjvJTD: 'ajv/dist/jtd',
|
|
8
8
|
Ajv2019: 'ajv/dist/2019',
|
|
9
9
|
Ajv2020: 'ajv/dist/2020',
|
|
10
|
-
Schema06: 'ajv/dist/refs/json-schema-draft-06.json'
|
|
10
|
+
Schema06: 'ajv/dist/refs/json-schema-draft-06.json',
|
|
11
|
+
Keywords: 'ajv-keywords',
|
|
12
|
+
Formats: 'ajv-formats',
|
|
13
|
+
Formats2019: 'ajv-formats-draft2019'
|
|
11
14
|
}
|
|
12
15
|
const requireAjv = name => {
|
|
13
16
|
const exported = require(ajv[name])
|
|
@@ -101,27 +104,38 @@
|
|
|
101
104
|
return error
|
|
102
105
|
}
|
|
103
106
|
|
|
104
|
-
function createAjv (environment) {
|
|
107
|
+
function createAjv (environment, ajvOptions) {
|
|
105
108
|
let ajv
|
|
106
109
|
if (!environment || environment === 'json-schema-draft-06' || environment === 'draft-06') {
|
|
107
110
|
const Ajv = requireAjv('Ajv07')
|
|
108
|
-
ajv = new Ajv()
|
|
111
|
+
ajv = new Ajv(ajvOptions)
|
|
109
112
|
ajv.addMetaSchema(requireAjv('Schema06'))
|
|
113
|
+
requireAjv('Formats')(ajv)
|
|
114
|
+
requireAjv('Keywords')(ajv)
|
|
110
115
|
} else if (environment === 'json-schema-draft-07' || environment === 'draft-07') {
|
|
111
116
|
const Ajv = requireAjv('Ajv07')
|
|
112
|
-
ajv = new Ajv()
|
|
117
|
+
ajv = new Ajv(ajvOptions)
|
|
118
|
+
requireAjv('Formats')(ajv)
|
|
119
|
+
requireAjv('Formats2019')(ajv)
|
|
120
|
+
requireAjv('Keywords')(ajv)
|
|
113
121
|
} else if (environment === 'json-schema-draft-04' || environment === 'draft-04') {
|
|
114
122
|
const Ajv = requireAjv('Ajv04')
|
|
115
|
-
ajv = new Ajv()
|
|
123
|
+
ajv = new Ajv(ajvOptions)
|
|
116
124
|
} else if (environment === 'json-schema-draft-2019-09' || environment === 'draft-2019-09') {
|
|
117
125
|
const Ajv = requireAjv('Ajv2019')
|
|
118
|
-
ajv = new Ajv()
|
|
126
|
+
ajv = new Ajv(ajvOptions)
|
|
127
|
+
requireAjv('Formats')(ajv)
|
|
128
|
+
requireAjv('Formats2019')(ajv)
|
|
129
|
+
requireAjv('Keywords')(ajv)
|
|
119
130
|
} else if (environment === 'json-schema-draft-2020-12' || environment === 'draft-2020-12') {
|
|
120
131
|
const Ajv = requireAjv('Ajv2020')
|
|
121
|
-
ajv = new Ajv()
|
|
132
|
+
ajv = new Ajv(ajvOptions)
|
|
133
|
+
requireAjv('Formats')(ajv)
|
|
134
|
+
requireAjv('Formats2019')(ajv)
|
|
135
|
+
requireAjv('Keywords')(ajv)
|
|
122
136
|
} else if (environment === 'json-type-definition' || environment === 'jtd' || environment === 'rfc8927') {
|
|
123
137
|
const Ajv = requireAjv('AjvJTD')
|
|
124
|
-
ajv = new Ajv()
|
|
138
|
+
ajv = new Ajv(ajvOptions)
|
|
125
139
|
} else {
|
|
126
140
|
throw new RangeError(`Unsupported environment for the JSON Schema validation: "${environment}".`)
|
|
127
141
|
}
|
|
@@ -160,7 +174,11 @@
|
|
|
160
174
|
options = environment
|
|
161
175
|
environment = options.environment
|
|
162
176
|
}
|
|
163
|
-
const
|
|
177
|
+
const ajvOptions = {}
|
|
178
|
+
if (options.strict === false) {
|
|
179
|
+
ajvOptions.strict = false
|
|
180
|
+
}
|
|
181
|
+
const ajv = createAjv(environment, ajvOptions)
|
|
164
182
|
const parseOptions = {
|
|
165
183
|
mode: options.mode,
|
|
166
184
|
ignoreBOM: options.ignoreBOM,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prantlf/jsonlint",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "16.1.0",
|
|
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": [
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"web"
|
|
37
37
|
],
|
|
38
38
|
"engines": {
|
|
39
|
-
"node": ">=
|
|
39
|
+
"node": ">=16.9"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "npm run compile:jsonlint && rollup -c && npm run minify && npm run compile:tests",
|
|
@@ -58,28 +58,32 @@
|
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"ajv": "8.17.1",
|
|
60
60
|
"ajv-draft-04": "1.0.0",
|
|
61
|
+
"ajv-formats": "^3.0.1",
|
|
62
|
+
"ajv-formats-draft2019": "^1.6.1",
|
|
63
|
+
"ajv-keywords": "^5.1.0",
|
|
61
64
|
"cosmiconfig": "9.0.0",
|
|
62
|
-
"diff": "
|
|
63
|
-
"fast-glob": "3.3.
|
|
65
|
+
"diff": "8.0.2",
|
|
66
|
+
"fast-glob": "3.3.3",
|
|
67
|
+
"picocolors": "^1.1.1"
|
|
64
68
|
},
|
|
65
69
|
"devDependencies": {
|
|
66
|
-
"@biomejs/biome": "^
|
|
67
|
-
"@rollup/plugin-commonjs": "
|
|
70
|
+
"@biomejs/biome": "^2.3.11",
|
|
71
|
+
"@rollup/plugin-commonjs": "29.0.0",
|
|
68
72
|
"@rollup/plugin-json": "6.1.0",
|
|
69
|
-
"@rollup/plugin-node-resolve": "
|
|
70
|
-
"@types/node": "
|
|
73
|
+
"@rollup/plugin-node-resolve": "16.0.3",
|
|
74
|
+
"@types/node": "25.0.3",
|
|
71
75
|
"@unixcompat/cat.js": "2.0.0",
|
|
72
76
|
"@unixcompat/mv.js": "2.0.0",
|
|
73
|
-
"c8": "10.1.
|
|
74
|
-
"esbuild": "0.
|
|
77
|
+
"c8": "10.1.3",
|
|
78
|
+
"esbuild": "0.27.2",
|
|
75
79
|
"http-server": "14.1.1",
|
|
76
|
-
"js-yaml": "4.1.
|
|
77
|
-
"rollup": "4.
|
|
78
|
-
"rollup-plugin-swc-minify": "1.
|
|
80
|
+
"js-yaml": "4.1.1",
|
|
81
|
+
"rollup": "4.54.0",
|
|
82
|
+
"rollup-plugin-swc-minify": "1.3.0",
|
|
79
83
|
"tehanu": "1.0.1",
|
|
80
84
|
"tehanu-repo-coco": "1.0.1",
|
|
81
85
|
"tehanu-teru": "1.0.1",
|
|
82
|
-
"typescript": "5.
|
|
86
|
+
"typescript": "5.9.3"
|
|
83
87
|
},
|
|
84
88
|
"keywords": [
|
|
85
89
|
"json",
|