source: trip-planner-front/node_modules/yargs/lib/platform-shims/browser.mjs@ 6a3a178

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

initial commit

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/* eslint-disable no-unused-vars */
2'use strict';
3
4import cliui from 'https://unpkg.com/cliui@7.0.1/index.mjs'; // eslint-disable-line
5import Parser from 'https://unpkg.com/yargs-parser@19.0.0/browser.js'; // eslint-disable-line
6import {getProcessArgvBin} from '../../build/lib/utils/process-argv.js';
7import {YError} from '../../build/lib/yerror.js';
8
9const REQUIRE_ERROR = 'require is not supported in browser';
10const REQUIRE_DIRECTORY_ERROR =
11 'loading a directory of commands is not supported in browser';
12
13export default {
14 assert: {
15 notStrictEqual: (a, b) => {
16 // noop.
17 },
18 strictEqual: (a, b) => {
19 // noop.
20 },
21 },
22 cliui,
23 findUp: () => undefined,
24 getEnv: key => {
25 // There is no environment in browser:
26 return undefined;
27 },
28 inspect: console.log,
29 getCallerFile: () => {
30 throw new YError(REQUIRE_DIRECTORY_ERROR);
31 },
32 getProcessArgvBin,
33 mainFilename: 'yargs',
34 Parser,
35 path: {
36 basename: str => str,
37 dirname: str => str,
38 extname: str => str,
39 relative: str => str,
40 },
41 process: {
42 argv: () => [],
43 cwd: () => '',
44 emitWarning: (warning, name) => {},
45 execPath: () => '',
46 // exit is noop browser:
47 exit: () => {},
48 nextTick: cb => {
49 // eslint-disable-next-line no-undef
50 window.setTimeout(cb, 1);
51 },
52 stdColumns: 80,
53 },
54 readFileSync: () => {
55 return '';
56 },
57 require: () => {
58 throw new YError(REQUIRE_ERROR);
59 },
60 requireDirectory: () => {
61 throw new YError(REQUIRE_DIRECTORY_ERROR);
62 },
63 stringWidth: str => {
64 return [...str].length;
65 },
66 // TODO: replace this with y18n once it's ported to ESM:
67 y18n: {
68 __: (...str) => {
69 if (str.length === 0) return '';
70 const args = str.slice(1);
71 return sprintf(str[0], ...args);
72 },
73 __n: (str1, str2, count, ...args) => {
74 if (count === 1) {
75 return sprintf(str1, ...args);
76 } else {
77 return sprintf(str2, ...args);
78 }
79 },
80 getLocale: () => {
81 return 'en_US';
82 },
83 setLocale: () => {},
84 updateLocale: () => {},
85 },
86};
87
88function sprintf(_str, ...args) {
89 let str = '';
90 const split = _str.split('%s');
91 split.forEach((token, i) => {
92 str += `${token}${split[i + 1] !== undefined && args[i] ? args[i] : ''}`;
93 });
94 return str;
95}
Note: See TracBrowser for help on using the repository browser.