@prantlf/jsonlint 11.6.0 → 11.7.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/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/jsonlint.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  type ParseMode = 'json' | 'cjson' | 'json5'
2
2
 
3
3
  interface ParseOptions {
4
+ ignoreBOM?: boolean
4
5
  ignoreComments?: boolean
5
6
  ignoreTrailingCommas?: boolean
6
7
  allowSingleQuotedStrings?: boolean
@@ -27,6 +28,7 @@ interface ParseOptions {
27
28
  declare function parse (input: string, reviverOrOptions?: Function | ParseOptions): object
28
29
 
29
30
  interface TokenizeOptions {
31
+ ignoreBOM?: boolean
30
32
  ignoreComments?: boolean
31
33
  ignoreTrailingCommas?: boolean
32
34
  allowSingleQuotedStrings?: boolean
@@ -58,6 +60,7 @@ declare module '@prantlf/jsonlint/lib/validator' {
58
60
  type Environment = 'json-schema-draft-04' | 'json-schema-draft-06' | 'json-schema-draft-07'
59
61
 
60
62
  interface CompileOptions {
63
+ ignoreBOM?: boolean
61
64
  ignoreComments?: boolean
62
65
  ignoreTrailingCommas?: boolean
63
66
  allowSingleQuotedStrings?: boolean
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.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": [
@@ -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",