Last change
on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
686 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | import {DelimiterCase} from './delimiter-case';
|
---|
| 2 |
|
---|
| 3 | /**
|
---|
| 4 | Convert a string literal to kebab-case.
|
---|
| 5 |
|
---|
| 6 | This 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 | ```
|
---|
| 10 | import {KebabCase} from 'type-fest';
|
---|
| 11 |
|
---|
| 12 | // Simple
|
---|
| 13 |
|
---|
| 14 | const someVariable: KebabCase<'fooBar'> = 'foo-bar';
|
---|
| 15 |
|
---|
| 16 | // Advanced
|
---|
| 17 |
|
---|
| 18 | type KebabCasedProps<T> = {
|
---|
| 19 | [K in keyof T as KebabCase<K>]: T[K]
|
---|
| 20 | };
|
---|
| 21 |
|
---|
| 22 | interface CliOptions {
|
---|
| 23 | dryRun: boolean;
|
---|
| 24 | includeFile: string;
|
---|
| 25 | foo: number;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | const rawCliOptions: KebabCasedProps<CliOptions> = {
|
---|
| 29 | 'dry-run': true,
|
---|
| 30 | 'include-file': 'bar.js',
|
---|
| 31 | foo: 123
|
---|
| 32 | };
|
---|
| 33 | ```
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | export type KebabCase<Value> = DelimiterCase<Value, '-'>;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.