feat: Effects that shouldn't be needed removed from utils

This commit is contained in:
BluJ
2023-06-09 10:58:29 -06:00
parent 817913c9df
commit bc80cc974a
8 changed files with 108 additions and 49 deletions

17
lib/util/splitCommand.ts Normal file
View 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)
}