mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 18:31:54 +00:00
feat: Effects that shouldn't be needed removed from utils
This commit is contained in:
17
lib/util/splitCommand.ts
Normal file
17
lib/util/splitCommand.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user