Skip to content

Instantly share code, notes, and snippets.

View sepsol's full-sized avatar
:electron:
Hyperstate

Sepehr Soltanieh sepsol

:electron:
Hyperstate
View GitHub Profile
@sepsol
sepsol / camelCase-snake_case-types.ts
Created March 6, 2023 21:19 — forked from kuroski/camelCase-snake_case-types.ts
Typescript type camelCase / snake_case conversion
type CamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}`
? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}`
: Lowercase<S>
type KeysToCamelCase<T> = {
[K in keyof T as CamelCase<string & K>]: T[K]
}
type CamelToSnakeCase<S extends string> = S extends `${infer T}${infer U}` ?