index.js 1.5 KB

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