Created
July 20, 2024 20:14
-
-
Save fgalassi/d4797738468292b7e1b9ba76ec57d623 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This is tricky because you cannot do Str extends `${infer Before}${UnionOfSep}${infer After}` ... | |
| type Split<Str, UnionOfSep extends string, CurrentWord extends string = "", Output extends string[] = []> = | |
| Str extends `${infer First}${infer Rest}` | |
| ? First extends UnionOfSep | |
| ? Split<Rest, UnionOfSep, "", [...Output, CurrentWord]> | |
| : Split<Rest, UnionOfSep, `${CurrentWord}${First}`, Output> | |
| : [...Output, CurrentWord]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment