UNPKG

@jahands/dagger-helpers

Version:

dagger.io helpers for my own projects - not meant for public use

34 lines 1.52 kB
/** * Helper type to capitalize the first letter of a string literal type. * e.g., 'hello' -> 'Hello' */ type CapitalizeString<S extends string> = S extends `${infer First}${infer Rest}` ? `${Uppercase<First>}${Rest}` : S; /** * Recursively transforms a snake_case string literal type to camelCase. * e.g., 'SOME_API_KEY' -> 'someApiKey' * 'HELLO_WORLD' -> 'helloWorld' * 'WORD' -> 'word' */ type SnakeToCamelCase<S extends string> = S extends `${infer T}_${infer U}` ? `${Lowercase<T>}${CapitalizeString<SnakeToCamelCase<U>>}` : Lowercase<S>; /** * Converts a string from snake_case, UPPER_SNAKE_CASE, PascalCase, * or ALL_CAPS to camelCase at runtime. * If the string is already camelCase or lowercase, it remains unchanged. * * @param str The input string in snake_case format. * @returns The converted string in camelCase format. */ export declare function snakeToCamel(str: string): string; /** * Converts an object's keys from snake_case or UPPER_SNAKE_CASE to camelCase. * The return type precisely maps the input keys to their camelCase versions. * * @template T The type of the input object, expected to have string keys. * @param input The object with snake_case keys. * @returns A new object with the same values but camelCase keys, with a specific inferred type. */ export declare function convertToCamel<T extends Record<string, any>>(input: T): { [K in keyof T as SnakeToCamelCase<K & string>]: T[K]; }; export {}; //# sourceMappingURL=snake-to-camel.d.ts.map