9.12.0 • Published 2 years ago

@mv-data-core/format-title v9.12.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Title Formatter

Custom string formatter that converts any string into Title Case

This package converts any string into title case. This means only using capital letters for the 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

$ npm install @directus/format-title

Usage

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

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.

Contributing

If your favorite specially cased word isn't being capitalized properly, please open an issue or submit a pull request!