@jvittechs/jai1-cli 0.1.96 → 0.1.97
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/dist/cli.js +658 -119
- package/dist/cli.js.map +1 -1
- package/dist/web-chat/README.md +418 -0
- package/dist/web-chat/app.js +1527 -0
- package/dist/web-chat/index.html +324 -0
- package/dist/web-chat/node_modules/.bin/0ecdsa-generate-keypair +15 -0
- package/dist/web-chat/node_modules/.bin/0gentesthtml +89 -0
- package/dist/web-chat/node_modules/.bin/0serve +97 -0
- package/dist/web-chat/node_modules/.bin/acorn +4 -0
- package/dist/web-chat/node_modules/.bin/autoprefixer +22 -0
- package/dist/web-chat/node_modules/.bin/baseline-browser-mapping +2 -0
- package/dist/web-chat/node_modules/.bin/browserslist +156 -0
- package/dist/web-chat/node_modules/.bin/esbuild +0 -0
- package/dist/web-chat/node_modules/.bin/jiti +34 -0
- package/dist/web-chat/node_modules/.bin/js-yaml +126 -0
- package/dist/web-chat/node_modules/.bin/jsesc +148 -0
- package/dist/web-chat/node_modules/.bin/json5 +152 -0
- package/dist/web-chat/node_modules/.bin/katex +112 -0
- package/dist/web-chat/node_modules/.bin/loose-envify +16 -0
- package/dist/web-chat/node_modules/.bin/lz-string +13 -0
- package/dist/web-chat/node_modules/.bin/nanoid +55 -0
- package/dist/web-chat/node_modules/.bin/parser +15 -0
- package/dist/web-chat/node_modules/.bin/prebuild-install +78 -0
- package/dist/web-chat/node_modules/.bin/rc +4 -0
- package/dist/web-chat/node_modules/.bin/rollup +1912 -0
- package/dist/web-chat/node_modules/.bin/semver +174 -0
- package/dist/web-chat/node_modules/.bin/tsc +2 -0
- package/dist/web-chat/node_modules/.bin/tsserver +2 -0
- package/dist/web-chat/node_modules/.bin/update-browserslist-db +42 -0
- package/dist/web-chat/node_modules/.bin/uuid +2 -0
- package/dist/web-chat/node_modules/.bin/uvu +35 -0
- package/dist/web-chat/node_modules/.bin/vite +61 -0
- package/dist/web-chat/node_modules/.package-lock.json +15371 -0
- package/dist/web-chat/node_modules/.vite/deps/_metadata.json +67 -0
- package/dist/web-chat/node_modules/.vite/deps/chunk-DC5AMYBS.js +39 -0
- package/dist/web-chat/node_modules/.vite/deps/chunk-DC5AMYBS.js.map +7 -0
- package/dist/web-chat/node_modules/.vite/deps/chunk-NUMECXU6.js +21628 -0
- package/dist/web-chat/node_modules/.vite/deps/chunk-NUMECXU6.js.map +7 -0
- package/dist/web-chat/node_modules/.vite/deps/chunk-RLJ2RCJQ.js +1906 -0
- package/dist/web-chat/node_modules/.vite/deps/chunk-RLJ2RCJQ.js.map +7 -0
- package/dist/web-chat/node_modules/.vite/deps/chunk-S725DACQ.js +928 -0
- package/dist/web-chat/node_modules/.vite/deps/chunk-S725DACQ.js.map +7 -0
- package/dist/web-chat/node_modules/.vite/deps/chunk-XJVUMEYI.js +8578 -0
- package/dist/web-chat/node_modules/.vite/deps/chunk-XJVUMEYI.js.map +7 -0
- package/dist/web-chat/node_modules/.vite/deps/package.json +3 -0
- package/dist/web-chat/node_modules/.vite/deps/react-dom.js +7 -0
- package/dist/web-chat/node_modules/.vite/deps/react-dom.js.map +7 -0
- package/dist/web-chat/node_modules/.vite/deps/react-dom_client.js +39 -0
- package/dist/web-chat/node_modules/.vite/deps/react-dom_client.js.map +7 -0
- package/dist/web-chat/node_modules/.vite/deps/react-markdown.js +8931 -0
- package/dist/web-chat/node_modules/.vite/deps/react-markdown.js.map +7 -0
- package/dist/web-chat/node_modules/.vite/deps/react.js +6 -0
- package/dist/web-chat/node_modules/.vite/deps/react.js.map +7 -0
- package/dist/web-chat/node_modules/.vite/deps/react_jsx-dev-runtime.js +913 -0
- package/dist/web-chat/node_modules/.vite/deps/react_jsx-dev-runtime.js.map +7 -0
- package/dist/web-chat/node_modules/.vite/deps/react_jsx-runtime.js +7 -0
- package/dist/web-chat/node_modules/.vite/deps/react_jsx-runtime.js.map +7 -0
- package/dist/web-chat/node_modules/.vite/deps/remark-gfm.js +7403 -0
- package/dist/web-chat/node_modules/.vite/deps/remark-gfm.js.map +7 -0
- package/dist/web-chat/node_modules/@codemirror/autocomplete/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/commands/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/lang-cpp/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/lang-css/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/lang-go/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/lang-html/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/lang-java/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/lang-javascript/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/lang-json/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/lang-less/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/lang-markdown/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/lang-python/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/lang-rust/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/lang-sass/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/lang-sql/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/lang-wast/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/lang-xml/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/lang-yaml/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/language/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/language-data/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/legacy-modes/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/lint/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/search/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/state/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/theme-one-dark/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@codemirror/view/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/@lezer/html/src/.tern-port +1 -0
- package/dist/web-chat/node_modules/@lezer/php/.tern-port +1 -0
- package/dist/web-chat/node_modules/@lezer/php/test/.tern-port +1 -0
- package/dist/web-chat/node_modules/@lezer/sass/src/.tern-port +1 -0
- package/dist/web-chat/node_modules/@lezer/yaml/.tern-port +1 -0
- package/dist/web-chat/node_modules/@ungap/structured-clone/.github/workflows/node.js.yml +31 -0
- package/dist/web-chat/node_modules/bl/.travis.yml +17 -0
- package/dist/web-chat/node_modules/clean-set/.prettierrc +4 -0
- package/dist/web-chat/node_modules/clean-set/.travis.yml +7 -0
- package/dist/web-chat/node_modules/codemirror/.github/workflows/dispatch.yml +16 -0
- package/dist/web-chat/node_modules/entities/src/generated/.eslintrc.json +10 -0
- package/dist/web-chat/node_modules/es5-ext/promise/.eslintrc.json +1 -0
- package/dist/web-chat/node_modules/es6-iterator/.editorconfig +14 -0
- package/dist/web-chat/node_modules/es6-iterator/test/.eslintrc.json +5 -0
- package/dist/web-chat/node_modules/es6-symbol/.testignore +1 -0
- package/dist/web-chat/node_modules/escape-carriage/.github/workflows/node.js.yml +19 -0
- package/dist/web-chat/node_modules/esniff/.prettierignore +2 -0
- package/dist/web-chat/node_modules/esniff/.testignore +3 -0
- package/dist/web-chat/node_modules/event-emitter/.lint +15 -0
- package/dist/web-chat/node_modules/event-emitter/.testignore +1 -0
- package/dist/web-chat/node_modules/event-emitter/.travis.yml +16 -0
- package/dist/web-chat/node_modules/expand-template/.travis.yml +6 -0
- package/dist/web-chat/node_modules/extend/.editorconfig +20 -0
- package/dist/web-chat/node_modules/extend/.eslintrc +17 -0
- package/dist/web-chat/node_modules/extend/.jscs.json +175 -0
- package/dist/web-chat/node_modules/extend/.travis.yml +230 -0
- package/dist/web-chat/node_modules/gensync/test/.babelrc +5 -0
- package/dist/web-chat/node_modules/github-from-package/.travis.yml +4 -0
- package/dist/web-chat/node_modules/intersection-observer/.eslintrc +45 -0
- package/dist/web-chat/node_modules/lib0/.github/workflows/node.js.yml +24 -0
- package/dist/web-chat/node_modules/lib0/.jsdoc.json +18 -0
- package/dist/web-chat/node_modules/lib0/.vscode/launch.json +17 -0
- package/dist/web-chat/node_modules/minimist/.eslintrc +29 -0
- package/dist/web-chat/node_modules/minimist/.github/FUNDING.yml +12 -0
- package/dist/web-chat/node_modules/minimist/.nycrc +14 -0
- package/dist/web-chat/node_modules/napi-build-utils/.github/workflows/run-npm-tests.yml +31 -0
- package/dist/web-chat/node_modules/next-tick/.editorconfig +16 -0
- package/dist/web-chat/node_modules/next-tick/.github/FUNDING.yml +1 -0
- package/dist/web-chat/node_modules/next-tick/.lint +16 -0
- package/dist/web-chat/node_modules/node-abi/node_modules/.bin/semver +191 -0
- package/dist/web-chat/node_modules/pump/.github/FUNDING.yml +2 -0
- package/dist/web-chat/node_modules/pump/.travis.yml +5 -0
- package/dist/web-chat/node_modules/simple-concat/.travis.yml +3 -0
- package/dist/web-chat/node_modules/simple-get/.github/dependabot.yml +15 -0
- package/dist/web-chat/node_modules/simple-get/.github/workflows/ci.yml +23 -0
- package/dist/web-chat/node_modules/tar-fs/.travis.yml +6 -0
- package/dist/web-chat/node_modules/tar-fs/test/fixtures/e/directory/.ignore +0 -0
- package/dist/web-chat/node_modules/w3c-keyname/.tern-port +1 -0
- package/dist/web-chat/style.css +1882 -0
- package/package.json +4 -2
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
var fs = require('fs')
|
|
4
|
+
var updateDb = require('update-browserslist-db')
|
|
5
|
+
|
|
6
|
+
var browserslist = require('./')
|
|
7
|
+
var pkg = require('./package.json')
|
|
8
|
+
|
|
9
|
+
var args = process.argv.slice(2)
|
|
10
|
+
|
|
11
|
+
var USAGE =
|
|
12
|
+
'Usage:\n' +
|
|
13
|
+
' npx browserslist\n' +
|
|
14
|
+
' npx browserslist "QUERIES"\n' +
|
|
15
|
+
' npx browserslist --json "QUERIES"\n' +
|
|
16
|
+
' npx browserslist --config="path/to/browserlist/file"\n' +
|
|
17
|
+
' npx browserslist --coverage "QUERIES"\n' +
|
|
18
|
+
' npx browserslist --coverage=US "QUERIES"\n' +
|
|
19
|
+
' npx browserslist --coverage=US,RU,global "QUERIES"\n' +
|
|
20
|
+
' npx browserslist --env="environment name defined in config"\n' +
|
|
21
|
+
' npx browserslist --stats="path/to/browserlist/stats/file"\n' +
|
|
22
|
+
' npx browserslist --mobile-to-desktop\n' +
|
|
23
|
+
' npx browserslist --ignore-unknown-versions\n'
|
|
24
|
+
|
|
25
|
+
function isArg(arg) {
|
|
26
|
+
return args.some(function (str) {
|
|
27
|
+
return str === arg || str.indexOf(arg + '=') === 0
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function error(msg) {
|
|
32
|
+
process.stderr.write('browserslist: ' + msg + '\n')
|
|
33
|
+
process.exit(1)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (isArg('--help') || isArg('-h')) {
|
|
37
|
+
process.stdout.write(pkg.description + '.\n\n' + USAGE + '\n')
|
|
38
|
+
} else if (isArg('--version') || isArg('-v')) {
|
|
39
|
+
process.stdout.write('browserslist ' + pkg.version + '\n')
|
|
40
|
+
} else if (isArg('--update-db')) {
|
|
41
|
+
/* c8 ignore next 8 */
|
|
42
|
+
process.stdout.write(
|
|
43
|
+
'The --update-db command is deprecated.\n' +
|
|
44
|
+
'Please use npx update-browserslist-db@latest instead.\n'
|
|
45
|
+
)
|
|
46
|
+
process.stdout.write('Browserslist DB update will still be made.\n')
|
|
47
|
+
updateDb(function (str) {
|
|
48
|
+
process.stdout.write(str)
|
|
49
|
+
})
|
|
50
|
+
} else {
|
|
51
|
+
var mode = 'browsers'
|
|
52
|
+
var opts = {}
|
|
53
|
+
var queries
|
|
54
|
+
var areas
|
|
55
|
+
|
|
56
|
+
for (var i = 0; i < args.length; i++) {
|
|
57
|
+
if (args[i][0] !== '-') {
|
|
58
|
+
queries = args[i].replace(/^["']|["']$/g, '')
|
|
59
|
+
continue
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
var arg = args[i].split('=')
|
|
63
|
+
var name = arg[0]
|
|
64
|
+
var value = arg[1]
|
|
65
|
+
|
|
66
|
+
if (value) value = value.replace(/^["']|["']$/g, '')
|
|
67
|
+
|
|
68
|
+
if (name === '--config' || name === '-b') {
|
|
69
|
+
opts.config = value
|
|
70
|
+
} else if (name === '--env' || name === '-e') {
|
|
71
|
+
opts.env = value
|
|
72
|
+
} else if (name === '--stats' || name === '-s') {
|
|
73
|
+
opts.stats = value
|
|
74
|
+
} else if (name === '--coverage' || name === '-c') {
|
|
75
|
+
if (mode !== 'json') mode = 'coverage'
|
|
76
|
+
if (value) {
|
|
77
|
+
areas = value.split(',')
|
|
78
|
+
} else {
|
|
79
|
+
areas = ['global']
|
|
80
|
+
}
|
|
81
|
+
} else if (name === '--json') {
|
|
82
|
+
mode = 'json'
|
|
83
|
+
} else if (name === '--mobile-to-desktop') {
|
|
84
|
+
/* c8 ignore next */
|
|
85
|
+
opts.mobileToDesktop = true
|
|
86
|
+
} else if (name === '--ignore-unknown-versions') {
|
|
87
|
+
/* c8 ignore next */
|
|
88
|
+
opts.ignoreUnknownVersions = true
|
|
89
|
+
} else {
|
|
90
|
+
error('Unknown arguments ' + args[i] + '.\n\n' + USAGE)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
var browsers
|
|
95
|
+
try {
|
|
96
|
+
browsers = browserslist(queries, opts)
|
|
97
|
+
} catch (e) {
|
|
98
|
+
if (e.name === 'BrowserslistError') {
|
|
99
|
+
error(e.message)
|
|
100
|
+
} /* c8 ignore start */ else {
|
|
101
|
+
throw e
|
|
102
|
+
} /* c8 ignore end */
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
var coverage
|
|
106
|
+
if (mode === 'browsers') {
|
|
107
|
+
browsers.forEach(function (browser) {
|
|
108
|
+
process.stdout.write(browser + '\n')
|
|
109
|
+
})
|
|
110
|
+
} else if (areas) {
|
|
111
|
+
coverage = areas.map(function (area) {
|
|
112
|
+
var stats
|
|
113
|
+
if (area !== 'global') {
|
|
114
|
+
stats = area
|
|
115
|
+
} else if (opts.stats) {
|
|
116
|
+
stats = JSON.parse(fs.readFileSync(opts.stats))
|
|
117
|
+
}
|
|
118
|
+
var result = browserslist.coverage(browsers, stats)
|
|
119
|
+
var round = Math.round(result * 100) / 100.0
|
|
120
|
+
|
|
121
|
+
return [area, round]
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
if (mode === 'coverage') {
|
|
125
|
+
var prefix = 'These browsers account for '
|
|
126
|
+
process.stdout.write(prefix)
|
|
127
|
+
coverage.forEach(function (data, index) {
|
|
128
|
+
var area = data[0]
|
|
129
|
+
var round = data[1]
|
|
130
|
+
var end = 'globally'
|
|
131
|
+
if (area && area !== 'global') {
|
|
132
|
+
end = 'in the ' + area.toUpperCase()
|
|
133
|
+
} else if (opts.stats) {
|
|
134
|
+
end = 'in custom statistics'
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (index !== 0) {
|
|
138
|
+
process.stdout.write(prefix.replace(/./g, ' '))
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
process.stdout.write(round + '% of all users ' + end + '\n')
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (mode === 'json') {
|
|
147
|
+
var data = { browsers: browsers }
|
|
148
|
+
if (coverage) {
|
|
149
|
+
data.coverage = coverage.reduce(function (object, j) {
|
|
150
|
+
object[j[0]] = j[1]
|
|
151
|
+
return object
|
|
152
|
+
}, {})
|
|
153
|
+
}
|
|
154
|
+
process.stdout.write(JSON.stringify(data, null, ' ') + '\n')
|
|
155
|
+
}
|
|
156
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import nodeModule from "node:module";
|
|
5
|
+
|
|
6
|
+
const script = process.argv.splice(2, 1)[0];
|
|
7
|
+
|
|
8
|
+
if (!script) {
|
|
9
|
+
console.error("Usage: jiti <path> [...arguments]");
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// https://nodejs.org/api/module.html#moduleenablecompilecachecachedir
|
|
14
|
+
// https://github.com/nodejs/node/pull/54501
|
|
15
|
+
if (nodeModule.enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) {
|
|
16
|
+
try {
|
|
17
|
+
nodeModule.enableCompileCache();
|
|
18
|
+
} catch {
|
|
19
|
+
// Ignore errors
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const pwd = process.cwd();
|
|
24
|
+
|
|
25
|
+
const { createJiti } = await import("./jiti.cjs");
|
|
26
|
+
|
|
27
|
+
const jiti = createJiti(pwd);
|
|
28
|
+
|
|
29
|
+
const resolved = (process.argv[1] = jiti.resolve(resolve(pwd, script)));
|
|
30
|
+
|
|
31
|
+
await jiti.import(resolved).catch((error) => {
|
|
32
|
+
console.error(error);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
/*eslint-disable no-console*/
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var fs = require('fs');
|
|
10
|
+
var argparse = require('argparse');
|
|
11
|
+
var yaml = require('..');
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var cli = new argparse.ArgumentParser({
|
|
18
|
+
prog: 'js-yaml',
|
|
19
|
+
add_help: true
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
cli.add_argument('-v', '--version', {
|
|
23
|
+
action: 'version',
|
|
24
|
+
version: require('../package.json').version
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
cli.add_argument('-c', '--compact', {
|
|
28
|
+
help: 'Display errors in compact mode',
|
|
29
|
+
action: 'store_true'
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// deprecated (not needed after we removed output colors)
|
|
33
|
+
// option suppressed, but not completely removed for compatibility
|
|
34
|
+
cli.add_argument('-j', '--to-json', {
|
|
35
|
+
help: argparse.SUPPRESS,
|
|
36
|
+
dest: 'json',
|
|
37
|
+
action: 'store_true'
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
cli.add_argument('-t', '--trace', {
|
|
41
|
+
help: 'Show stack trace on error',
|
|
42
|
+
action: 'store_true'
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
cli.add_argument('file', {
|
|
46
|
+
help: 'File to read, utf-8 encoded without BOM',
|
|
47
|
+
nargs: '?',
|
|
48
|
+
default: '-'
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
var options = cli.parse_args();
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
59
|
+
|
|
60
|
+
function readFile(filename, encoding, callback) {
|
|
61
|
+
if (options.file === '-') {
|
|
62
|
+
// read from stdin
|
|
63
|
+
|
|
64
|
+
var chunks = [];
|
|
65
|
+
|
|
66
|
+
process.stdin.on('data', function (chunk) {
|
|
67
|
+
chunks.push(chunk);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
process.stdin.on('end', function () {
|
|
71
|
+
return callback(null, Buffer.concat(chunks).toString(encoding));
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
fs.readFile(filename, encoding, callback);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
readFile(options.file, 'utf8', function (error, input) {
|
|
79
|
+
var output, isYaml;
|
|
80
|
+
|
|
81
|
+
if (error) {
|
|
82
|
+
if (error.code === 'ENOENT') {
|
|
83
|
+
console.error('File not found: ' + options.file);
|
|
84
|
+
process.exit(2);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
console.error(
|
|
88
|
+
options.trace && error.stack ||
|
|
89
|
+
error.message ||
|
|
90
|
+
String(error));
|
|
91
|
+
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
output = JSON.parse(input);
|
|
97
|
+
isYaml = false;
|
|
98
|
+
} catch (err) {
|
|
99
|
+
if (err instanceof SyntaxError) {
|
|
100
|
+
try {
|
|
101
|
+
output = [];
|
|
102
|
+
yaml.loadAll(input, function (doc) { output.push(doc); }, {});
|
|
103
|
+
isYaml = true;
|
|
104
|
+
|
|
105
|
+
if (output.length === 0) output = null;
|
|
106
|
+
else if (output.length === 1) output = output[0];
|
|
107
|
+
|
|
108
|
+
} catch (e) {
|
|
109
|
+
if (options.trace && err.stack) console.error(e.stack);
|
|
110
|
+
else console.error(e.toString(options.compact));
|
|
111
|
+
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
console.error(
|
|
116
|
+
options.trace && err.stack ||
|
|
117
|
+
err.message ||
|
|
118
|
+
String(err));
|
|
119
|
+
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (isYaml) console.log(JSON.stringify(output, null, ' '));
|
|
125
|
+
else console.log(yaml.dump(output));
|
|
126
|
+
});
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
(function() {
|
|
3
|
+
|
|
4
|
+
var fs = require('fs');
|
|
5
|
+
var stringEscape = require('../jsesc.js');
|
|
6
|
+
var strings = process.argv.splice(2);
|
|
7
|
+
var stdin = process.stdin;
|
|
8
|
+
var data;
|
|
9
|
+
var timeout;
|
|
10
|
+
var isObject = false;
|
|
11
|
+
var options = {};
|
|
12
|
+
var log = console.log;
|
|
13
|
+
|
|
14
|
+
var main = function() {
|
|
15
|
+
var option = strings[0];
|
|
16
|
+
|
|
17
|
+
if (/^(?:-h|--help|undefined)$/.test(option)) {
|
|
18
|
+
log(
|
|
19
|
+
'jsesc v%s - https://mths.be/jsesc',
|
|
20
|
+
stringEscape.version
|
|
21
|
+
);
|
|
22
|
+
log([
|
|
23
|
+
'\nUsage:\n',
|
|
24
|
+
'\tjsesc [string]',
|
|
25
|
+
'\tjsesc [-s | --single-quotes] [string]',
|
|
26
|
+
'\tjsesc [-d | --double-quotes] [string]',
|
|
27
|
+
'\tjsesc [-w | --wrap] [string]',
|
|
28
|
+
'\tjsesc [-e | --escape-everything] [string]',
|
|
29
|
+
'\tjsesc [-t | --escape-etago] [string]',
|
|
30
|
+
'\tjsesc [-6 | --es6] [string]',
|
|
31
|
+
'\tjsesc [-l | --lowercase-hex] [string]',
|
|
32
|
+
'\tjsesc [-j | --json] [string]',
|
|
33
|
+
'\tjsesc [-o | --object] [stringified_object]', // `JSON.parse()` the argument
|
|
34
|
+
'\tjsesc [-p | --pretty] [string]', // `compact: false`
|
|
35
|
+
'\tjsesc [-v | --version]',
|
|
36
|
+
'\tjsesc [-h | --help]',
|
|
37
|
+
'\nExamples:\n',
|
|
38
|
+
'\tjsesc \'f\xF6o \u2665 b\xE5r \uD834\uDF06 baz\'',
|
|
39
|
+
'\tjsesc --json \'f\xF6o \u2665 b\xE5r \uD834\uDF06 baz\'',
|
|
40
|
+
'\tjsesc --json --escape-everything \'f\xF6o \u2665 b\xE5r \uD834\uDF06 baz\'',
|
|
41
|
+
'\tjsesc --double-quotes --wrap \'f\xF6o \u2665 b\xE5r \uD834\uDF06 baz\'',
|
|
42
|
+
'\techo \'f\xF6o \u2665 b\xE5r \uD834\uDF06 baz\' | jsesc'
|
|
43
|
+
].join('\n'));
|
|
44
|
+
return process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (/^(?:-v|--version)$/.test(option)) {
|
|
48
|
+
log('v%s', stringEscape.version);
|
|
49
|
+
return process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
strings.forEach(function(string) {
|
|
53
|
+
// Process options
|
|
54
|
+
if (/^(?:-s|--single-quotes)$/.test(string)) {
|
|
55
|
+
options.quotes = 'single';
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (/^(?:-d|--double-quotes)$/.test(string)) {
|
|
59
|
+
options.quotes = 'double';
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (/^(?:-w|--wrap)$/.test(string)) {
|
|
63
|
+
options.wrap = true;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (/^(?:-e|--escape-everything)$/.test(string)) {
|
|
67
|
+
options.escapeEverything = true;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (/^(?:-t|--escape-etago)$/.test(string)) {
|
|
71
|
+
options.escapeEtago = true;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (/^(?:-6|--es6)$/.test(string)) {
|
|
75
|
+
options.es6 = true;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (/^(?:-l|--lowercase-hex)$/.test(string)) {
|
|
79
|
+
options.lowercaseHex = true;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (/^(?:-j|--json)$/.test(string)) {
|
|
83
|
+
options.json = true;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (/^(?:-o|--object)$/.test(string)) {
|
|
87
|
+
isObject = true;
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (/^(?:-p|--pretty)$/.test(string)) {
|
|
91
|
+
isObject = true;
|
|
92
|
+
options.compact = false;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Process string(s)
|
|
97
|
+
var result;
|
|
98
|
+
try {
|
|
99
|
+
if (isObject) {
|
|
100
|
+
string = JSON.parse(string);
|
|
101
|
+
}
|
|
102
|
+
result = stringEscape(string, options);
|
|
103
|
+
log(result);
|
|
104
|
+
} catch(error) {
|
|
105
|
+
log(error.message + '\n');
|
|
106
|
+
log('Error: failed to escape.');
|
|
107
|
+
log('If you think this is a bug in jsesc, please report it:');
|
|
108
|
+
log('https://github.com/mathiasbynens/jsesc/issues/new');
|
|
109
|
+
log(
|
|
110
|
+
'\nStack trace using jsesc@%s:\n',
|
|
111
|
+
stringEscape.version
|
|
112
|
+
);
|
|
113
|
+
log(error.stack);
|
|
114
|
+
return process.exit(1);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
// Return with exit status 0 outside of the `forEach` loop, in case
|
|
118
|
+
// multiple strings were passed in.
|
|
119
|
+
return process.exit(0);
|
|
120
|
+
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
if (stdin.isTTY) {
|
|
124
|
+
// handle shell arguments
|
|
125
|
+
main();
|
|
126
|
+
} else {
|
|
127
|
+
// Either the script is called from within a non-TTY context,
|
|
128
|
+
// or `stdin` content is being piped in.
|
|
129
|
+
if (!process.stdout.isTTY) { // called from a non-TTY context
|
|
130
|
+
timeout = setTimeout(function() {
|
|
131
|
+
// if no piped data arrived after a while, handle shell arguments
|
|
132
|
+
main();
|
|
133
|
+
}, 250);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
data = '';
|
|
137
|
+
stdin.on('data', function(chunk) {
|
|
138
|
+
clearTimeout(timeout);
|
|
139
|
+
data += chunk;
|
|
140
|
+
});
|
|
141
|
+
stdin.on('end', function() {
|
|
142
|
+
strings.push(data.trim());
|
|
143
|
+
main();
|
|
144
|
+
});
|
|
145
|
+
stdin.resume();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
}());
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const pkg = require('../package.json')
|
|
6
|
+
const JSON5 = require('./')
|
|
7
|
+
|
|
8
|
+
const argv = parseArgs()
|
|
9
|
+
|
|
10
|
+
if (argv.version) {
|
|
11
|
+
version()
|
|
12
|
+
} else if (argv.help) {
|
|
13
|
+
usage()
|
|
14
|
+
} else {
|
|
15
|
+
const inFilename = argv.defaults[0]
|
|
16
|
+
|
|
17
|
+
let readStream
|
|
18
|
+
if (inFilename) {
|
|
19
|
+
readStream = fs.createReadStream(inFilename)
|
|
20
|
+
} else {
|
|
21
|
+
readStream = process.stdin
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let json5 = ''
|
|
25
|
+
readStream.on('data', data => {
|
|
26
|
+
json5 += data
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
readStream.on('end', () => {
|
|
30
|
+
let space
|
|
31
|
+
if (argv.space === 't' || argv.space === 'tab') {
|
|
32
|
+
space = '\t'
|
|
33
|
+
} else {
|
|
34
|
+
space = Number(argv.space)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let value
|
|
38
|
+
try {
|
|
39
|
+
value = JSON5.parse(json5)
|
|
40
|
+
if (!argv.validate) {
|
|
41
|
+
const json = JSON.stringify(value, null, space)
|
|
42
|
+
|
|
43
|
+
let writeStream
|
|
44
|
+
|
|
45
|
+
// --convert is for backward compatibility with v0.5.1. If
|
|
46
|
+
// specified with <file> and not --out-file, then a file with
|
|
47
|
+
// the same name but with a .json extension will be written.
|
|
48
|
+
if (argv.convert && inFilename && !argv.outFile) {
|
|
49
|
+
const parsedFilename = path.parse(inFilename)
|
|
50
|
+
const outFilename = path.format(
|
|
51
|
+
Object.assign(
|
|
52
|
+
parsedFilename,
|
|
53
|
+
{base: path.basename(parsedFilename.base, parsedFilename.ext) + '.json'}
|
|
54
|
+
)
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
writeStream = fs.createWriteStream(outFilename)
|
|
58
|
+
} else if (argv.outFile) {
|
|
59
|
+
writeStream = fs.createWriteStream(argv.outFile)
|
|
60
|
+
} else {
|
|
61
|
+
writeStream = process.stdout
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
writeStream.write(json)
|
|
65
|
+
}
|
|
66
|
+
} catch (err) {
|
|
67
|
+
console.error(err.message)
|
|
68
|
+
process.exit(1)
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function parseArgs () {
|
|
74
|
+
let convert
|
|
75
|
+
let space
|
|
76
|
+
let validate
|
|
77
|
+
let outFile
|
|
78
|
+
let version
|
|
79
|
+
let help
|
|
80
|
+
const defaults = []
|
|
81
|
+
|
|
82
|
+
const args = process.argv.slice(2)
|
|
83
|
+
for (let i = 0; i < args.length; i++) {
|
|
84
|
+
const arg = args[i]
|
|
85
|
+
switch (arg) {
|
|
86
|
+
case '--convert':
|
|
87
|
+
case '-c':
|
|
88
|
+
convert = true
|
|
89
|
+
break
|
|
90
|
+
|
|
91
|
+
case '--space':
|
|
92
|
+
case '-s':
|
|
93
|
+
space = args[++i]
|
|
94
|
+
break
|
|
95
|
+
|
|
96
|
+
case '--validate':
|
|
97
|
+
case '-v':
|
|
98
|
+
validate = true
|
|
99
|
+
break
|
|
100
|
+
|
|
101
|
+
case '--out-file':
|
|
102
|
+
case '-o':
|
|
103
|
+
outFile = args[++i]
|
|
104
|
+
break
|
|
105
|
+
|
|
106
|
+
case '--version':
|
|
107
|
+
case '-V':
|
|
108
|
+
version = true
|
|
109
|
+
break
|
|
110
|
+
|
|
111
|
+
case '--help':
|
|
112
|
+
case '-h':
|
|
113
|
+
help = true
|
|
114
|
+
break
|
|
115
|
+
|
|
116
|
+
default:
|
|
117
|
+
defaults.push(arg)
|
|
118
|
+
break
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
convert,
|
|
124
|
+
space,
|
|
125
|
+
validate,
|
|
126
|
+
outFile,
|
|
127
|
+
version,
|
|
128
|
+
help,
|
|
129
|
+
defaults,
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function version () {
|
|
134
|
+
console.log(pkg.version)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function usage () {
|
|
138
|
+
console.log(
|
|
139
|
+
`
|
|
140
|
+
Usage: json5 [options] <file>
|
|
141
|
+
|
|
142
|
+
If <file> is not provided, then STDIN is used.
|
|
143
|
+
|
|
144
|
+
Options:
|
|
145
|
+
|
|
146
|
+
-s, --space The number of spaces to indent or 't' for tabs
|
|
147
|
+
-o, --out-file [file] Output to the specified file, otherwise STDOUT
|
|
148
|
+
-v, --validate Validate JSON5 but do not output JSON
|
|
149
|
+
-V, --version Output the version number
|
|
150
|
+
-h, --help Output usage information`
|
|
151
|
+
)
|
|
152
|
+
}
|