-
Notifications
You must be signed in to change notification settings - Fork 58
Description
Wouldn't it be nice if we could write things like Strings.Replace<'([A-Z]_?[a-z])|([a-z]_?[A-Z])', '&1-&2'>?
If somebody is up for a type challenge, here is a playground: Playground 😘
import {Pipe, S, T, Compose} from 'hotscript'
export type CamelCase<Str> = Pipe<
Str,
[
S.Replace<"/([a-z])([A-Z])/g", "$1-$2">,
S.Replace<"_", "-">,
S.Split<"-">,
T.Map<Compose<[S.Capitalize, S.Lowercase]>>,
T.Join<"">,
S.Uncapitalize
]
>;
type res1 = CamelCase<"ONE_two-three">;
// ^?
type test1 = Expect<Equal<res1, "oneTwoThree">>;
type res2 = CamelCase<"one_TWO-three">;
// ^?
type test2 = Expect<Equal<res2, "oneTwoThree">>;
type res3 = CamelCase<"one_two-THREE">;
// ^?
type test3 = Expect<Equal<res3, "oneTwoThree">>;
type res4 = CamelCase<"ONE_TWO-THREE">;
// ^?
type test4 = Expect<Equal<res4, "oneTwoThree">>;
type res5 = CamelCase<"alreadyInCamelCase">;
// ^?
type test5 = Expect<Equal<res5, "alreadyInCamelCase">>;Metadata
Metadata
Assignees
Labels
No labels