Last change
on this file since 84d0fbb was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
672 bytes
|
Line | |
---|
1 | import {DelimiterCase} from './delimiter-case';
|
---|
2 |
|
---|
3 | /**
|
---|
4 | Convert a string literal to snake-case.
|
---|
5 |
|
---|
6 | This can be useful when, for example, converting a camel-cased object property to a snake-cased SQL column name.
|
---|
7 |
|
---|
8 | @example
|
---|
9 | ```
|
---|
10 | import {SnakeCase} from 'type-fest';
|
---|
11 |
|
---|
12 | // Simple
|
---|
13 |
|
---|
14 | const someVariable: SnakeCase<'fooBar'> = 'foo_bar';
|
---|
15 |
|
---|
16 | // Advanced
|
---|
17 |
|
---|
18 | type SnakeCasedProps<T> = {
|
---|
19 | [K in keyof T as SnakeCase<K>]: T[K]
|
---|
20 | };
|
---|
21 |
|
---|
22 | interface ModelProps {
|
---|
23 | isHappy: boolean;
|
---|
24 | fullFamilyName: string;
|
---|
25 | foo: number;
|
---|
26 | }
|
---|
27 |
|
---|
28 | const dbResult: SnakeCasedProps<ModelProps> = {
|
---|
29 | 'is_happy': true,
|
---|
30 | 'full_family_name': 'Carla Smith',
|
---|
31 | foo: 123
|
---|
32 | };
|
---|
33 | ```
|
---|
34 | */
|
---|
35 | export type SnakeCase<Value> = DelimiterCase<Value, '_'>;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.