vtils

Home > types > ConstantCase

ConstantCase type

Convert a string literal to screaming-snake-case.

This can be useful when, for example, converting a camel-cased object property to a screaming-snake-cased SQL column name.

Signature:

export declare type ConstantCase<Value> = Value extends string
	? IsScreamingSnakeCase<Value> extends true
		? Value
		: Uppercase<SnakeCase<Value>>
	: Value;

References: SnakeCase

Example

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

const someVariable: ScreamingSnakeCase<‘fooBar’> = ‘FOO_BAR’; ```

Template Literals