@prantlf/jsonlint 14.0.2 → 14.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/printer.js CHANGED
@@ -22,11 +22,11 @@
22
22
  }
23
23
 
24
24
  function print (tokens, options) {
25
- if (!(tokens && tokens.length)) {
25
+ if (!(tokens?.length)) {
26
26
  throw new Error('JSON tokens missing.')
27
27
  }
28
28
  // Whitespace and comments are available only as raw token content.
29
- if (!(tokens[0] && tokens[0].raw)) {
29
+ if (!(tokens[0]?.raw)) {
30
30
  throw new Error('JSON tokens lack raw values.')
31
31
  }
32
32
 
@@ -50,14 +50,20 @@
50
50
  const trimTrailingCommas = options.trimTrailingCommas
51
51
 
52
52
  let outputString = ''
53
- let foundLineBreak, addedLineBreak, needsLineBreak
54
- let addedSpace, needsSpace
53
+ let foundLineBreak
54
+ let addedLineBreak
55
+ let needsLineBreak
56
+ let addedSpace
57
+ let needsSpace
55
58
  let indentLevel = 0
56
59
  const scopes = []
57
60
  let scopeType
58
61
  let isValue
59
62
  const tokenCount = tokens.length
60
- let tokenIndex, token, tokenType, tokenContent
63
+ let tokenIndex
64
+ let token
65
+ let tokenType
66
+ let tokenContent
61
67
 
62
68
  function peekAtNextToken () {
63
69
  let nextTokenIndex = tokenIndex
@@ -80,7 +86,8 @@
80
86
  addIndent = noop
81
87
  }
82
88
 
83
- let addLineBreak, addDelayedSpaceOrLineBreak
89
+ let addLineBreak
90
+ let addDelayedSpaceOrLineBreak
84
91
  if (prettyPrint) {
85
92
  addLineBreak = function () {
86
93
  outputString += '\n'
@@ -100,7 +107,8 @@
100
107
  addLineBreak = addDelayedSpaceOrLineBreak = noop
101
108
  }
102
109
 
103
- let addStandaloneComment, tryAddingInlineComment
110
+ let addStandaloneComment
111
+ let tryAddingInlineComment
104
112
  if (pruneComments) {
105
113
  addStandaloneComment = tryAddingInlineComment = noop
106
114
  } else {
@@ -198,7 +206,7 @@
198
206
  if (enforceDoubleQuotes && tokenContent[0] !== '"') {
199
207
  outputString += JSON.stringify(tokenValue)
200
208
  } else if (enforceSingleQuotes && tokenContent[0] !== '\'') {
201
- outputString += '\'' + tokenValue.replace(/'/g, '\\\'') + '\''
209
+ outputString += `\'${tokenValue.replace(/'/g, '\\\'')}\'`
202
210
  } else {
203
211
  outputString += tokenContent
204
212
  }
package/lib/sorter.js CHANGED
@@ -6,22 +6,39 @@
6
6
  'use strict'
7
7
 
8
8
  // from http://stackoverflow.com/questions/1359761/sorting-a-json-object-in-javascript
9
- const hasOwnProperty = Object.prototype.hasOwnProperty
10
- function sortObject (o) {
9
+ const ownsProperty = Object.prototype.hasOwnProperty
10
+ function sortObject (o, { ignoreCase, locale, caseFirst, numeric } = {}) {
11
11
  if (Array.isArray(o)) {
12
12
  return o.map(sortObject)
13
- } else if (Object.prototype.toString.call(o) !== '[object Object]') {
13
+ }if (Object.prototype.toString.call(o) !== '[object Object]') {
14
14
  return o
15
15
  }
16
16
  const sorted = {}
17
17
  let key
18
18
  const a = []
19
19
  for (key in o) {
20
- if (hasOwnProperty.call(o, key)) {
20
+ if (ownsProperty.call(o, key)) {
21
21
  a.push(key)
22
22
  }
23
23
  }
24
- a.sort()
24
+ if (locale || caseFirst || numeric) {
25
+ if (locale === 'default') {
26
+ locale = undefined
27
+ }
28
+ const sortOptions = { caseFirst, numeric }
29
+ if (ignoreCase) {
30
+ sortOptions.sensitivity = 'accent'
31
+ }
32
+ a.sort((l, r) => l.localeCompare(r, locale, sortOptions))
33
+ } else if (ignoreCase) {
34
+ a.sort((l, r) => {
35
+ l = l.toLowerCase()
36
+ r = r.toLowerCase()
37
+ return l < r ? -1 : l > r ? 1 : 0
38
+ })
39
+ } else {
40
+ a.sort()
41
+ }
25
42
  for (key = 0; key < a.length; key++) {
26
43
  sorted[a[key]] = sortObject(o[a[key]])
27
44
  }
package/lib/validator.js CHANGED
@@ -63,7 +63,7 @@
63
63
  function errorToProblem (error, input, tokens) {
64
64
  const dataPath = error.dataPath
65
65
  const schemaPath = error.schemaPath
66
- const reason = (dataPath || '/') + ' ' + error.message + '; see ' + schemaPath
66
+ const reason = `${dataPath || '/'} ${error.message}; see ${schemaPath}`
67
67
  const problem = {
68
68
  reason,
69
69
  dataPath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prantlf/jsonlint",
3
- "version": "14.0.2",
3
+ "version": "14.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": [
@@ -40,10 +40,11 @@
40
40
  },
41
41
  "scripts": {
42
42
  "build": "npm run compile:jsonlint && rollup -c && npm run minify && npm run compile:tests",
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",
43
+ "compile:jsonlint": "cat-j 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
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
- "compile:tests": "tsc --moduleResolution node --module es2022 test/types.test.ts && mv.js test/types.test.js test/types.test.mjs",
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",
45
+ "compile:tests": "tsc --moduleResolution node --module es2022 test/types.test.ts && mv-j test/types.test.js test/types.test.mjs",
46
+ "lint": "biome lint *.mjs lib src test/*.js",
47
+ "test": "biome lint *.mjs lib src test/*.js && 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 -r text -r lcov",
47
48
  "start": "http-server -c 5",
48
49
  "web": "npm run web:sync && npm run web:deploy",
49
50
  "web:clone": "test ! -d ../jsonlint-pages && git clone --single-branch --branch gh-pages `git remote get-url origin` ../jsonlint-pages",
@@ -52,53 +53,33 @@
52
53
  "web:deploy": "cd ../jsonlint-pages && git commit -a -m 'Deploy site updates' && git push origin gh-pages"
53
54
  },
54
55
  "c8": {
55
- "reporter": [
56
- "lcov",
57
- "text"
58
- ]
59
- },
60
- "release": {
61
- "plugins": [
62
- "@semantic-release/commit-analyzer",
63
- "@semantic-release/release-notes-generator",
64
- "@semantic-release/changelog",
65
- "@semantic-release/npm",
66
- [
67
- "@semantic-release/github",
68
- {
69
- "failComment": false
70
- }
71
- ],
72
- "@semantic-release/git"
73
- ]
56
+ "reporter": []
74
57
  },
75
58
  "dependencies": {
76
- "ajv": "8.12.0",
59
+ "ajv": "8.17.1",
77
60
  "ajv-draft-04": "1.0.0",
78
- "cosmiconfig": "8.1.0",
79
- "diff": "5.1.0",
80
- "fast-glob": "3.2.12"
61
+ "cosmiconfig": "9.0.0",
62
+ "diff": "5.2.0",
63
+ "fast-glob": "3.3.2"
81
64
  },
82
65
  "devDependencies": {
83
- "@rollup/plugin-commonjs": "24.0.1",
84
- "@rollup/plugin-json": "6.0.0",
85
- "@rollup/plugin-node-resolve": "15.0.1",
86
- "@semantic-release/changelog": "6.0.2",
87
- "@semantic-release/git": "10.0.1",
88
- "@types/node": "18.14.6",
89
- "@unixcompat/cat.js": "1.0.2",
90
- "@unixcompat/mv.js": "1.0.1",
91
- "c8": "7.13.0",
92
- "denolint": "2.0.7",
93
- "esbuild": "0.17.11",
66
+ "@biomejs/biome": "^1.8.3",
67
+ "@rollup/plugin-commonjs": "26.0.1",
68
+ "@rollup/plugin-json": "6.1.0",
69
+ "@rollup/plugin-node-resolve": "15.2.3",
70
+ "@types/node": "22.1.0",
71
+ "@unixcompat/cat.js": "2.0.0",
72
+ "@unixcompat/mv.js": "2.0.0",
73
+ "c8": "10.1.2",
74
+ "esbuild": "0.23.0",
94
75
  "http-server": "14.1.1",
95
76
  "js-yaml": "4.1.0",
96
- "rollup": "3.18.0",
97
- "rollup-plugin-swc-minify": "1.0.5",
77
+ "rollup": "4.20.0",
78
+ "rollup-plugin-swc-minify": "1.1.2",
98
79
  "tehanu": "1.0.1",
99
- "tehanu-repo-coco": "1.0.0",
100
- "tehanu-teru": "1.0.0",
101
- "typescript": "4.9.5"
80
+ "tehanu-repo-coco": "1.0.1",
81
+ "tehanu-teru": "1.0.1",
82
+ "typescript": "5.5.4"
102
83
  },
103
84
  "keywords": [
104
85
  "json",
@@ -106,4 +87,4 @@
106
87
  "lint",
107
88
  "jsonlint"
108
89
  ]
109
- }
90
+ }