deno.land / x / astring@v1.8.6 / bin / astring

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env node
const generate = require('../dist/astring').generateconst version = require('../package').versionconst fs = require('fs')const path = require('path')
const argv = process.argv.slice(2)const options = { indent: ' ', lindeEnd: '\n', startingIndentLevel: 0,}const files = []
function printHelp(status) { // eslint-disable-next-line no-console const print = status === 0 ? console.log : console.error const binName = path.basename(process.argv[1]) print('Usage: ' + binName + ' [-h, --help] [-v, --version]') print( ' ' + binName + ' [-i, --indent INDENT] [-l, --line-end LINE_END] [-s, --starting-indent-level LEVEL] files...', ) process.exit(status)}
function printVersion() { // eslint-disable-next-line no-console console.log(version) process.exit(0)}
for (let i = 0, length = argv.length; i < length; i++) { let arg = argv[i] if (arg[0] === '-') { switch (arg) { case '-i': case '--indent': options.indent = argv[++i] break case '-l': case '--line-end': options.lineEnd = argv[++i] break case '-s': case '--starting-indent-level': options.startingIndentLevel = parseInt(argv[++i]) break case '-h': case '--help': printHelp(0) break case '-v': case '--version': printVersion() break default: console.error('Option "' + arg + '" not supported.') printHelp(1) break } } else { files.push(arg) }}
options.output = process.stdout
if (files.length === 0) { let data = '' process.stdin.setEncoding('utf8') process.stdin.resume() process.stdin .on('data', function (chunk) { data += chunk }) .on('end', function () { try { generate(JSON.parse(data), options) } catch (error) { console.error('Error: ' + error.message) process.exit(1) } })} else { let hasError = false for (let i = 0, length = files.length; i < length; i++) { try { let file = files[i] generate(JSON.parse(fs.readFileSync(file, 'utf8')), options) } catch (error) { console.error('Error: ' + error.message) if (hasError !== true) { hasError = true } } } if (hasError) { process.exit(1) }}
astring

Version Info

Tagged at
11 months ago