-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathsnake-cased-properties-deep.d.ts
More file actions
72 lines (61 loc) · 1.54 KB
/
snake-cased-properties-deep.d.ts
File metadata and controls
72 lines (61 loc) · 1.54 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
import type {_DefaultDelimiterCaseOptions} from './delimiter-case.d.ts';
import type {DelimiterCasedPropertiesDeep} from './delimiter-cased-properties-deep.d.ts';
import type {ApplyDefaultOptions} from './internal/index.d.ts';
import type {WordsOptions} from './words.d.ts';
/**
Convert object properties to snake case recursively.
This can be useful when, for example, converting some API types from a different style.
@see {@link SnakeCase}
@see {@link SnakeCasedProperties}
@example
```
import type {SnakeCasedPropertiesDeep} from 'type-fest';
type User = {
userId: number;
userName: string;
};
type UserWithFriends = {
userInfo: User;
userFriends: User[];
};
const result: SnakeCasedPropertiesDeep<UserWithFriends> = {
user_info: {
user_id: 1,
user_name: 'Tom',
},
user_friends: [
{
user_id: 2,
user_name: 'Jerry',
},
{
user_id: 3,
user_name: 'Spike',
},
],
};
const splitOnNumbers: SnakeCasedPropertiesDeep<{line1: {line2: [{line3: string}]}}, {splitOnNumbers: true}> = {
line_1: {
line_2: [
{
line_3: 'string',
},
],
},
};
const splitOnPunctuation: SnakeCasedPropertiesDeep<{'user@info': {'user::id': number; 'user::name': string}}, {splitOnPunctuation: true}> = {
'user_info': {
'user_id': 1,
'user_name': 'Tom',
},
};
```
@category Change case
@category Template literal
@category Object
*/
export type SnakeCasedPropertiesDeep<
Value,
Options extends WordsOptions = {},
> = DelimiterCasedPropertiesDeep<Value, '_', ApplyDefaultOptions<WordsOptions, _DefaultDelimiterCaseOptions, Options>>;
export {};