type-fest
Version:
A collection of essential TypeScript types
70 lines (58 loc) • 1.5 kB
TypeScript
import type {CamelCaseOptions, CamelCase} from './camel-case.d.ts';
import type {CasedPropertiesDeep} from './internal/cased-properties-deep.d.ts';
import type {CamelCasedProperties} from './camel-cased-properties.d.ts'; // For `@link`
/**
Convert object properties to camel case recursively.
This can be useful when, for example, converting some API types from a different style.
```
import type {CamelCasedPropertiesDeep} from 'type-fest';
type User = {
UserId: number;
UserName: string;
};
type UserWithFriends = {
UserInfo: User;
UserFriends: User[];
};
const result: CamelCasedPropertiesDeep<UserWithFriends> = {
userInfo: {
userId: 1,
userName: 'Tom',
},
userFriends: [
{
userId: 2,
userName: 'Jerry',
},
{
userId: 3,
userName: 'Spike',
},
],
};
const preserveConsecutiveUppercase: CamelCasedPropertiesDeep<{fooBAR: {fooBARBiz: [{fooBARBaz: string}]}}, {preserveConsecutiveUppercase: true}> = {
fooBAR: {
fooBARBiz: [{
fooBARBaz: 'string',
}],
},
};
const noSplitOnPunctuation: CamelCasedPropertiesDeep<{'user@info': {'user::id': number; 'user::name': string}}, {splitOnPunctuation: false}> = {
'user@info': {
'user::id': 1,
'user::name': 'Tom',
},
};
```
*/
export type CamelCasedPropertiesDeep<
Value,
Options extends CamelCaseOptions = {},
> = CasedPropertiesDeep<Value, 'camel', Options>;
export {};