/
snake-case.d.ts
38 lines (28 loc) · 742 Bytes
/
snake-case.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type {DelimiterCase} from './delimiter-case';
/**
Convert a string literal to snake-case.
This can be useful when, for example, converting a camel-cased object property to a snake-cased SQL column name.
@example
```
import type {SnakeCase} from 'type-fest';
// Simple
const someVariable: SnakeCase<'fooBar'> = 'foo_bar';
// Advanced
type SnakeCasedProperties<T> = {
[K in keyof T as SnakeCase<K>]: T[K]
};
interface ModelProps {
isHappy: boolean;
fullFamilyName: string;
foo: number;
}
const dbResult: SnakeCasedProperties<ModelProps> = {
'is_happy': true,
'full_family_name': 'Carla Smith',
foo: 123
};
```
@category Change case
@category Template literal
*/
export type SnakeCase<Value> = DelimiterCase<Value, '_'>;