MCPcopy Create free account
hub / github.com/formkit/formkit / parseArgs

Function parseArgs

packages/utils/src/index.ts:496–525  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

494 * @public
495 */
496export 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.

Callers 2

utils.spec.tsFile · 0.90
evaluateFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected