1 | type IsStringLiteral<Type> = Type extends string ? (string extends Type ? false : true) : false;
|
2 | type WordInCamelCase<Type, Word extends string = ""> = Type extends `${Word}${infer NextCharacter}${infer _}` ? NextCharacter extends Capitalize<NextCharacter> ? Word : WordInCamelCase<Type, `${Word}${NextCharacter}`> : Word;
|
3 | type Separator = "_" | "-";
|
4 | type IncludesSeparator<Type> = Type extends `${string}${Separator}${string}` ? true : false;
|
5 | type IsOneWord<Type> = Type extends Lowercase<Type & string> ? true : Type extends Uppercase<Type & string> ? true : false;
|
6 | type IsCamelCase<Type> = Type extends Uncapitalize<Type & string> ? true : false;
|
7 | type IsPascalCase<Type> = Type extends Capitalize<Type & string> ? true : false;
|
8 |
|
9 | type SeparatorCaseParser<Type, Tuple extends readonly any[] = []> = Type extends `${infer Word}${Separator}${infer Tail}` ? SeparatorCaseParser<Tail, [...Tuple, Lowercase<Word>]> : Type extends `${infer Word}` ? [...Tuple, Lowercase<Word>] : Tuple;
|
10 | type CamelCaseParser<Type, Tuple extends readonly any[] = []> = Type extends "" ? Tuple : Type extends `${WordInCamelCase<Type>}${infer Tail}` ? Type extends `${infer Word}${Tail}` ? CamelCaseParser<Uncapitalize<Tail>, [...Tuple, Lowercase<Word>]> : never : never;
|
11 | type PascalCaseParser<Type> = Type extends string ? CamelCaseParser<Uncapitalize<Type>> : never;
|
12 | type SplitAnyCase<Type> = IncludesSeparator<Type> extends true ? SeparatorCaseParser<Type> : IsOneWord<Type> extends true ? [Lowercase<Type & string>] : IsCamelCase<Type> extends true ? CamelCaseParser<Type> : IsPascalCase<Type> extends true ? PascalCaseParser<Type> : [];
|
13 | type PascalCapitalizer<Type, Tuple extends readonly any[] = []> = Type extends [infer Head, ...infer Tail] ? Head extends string ? PascalCapitalizer<Tail, [...Tuple, Capitalize<Head>]> : PascalCapitalizer<Tail, Tuple> : Tuple;
|
14 | type CamelCapitalizer<Type> = Type extends [infer First, ...infer Tail] ? PascalCapitalizer<Tail, [First]> : [];
|
15 | type Join<Type, JoinedString extends string = ""> = Type extends [infer Head, ...infer Tail] ? Head extends string ? Join<Tail, `${JoinedString}${Head}`> : Join<Tail> : JoinedString;
|
16 | export type CamelCase<Type> = IsStringLiteral<Type> extends true ? Join<CamelCapitalizer<SplitAnyCase<Type>>> : Type;
|
17 | export {};
|