1
- import type { DelimiterCase } from './delimiter-case' ;
2
- import type { NonRecursiveType } from './internal' ;
1
+ import type { DefaultDelimiterCaseOptions , DelimiterCase } from './delimiter-case' ;
2
+ import type { ApplyDefaultOptions , NonRecursiveType } from './internal' ;
3
3
import type { UnknownArray } from './unknown-array' ;
4
+ import type { WordsOptions } from './words' ;
4
5
5
6
/**
6
7
Convert object properties to delimiter case recursively.
@@ -40,6 +41,16 @@ const result: DelimiterCasedPropertiesDeep<UserWithFriends, '-'> = {
40
41
},
41
42
],
42
43
};
44
+
45
+ const splitOnNumbers: DelimiterCasedPropertiesDeep<{line1: { line2: [{ line3: string }] }}, '-', {splitOnNumbers: true}> = {
46
+ 'line-1': {
47
+ 'line-2': [
48
+ {
49
+ 'line-3': 'string',
50
+ },
51
+ ],
52
+ },
53
+ };
43
54
```
44
55
45
56
@category Change case
@@ -49,34 +60,47 @@ const result: DelimiterCasedPropertiesDeep<UserWithFriends, '-'> = {
49
60
export type DelimiterCasedPropertiesDeep <
50
61
Value ,
51
62
Delimiter extends string ,
63
+ Options extends WordsOptions = { } ,
64
+ > = _DelimiterCasedPropertiesDeep < Value , Delimiter , ApplyDefaultOptions < WordsOptions , DefaultDelimiterCaseOptions , Options > > ;
65
+
66
+ type _DelimiterCasedPropertiesDeep <
67
+ Value ,
68
+ Delimiter extends string ,
69
+ Options extends Required < WordsOptions > ,
52
70
> = Value extends NonRecursiveType
53
71
? Value
54
72
: Value extends UnknownArray
55
- ? DelimiterCasedPropertiesArrayDeep < Value , Delimiter >
73
+ ? DelimiterCasedPropertiesArrayDeep < Value , Delimiter , Options >
56
74
: Value extends Set < infer U >
57
- ? Set < DelimiterCasedPropertiesDeep < U , Delimiter > > : {
75
+ ? Set < _DelimiterCasedPropertiesDeep < U , Delimiter , Options > > : {
58
76
[ K in keyof Value as DelimiterCase <
59
77
K ,
60
- Delimiter
61
- > ] : DelimiterCasedPropertiesDeep < Value [ K ] , Delimiter > ;
78
+ Delimiter ,
79
+ Options
80
+ > ] : _DelimiterCasedPropertiesDeep < Value [ K ] , Delimiter , Options > ;
62
81
} ;
63
82
64
83
// This is a copy of CamelCasedPropertiesArrayDeep (see: camel-cased-properties-deep.d.ts).
65
84
// These types should be kept in sync.
66
- type DelimiterCasedPropertiesArrayDeep < Value extends UnknownArray , Delimiter extends string > =
67
- Value extends [ ]
68
- ? [ ]
69
- // Tailing spread array
70
- : Value extends [ infer U , ...infer V ]
71
- ? [ DelimiterCasedPropertiesDeep < U , Delimiter > , ...DelimiterCasedPropertiesDeep < V , Delimiter > ]
72
- : Value extends readonly [ infer U , ...infer V ]
73
- ? readonly [ DelimiterCasedPropertiesDeep < U , Delimiter > , ...DelimiterCasedPropertiesDeep < V , Delimiter > ]
74
- // Leading spread array
85
+ type DelimiterCasedPropertiesArrayDeep <
86
+ Value extends UnknownArray ,
87
+ Delimiter extends string ,
88
+ Options extends Required < WordsOptions > ,
89
+ > = Value extends [ ]
90
+ ? [ ]
91
+ // Trailing spread array
92
+ : Value extends [ infer U , ...infer V ]
93
+ ? [ _DelimiterCasedPropertiesDeep < U , Delimiter , Options > , ..._DelimiterCasedPropertiesDeep < V , Delimiter , Options > ]
94
+ : Value extends readonly [ infer U , ...infer V ]
95
+ ? readonly [ _DelimiterCasedPropertiesDeep < U , Delimiter , Options > , ..._DelimiterCasedPropertiesDeep < V , Delimiter , Options > ]
96
+ // Leading spread array
97
+ : Value extends [ ...infer U , infer V ]
98
+ ? [ ..._DelimiterCasedPropertiesDeep < U , Delimiter , Options > , _DelimiterCasedPropertiesDeep < V , Delimiter , Options > ]
75
99
: Value extends readonly [ ...infer U , infer V ]
76
- ? [ ...DelimiterCasedPropertiesDeep < U , Delimiter > , DelimiterCasedPropertiesDeep < V , Delimiter > ]
100
+ ? readonly [ ..._DelimiterCasedPropertiesDeep < U , Delimiter , Options > , _DelimiterCasedPropertiesDeep < V , Delimiter , Options > ]
77
101
// Array
78
102
: Value extends Array < infer U >
79
- ? Array < DelimiterCasedPropertiesDeep < U , Delimiter > >
103
+ ? Array < _DelimiterCasedPropertiesDeep < U , Delimiter , Options > >
80
104
: Value extends ReadonlyArray < infer U >
81
- ? ReadonlyArray < DelimiterCasedPropertiesDeep < U , Delimiter > >
105
+ ? ReadonlyArray < _DelimiterCasedPropertiesDeep < U , Delimiter , Options > >
82
106
: never ;
0 commit comments