Skip to content

toTitleCase()

toTitleCase(input, options?): string

Defined in: utils/string/toTitleCase.ts:44

Convert a string to "Title Case", with support for:

  • minor words that usually stay lowercase (e.g. "and", "of"),
  • preserving existing ALL-CAPS acronyms.

Whitespace between words is preserved, but punctuation is not treated specially.

Parameters

input

string

The input string.

options?

TitleCaseOptions = {}

Optional configuration.

Returns

string

The title-cased string.

Example

ts
toTitleCase('the lord of the rings');
// 'The Lord of the Rings'

toTitleCase('api reference for HTTP', { preserveUpper: true });
// 'API Reference for HTTP'

Released under the MIT License.