type-fest
Version:
A collection of essential TypeScript types
73 lines (61 loc) • 1.55 kB
TypeScript
import type {DelimiterCasedPropertiesDeep} from './delimiter-cased-properties-deep.d.ts';
import type {WordsOptions} from './words.d.ts';
import type {KebabCase} from './kebab-case.d.ts'; // For `@link`
import type {KebabCasedProperties} from './kebab-cased-properties.d.ts'; // For `@link`
/**
Convert object properties to kebab case recursively.
This can be useful when, for example, converting some API types from a different style.
```
import type {KebabCasedPropertiesDeep} from 'type-fest';
type User = {
userId: number;
userName: string;
};
type UserWithFriends = {
userInfo: User;
userFriends: User[];
};
const result: KebabCasedPropertiesDeep<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: KebabCasedPropertiesDeep<{line1: {line2: [{line3: string}]}}, {splitOnNumbers: true}> = {
'line-1': {
'line-2': [
{
'line-3': 'string',
},
],
},
};
const noSplitOnPunctuation: KebabCasedPropertiesDeep<{'user@info': {'user::id': number; 'user::name': string}}, {splitOnPunctuation: false}> = {
'user@info': {
'user::id': 1,
'user::name': 'Tom',
},
};
```
*/
export type KebabCasedPropertiesDeep<
Value,
Options extends WordsOptions = {},
> = DelimiterCasedPropertiesDeep<Value, '-', Options>;
export {};