command.js
This file
Path
lib/methods/command.js
27 lines · 813 bytes · JavaScript
Last changed by
Remove `execaCommand()` and `execaCommandSync()` (#1244)Sindre Sorhusbefore adoption3ced394
History of this fileTake it
The walk stopped after 200 commits: lines older than 7cde496 point at it.
Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 1–11why, one step back1// Convert `command` string into an array of file or arguments to pass to $`${...fileOrCommandArguments}`2export const parseCommandString = command => {3 if (typeof command !== 'string') {4 throw new TypeError(`The command must be a string: ${String(command)}.`);5 }67 const trimmedCommand = command.trim();8 if (trimmedCommand === '') {9 return [];10 }11Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 12why, one step back12 const tokens = [];Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 13why, one step back13 for (const token of trimmedCommand.split(SPACES_REGEXP)) {Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 14–23why, one step back14 // Allow spaces to be escaped by a backslash if not meant as a delimiter15 const previousToken = tokens.at(-1);16 if (previousToken && previousToken.endsWith('\\')) {17 // Merge previous token with current one18 tokens[tokens.length - 1] = `${previousToken.slice(0, -1)} ${token}`;19 } else {20 tokens.push(token);21 }22 }23Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 24why, one step back24 return tokens;Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 25–27why, one step back25};2627const SPACES_REGEXP = / +/g;