Files
directus/packages/format-title
Jian Liao 70c825af56 Add DNA and correct macOS for format title (#4848)
* add more ignore pattern for git

* revert the change for api/.gitignore

* Add DNA and change MacOS to macOS to align with Apple official name

* Move DNA to acronyms

Co-authored-by: Jian Liao <jianliao@adobe.com>
2021-04-05 21:13:25 -04:00
..
2020-10-14 12:15:25 -04:00
2020-10-14 12:15:25 -04:00
2021-03-30 13:17:52 -04:00
2020-10-14 12:15:25 -04:00

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

input output
snowWhiteAndTheSevenDwarfs Snow White and the Seven Dwarfs
NewcastleUponTyne Newcastle upon Tyne
brighton_on_sea Brighton on Sea
apple_releases_new_ipad Apple Releases New iPad
7-food-trends 7 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" scentences 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!