blob: 241202c7e2bb27983e2648a8524a8f3a52d21667 [file] [log] [blame]
Tim van der Lippe6d109a92021-02-16 16:00:32 +00001// Main entrypoint for ESM web browser environments. Avoids using Node.js
2// specific libraries, such as "path".
3//
4// TODO: figure out reasonable web equivalents for "resolve", "normalize", etc.
5import { camelCase, decamelize, looksLikeNumber } from './build/lib/string-utils.js'
6import { YargsParser } from './build/lib/yargs-parser.js'
7const parser = new YargsParser({
8 cwd: () => { return '' },
9 format: (str, arg) => { return str.replace('%s', arg) },
10 normalize: (str) => { return str },
11 resolve: (str) => { return str },
12 require: () => {
13 throw Error('loading config from files not currently supported in browser')
14 },
15 env: () => {}
16})
17
18const yargsParser = function Parser (args, opts) {
19 const result = parser.parse(args.slice(), opts)
20 return result.argv
21}
22yargsParser.detailed = function (args, opts) {
23 return parser.parse(args.slice(), opts)
24}
25yargsParser.camelCase = camelCase
26yargsParser.decamelize = decamelize
27yargsParser.looksLikeNumber = looksLikeNumber
28
29export default yargsParser