Camelize
提出詳細
type _ToCamel<S extends string, A extends string = ""> = S extends `${infer L}_${infer R}` ? `${Capitalize<L>}${_ToCamel<R>}` : Capitalize<S> type SnakeToCamel<S extends string> = Uncapitalize<_ToCamel<S>> type CamelizeArray<T extends unknown[]> = T extends [infer L, ...infer R] ? [Camelize<L>, ...CamelizeArray<R>] : [] type Camelize<T> = T extends Record<string, unknown> ? { [P in keyof T as P extends string ? SnakeToCamel<P> : never]: Camelize<T[P]> } : T extends unknown[] ? CamelizeArray<T> : T
提出日時 | 2024-09-12 15:14:43 |
---|---|
問題 | Camelize |
ユーザー | ookkoouu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal< Camelize<{ some_prop: string prop: { another_prop: string } array: [{ snake_case: string }] }>, { someProp: string prop: { anotherProp: string } array: [{ snakeCase: string }] } >>, ]