mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 18:31:54 +00:00
18 lines
487 B
TypeScript
18 lines
487 B
TypeScript
import { arrayOf, string } from "ts-matches"
|
|
import { ValidIfNoStupidEscape } from "../types"
|
|
|
|
export const splitCommand = <A>(
|
|
command: ValidIfNoStupidEscape<A> | [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)
|
|
}
|