Skip to content

capitalize ​

Converts the first character of a string to uppercase and the rest to lowercase.

Syntax ​

typescript
capitalize(str: string): string

Parameters ​

ParameterTypeDescription
strstringThe string to be capitalized.

Returns ​

TypeDescription
stringThe resulting string with the first character in uppercase and the rest in lowercase.

Example ​

typescript
capitalize("exemplo"); // "Exemplo"
capitalize("eXEMPLO"); // "Exemplo"
capitalize(""); // ""

Notes ​

  • Throws TypeError if the argument is not a string.
  • Returns an empty string if the input is empty.

References ​

Released under the MIT License.