Skip to content
On this page

This is an auto-generated document to support extension builders understand the internal packages they can utilize. To find our written guides, tutorials, and API/SDK reference, check out our main docs .

Directus / @directus/format-title

@directus/format-title

Custom formatter that converts any string into Title Case.

Capital letters are used for principal words. Articles, conjunctions, and prepositions do not get capital letters unless they start or end the title.

InputOutput
snowWhiteAndTheSevenDwarfsSnow White and the Seven Dwarfs
NewcastleUponTyneNewcastle Upon Tyne
brighton_on_seaBrighton on Sea
apple_releases_new_ipadApple Releases New iPad
7-food-trends7 Food Trends

The package contains a list of words that use some sort of special casing, for example: McDonalds, iPhone, and YouTube.

Installation

shell
npm install @directus/format-title
npm install @directus/format-title

Usage

The package by default converts camelCase, PascalCase, underscore, and "regular" sentences to Title Case.

js
formatTitle(string, [separator]);

formatTitle('snowWhiteAndTheSevenDwarfs');
// => Snow White and the Seven Dwarfs
formatTitle(string, [separator]);

formatTitle('snowWhiteAndTheSevenDwarfs');
// => Snow White and the Seven Dwarfs

You can provide an optional separator regex as a second parameter to support splitting the string on different characters. By default, this regex is set to /\s|-|_/g.

License

This package is licensed under the MIT License. See the LICENSE file for more information.

Additional Resources