es-toolkit/docs/reference/string/constantCase.md
raon0211 92500e54da
Some checks are pending
CI / codecov (push) Waiting to run
Release / release (push) Waiting to run
docs: Add docs for functions
2024-09-25 17:37:03 +09:00

773 B

constantCase

Converts a string to constant case.

Constant case is a naming convention where each word is written in uppercase letters and separated by an underscore (_). For example, CONSTANT_CASE.

Signature

function constantCase(str: string): string;

Parameters

  • str (string): The string that is to be changed to constant case.

Returns

(string): The converted string to constant case.

Examples

const convertedStr1 = constantCase('camelCase') // returns 'CAMEL_CASE'
const convertedStr2 = constantCase('some whitespace') // returns 'SOME_WHITESPACE'
const convertedStr3 = constantCase('hyphen-text') // returns 'HYPHEN_TEXT'
const convertedStr4 = constantCase('HTTPRequest') // returns 'HTTP_REQUEST'