Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than 7cde496 point at it.

Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3

lines 1–11why, one step back
1// 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 }11

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 12why, one step back
12 const tokens = [];

Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3

line 13why, one step back
13 for (const token of trimmedCommand.split(SPACES_REGEXP)) {

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 14–23why, one step back
14 // Allow spaces to be escaped by a backslash if not meant as a delimiter
15 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 }23

Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3

line 24why, one step back
24 return tokens;

Move API reference to its own page (#996)ehmickybefore adoption7cde496

lines 25–27why, one step back
25};
2627const SPACES_REGEXP = / +/g;