@prantlf/jsonlint 10.2.0 → 11.0.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/printer.js CHANGED
@@ -1,7 +1,7 @@
1
1
  (function (global, factory) {
2
- // eslint-disable-next-line no-unused-expressions
2
+ // eslint-disable-next-line no-unused-expressions, multiline-ternary
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports)
4
- // eslint-disable-next-line no-undef
4
+ // eslint-disable-next-line no-undef, multiline-ternary
5
5
  : typeof define === 'function' && define.amd ? define('jsonlint-printer', ['exports'], factory)
6
6
  // eslint-disable-next-line no-undef
7
7
  : (global = global || self, factory(global.jsonlintPrinter = {}))
@@ -15,9 +15,9 @@
15
15
  }
16
16
 
17
17
  function concatenateTokens (tokens) {
18
- var outputString = ''
19
- var tokenCount = tokens.length
20
- var tokenIndex
18
+ let outputString = ''
19
+ const tokenCount = tokens.length
20
+ let tokenIndex
21
21
  for (tokenIndex = 0; tokenIndex < tokenCount; ++tokenIndex) {
22
22
  outputString += tokens[tokenIndex].raw
23
23
  }
@@ -39,32 +39,32 @@
39
39
  return concatenateTokens(tokens)
40
40
  }
41
41
 
42
- var indentString = options.indent
42
+ let indentString = options.indent
43
43
  if (typeof indentString === 'number') {
44
44
  indentString = new Array(indentString + 1).join(' ')
45
45
  }
46
46
  // Setting the indent to an empty string enables pretty-printing too.
47
47
  // It will just insert line breaks without any indentation.
48
- var prettyPrint = indentString !== undefined
49
- var pruneComments = options.pruneComments
50
- var stripObjectKeys = options.stripObjectKeys
51
- var enforceDoubleQuotes = options.enforceDoubleQuotes
52
- var enforceSingleQuotes = options.enforceSingleQuotes
53
- var trimTrailingCommas = options.trimTrailingCommas
48
+ const prettyPrint = indentString !== undefined
49
+ const pruneComments = options.pruneComments
50
+ const stripObjectKeys = options.stripObjectKeys
51
+ const enforceDoubleQuotes = options.enforceDoubleQuotes
52
+ const enforceSingleQuotes = options.enforceSingleQuotes
53
+ const trimTrailingCommas = options.trimTrailingCommas
54
54
 
55
- var outputString = ''
56
- var foundLineBreak, addedLineBreak, needsLineBreak
57
- var addedSpace, needsSpace
58
- var indentLevel = 0
59
- var scopes = []
60
- var scopeType
61
- var isValue
62
- var tokenCount = tokens.length
63
- var tokenIndex, token, tokenType, tokenContent
55
+ let outputString = ''
56
+ let foundLineBreak, addedLineBreak, needsLineBreak
57
+ let addedSpace, needsSpace
58
+ let indentLevel = 0
59
+ const scopes = []
60
+ let scopeType
61
+ let isValue
62
+ const tokenCount = tokens.length
63
+ let tokenIndex, token, tokenType, tokenContent
64
64
 
65
65
  function peekAtNextToken () {
66
- var nextTokenIndex = tokenIndex
67
- var nextToken
66
+ let nextTokenIndex = tokenIndex
67
+ let nextToken
68
68
  do {
69
69
  nextToken = tokens[++nextTokenIndex]
70
70
  } while (nextToken && (nextToken.type === 'whitespace' ||
@@ -72,10 +72,10 @@
72
72
  return nextToken
73
73
  }
74
74
 
75
- var addIndent
75
+ let addIndent
76
76
  if (prettyPrint && indentString) {
77
77
  addIndent = function () {
78
- for (var i = 0; i < indentLevel; ++i) {
78
+ for (let i = 0; i < indentLevel; ++i) {
79
79
  outputString += indentString
80
80
  }
81
81
  }
@@ -83,7 +83,7 @@
83
83
  addIndent = noop
84
84
  }
85
85
 
86
- var addLineBreak, addDelayedSpaceOrLineBreak
86
+ let addLineBreak, addDelayedSpaceOrLineBreak
87
87
  if (prettyPrint) {
88
88
  addLineBreak = function () {
89
89
  outputString += '\n'
@@ -103,7 +103,7 @@
103
103
  addLineBreak = addDelayedSpaceOrLineBreak = noop
104
104
  }
105
105
 
106
- var addStandaloneComment, tryAddingInlineComment
106
+ let addStandaloneComment, tryAddingInlineComment
107
107
  if (pruneComments) {
108
108
  addStandaloneComment = tryAddingInlineComment = noop
109
109
  } else {
@@ -130,10 +130,10 @@
130
130
  addedSpace = false
131
131
 
132
132
  // Start with the character after the just processed one.
133
- var tryTokenIndex = tokenIndex + 1
133
+ let tryTokenIndex = tokenIndex + 1
134
134
 
135
135
  function skipWhitespace () {
136
- var token = tokens[tryTokenIndex]
136
+ let token = tokens[tryTokenIndex]
137
137
  if (token && token.type === 'whitespace') {
138
138
  foundLineBreak = token.raw.indexOf('\n') >= 0
139
139
  token = tokens[++tryTokenIndex]
@@ -141,7 +141,7 @@
141
141
  return token
142
142
  }
143
143
 
144
- var token = skipWhitespace()
144
+ const token = skipWhitespace()
145
145
  // If line break followed the previous token, leave the comment
146
146
  // to be handled by the next usual token processing.
147
147
  if (!foundLineBreak && token && token.type === 'comment') {
@@ -193,7 +193,7 @@
193
193
 
194
194
  function addLiteral () {
195
195
  addDelayedSpaceOrLineBreak()
196
- var tokenValue = token.value
196
+ const tokenValue = token.value
197
197
  if (stripObjectKeys && scopeType === '{' && !isValue &&
198
198
  isIdentifierName(tokenValue)) {
199
199
  outputString += tokenValue
@@ -234,7 +234,7 @@
234
234
 
235
235
  function addComma () {
236
236
  if (trimTrailingCommas) {
237
- var nextToken = peekAtNextToken()
237
+ const nextToken = peekAtNextToken()
238
238
  if (nextToken && nextToken.type === 'symbol') {
239
239
  return tryAddingInlineComment()
240
240
  }
@@ -1,7 +1,10 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define('jsonlintSchemaDrafts', ['exports'], factory) :
4
- (global = global || self, factory(global.jsonlintSchemaDrafts = {}));
2
+ // eslint-disable-next-line no-unused-expressions, multiline-ternary
3
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports)
4
+ // eslint-disable-next-line no-undef, multiline-ternary
5
+ : typeof define === 'function' && define.amd ? define('jsonlintSchemaDrafts', ['exports'], factory)
6
+ // eslint-disable-next-line no-undef
7
+ : (global = global || self, factory(global.jsonlintSchemaDrafts = {}));
5
8
  }(this, function (exports) { 'use strict';
6
9
 
7
10
  exports["json-schema-draft-04"] = {
package/lib/sorter.js CHANGED
@@ -1,7 +1,7 @@
1
1
  (function (global, factory) {
2
- // eslint-disable-next-line no-unused-expressions
2
+ // eslint-disable-next-line no-unused-expressions, multiline-ternary
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports)
4
- // eslint-disable-next-line no-undef
4
+ // eslint-disable-next-line no-undef, multiline-ternary
5
5
  : typeof define === 'function' && define.amd ? define('jsonlint-sorter', ['exports'], factory)
6
6
  // eslint-disable-next-line no-undef
7
7
  : (global = global || self, factory(global.jsonlintSorter = {}))
@@ -9,16 +9,16 @@
9
9
  'use strict'
10
10
 
11
11
  // from http://stackoverflow.com/questions/1359761/sorting-a-json-object-in-javascript
12
- var hasOwnProperty = Object.prototype.hasOwnProperty
12
+ const hasOwnProperty = Object.prototype.hasOwnProperty
13
13
  function sortObject (o) {
14
14
  if (Array.isArray(o)) {
15
15
  return o.map(sortObject)
16
16
  } else if (Object.prototype.toString.call(o) !== '[object Object]') {
17
17
  return o
18
18
  }
19
- var sorted = {}
20
- var key
21
- var a = []
19
+ const sorted = {}
20
+ let key
21
+ const a = []
22
22
  for (key in o) {
23
23
  if (hasOwnProperty.call(o, key)) {
24
24
  a.push(key)
package/lib/validator.js CHANGED
@@ -1,7 +1,7 @@
1
1
  (function (global, factory) {
2
2
  if (typeof exports === 'object' && typeof module !== 'undefined') {
3
- var jsonlint = require('./jsonlint')
4
- var Ajv = require('ajv')
3
+ const jsonlint = require('./jsonlint')
4
+ const Ajv = require('ajv')
5
5
  // eslint-disable-next-line no-inner-declarations
6
6
  function requireSchemaDraft (environment) {
7
7
  return require('ajv/lib/refs/' + environment + '.json')
@@ -20,7 +20,7 @@
20
20
  } else {
21
21
  // eslint-disable-next-line no-undef
22
22
  global = global || self
23
- var requireSchemaDraft = function (environment) {
23
+ const requireSchemaDraft = function (environment) {
24
24
  return global.jsonlintSchemaDrafts[environment]
25
25
  }
26
26
  factory(global.jsonlintValidator = {}, global.Ajv, global.jsonlint, requireSchemaDraft)
@@ -29,24 +29,24 @@
29
29
  'use strict'
30
30
 
31
31
  function addErrorLocation (problem, input, tokens, dataPath) {
32
- var token = tokens.find(function (token) {
32
+ const token = tokens.find(function (token) {
33
33
  return dataPath === jsonlint.pathToPointer(token.path)
34
34
  })
35
35
  if (token) {
36
- var location = token.location.start
37
- var offset = location.offset
38
- var line = location.line
39
- var column = location.column
40
- var texts = jsonlint.getErrorTexts(problem.reason, input, offset, line, column)
36
+ const location = token.location.start
37
+ const offset = location.offset
38
+ const line = location.line
39
+ const column = location.column
40
+ const texts = jsonlint.getErrorTexts(problem.reason, input, offset, line, column)
41
41
  problem.message = texts.message
42
42
  problem.excerpt = texts.excerpt
43
43
  if (texts.pointer) {
44
44
  problem.pointer = texts.pointer
45
45
  problem.location = {
46
46
  start: {
47
- column: column,
48
- line: line,
49
- offset: offset
47
+ column,
48
+ line,
49
+ offset
50
50
  }
51
51
  }
52
52
  }
@@ -55,13 +55,13 @@
55
55
  }
56
56
 
57
57
  function errorToProblem (error, input, tokens) {
58
- var dataPath = error.dataPath
59
- var schemaPath = error.schemaPath
60
- var reason = (dataPath || '/') + ' ' + error.message + '; see ' + schemaPath
61
- var problem = {
62
- reason: reason,
63
- dataPath: dataPath,
64
- schemaPath: schemaPath
58
+ const dataPath = error.dataPath
59
+ const schemaPath = error.schemaPath
60
+ const reason = (dataPath || '/') + ' ' + error.message + '; see ' + schemaPath
61
+ const problem = {
62
+ reason,
63
+ dataPath,
64
+ schemaPath
65
65
  }
66
66
  if (!addErrorLocation(problem, input, tokens, dataPath)) {
67
67
  problem.message = reason
@@ -80,7 +80,7 @@
80
80
  tokenLocations: true,
81
81
  tokenPaths: true
82
82
  })
83
- var tokens = jsonlint.tokenize(input, options)
83
+ const tokens = jsonlint.tokenize(input, options)
84
84
  // var problems = errors.map(function (error) {
85
85
  // return errorToProblem(error, input, tokens)
86
86
  // })
@@ -89,15 +89,15 @@
89
89
  // return problem.message
90
90
  // })
91
91
  // .join('\n')
92
- var problem = errorToProblem(errors[0], input, tokens)
93
- var error = new SyntaxError(problem.message)
92
+ const problem = errorToProblem(errors[0], input, tokens)
93
+ const error = new SyntaxError(problem.message)
94
94
  Object.assign(error, problem)
95
95
  return error
96
96
  }
97
97
 
98
98
  function createAjv (environment) {
99
- var ajvOptions = { jsonPointers: true }
100
- var ajv
99
+ const ajvOptions = { jsonPointers: true }
100
+ let ajv
101
101
  if (!environment) {
102
102
  ajvOptions.schemaId = 'auto'
103
103
  ajv = new Ajv(ajvOptions)
@@ -120,7 +120,7 @@
120
120
  }
121
121
 
122
122
  function compileSchema (ajv, schema, parseOptions) {
123
- var parsed
123
+ let parsed
124
124
  try {
125
125
  parsed = jsonlint.parse(schema, parseOptions)
126
126
  } catch (error) {
@@ -130,8 +130,8 @@
130
130
  try {
131
131
  return ajv.compile(parsed)
132
132
  } catch (originalError) {
133
- var errors = ajv.errors
134
- var betterError = errors
133
+ const errors = ajv.errors
134
+ const betterError = errors
135
135
  ? createError(errors, parsed, schema, parseOptions)
136
136
  : originalError
137
137
  betterError.message = 'Compiling the JSON schema failed.\n' + betterError.message
@@ -140,20 +140,20 @@
140
140
  }
141
141
 
142
142
  function compile (schema, environment) {
143
- var options = {}
143
+ let options = {}
144
144
  if (typeof environment === 'object' && !(environment instanceof String)) {
145
145
  options = environment
146
146
  environment = options.environment
147
147
  }
148
- var ajv = createAjv(environment)
149
- var parseOptions = {
148
+ const ajv = createAjv(environment)
149
+ const parseOptions = {
150
150
  mode: options.mode,
151
151
  ignoreComments: options.ignoreComments,
152
152
  ignoreTrailingCommas: options.ignoreTrailingCommas,
153
153
  allowSingleQuotedStrings: options.allowSingleQuotedStrings,
154
154
  allowDuplicateObjectKeys: options.allowDuplicateObjectKeys
155
155
  }
156
- var validate = compileSchema(ajv, schema, parseOptions)
156
+ const validate = compileSchema(ajv, schema, parseOptions)
157
157
  return function (data, input, options) {
158
158
  if (typeof data === 'string' || data instanceof String) {
159
159
  options = input
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prantlf/jsonlint",
3
- "version": "10.2.0",
4
- "description": "JSON parser, syntax and schema validator and pretty-printer.",
3
+ "version": "11.0.0",
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": [
7
7
  "Greg Inman <ginman@itriagehealth.com>",
@@ -29,16 +29,20 @@
29
29
  "bin": {
30
30
  "jsonlint": "lib/cli.js"
31
31
  },
32
+ "files": [
33
+ "lib",
34
+ "web"
35
+ ],
32
36
  "engines": {
33
- "node": ">= 6"
37
+ "node": ">= 12"
34
38
  },
35
39
  "scripts": {
36
40
  "prepare": "npm run lint && npm run build",
37
41
  "lint": "npm run lint:js && npm run lint:ts",
38
- "lint:js": "standard --fix -v",
39
- "lint:ts": "tslint --fix -t stylish lib/*.ts test/*.ts",
42
+ "lint:js": "eslint --fix lib scripts src test",
43
+ "lint:ts": "eslint -c .tslintrc.yml --fix lib/*.ts test/*.ts",
40
44
  "build": "npm run compile && npm run compile:tests",
41
- "compile": "node scripts/bundle-jsonlint && uglifyjs -o web/jsonlint.min.js --source-map \"filename='jsonlint.js',url='jsonlint.min.js.map',includeSources=true\" lib/jsonlint.js && uglifyjs -o web/validator.min.js --source-map \"filename='validator.js',url='validator.min.js.map',includeSources=true\" lib/validator.js && uglifyjs -o web/formatter.min.js --source-map \"filename='formatter.js',url='formatter.min.js.map',includeSources=true\" lib/formatter.js && uglifyjs -o web/sorter.min.js --source-map \"filename='sorter.js',url='sorter.min.js.map',includeSources=true\" lib/sorter.js && uglifyjs -o web/printer.min.js --source-map \"filename='printer.js',url='printer.min.js.map',includeSources=true\" lib/printer.js && node scripts/bundle-schema-drafts && uglifyjs -o web/schema-drafts.min.js --source-map \"filename='schema-drafts.js',url='schema-drafts.min.js.map',includeSources=true\" lib/schema-drafts.js && uglifyjs -o web/ajv.min.js --source-map \"filename='ajv.js',url='ajv.min.js.map',includeSources=true\" node_modules/ajv/dist/ajv.bundle.js",
45
+ "compile": "node scripts/bundle-jsonlint && terser -o web/jsonlint.min.js --source-map \"filename='jsonlint.js',url='jsonlint.min.js.map',includeSources=true\" lib/jsonlint.js && terser -o web/validator.min.js --source-map \"filename='validator.js',url='validator.min.js.map',includeSources=true\" lib/validator.js && terser -o web/formatter.min.js --source-map \"filename='formatter.js',url='formatter.min.js.map',includeSources=true\" lib/formatter.js && terser -o web/sorter.min.js --source-map \"filename='sorter.js',url='sorter.min.js.map',includeSources=true\" lib/sorter.js && terser -o web/printer.min.js --source-map \"filename='printer.js',url='printer.min.js.map',includeSources=true\" lib/printer.js && node scripts/bundle-schema-drafts && terser -o web/schema-drafts.min.js --source-map \"filename='schema-drafts.js',url='schema-drafts.min.js.map',includeSources=true\" lib/schema-drafts.js && terser -o web/ajv.min.js --source-map \"filename='ajv.js',url='ajv.min.js.map',includeSources=true\" node_modules/ajv/dist/ajv.bundle.js",
42
46
  "compile:tests": "tsc --lib es6 test/typings.test.ts",
43
47
  "test": "nyc --silent node test/typings.test.js && nyc --silent --no-clean node test/parse1 && nyc --silent --no-clean node test/parse1 --native-parser && nyc --silent --no-clean node test/parse2 && nyc --silent --no-clean node test/parse3 && nyc --silent --no-clean node test/parse4 && nyc --silent --no-clean node test/parse5 && nyc --silent --no-clean node test/portable && nyc --silent --no-clean node test/tokenize && nyc --silent --no-clean node test/print && nyc --silent --no-clean node lib/cli package.json test/recursive && nyc --silent --no-clean node lib/cli -sq test/passes/hasOwnProperty.json && nyc --silent --no-clean node lib/cli -s -e json-schema-draft-04 -V test/passes/3.schema.json test/passes/3.json && nyc --silent --no-clean node lib/cli -C test/passes/comments.txt && nyc --silent --no-clean node lib/cli -pS test/passes/strings.txt && nyc --silent --no-clean node lib/cli -M json5 test/passes/json5.text && nyc --silent --no-clean node lib/cli -v && nyc --silent --no-clean node lib/cli -h && nyc --silent --no-clean node lib/cli -Pc test/fails/10.json || nyc report",
44
48
  "start": "http-server -c 5",
@@ -48,6 +52,12 @@
48
52
  "web:sync": "cp web/*.min.* ../jsonlint-pages/ && cp web/jsonlint.html ../jsonlint-pages/index.html",
49
53
  "web:deploy": "cd ../jsonlint-pages && git commit -a -m 'Deploy site updates' && git push origin gh-pages"
50
54
  },
55
+ "nyc": {
56
+ "reporter": [
57
+ "lcov",
58
+ "text"
59
+ ]
60
+ },
51
61
  "standard": {
52
62
  "ignore": [
53
63
  "benchmarks/jison",
@@ -66,19 +76,23 @@
66
76
  "jsonlint"
67
77
  ],
68
78
  "dependencies": {
69
- "ajv": "6.10.2",
70
- "commander": "4.0.1"
79
+ "ajv": "6.12.6",
80
+ "commander": "9.2.0"
71
81
  },
72
82
  "devDependencies": {
73
- "@types/node": "13.1.1",
74
- "http-server": "0.12.0",
75
- "js-yaml": "3.13.1",
76
- "nyc": "15.0.0",
77
- "standard": "14.3.1",
83
+ "@types/node": "17.0.30",
84
+ "@typescript-eslint/eslint-plugin": "5.21.0",
85
+ "@typescript-eslint/parser": "5.21.0",
86
+ "eslint": "8.14.0",
87
+ "eslint-config-standard": "17.0.0",
88
+ "eslint-plugin-import": "2.26.0",
89
+ "eslint-plugin-n": "15.2.0",
90
+ "eslint-plugin-promise": "6.0.0",
91
+ "http-server": "14.1.0",
92
+ "js-yaml": "4.1.0",
93
+ "nyc": "15.1.0",
94
+ "terser": "5.13.1",
78
95
  "test": "0.6.0",
79
- "tslint": "5.20.1",
80
- "tslint-config-standard": "9.0.0",
81
- "typescript": "3.7.4",
82
- "uglify-js": "3.7.3"
96
+ "typescript": "4.6.4"
83
97
  }
84
98
  }