Skip to content

capitalize() ​

capitalize(input): string

Defined in: utils/string/capitalize.ts:15

Capitalizes the first letter of a string. Just like String.prototype.charAt(0).toUpperCase(), but without the need to call slice(1) to get the rest of the string.

Parameters ​

input ​

string

The string to capitalize.

Returns ​

string

The capitalized string. Returns an empty string if the input is empty.

Example ​

tsx
capitalize('hello'); // 'Hello'
capitalize('Hello'); // 'Hello'
capitalize(''); // ''

Released under the MIT License.