@prantlf/jsonlint 13.0.0 → 13.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/lib/validator.js CHANGED
@@ -2,12 +2,11 @@
2
2
  if (typeof exports === 'object' && typeof module !== 'undefined') {
3
3
  const jsonlint = require('./jsonlint')
4
4
  const ajv = {
5
- AjvOld: 'ajv6',
5
+ Ajv04: 'ajv-draft-04',
6
6
  Ajv07: 'ajv',
7
7
  AjvJTD: 'ajv/dist/jtd',
8
8
  Ajv2019: 'ajv/dist/2019',
9
9
  Ajv2020: 'ajv/dist/2020',
10
- Schema04: 'ajv6/lib/refs/json-schema-draft-04.json',
11
10
  Schema06: 'ajv/dist/refs/json-schema-draft-06.json'
12
11
  }
13
12
  const requireAjv = name => {
@@ -16,11 +15,10 @@
16
15
  }
17
16
  factory(exports, jsonlint, requireAjv)
18
17
  } else if (typeof define === 'function' && define.amd) {
19
- define('jsonlint-validator', ['exports', 'jsonlint', 'ajv', 'ajv7'],
20
- function (exports, jsonlint, ajv, ajv7) {
18
+ define('jsonlint-validator', ['exports', 'jsonlint', 'ajv'],
19
+ function (exports, jsonlint, ajv) {
21
20
  const requireAjv = name => {
22
- if (name === 'AjvOld') return ajv
23
- const exported = ajv7[name]
21
+ const exported = ajv[name]
24
22
  return !exported.$schema && exported.default || exported
25
23
  }
26
24
  factory(exports, jsonlint, requireAjv)
@@ -28,8 +26,7 @@
28
26
  } else {
29
27
  global = global || self
30
28
  const requireAjv = name => {
31
- if (name === 'AjvOld') return global.Ajv
32
- const exported = global.ajv7[name]
29
+ const exported = global.ajv[name]
33
30
  return !exported.$schema && exported.default || exported
34
31
  }
35
32
  factory(global.jsonlintValidator = {}, global.jsonlint, requireAjv)
@@ -114,9 +111,8 @@
114
111
  const Ajv = requireAjv('Ajv07')
115
112
  ajv = new Ajv()
116
113
  } else if (environment === 'json-schema-draft-04' || environment === 'draft-04') {
117
- const Ajv = requireAjv('AjvOld')
118
- ajv = new Ajv({ schemaId: 'id' })
119
- ajv.addMetaSchema(requireAjv('Schema04'))
114
+ const Ajv = requireAjv('Ajv04')
115
+ ajv = new Ajv()
120
116
  } else if (environment === 'json-schema-draft-2019-09' || environment === 'draft-2019-09') {
121
117
  const Ajv = requireAjv('Ajv2019')
122
118
  ajv = new Ajv()
@@ -127,28 +123,33 @@
127
123
  const Ajv = requireAjv('AjvJTD')
128
124
  ajv = new Ajv()
129
125
  } else {
130
- throw new RangeError('Unsupported environment for the JSON Schema validation: "' +
131
- environment + '".')
126
+ throw new RangeError(`Unsupported environment for the JSON Schema validation: "${environment}".`)
132
127
  }
133
128
  return ajv
134
129
  }
135
130
 
136
131
  function compileSchema (ajv, schema, parseOptions) {
137
- let parsed
138
- try {
139
- parsed = jsonlint.parse(schema, parseOptions)
140
- } catch (error) {
141
- error.message = 'Parsing the JSON Schema failed.\n' + error.message
142
- throw error
143
- }
132
+ if (!Array.isArray(schema)) schema = [schema]
133
+ const [main, ...others] = schema.map((schema, index) => {
134
+ if (typeof schema !== 'string') return schema
135
+ try {
136
+ return jsonlint.parse(schema, parseOptions)
137
+ } catch (error) {
138
+ error.message = `Parsing the JSON Schema #${index + 1} failed.\n${error.message}`
139
+ throw error
140
+ }
141
+ })
144
142
  try {
145
- return ajv.compile(parsed)
143
+ for (const schema of others) {
144
+ ajv.addSchema(schema)
145
+ }
146
+ return ajv.compile(main)
146
147
  } catch (originalError) {
147
148
  const errors = ajv.errors
148
149
  const betterError = errors
149
150
  ? createError(errors, parsed, schema, parseOptions)
150
151
  : originalError
151
- betterError.message = 'Compiling the JSON Schema failed.\n' + betterError.message
152
+ betterError.message = `Compiling the JSON Schema failed.\n${betterError.message}`
152
153
  throw betterError
153
154
  }
154
155
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prantlf/jsonlint",
3
- "version": "13.0.0",
3
+ "version": "13.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": [
@@ -41,7 +41,7 @@
41
41
  "scripts": {
42
42
  "build": "npm run compile:jsonlint && rollup -c && npm run minify && npm run compile:tests",
43
43
  "compile:jsonlint": "cat.js src/prefix.js.txt src/unicode.js src/custom-parser.js src/pointer.js src/native-parser.js src/configurable-parser.js src/suffix.js.txt > lib/jsonlint.js",
44
- "minify": "esbuild --minify --sourcemap --outfile=web/jsonlint.min.js lib/jsonlint.js && esbuild --minify --sourcemap --outfile=web/validator.min.js lib/validator.js && esbuild --minify --sourcemap --outfile=web/formatter.min.js lib/formatter.js && esbuild --minify --sourcemap --outfile=web/sorter.min.js lib/sorter.js && esbuild --minify --sourcemap --outfile=web/printer.min.js lib/printer.js && esbuild --minify --sourcemap --outfile=web/ajv.min.js node_modules/ajv6/dist/ajv.bundle.js",
44
+ "minify": "esbuild --minify --sourcemap --outfile=web/jsonlint.min.js lib/jsonlint.js && esbuild --minify --sourcemap --outfile=web/validator.min.js lib/validator.js && esbuild --minify --sourcemap --outfile=web/formatter.min.js lib/formatter.js && esbuild --minify --sourcemap --outfile=web/sorter.min.js lib/sorter.js && esbuild --minify --sourcemap --outfile=web/printer.min.js lib/printer.js",
45
45
  "compile:tests": "tsc --moduleResolution node --module es2022 test/types.test.ts && mv.js test/types.test.js test/types.test.mjs",
46
46
  "test": "denolint && c8 node test/types.test.mjs && c8 --no-clean node test/parse1 && c8 --no-clean node test/parse1 --native-parser && c8 --no-clean node test/parse2 && c8 --no-clean node test/parse3 && c8 --no-clean node test/parse4 && c8 --no-clean node test/parse5 && c8 --no-clean node test/portable && c8 --no-clean node test/tokenize && c8 --no-clean node test/print && c8 --no-clean node lib/cli package.json test/recursive && c8 --no-clean node lib/cli -sq test/passes/hasOwnProperty.json && c8 --no-clean node lib/cli -s -e json-schema-draft-04 -V test/passes/schema-04.json test/passes/data-04.json && c8 --no-clean node lib/cli -s -e json-schema-draft-07 -V test/passes/schema-07.json test/passes/data-07.json && c8 --no-clean node lib/cli -C test/passes/comments.txt && c8 --no-clean node lib/cli -pS test/passes/strings.txt && c8 --no-clean node lib/cli -M json5 test/passes/json5.text && c8 --no-clean node lib/cli -v && c8 --no-clean node lib/cli -h && c8 --no-clean node lib/cli -Pc test/fails/10.json || c8 --no-clean node lib/cli -f test/.jsonrc.yml 'test/**/*.json' '!**/fails' && c8 report",
47
47
  "start": "http-server -c 5",
@@ -74,7 +74,7 @@
74
74
  },
75
75
  "dependencies": {
76
76
  "ajv": "8.12.0",
77
- "ajv6": "npm:ajv@6.12.6",
77
+ "ajv-draft-04": "1.0.0",
78
78
  "commander": "10.0.0",
79
79
  "cosmiconfig": "8.1.0",
80
80
  "diff": "5.1.0",