Created
April 21, 2022 18:21
-
-
Save findscode/0dd88be05b7bc7f1ae912674eebe2351 to your computer and use it in GitHub Desktop.
TypeScript `CamelCase to UPPER_SNAKE_CASE` type
This file contains 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
type CamelToUpperSnake<T extends string, P extends string = ''> = string extends Uncapitalize<T> ? string : | |
T extends `${infer C0}${infer R}` ? | |
CamelToUpperSnake<R, `${P}${C0 extends Uppercase<C0> ? '_' : ''}${Uppercase<C0>}`> : P; | |
// works with both camelCase and CamelCase |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment