GSI - Employe Self Service Mobile
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.1 KiB

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