mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 18:31:52 +00:00
17 lines
417 B
TypeScript
17 lines
417 B
TypeScript
import { arrayOf, string } from "ts-matches"
|
|
|
|
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)
|
|
}
|