frontend/.pnpm-store/v3/files/6d/401bd26bb8dfbb128a2924b8de1dbbc40d08cfcea8f55f28acc2ec6c54e6d17fb47b4094741879f48c6956844e08cd6bf1109fcfc3b3da6c2b056c07228b00

34 lines
935 B
Plaintext

import type {SplitIncludingDelimiters} from './delimiter-case';
import type {SnakeCase} from './snake-case';
import type {Includes} from './includes';
/**
Returns a boolean for whether the string is screaming snake case.
*/
type IsScreamingSnakeCase<Value extends string> = Value extends Uppercase<Value>
? Includes<SplitIncludingDelimiters<Lowercase<Value>, '_'>, '_'> extends true
? true
: false
: false;
/**
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.
@example
```
import type {ScreamingSnakeCase} from 'type-fest';
const someVariable: ScreamingSnakeCase<'fooBar'> = 'FOO_BAR';
```
@category Change case
@category Template literal
*/
export type ScreamingSnakeCase<Value> = Value extends string
? IsScreamingSnakeCase<Value> extends true
? Value
: Uppercase<SnakeCase<Value>>
: Value;