@prantlf/jsonlint 11.6.0 → 11.7.1

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/README.md CHANGED
@@ -12,6 +12,7 @@ This is a fork of the original project ([zaach/jsonlint](https://github.com/zaac
12
12
  * Handles multiple files on the command line (by Greg Inman).
13
13
  * Walks directories recursively (by Paul Vollmer).
14
14
  * Provides 100% compatible interface to the native `JSON.parse` method.
15
+ * Optionally ignores the leading UTF-8 byte-order mark (BOM).
15
16
  * Optionally recognizes JavaScript-style comments (CJSON) and single quoted strings (JSON5).
16
17
  * Optionally ignores trailing commas and reports duplicate object keys as an error.
17
18
  * Optionally checks that also the expected format matches, including sorted object keys.
@@ -129,6 +130,7 @@ Usage: `jsonlint [options] [<file, directory, pattern> ...]`
129
130
  -c, --compact compact error display
130
131
  -M, --mode [mode] set other parsing flags according to a format
131
132
  type (default: "json")
133
+ -B, --bom ignore the leading UTF-8 byte-order mark
132
134
  -C, --comments recognize and ignore JavaScript-style comments
133
135
  -S, --single-quoted-strings support single quotes as string delimiters
134
136
  -T, --trailing-commas ignore trailing commas in objects and arrays
@@ -157,7 +159,7 @@ Usage: `jsonlint [options] [<file, directory, pattern> ...]`
157
159
  -h, --help output usage information
158
160
 
159
161
  You can use BASH patterns for including and excluding files (only files).
160
- Patterns are case-sensitive and have to use slashes as a path separators.
162
+ Patterns are case-sensitive and have to use slashes as directory separators.
161
163
  A pattern to exclude from processing starts with "!".
162
164
 
163
165
  Parsing mode can be "cjson" or "json5" to enable other flags automatically.
@@ -194,6 +196,7 @@ The configuration is an object with the following properties, described above, w
194
196
  | indent | |
195
197
  | compact | |
196
198
  | mode | |
199
+ | bom | |
197
200
  | comments | |
198
201
  | single-quoted-strings | singleQuotedStrings |
199
202
  | trailing-commas | trailingCommas |
@@ -251,6 +254,7 @@ The `parse` method offers more detailed [error information](#error-handling), th
251
254
 
252
255
  | Option | Description |
253
256
  | -------------------------- | ------------------------------------------- |
257
+ | `ignoreBOM` | ignores the leading UTF-8 byte-order mark (boolean) |
254
258
  | `ignoreComments` | ignores single-line and multi-line JavaScript-style comments during parsing as another "whitespace" (boolean) |
255
259
  | `ignoreTrailingCommas` | ignores trailing commas in objects and arrays (boolean) |
256
260
  | `allowSingleQuotedStrings` | accepts strings delimited by single-quotes too (boolean) |
package/lib/cli.js CHANGED
@@ -26,6 +26,7 @@ const commander = require('commander')
26
26
  .option('-t, --indent [num|char]', 'number of spaces or specific characters to use for indentation', 2)
27
27
  .option('-c, --compact', 'compact error display')
28
28
  .option('-M, --mode [mode]', 'set other parsing flags according to a format type', 'json')
29
+ .option('-B, --bom', 'ignore the leading UTF-8 byte-order mark')
29
30
  .option('-C, --comments', 'recognize and ignore JavaScript-style comments')
30
31
  .option('-S, --single-quoted-strings', 'support single quotes as string delimiters')
31
32
  .option('-T, --trailing-commas', 'ignore trailing commas in objects and arrays')
@@ -49,7 +50,7 @@ const commander = require('commander')
49
50
  .on('--help', () => {
50
51
  console.log()
51
52
  console.log('You can use BASH patterns for including and excluding files (only files).')
52
- console.log('Patterns are case-sensitive and have to use slashes as a path separators.')
53
+ console.log('Patterns are case-sensitive and have to use slashes as directory separators.')
53
54
  console.log('A pattern to exclude from processing starts with "!".')
54
55
  console.log()
55
56
  console.log('Parsing mode can be "cjson" or "json5" to enable other flags automatically.')
@@ -135,6 +136,7 @@ function processContents (source, file) {
135
136
  try {
136
137
  parserOptions = {
137
138
  mode: options.mode,
139
+ ignoreBOM: options.bom,
138
140
  ignoreComments: options.comments,
139
141
  ignoreTrailingCommas: options.trailingCommas,
140
142
  allowSingleQuotedStrings: options.singleQuotedStrings,
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/lib/jsonlint.js CHANGED
@@ -84,6 +84,12 @@ function isDecDigit (x) {
84
84
  return x >= '0' && x <= '9'
85
85
  }
86
86
 
87
+ function isBOM (x) {
88
+ // This catches EFBBBF (UTF-8 BOM) because the buffer-to-string
89
+ // conversion in `fs.readFileSync()` translates it to FEFF (UTF-16 BOM).
90
+ return x.charCodeAt(0) === 0xFEFF
91
+ }
92
+
87
93
  const unescapeMap = {
88
94
  '\'': '\'',
89
95
  '"': '"',
@@ -103,6 +109,7 @@ function parseInternal (input, options) {
103
109
  }
104
110
 
105
111
  const json5 = options.mode === 'json5'
112
+ const ignoreBOM = options.ignoreBOM
106
113
  const ignoreComments = options.ignoreComments || options.mode === 'cjson' || json5
107
114
  const ignoreTrailingCommas = options.ignoreTrailingCommas || json5
108
115
  const allowSingleQuotedStrings = options.allowSingleQuotedStrings || json5
@@ -289,6 +296,14 @@ function parseInternal (input, options) {
289
296
  }
290
297
  }
291
298
 
299
+ function skipBOM () {
300
+ if (isBOM(input)) {
301
+ startToken && startToken()
302
+ ++position
303
+ endToken && endToken('bom')
304
+ }
305
+ }
306
+
292
307
  function skipWhiteSpace () {
293
308
  let insideWhiteSpace
294
309
  function startWhiteSpace () {
@@ -683,6 +698,9 @@ function parseInternal (input, options) {
683
698
  fail()
684
699
  }
685
700
 
701
+ if (ignoreBOM) {
702
+ skipBOM()
703
+ }
686
704
  skipWhiteSpace()
687
705
  let returnValue = parseGeneric()
688
706
  if (returnValue !== undefined || position < inputLength) {
@@ -929,7 +947,7 @@ const isSafari = typeof navigator !== 'undefined' && /Safari/.test(navigator.use
929
947
  const oldNode = typeof process !== 'undefined' && process.version.startsWith('v4.')
930
948
 
931
949
  function needsCustomParser (options) {
932
- return options.ignoreComments || options.ignoreTrailingCommas ||
950
+ return options.ignoreBOM || options.ignoreComments || options.ignoreTrailingCommas ||
933
951
  options.allowSingleQuotedStrings || options.allowDuplicateObjectKeys === false ||
934
952
  options.mode === 'cjson' || options.mode === 'json5' || isSafari || oldNode
935
953
  }
package/lib/validator.js CHANGED
@@ -148,6 +148,7 @@
148
148
  const ajv = createAjv(environment)
149
149
  const parseOptions = {
150
150
  mode: options.mode,
151
+ ignoreBOM: options.ignoreBOM,
151
152
  ignoreComments: options.ignoreComments,
152
153
  ignoreTrailingCommas: options.ignoreTrailingCommas,
153
154
  allowSingleQuotedStrings: options.allowSingleQuotedStrings,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prantlf/jsonlint",
3
- "version": "11.6.0",
3
+ "version": "11.7.1",
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": [
@@ -16,7 +16,7 @@
16
16
  "url": "https://github.com/prantlf/jsonlint/blob/master/LICENSE"
17
17
  }
18
18
  ],
19
- "homepage": "http://prantlf.github.com/jsonlint/",
19
+ "homepage": "http://prantlf.github.io/jsonlint/",
20
20
  "repository": {
21
21
  "type": "git",
22
22
  "url": "https://github.com/prantlf/jsonlint.git"
@@ -76,28 +76,28 @@
76
76
  },
77
77
  "dependencies": {
78
78
  "ajv": "6.12.6",
79
- "commander": "9.2.0",
79
+ "commander": "9.4.0",
80
80
  "cosmiconfig": "7.0.1",
81
- "diff": "5.0.0",
82
- "fast-glob": "3.2.11"
81
+ "diff": "5.1.0",
82
+ "fast-glob": "3.2.12"
83
83
  },
84
84
  "devDependencies": {
85
85
  "@semantic-release/changelog": "6.0.1",
86
86
  "@semantic-release/git": "10.0.1",
87
- "@types/node": "17.0.31",
88
- "@typescript-eslint/eslint-plugin": "5.22.0",
89
- "@typescript-eslint/parser": "5.22.0",
90
- "eslint": "8.14.0",
87
+ "@types/node": "18.7.21",
88
+ "@typescript-eslint/eslint-plugin": "5.38.0",
89
+ "@typescript-eslint/parser": "5.38.0",
90
+ "eslint": "8.24.0",
91
91
  "eslint-config-standard": "17.0.0",
92
92
  "eslint-plugin-import": "2.26.0",
93
- "eslint-plugin-n": "15.2.0",
94
- "eslint-plugin-promise": "6.0.0",
95
- "http-server": "14.1.0",
93
+ "eslint-plugin-n": "15.3.0",
94
+ "eslint-plugin-promise": "6.0.1",
95
+ "http-server": "14.1.1",
96
96
  "js-yaml": "4.1.0",
97
97
  "nyc": "15.1.0",
98
- "terser": "5.13.1",
98
+ "terser": "5.15.0",
99
99
  "test": "0.6.0",
100
- "typescript": "4.6.4"
100
+ "typescript": "4.8.3"
101
101
  },
102
102
  "keywords": [
103
103
  "json",