source: trip-planner-front/node_modules/yargs-parser/build/lib/index.js@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/**
2 * @fileoverview Main entrypoint for libraries using yargs-parser in Node.js
3 * CJS and ESM environments.
4 *
5 * @license
6 * Copyright (c) 2016, Contributors
7 * SPDX-License-Identifier: ISC
8 */
9import { format } from 'util';
10import { readFileSync } from 'fs';
11import { normalize, resolve } from 'path';
12import { camelCase, decamelize, looksLikeNumber } from './string-utils.js';
13import { YargsParser } from './yargs-parser.js';
14// See https://github.com/yargs/yargs-parser#supported-nodejs-versions for our
15// version support policy. The YARGS_MIN_NODE_VERSION is used for testing only.
16const minNodeVersion = (process && process.env && process.env.YARGS_MIN_NODE_VERSION)
17 ? Number(process.env.YARGS_MIN_NODE_VERSION)
18 : 10;
19if (process && process.version) {
20 const major = Number(process.version.match(/v([^.]+)/)[1]);
21 if (major < minNodeVersion) {
22 throw Error(`yargs parser supports a minimum Node.js version of ${minNodeVersion}. Read our version support policy: https://github.com/yargs/yargs-parser#supported-nodejs-versions`);
23 }
24}
25// Creates a yargs-parser instance using Node.js standard libraries:
26const env = process ? process.env : {};
27const parser = new YargsParser({
28 cwd: process.cwd,
29 env: () => {
30 return env;
31 },
32 format,
33 normalize,
34 resolve,
35 // TODO: figure out a way to combine ESM and CJS coverage, such that
36 // we can exercise all the lines below:
37 require: (path) => {
38 if (typeof require !== 'undefined') {
39 return require(path);
40 }
41 else if (path.match(/\.json$/)) {
42 return readFileSync(path, 'utf8');
43 }
44 else {
45 throw Error('only .json config files are supported in ESM');
46 }
47 }
48});
49const yargsParser = function Parser(args, opts) {
50 const result = parser.parse(args.slice(), opts);
51 return result.argv;
52};
53yargsParser.detailed = function (args, opts) {
54 return parser.parse(args.slice(), opts);
55};
56yargsParser.camelCase = camelCase;
57yargsParser.decamelize = decamelize;
58yargsParser.looksLikeNumber = looksLikeNumber;
59export default yargsParser;
Note: See TracBrowser for help on using the repository browser.