UNPKG

755 BTypeScriptView Raw
1import type {DelimiterCase} from './delimiter-case';
2
3/**
4Convert a string literal to kebab-case.
5
6This can be useful when, for example, converting a camel-cased object property to a kebab-cased CSS class name or a command-line flag.
7
8@example
9```
10import type {KebabCase} from 'type-fest';
11
12// Simple
13
14const someVariable: KebabCase<'fooBar'> = 'foo-bar';
15
16// Advanced
17
18type KebabCasedProperties<T> = {
19 [K in keyof T as KebabCase<K>]: T[K]
20};
21
22interface CliOptions {
23 dryRun: boolean;
24 includeFile: string;
25 foo: number;
26}
27
28const rawCliOptions: KebabCasedProperties<CliOptions> = {
29 'dry-run': true,
30 'include-file': 'bar.js',
31 foo: 123
32};
33```
34
35@category Change case
36@category Template literal
37*/
38export type KebabCase<Value> = DelimiterCase<Value, '-'>;