1 | import type {DelimiterCase} from './delimiter-case';
|
2 |
|
3 | /**
|
4 | Convert object properties to delimiter case but not recursively.
|
5 |
|
6 | This can be useful when, for example, converting some API types from a different style.
|
7 |
|
8 | @see DelimiterCase
|
9 | @see DelimiterCasedPropertiesDeep
|
10 |
|
11 | @example
|
12 | ```
|
13 | import type {DelimiterCasedProperties} from 'type-fest';
|
14 |
|
15 | interface User {
|
16 | userId: number;
|
17 | userName: string;
|
18 | }
|
19 |
|
20 | const result: DelimiterCasedProperties<User, '-'> = {
|
21 | 'user-id': 1,
|
22 | 'user-name': 'Tom',
|
23 | };
|
24 | ```
|
25 |
|
26 | @category Change case
|
27 | @category Template literal
|
28 | @category Object
|
29 | */
|
30 | export type DelimiterCasedProperties<
|
31 | Value,
|
32 | Delimiter extends string,
|
33 | > = Value extends Function
|
34 | ? Value
|
35 | : Value extends Array<infer U>
|
36 | ? Value
|
37 | : {[K in keyof Value as DelimiterCase<K, Delimiter>]: Value[K]};
|