All files / util splitCommand.ts

100% Statements 9/9
100% Branches 5/5
100% Functions 4/4
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 181x     1x     13x 9x     15x   16x   92x      
import { arrayOf, string } from "ts-matches"
import { ValidIfNoStupidEscape } from "../types"
 
export const splitCommand = (
  command: string | [string, ...string[]],
): string[] => {
  if (arrayOf(string).test(command)) return command
  return String(command)
    .split('"')
    .flatMap((x, i) =>
      i % 2 !== 0
        ? [x]
        : x.split("'").flatMap((x, i) => (i % 2 !== 0 ? [x] : x.split(" "))),
    )
    .map((x) => x.trim())
    .filter(Boolean)
}