@prantlf/jsonlint 16.1.0 → 17.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/README.md +5 -2
- package/lib/cli.js +41 -31
- package/lib/index.d.ts +6 -1
- package/lib/printer.js +13 -6
- package/package.json +2 -3
- package/web/printer.min.js +4 -4
- package/web/printer.min.js.map +3 -3
package/README.md
CHANGED
|
@@ -163,7 +163,8 @@ Usage: `jsonlint [options] [--] [<file, directory, pattern> ...]`
|
|
|
163
163
|
--enforce-double-quotes surrounds all strings with double quotes
|
|
164
164
|
--enforce-single-quotes surrounds all strings with single quotes
|
|
165
165
|
--trim-trailing-commas omit trailing commas from objects and arrays
|
|
166
|
-
--
|
|
166
|
+
--no-compact-empty-objects insert line break between empty {} and []
|
|
167
|
+
--force-crlf make sure all line breaks are CRLF
|
|
167
168
|
--succeed-with-no-files succeed (exit code 0) if no files were found
|
|
168
169
|
--[no-]color force or disable colourful output of the diff
|
|
169
170
|
-v, --version output the version number
|
|
@@ -238,6 +239,7 @@ The configuration is an object with the following properties, described above, w
|
|
|
238
239
|
| enforce-double-quotes | enforceDoubleQuotes |
|
|
239
240
|
| enforce-single-quotes | enforceSingleQuotes |
|
|
240
241
|
| trim-trailing-commas | trimTrailingCommas |
|
|
242
|
+
| compact-empty-objects | compactEmptyObjects |
|
|
241
243
|
| force-crlf | forceCrlf |
|
|
242
244
|
|
|
243
245
|
The parameter `config` will be ignored in configuration files. The extra parameter `patterns` can be set to an array of strings with paths or patterns instead of putting them to the command line.
|
|
@@ -349,7 +351,8 @@ The [`print`](#pretty-printing) method accepts an object `options` as the second
|
|
|
349
351
|
| `enforceDoubleQuotes` | will surround all strings with double quotes |
|
|
350
352
|
| `enforceSingleQuotes` | will surround all strings with single quotes |
|
|
351
353
|
| `trimTrailingCommas` | will omit all trailing commas after the last object entry or array item |
|
|
352
|
-
| `
|
|
354
|
+
| `compactEmptyObjects` | if set to `false`, will insert a line break between empty `{}` and `[]` |
|
|
355
|
+
| `forceCrlf` | make sure all line breaks are CRLF |
|
|
353
356
|
|
|
354
357
|
```js
|
|
355
358
|
// Just concatenate the tokens to produce the same output as was the input.
|
package/lib/cli.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const { readdirSync, readFileSync,
|
|
4
|
-
const { extname, join } = require('path')
|
|
5
|
-
const { isDynamicPattern, sync } = require('fast-glob')
|
|
3
|
+
const { globSync, readdirSync, readFileSync, writeFileSync } = require('node:fs')
|
|
4
|
+
const { extname, join } = require('node:path')
|
|
6
5
|
const pico = require('picocolors')
|
|
7
6
|
const { parse, tokenize } = require('./jsonlint')
|
|
8
7
|
const { format } = require('./formatter')
|
|
@@ -58,10 +57,11 @@ Options:
|
|
|
58
57
|
--no-strict disable the strict schema validation mode
|
|
59
58
|
--prune-comments omit comments from the prettified output
|
|
60
59
|
--strip-object-keys strip quotes from object keys if possible
|
|
61
|
-
--enforce-double-quotes
|
|
62
|
-
--enforce-single-quotes
|
|
60
|
+
--enforce-double-quotes surround all strings with double quotes
|
|
61
|
+
--enforce-single-quotes surround all strings with single quotes
|
|
63
62
|
--trim-trailing-commas omit trailing commas from objects and arrays
|
|
64
|
-
--
|
|
63
|
+
--no-compact-empty-objects insert line break between empty {} and []
|
|
64
|
+
--force-crlf make sure all line breaks are CRLF
|
|
65
65
|
--succeed-with-no-files succeed (exit code 0) if no files were found
|
|
66
66
|
--[no-]color force or disable colourful output of the diff
|
|
67
67
|
-v, --version output the version number
|
|
@@ -242,6 +242,9 @@ for (let i = 2, l = argv.length; i < l; ++i) {
|
|
|
242
242
|
case 'trim-trailing-commas':
|
|
243
243
|
params.trimTrailingCommas = flag
|
|
244
244
|
return
|
|
245
|
+
case 'compact-empty-objects':
|
|
246
|
+
params.compactEmptyObjects = flag
|
|
247
|
+
return
|
|
245
248
|
case 'force-crlf':
|
|
246
249
|
params.forceCrlf = flag
|
|
247
250
|
return
|
|
@@ -285,6 +288,7 @@ const paramNames = {
|
|
|
285
288
|
'enforce-double-quotes': 'enforceDoubleQuotes',
|
|
286
289
|
'enforce-single-quotes': 'enforceSingleQuotes',
|
|
287
290
|
'trim-trailing-commas': 'trimTrailingCommas',
|
|
291
|
+
'compact-empty-objects': 'compactEmptyObjects',
|
|
288
292
|
'force-crlf': 'forceCrlf',
|
|
289
293
|
'sort-keys': 'sortKeys',
|
|
290
294
|
'sort-keys-ignore-case': 'sortKeysIgnoreCase',
|
|
@@ -396,6 +400,7 @@ function processContents (source, file) {
|
|
|
396
400
|
enforceDoubleQuotes: params.enforceDoubleQuotes,
|
|
397
401
|
enforceSingleQuotes: params.enforceSingleQuotes,
|
|
398
402
|
trimTrailingCommas: params.trimTrailingCommas,
|
|
403
|
+
compactEmptyObjects: params.compactEmptyObjects,
|
|
399
404
|
forceCrlf: params.forceCrlf
|
|
400
405
|
})
|
|
401
406
|
}
|
|
@@ -583,22 +588,26 @@ function processFile (file) {
|
|
|
583
588
|
}
|
|
584
589
|
}
|
|
585
590
|
|
|
586
|
-
function processSource (
|
|
591
|
+
function processSource (path, isFile, isDirectory, checkExtension) {
|
|
587
592
|
try {
|
|
588
|
-
|
|
589
|
-
if (srcStat.isFile()) {
|
|
593
|
+
if (isFile) {
|
|
590
594
|
if (checkExtension) {
|
|
591
|
-
const ext = extname(
|
|
595
|
+
const ext = extname(path)
|
|
592
596
|
if (extensions.indexOf(ext) < 0) {
|
|
593
597
|
return
|
|
594
598
|
}
|
|
595
599
|
}
|
|
596
|
-
processFile(
|
|
597
|
-
} else if (
|
|
598
|
-
const sources = readdirSync(
|
|
600
|
+
processFile(path)
|
|
601
|
+
} else if (isDirectory) {
|
|
602
|
+
const sources = readdirSync(path, { withFileTypes: true })
|
|
599
603
|
for (const source of sources) {
|
|
600
|
-
|
|
604
|
+
const subpath = join(path, source.name)
|
|
605
|
+
const isFile = source.isFile()
|
|
606
|
+
const isDirectory = source.isDirectory()
|
|
607
|
+
processSource(subpath, isFile, isDirectory, false)
|
|
601
608
|
}
|
|
609
|
+
} else {
|
|
610
|
+
console.warn('WARN', 'Not a file or directory:', path)
|
|
602
611
|
}
|
|
603
612
|
} catch ({ message }) {
|
|
604
613
|
console.warn('WARN', message)
|
|
@@ -606,31 +615,32 @@ function processSource (src, checkExtension) {
|
|
|
606
615
|
}
|
|
607
616
|
|
|
608
617
|
function processPatterns (patterns) {
|
|
609
|
-
const
|
|
610
|
-
|
|
611
|
-
|
|
618
|
+
const include = []
|
|
619
|
+
const exclude = []
|
|
620
|
+
for (const pattern of patterns) {
|
|
621
|
+
if (pattern.startsWith('!')) {
|
|
622
|
+
exclude.push(pattern.slice(1))
|
|
623
|
+
} else {
|
|
624
|
+
include.push(pattern)
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
const sources = globSync(include, { exclude, withFileTypes: true })
|
|
628
|
+
if (!sources.length) {
|
|
629
|
+
console.error('no files or directories found for the input patterns')
|
|
612
630
|
process.exit(params.succeedWithNoFiles ? 0 : 1)
|
|
613
631
|
}
|
|
614
|
-
for (const
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
}
|
|
632
|
+
for (const source of sources) {
|
|
633
|
+
const path = join(source.parentPath, source.name)
|
|
634
|
+
const isFile = source.isFile()
|
|
635
|
+
const isDirectory = source.isDirectory()
|
|
636
|
+
processSource(path, isFile, isDirectory, false)
|
|
620
637
|
}
|
|
621
638
|
}
|
|
622
639
|
|
|
623
640
|
function main () {
|
|
624
641
|
const files = args.length && args || params.patterns || []
|
|
625
642
|
if (files.length) {
|
|
626
|
-
|
|
627
|
-
if (dynamic) {
|
|
628
|
-
processPatterns(files)
|
|
629
|
-
} else {
|
|
630
|
-
for (const file of files) {
|
|
631
|
-
processSource(file, false)
|
|
632
|
-
}
|
|
633
|
-
}
|
|
643
|
+
processPatterns(files)
|
|
634
644
|
} else {
|
|
635
645
|
let source = ''
|
|
636
646
|
const stdin = process.openStdin()
|
package/lib/index.d.ts
CHANGED
|
@@ -508,7 +508,12 @@ declare module '@prantlf/jsonlint/lib/printer' {
|
|
|
508
508
|
trimTrailingCommas?: boolean
|
|
509
509
|
|
|
510
510
|
/**
|
|
511
|
-
*
|
|
511
|
+
* If set to `false`, will insert a line break between empty `{}` and `[]`.
|
|
512
|
+
*/
|
|
513
|
+
compactEmptyObjects?: boolean
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Make sure all line breaks are CRLF.
|
|
512
517
|
*/
|
|
513
518
|
forceCrlf?: boolean
|
|
514
519
|
}
|
package/lib/printer.js
CHANGED
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
const enforceDoubleQuotes = options.enforceDoubleQuotes
|
|
49
49
|
const enforceSingleQuotes = options.enforceSingleQuotes
|
|
50
50
|
const trimTrailingCommas = options.trimTrailingCommas
|
|
51
|
+
const compactEmptyObjects = options.compactEmptyObjects !== false
|
|
51
52
|
const newLineChar = options.forceCrlf === true ? "\r\n" : "\n"
|
|
52
53
|
|
|
53
54
|
let outputString = ''
|
|
@@ -217,6 +218,8 @@
|
|
|
217
218
|
tryAddingInlineComment()
|
|
218
219
|
}
|
|
219
220
|
|
|
221
|
+
let justOpenedScope
|
|
222
|
+
|
|
220
223
|
function openScope () {
|
|
221
224
|
addDelayedSpaceOrLineBreak()
|
|
222
225
|
scopes.push(scopeType)
|
|
@@ -225,15 +228,17 @@
|
|
|
225
228
|
outputString += tokenContent
|
|
226
229
|
tryAddingInlineComment()
|
|
227
230
|
++indentLevel
|
|
228
|
-
needsLineBreak = true
|
|
231
|
+
needsLineBreak = justOpenedScope = true
|
|
229
232
|
}
|
|
230
233
|
|
|
231
234
|
function closeScope () {
|
|
232
235
|
scopeType = scopes.pop()
|
|
233
|
-
addLineBreak()
|
|
234
236
|
--indentLevel
|
|
235
|
-
|
|
236
|
-
|
|
237
|
+
if (!compactEmptyObjects || !justOpenedScope) {
|
|
238
|
+
addLineBreak()
|
|
239
|
+
addIndent()
|
|
240
|
+
}
|
|
241
|
+
needsSpace = needsLineBreak = justOpenedScope = false
|
|
237
242
|
outputString += tokenContent
|
|
238
243
|
tryAddingInlineComment()
|
|
239
244
|
}
|
|
@@ -279,11 +284,11 @@
|
|
|
279
284
|
case '{':
|
|
280
285
|
case '[':
|
|
281
286
|
openScope()
|
|
282
|
-
|
|
287
|
+
continue
|
|
283
288
|
case '}':
|
|
284
289
|
case ']':
|
|
285
290
|
closeScope()
|
|
286
|
-
|
|
291
|
+
continue
|
|
287
292
|
case ',':
|
|
288
293
|
addComma()
|
|
289
294
|
break
|
|
@@ -293,7 +298,9 @@
|
|
|
293
298
|
break
|
|
294
299
|
default: // whitespace
|
|
295
300
|
foundLineBreak = tokenContent.indexOf('\n') >= 0
|
|
301
|
+
continue
|
|
296
302
|
}
|
|
303
|
+
justOpenedScope = false
|
|
297
304
|
}
|
|
298
305
|
|
|
299
306
|
return outputString
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prantlf/jsonlint",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "17.0.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": [
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"web"
|
|
37
37
|
],
|
|
38
38
|
"engines": {
|
|
39
|
-
"node": ">=
|
|
39
|
+
"node": ">=22.2"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "npm run compile:jsonlint && rollup -c && npm run minify && npm run compile:tests",
|
|
@@ -63,7 +63,6 @@
|
|
|
63
63
|
"ajv-keywords": "^5.1.0",
|
|
64
64
|
"cosmiconfig": "9.0.0",
|
|
65
65
|
"diff": "8.0.2",
|
|
66
|
-
"fast-glob": "3.3.3",
|
|
67
66
|
"picocolors": "^1.1.1"
|
|
68
67
|
},
|
|
69
68
|
"devDependencies": {
|
package/web/printer.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(m,
|
|
1
|
+
(function(m,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define("jsonlint-printer",["exports"],s):(m=m||self,s(m.jsonlintPrinter={}))})(this,function(m){"use strict";function s(){}function B(i){return/^[a-zA-Z$_][a-zA-Z0-9$_]*$/.test(i)}function N(i){let o="";const f=i.length;let c;for(c=0;c<f;++c)o+=i[c].raw;return o}function v(i,o){if(!i?.length)throw new Error("JSON tokens missing.");if(!i[0]?.raw)throw new Error("JSON tokens lack raw values.");if(!o)return N(i);let f=o.indent;typeof f=="number"&&(f=new Array(f+1).join(" "));const c=f!==void 0,E=o.pruneComments,Q=o.stripObjectKeys,_=o.enforceDoubleQuotes,$=o.enforceSingleQuotes,D=o.trimTrailingCommas,J=o.compactEmptyObjects!==!1,P=o.forceCrlf===!0?`\r
|
|
2
2
|
`:`
|
|
3
|
-
`;let e="",
|
|
4
|
-
`)>=0,
|
|
5
|
-
`)>=0}return e}m.print=
|
|
3
|
+
`;let e="",y,S,r,L,k,j=0;const I=[];let w,g;const z=i.length;let a,C,A,n;function K(){let t=a,u;do u=i[++t];while(u&&(u.type==="whitespace"||u.type==="comment"));return u}let d;c&&f?d=function(){for(let t=0;t<j;++t)e+=f}:d=s;let p,h;c?(p=function(){e+=P},h=function(){r?(p(),d()):k&&(e+=" "),k=r=!1}):p=h=s;let x,l;E?x=l=s:c?(x=function(){!S&&a>0&&(p(),d()),e+=n,y=!1,S=!1,r=!0},l=function(){y=!1,S=!1,L=!1;let t=a+1;function u(){let b=i[t];return b&&b.type==="whitespace"&&(y=b.raw.indexOf(`
|
|
4
|
+
`)>=0,b=i[++t]),b}const T=u();!y&&T&&T.type==="comment"&&(r?S||(p(),d()):L||(e+=" "),e+=T.raw,a=t++,u(),y?(k=!1,r=!0):(k=!0,r=!1))}):(x=function(){n[1]==="/"?(e+="/*",e+=n.substr(2,n.length-2),e+=" */"):e+=n},l=s);function V(){h();const t=C.value;Q&&w==="{"&&!g&&B(t)?e+=t:typeof t=="string"?_&&n[0]!=='"'?e+=JSON.stringify(t):$&&n[0]!=="'"?e+=`'${t.replace(/'/g,"\\'")}'`:e+=n:e+=n,l()}let O;function Z(){h(),I.push(w),w=n,g=w==="[",e+=n,l(),++j,r=O=!0}function M(){w=I.pop(),--j,(!J||!O)&&(p(),d()),k=r=O=!1,e+=n,l()}function W(){if(D){const t=K();if(t&&t.type==="symbol")return l()}h(),e+=",",l(),p(),d(),S=!0,r=!1,g=w==="["}function q(){h(),e+=":",k=!0,l(),g=!0}for(a=0;a<z;++a){switch(C=i[a],A=C.type,n=C.raw,A){case"literal":V();break;case"comment":x();break;case"symbol":switch(n){case"{":case"[":Z();continue;case"}":case"]":M();continue;case",":W();break;case":":q()}break;default:y=n.indexOf(`
|
|
5
|
+
`)>=0;continue}O=!1}return e}m.print=v,Object.defineProperty(m,"__esModule",{value:!0})});
|
|
6
6
|
//# sourceMappingURL=printer.min.js.map
|
package/web/printer.min.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../lib/printer.js"],
|
|
4
|
-
"sourcesContent": ["(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports)\n : typeof define === 'function' && define.amd ? define('jsonlint-printer', ['exports'], factory)\n : (global = global || self, factory(global.jsonlintPrinter = {}))\n}(this, function (exports) {\n 'use strict'\n\n function noop () {}\n\n function isIdentifierName (value) {\n return /^[a-zA-Z$_][a-zA-Z0-9$_]*$/.test(value)\n }\n\n function concatenateTokens (tokens) {\n let outputString = ''\n const tokenCount = tokens.length\n let tokenIndex\n for (tokenIndex = 0; tokenIndex < tokenCount; ++tokenIndex) {\n outputString += tokens[tokenIndex].raw\n }\n return outputString\n }\n\n function print (tokens, options) {\n if (!(tokens?.length)) {\n throw new Error('JSON tokens missing.')\n }\n // Whitespace and comments are available only as raw token content.\n if (!(tokens[0]?.raw)) {\n throw new Error('JSON tokens lack raw values.')\n }\n\n if (!options) {\n // If no options, not even an empty object is passed, just concatenate\n // the raw tokens with neither minification, nor pretty-printing.\n return concatenateTokens(tokens)\n }\n\n let indentString = options.indent\n if (typeof indentString === 'number') {\n indentString = new Array(indentString + 1).join(' ')\n }\n // Setting the indent to an empty string enables pretty-printing too.\n // It will just insert line breaks without any indentation.\n const prettyPrint = indentString !== undefined\n const pruneComments = options.pruneComments\n const stripObjectKeys = options.stripObjectKeys\n const enforceDoubleQuotes = options.enforceDoubleQuotes\n const enforceSingleQuotes = options.enforceSingleQuotes\n const trimTrailingCommas = options.trimTrailingCommas\n const newLineChar = options.forceCrlf === true ? \"\\r\\n\" : \"\\n\"\n\n let outputString = ''\n let foundLineBreak\n let addedLineBreak\n let needsLineBreak\n let addedSpace\n let needsSpace\n let indentLevel = 0\n const scopes = []\n let scopeType\n let isValue\n const tokenCount = tokens.length\n let tokenIndex\n let token\n let tokenType\n let tokenContent\n\n function peekAtNextToken () {\n let nextTokenIndex = tokenIndex\n let nextToken\n do {\n nextToken = tokens[++nextTokenIndex]\n } while (nextToken && (nextToken.type === 'whitespace' ||\n nextToken.type === 'comment'))\n return nextToken\n }\n\n let addIndent\n if (prettyPrint && indentString) {\n addIndent = function () {\n for (let i = 0; i < indentLevel; ++i) {\n outputString += indentString\n }\n }\n } else {\n addIndent = noop\n }\n\n let addLineBreak\n let addDelayedSpaceOrLineBreak\n if (prettyPrint) {\n addLineBreak = function () {\n outputString += newLineChar\n }\n\n addDelayedSpaceOrLineBreak = function () {\n // A line break is more important than a space.\n if (needsLineBreak) {\n addLineBreak()\n addIndent()\n } else if (needsSpace) {\n outputString += ' '\n }\n needsSpace = needsLineBreak = false\n }\n } else {\n addLineBreak = addDelayedSpaceOrLineBreak = noop\n }\n\n let addStandaloneComment\n let tryAddingInlineComment\n if (pruneComments) {\n addStandaloneComment = tryAddingInlineComment = noop\n } else {\n if (prettyPrint) {\n addStandaloneComment = function () {\n // If a comment is not appended to the end of a line, it will start\n // on a new line with the current indentation.\n if (!addedLineBreak && tokenIndex > 0) {\n addLineBreak()\n addIndent()\n }\n outputString += tokenContent\n foundLineBreak = false\n addedLineBreak = false\n // If a comment is not appended to the end of a line, it will take\n // the whole line and has to end by a line break.\n needsLineBreak = true\n }\n\n tryAddingInlineComment = function () {\n // This function is called after printing a non-line-break character.\n foundLineBreak = false\n addedLineBreak = false\n addedSpace = false\n\n // Start with the character after the just processed one.\n let tryTokenIndex = tokenIndex + 1\n\n function skipWhitespace () {\n let token = tokens[tryTokenIndex]\n if (token && token.type === 'whitespace') {\n foundLineBreak = token.raw.indexOf('\\n') >= 0\n token = tokens[++tryTokenIndex]\n }\n return token\n }\n\n const token = skipWhitespace()\n // If line break followed the previous token, leave the comment\n // to be handled by the next usual token processing.\n if (!foundLineBreak && token && token.type === 'comment') {\n if (needsLineBreak) {\n // If the previous non-whitespace token was ended by a line\n // break, retain it. Print the comment after the line break too.\n if (!addedLineBreak) {\n addLineBreak()\n addIndent()\n }\n } else {\n // If the previous non-whitespace token was not ended by a line\n // break, ensure that the comment is separated from it.\n if (!addedSpace) {\n outputString += ' '\n }\n }\n outputString += token.raw\n // Set the current token to the just processed comment.\n tokenIndex = tryTokenIndex++\n // Check the whitespace after the comment to give a hint\n // about the next whitespace to the further processing.\n skipWhitespace()\n if (foundLineBreak) {\n needsSpace = false\n needsLineBreak = true\n } else {\n needsSpace = true\n needsLineBreak = false\n }\n }\n }\n } else {\n // If all whitespace is omitted, convert single-line comments\n // to multi-line ones, which include a comment-closing token.\n addStandaloneComment = function () {\n if (tokenContent[1] === '/') {\n outputString += '/*'\n outputString += tokenContent.substr(2, tokenContent.length - 2)\n outputString += ' */'\n } else {\n outputString += tokenContent\n }\n }\n\n tryAddingInlineComment = noop\n }\n }\n\n function addLiteral () {\n addDelayedSpaceOrLineBreak()\n const tokenValue = token.value\n if (stripObjectKeys && scopeType === '{' && !isValue &&\n isIdentifierName(tokenValue)) {\n outputString += tokenValue\n } else if (typeof tokenValue === 'string') {\n if (enforceDoubleQuotes && tokenContent[0] !== '\"') {\n outputString += JSON.stringify(tokenValue)\n } else if (enforceSingleQuotes && tokenContent[0] !== '\\'') {\n outputString += `'${tokenValue.replace(/'/g, '\\\\\\'')}'`\n } else {\n outputString += tokenContent\n }\n } else {\n outputString += tokenContent\n }\n tryAddingInlineComment()\n }\n\n function openScope () {\n addDelayedSpaceOrLineBreak()\n scopes.push(scopeType)\n scopeType = tokenContent\n isValue = scopeType === '['\n outputString += tokenContent\n tryAddingInlineComment()\n ++indentLevel\n needsLineBreak = true\n }\n\n function closeScope () {\n scopeType = scopes.pop()\n
|
|
5
|
-
"mappings": "CAAC,SAAUA,EAAQC,EAAS,CAC1B,OAAO,SAAY,UAAY,OAAO,OAAW,IAAcA,EAAQ,OAAO,EAC1E,OAAO,QAAW,YAAc,OAAO,IAAM,OAAO,mBAAoB,CAAC,SAAS,EAAGA,CAAO,GACzFD,EAASA,GAAU,KAAMC,EAAQD,EAAO,gBAAkB,CAAC,CAAC,EACrE,GAAE,KAAM,SAAUE,EAAS,CACzB,aAEA,SAASC,GAAQ,CAAC,CAElB,SAASC,EAAkBC,EAAO,CAChC,MAAO,6BAA6B,KAAKA,CAAK,CAChD,CAEA,SAASC,EAAmBC,EAAQ,CAClC,IAAIC,EAAe,GACnB,MAAMC,EAAaF,EAAO,OAC1B,IAAIG,EACJ,IAAKA,EAAa,EAAGA,EAAaD,EAAY,EAAEC,EAC9CF,GAAgBD,EAAOG,CAAU,EAAE,IAErC,OAAOF,CACT,CAEA,SAASG,EAAOJ,EAAQK,EAAS,CAC/B,GAAI,CAAEL,GAAQ,OACZ,MAAM,IAAI,MAAM,sBAAsB,EAGxC,GAAI,CAAEA,EAAO,CAAC,GAAG,IACf,MAAM,IAAI,MAAM,8BAA8B,EAGhD,GAAI,CAACK,EAGH,OAAON,EAAkBC,CAAM,EAGjC,IAAIM,EAAeD,EAAQ,OACvB,OAAOC,GAAiB,WAC1BA,EAAe,IAAI,MAAMA,EAAe,CAAC,EAAE,KAAK,GAAG,GAIrD,MAAMC,EAAcD,IAAiB,OAC/BE,EAAgBH,EAAQ,cACxBI,EAAkBJ,EAAQ,gBAC1BK,EAAsBL,EAAQ,oBAC9BM,EAAsBN,EAAQ,oBAC9BO,EAAqBP,EAAQ,mBAC7BQ,
|
|
6
|
-
"names": ["global", "factory", "exports", "noop", "isIdentifierName", "value", "concatenateTokens", "tokens", "outputString", "tokenCount", "tokenIndex", "print", "options", "indentString", "prettyPrint", "pruneComments", "stripObjectKeys", "enforceDoubleQuotes", "enforceSingleQuotes", "trimTrailingCommas", "newLineChar", "foundLineBreak", "addedLineBreak", "needsLineBreak", "addedSpace", "needsSpace", "indentLevel", "scopes", "scopeType", "isValue", "token", "tokenType", "tokenContent", "peekAtNextToken", "nextTokenIndex", "nextToken", "addIndent", "i", "addLineBreak", "addDelayedSpaceOrLineBreak", "addStandaloneComment", "tryAddingInlineComment", "tryTokenIndex", "skipWhitespace", "addLiteral", "tokenValue", "openScope", "closeScope", "addComma", "addColon"]
|
|
4
|
+
"sourcesContent": ["(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports)\n : typeof define === 'function' && define.amd ? define('jsonlint-printer', ['exports'], factory)\n : (global = global || self, factory(global.jsonlintPrinter = {}))\n}(this, function (exports) {\n 'use strict'\n\n function noop () {}\n\n function isIdentifierName (value) {\n return /^[a-zA-Z$_][a-zA-Z0-9$_]*$/.test(value)\n }\n\n function concatenateTokens (tokens) {\n let outputString = ''\n const tokenCount = tokens.length\n let tokenIndex\n for (tokenIndex = 0; tokenIndex < tokenCount; ++tokenIndex) {\n outputString += tokens[tokenIndex].raw\n }\n return outputString\n }\n\n function print (tokens, options) {\n if (!(tokens?.length)) {\n throw new Error('JSON tokens missing.')\n }\n // Whitespace and comments are available only as raw token content.\n if (!(tokens[0]?.raw)) {\n throw new Error('JSON tokens lack raw values.')\n }\n\n if (!options) {\n // If no options, not even an empty object is passed, just concatenate\n // the raw tokens with neither minification, nor pretty-printing.\n return concatenateTokens(tokens)\n }\n\n let indentString = options.indent\n if (typeof indentString === 'number') {\n indentString = new Array(indentString + 1).join(' ')\n }\n // Setting the indent to an empty string enables pretty-printing too.\n // It will just insert line breaks without any indentation.\n const prettyPrint = indentString !== undefined\n const pruneComments = options.pruneComments\n const stripObjectKeys = options.stripObjectKeys\n const enforceDoubleQuotes = options.enforceDoubleQuotes\n const enforceSingleQuotes = options.enforceSingleQuotes\n const trimTrailingCommas = options.trimTrailingCommas\n const compactEmptyObjects = options.compactEmptyObjects !== false\n const newLineChar = options.forceCrlf === true ? \"\\r\\n\" : \"\\n\"\n\n let outputString = ''\n let foundLineBreak\n let addedLineBreak\n let needsLineBreak\n let addedSpace\n let needsSpace\n let indentLevel = 0\n const scopes = []\n let scopeType\n let isValue\n const tokenCount = tokens.length\n let tokenIndex\n let token\n let tokenType\n let tokenContent\n\n function peekAtNextToken () {\n let nextTokenIndex = tokenIndex\n let nextToken\n do {\n nextToken = tokens[++nextTokenIndex]\n } while (nextToken && (nextToken.type === 'whitespace' ||\n nextToken.type === 'comment'))\n return nextToken\n }\n\n let addIndent\n if (prettyPrint && indentString) {\n addIndent = function () {\n for (let i = 0; i < indentLevel; ++i) {\n outputString += indentString\n }\n }\n } else {\n addIndent = noop\n }\n\n let addLineBreak\n let addDelayedSpaceOrLineBreak\n if (prettyPrint) {\n addLineBreak = function () {\n outputString += newLineChar\n }\n\n addDelayedSpaceOrLineBreak = function () {\n // A line break is more important than a space.\n if (needsLineBreak) {\n addLineBreak()\n addIndent()\n } else if (needsSpace) {\n outputString += ' '\n }\n needsSpace = needsLineBreak = false\n }\n } else {\n addLineBreak = addDelayedSpaceOrLineBreak = noop\n }\n\n let addStandaloneComment\n let tryAddingInlineComment\n if (pruneComments) {\n addStandaloneComment = tryAddingInlineComment = noop\n } else {\n if (prettyPrint) {\n addStandaloneComment = function () {\n // If a comment is not appended to the end of a line, it will start\n // on a new line with the current indentation.\n if (!addedLineBreak && tokenIndex > 0) {\n addLineBreak()\n addIndent()\n }\n outputString += tokenContent\n foundLineBreak = false\n addedLineBreak = false\n // If a comment is not appended to the end of a line, it will take\n // the whole line and has to end by a line break.\n needsLineBreak = true\n }\n\n tryAddingInlineComment = function () {\n // This function is called after printing a non-line-break character.\n foundLineBreak = false\n addedLineBreak = false\n addedSpace = false\n\n // Start with the character after the just processed one.\n let tryTokenIndex = tokenIndex + 1\n\n function skipWhitespace () {\n let token = tokens[tryTokenIndex]\n if (token && token.type === 'whitespace') {\n foundLineBreak = token.raw.indexOf('\\n') >= 0\n token = tokens[++tryTokenIndex]\n }\n return token\n }\n\n const token = skipWhitespace()\n // If line break followed the previous token, leave the comment\n // to be handled by the next usual token processing.\n if (!foundLineBreak && token && token.type === 'comment') {\n if (needsLineBreak) {\n // If the previous non-whitespace token was ended by a line\n // break, retain it. Print the comment after the line break too.\n if (!addedLineBreak) {\n addLineBreak()\n addIndent()\n }\n } else {\n // If the previous non-whitespace token was not ended by a line\n // break, ensure that the comment is separated from it.\n if (!addedSpace) {\n outputString += ' '\n }\n }\n outputString += token.raw\n // Set the current token to the just processed comment.\n tokenIndex = tryTokenIndex++\n // Check the whitespace after the comment to give a hint\n // about the next whitespace to the further processing.\n skipWhitespace()\n if (foundLineBreak) {\n needsSpace = false\n needsLineBreak = true\n } else {\n needsSpace = true\n needsLineBreak = false\n }\n }\n }\n } else {\n // If all whitespace is omitted, convert single-line comments\n // to multi-line ones, which include a comment-closing token.\n addStandaloneComment = function () {\n if (tokenContent[1] === '/') {\n outputString += '/*'\n outputString += tokenContent.substr(2, tokenContent.length - 2)\n outputString += ' */'\n } else {\n outputString += tokenContent\n }\n }\n\n tryAddingInlineComment = noop\n }\n }\n\n function addLiteral () {\n addDelayedSpaceOrLineBreak()\n const tokenValue = token.value\n if (stripObjectKeys && scopeType === '{' && !isValue &&\n isIdentifierName(tokenValue)) {\n outputString += tokenValue\n } else if (typeof tokenValue === 'string') {\n if (enforceDoubleQuotes && tokenContent[0] !== '\"') {\n outputString += JSON.stringify(tokenValue)\n } else if (enforceSingleQuotes && tokenContent[0] !== '\\'') {\n outputString += `'${tokenValue.replace(/'/g, '\\\\\\'')}'`\n } else {\n outputString += tokenContent\n }\n } else {\n outputString += tokenContent\n }\n tryAddingInlineComment()\n }\n\n let justOpenedScope\n\n function openScope () {\n addDelayedSpaceOrLineBreak()\n scopes.push(scopeType)\n scopeType = tokenContent\n isValue = scopeType === '['\n outputString += tokenContent\n tryAddingInlineComment()\n ++indentLevel\n needsLineBreak = justOpenedScope = true\n }\n\n function closeScope () {\n scopeType = scopes.pop()\n --indentLevel\n if (!compactEmptyObjects || !justOpenedScope) {\n addLineBreak()\n addIndent()\n }\n needsSpace = needsLineBreak = justOpenedScope = false\n outputString += tokenContent\n tryAddingInlineComment()\n }\n\n function addComma () {\n if (trimTrailingCommas) {\n const nextToken = peekAtNextToken()\n if (nextToken && nextToken.type === 'symbol') {\n return tryAddingInlineComment()\n }\n }\n addDelayedSpaceOrLineBreak()\n outputString += ','\n tryAddingInlineComment()\n addLineBreak()\n addIndent()\n addedLineBreak = true\n needsLineBreak = false\n isValue = scopeType === '['\n }\n\n function addColon () {\n addDelayedSpaceOrLineBreak()\n outputString += ':'\n needsSpace = true\n tryAddingInlineComment()\n isValue = true\n }\n\n for (tokenIndex = 0; tokenIndex < tokenCount; ++tokenIndex) {\n token = tokens[tokenIndex]\n tokenType = token.type\n tokenContent = token.raw\n switch (tokenType) {\n case 'literal':\n addLiteral()\n break\n case 'comment':\n addStandaloneComment()\n break\n case 'symbol':\n switch (tokenContent) {\n case '{':\n case '[':\n openScope()\n continue\n case '}':\n case ']':\n closeScope()\n continue\n case ',':\n addComma()\n break\n case ':':\n addColon()\n }\n break\n default: // whitespace\n foundLineBreak = tokenContent.indexOf('\\n') >= 0\n continue\n }\n justOpenedScope = false\n }\n\n return outputString\n }\n\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EACVd,EAAiB,GACjBC,EAAiB,GACjBM,EAAUD,IAAc,GAC1B,CAEA,SAASsB,GAAY,CACnBX,EAA2B,EAC3BhC,GAAgB,IAChBkB,EAAa,GACbgB,EAAuB,EACvBZ,EAAU,EACZ,CAEA,IAAKpB,EAAa,EAAGA,EAAaD,EAAY,EAAEC,EAAY,CAI1D,OAHAqB,EAAQxB,EAAOG,CAAU,EACzBsB,EAAYD,EAAM,KAClBE,EAAeF,EAAM,IACbC,EAAW,CACjB,IAAK,UACHa,EAAW,EACX,MACF,IAAK,UACHJ,EAAqB,EACrB,MACF,IAAK,SACH,OAAQR,EAAc,CACpB,IAAK,IACL,IAAK,IACHe,EAAU,EACV,SACF,IAAK,IACL,IAAK,IACHC,EAAW,EACX,SACF,IAAK,IACHC,EAAS,EACT,MACF,IAAK,IACHC,EAAS,CACb,CACA,MACF,QACE7B,EAAiBW,EAAa,QAAQ;AAAA,CAAI,GAAK,EAC/C,QACJ,CACAc,EAAkB,EACpB,CAEA,OAAOvC,CACT,CAEAN,EAAQ,MAAQS,EAEhB,OAAO,eAAeT,EAAS,aAAc,CAAE,MAAO,EAAK,CAAC,CAC9D,CAAC",
|
|
6
|
+
"names": ["global", "factory", "exports", "noop", "isIdentifierName", "value", "concatenateTokens", "tokens", "outputString", "tokenCount", "tokenIndex", "print", "options", "indentString", "prettyPrint", "pruneComments", "stripObjectKeys", "enforceDoubleQuotes", "enforceSingleQuotes", "trimTrailingCommas", "compactEmptyObjects", "newLineChar", "foundLineBreak", "addedLineBreak", "needsLineBreak", "addedSpace", "needsSpace", "indentLevel", "scopes", "scopeType", "isValue", "token", "tokenType", "tokenContent", "peekAtNextToken", "nextTokenIndex", "nextToken", "addIndent", "i", "addLineBreak", "addDelayedSpaceOrLineBreak", "addStandaloneComment", "tryAddingInlineComment", "tryTokenIndex", "skipWhitespace", "addLiteral", "tokenValue", "justOpenedScope", "openScope", "closeScope", "addComma", "addColon"]
|
|
7
7
|
}
|