frontend/.pnpm-store/v3/files/60/8b65d937f6dcb24a3c3d351db1bca2b70951597d7d38eec169f472db3c5039cb90da85e34151c8355f3a088055ef097b1cab6314db8e7515027e3ab3dc0a82

55 lines
1.1 KiB
Plaintext

import type {CamelCase, CamelCaseOptions} from './camel-case';
/**
Convert object properties to camel case recursively.
This can be useful when, for example, converting some API types from a different style.
@see CamelCasedProperties
@see CamelCase
@example
```
import type {CamelCasedPropertiesDeep} from 'type-fest';
interface User {
UserId: number;
UserName: string;
}
interface UserWithFriends {
UserInfo: User;
UserFriends: User[];
}
const result: CamelCasedPropertiesDeep<UserWithFriends> = {
userInfo: {
userId: 1,
userName: 'Tom',
},
userFriends: [
{
userId: 2,
userName: 'Jerry',
},
{
userId: 3,
userName: 'Spike',
},
],
};
```
@category Change case
@category Template literal
@category Object
*/
export type CamelCasedPropertiesDeep<Value, Options extends CamelCaseOptions = {preserveConsecutiveUppercase: true}> = Value extends Function
? Value
: Value extends Array<infer U>
? Array<CamelCasedPropertiesDeep<U, Options>>
: Value extends Set<infer U>
? Set<CamelCasedPropertiesDeep<U, Options>> : {
[K in keyof Value as CamelCase<K, Options>]: CamelCasedPropertiesDeep<Value[K], Options>;
};