-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathpascal-cased-properties-deep.d.ts
More file actions
79 lines (67 loc) · 1.92 KB
/
pascal-cased-properties-deep.d.ts
File metadata and controls
79 lines (67 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import type {CamelCaseOptions, _DefaultCamelCaseOptions} from './camel-case.d.ts';
import type {ApplyDefaultOptions} from './internal/index.d.ts';
import type {PascalCase} from './pascal-case.d.ts';
/**
Convert object properties to pascal case recursively.
This can be useful when, for example, converting some API types from a different style.
@see {@link PascalCase}
@see {@link PascalCasedProperties}
@example
```
import type {PascalCasedPropertiesDeep} from 'type-fest';
type User = {
userId: number;
userName: string;
};
type UserWithFriends = {
userInfo: User;
userFriends: User[];
};
const result: PascalCasedPropertiesDeep<UserWithFriends> = {
UserInfo: {
UserId: 1,
UserName: 'Tom',
},
UserFriends: [
{
UserId: 2,
UserName: 'Jerry',
},
{
UserId: 3,
UserName: 'Spike',
},
],
};
const preserveConsecutiveUppercase: PascalCasedPropertiesDeep<{fooBAR: {fooBARBiz: [{fooBARBaz: string}]}}, {preserveConsecutiveUppercase: true}> = {
FooBAR: {
FooBARBiz: [{
FooBARBaz: 'string',
}],
},
};
const splitOnPunctuation: PascalCasedPropertiesDeep<{'user@info': {'user::id': number; 'user::name': string}}, {splitOnPunctuation: true}> = {
UserInfo: {
UserId: 1,
UserName: 'Tom',
},
};
```
@category Change case
@category Template literal
@category Object
*/
export type PascalCasedPropertiesDeep<Value, Options extends CamelCaseOptions = {}> =
_PascalCasedPropertiesDeep<Value, ApplyDefaultOptions<CamelCaseOptions, _DefaultCamelCaseOptions, Options>>;
type _PascalCasedPropertiesDeep<Value, Options extends Required<CamelCaseOptions>> = Value extends Function | Date | RegExp
? Value
: Value extends Array<infer U>
? Array<_PascalCasedPropertiesDeep<U, Options>>
: Value extends Set<infer U>
? Set<_PascalCasedPropertiesDeep<U, Options>>
: Value extends object
? {
[K in keyof Value as PascalCase<K, Options>]: _PascalCasedPropertiesDeep<Value[K], Options>;
}
: Value;
export {};