command.js
This file
Path
lib/methods/command.js
25 lines · 953 bytes · JavaScript
Last changed by
Upgrade xo (#980)ehmickybefore adoptionccfa412
History of this fileTake it
Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 1–2why, one step back1export const mapCommandAsync = ({file, commandArguments}) => parseCommand(file, commandArguments);2export const mapCommandSync = ({file, commandArguments}) => ({...parseCommand(file, commandArguments), isSync: true});Rename files (#977)ehmickybefore adoption4b2e316
line 3why, one step back3Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 4–6why, one step back4const parseCommand = (command, unusedArguments) => {5 if (unusedArguments.length > 0) {6 throw new TypeError(`The command and its arguments must be passed as a single string: ${command} ${unusedArguments}.`);Rename files (#977)ehmickybefore adoption4b2e316
lines 7–20why, one step back7 }89 const tokens = [];10 for (const token of command.trim().split(SPACES_REGEXP)) {11 // Allow spaces to be escaped by a backslash if not meant as a delimiter12 const previousToken = tokens.at(-1);13 if (previousToken && previousToken.endsWith('\\')) {14 // Merge previous token with current one15 tokens[tokens.length - 1] = `${previousToken.slice(0, -1)} ${token}`;16 } else {17 tokens.push(token);18 }19 }20Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 21–22why, one step back21 const [file, ...commandArguments] = tokens;22 return {file, commandArguments};Rename files (#977)ehmickybefore adoption4b2e316
lines 23–25why, one step back23};2425const SPACES_REGEXP = / +/g;