Skip to content
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

Open
kscory opened this issue Mar 14, 2024 · 4 comments
Open

Type Challenges 612-KebabCase #53

kscory opened this issue Mar 14, 2024 · 4 comments
Labels
Challenges Problems of Typescript-Challenges

Comments

@kscory
Copy link
Member

kscory commented Mar 14, 2024

답안을 작성해주세요.

@kscory kscory added the Challenges Problems of Typescript-Challenges label Mar 14, 2024
@bananana0118
Copy link
Collaborator

type KebabCase<S extends string> =S extends `${infer F}${infer Rest}` ? 
                                  Rest extends Uncapitalize<Rest> ?
                                  `${Uncapitalize<F>}${KebabCase<Rest>}`:
                                  `${Uncapitalize<F>}-${KebabCase<Rest>}`
                                  :S
                                  

미리 대소문자 판단을 한 후 집어넣음

@kscory
Copy link
Member Author

kscory commented Apr 2, 2024

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

@kscory
Copy link
Member Author

kscory commented Apr 2, 2024

type KebabCase<S extends string> =S extends `${infer F}${infer Rest}` ? 
                                  Rest extends Uncapitalize<Rest> ?
                                  `${Uncapitalize<F>}${KebabCase<Rest>}`:
                                  `${Uncapitalize<F>}-${KebabCase<Rest>}`
                                  :S
                                  

미리 대소문자 판단을 한 후 집어넣음

이런 삽질했네요...

@wogha95
Copy link
Member

wogha95 commented Apr 2, 2024

  • 경석님 답안 참고
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
Labels
Challenges Problems of Typescript-Challenges
Projects
None yet
Development

No branches or pull requests

3 participants