(str: string)
| 494 | * @public |
| 495 | */ |
| 496 | export function parseArgs(str: string): string[] { |
| 497 | const args: string[] = [] |
| 498 | let arg = '' |
| 499 | let depth = 0 |
| 500 | let quote = '' |
| 501 | let lastChar = '' |
| 502 | for (let p = 0; p < str.length; p++) { |
| 503 | const char = str.charAt(p) |
| 504 | if (char === quote && lastChar !== '\\') { |
| 505 | quote = '' |
| 506 | } else if ((char === "'" || char === '"') && !quote && lastChar !== '\\') { |
| 507 | quote = char |
| 508 | } else if (char === '(' && !quote) { |
| 509 | depth++ |
| 510 | } else if (char === ')' && !quote) { |
| 511 | depth-- |
| 512 | } |
| 513 | if (char === ',' && !quote && depth === 0) { |
| 514 | args.push(arg) |
| 515 | arg = '' |
| 516 | } else if (char !== ' ' || quote) { |
| 517 | arg += char |
| 518 | } |
| 519 | lastChar = char |
| 520 | } |
| 521 | if (arg) { |
| 522 | args.push(arg) |
| 523 | } |
| 524 | return args |
| 525 | } |
| 526 | |
| 527 | /** |
| 528 | * Return a new (shallow) object with any desired props removed. |
no outgoing calls
no test coverage detected