-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type Challenges 612-KebabCase #53
Labels
Challenges
Problems of Typescript-Challenges
Comments
type KebabCase<S extends string> =S extends `${infer F}${infer Rest}` ?
Rest extends Uncapitalize<Rest> ?
`${Uncapitalize<F>}${KebabCase<Rest>}`:
`${Uncapitalize<F>}-${KebabCase<Rest>}`
:S
미리 대소문자 판단을 한 후 집어넣음 |
type UpperAlphabet = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z' ;
type KebabCase<S> = S extends `${infer F}${infer R}`
? R extends `${UpperAlphabet}${string}`
? `${Lowercase<F>}-${KebabCase<R>}`
: `${Lowercase<F>}${KebabCase<R>}`
: S |
이런 삽질했네요... |
type CapitalAlphabet = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z' ;
type KebabCase<S> = S extends `${infer K}${infer U}`
? U extends `${CapitalAlphabet}${string}`
? `${Lowercase<K>}-${KebabCase<U>}`
: `${Lowercase<K>}${KebabCase<U>}`
: S; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
답안을 작성해주세요.
The text was updated successfully, but these errors were encountered: