index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.parseArgsStringToArgv = void 0;
  4. function parseArgsStringToArgv(value, env, file) {
  5. // ([^\s'"]([^\s'"]*(['"])([^\3]*?)\3)+[^\s'"]*) Matches nested quotes until the first space outside of quotes
  6. // [^\s'"]+ or Match if not a space ' or "
  7. // (['"])([^\5]*?)\5 or Match "quoted text" without quotes
  8. // `\3` and `\5` are a backreference to the quote style (' or ") captured
  9. var myRegexp = /([^\s'"]([^\s'"]*(['"])([^\3]*?)\3)+[^\s'"]*)|[^\s'"]+|(['"])([^\5]*?)\5/gi;
  10. var myString = value;
  11. var myArray = [];
  12. if (env) {
  13. myArray.push(env);
  14. }
  15. if (file) {
  16. myArray.push(file);
  17. }
  18. var match;
  19. do {
  20. // Each call to exec returns the next regex match as an array
  21. match = myRegexp.exec(myString);
  22. if (match !== null) {
  23. // Index 1 in the array is the captured group if it exists
  24. // Index 0 is the matched text, which we use if no captured group exists
  25. myArray.push(firstString(match[1], match[6], match[0]));
  26. }
  27. } while (match !== null);
  28. return myArray;
  29. }
  30. exports["default"] = parseArgsStringToArgv;
  31. exports.parseArgsStringToArgv = parseArgsStringToArgv;
  32. // Accepts any number of arguments, and returns the first one that is a string
  33. // (even an empty string)
  34. function firstString() {
  35. var args = [];
  36. for (var _i = 0; _i < arguments.length; _i++) {
  37. args[_i] = arguments[_i];
  38. }
  39. for (var i = 0; i < args.length; i++) {
  40. var arg = args[i];
  41. if (typeof arg === "string") {
  42. return arg;
  43. }
  44. }
  45. }