vtils

Home > types > SnakeCase

SnakeCase type

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.

Signature:

export declare type SnakeCase<Value> = DelimiterCase<Value, '_'>;

References: DelimiterCase

Example

``` import {SnakeCase} from ‘type-fest’;

// Simple

const someVariable: SnakeCase<‘fooBar’> = ‘foo_bar’;

// Advanced

type SnakeCasedProperties = { \[K in keyof T as SnakeCase\]: T\[K\] };

interface ModelProps { isHappy: boolean; fullFamilyName: string; foo: number; }

const dbResult: SnakeCasedProperties = { 'is\_happy': true, 'full\_family\_name': 'Carla Smith', foo: 123 }; \`\`\`

Template Literals