Directus Title Formatter — Converts any string into properly formatted title case
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.editorconfig
.eslintrc.js
.gitignore
.npmignore
LICENSE
README.md
package-lock.json
package.json
rollup.config.js

README.md

Directus Logo

 

The All-New Directus 7
Future-Proof Headless CMS

WebsiteDocsAPI ReferenceUser GuideDemoContribute

 

The Directus 7 App has been rebuilt from the ground-up in Vue.js and decoupled from our new "versionless" API. Both can easily be customized and extended to suit your project's needs.

 

🐰 Directus 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 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

Bonus: the package also handles specially-cased words such as iPad, PDFs, or McDonalds

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 on the repo that contains those words!

 


Directus Thumbnailer is released under the MIT license. Directus (proper) is released under the GPLv3 license. RANGER Studio LLC owns all Directus trademarks and logos on behalf of our project's community. Copyright © 2006-2018, RANGER Studio LLC.