All Projects → gouch → To Title Case

gouch / To Title Case

Licence: mit
A JavaScript method for intelligently converting strings to title case.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to To Title Case

project-template
Sample Go Project Template (based on the layout from the Standard Project Layout repo)
Stars: ✭ 81 (-73.53%)
Mutual labels:  standards
Org Transclusion
(alpha) Emacs package to enable transclusion with Org Mode
Stars: ✭ 251 (-17.97%)
Mutual labels:  writing
Javascript Style Guide
Guía de Estilo para programar con JavaScript, en español. Apoyo es bienvenido :)
Stars: ✭ 278 (-9.15%)
Mutual labels:  styleguide
ad-hoc-reckons
www.youtube.com/watch?v=oqnd5ilkx2y
Stars: ✭ 85 (-72.22%)
Mutual labels:  writing
learningHub
Style guides and learning materials for devs, to build lightning-fast web apps 🚀 | HTML | CSS | JS | REACT
Stars: ✭ 19 (-93.79%)
Mutual labels:  styleguide
Css
Believe in Better CSS
Stars: ✭ 262 (-14.38%)
Mutual labels:  styleguide
vim-wordy
Uncover usage problems in your writing
Stars: ✭ 677 (+121.24%)
Mutual labels:  writing
Bee Stylish
🕶 Styleguides da moda (ou não)
Stars: ✭ 286 (-6.54%)
Mutual labels:  styleguide
nuxt-styleguide
Increase the quality and efficiency of product design and development workflows
Stars: ✭ 15 (-95.1%)
Mutual labels:  styleguide
Deno Manual Cn
Deno 中文手册
Stars: ✭ 278 (-9.15%)
Mutual labels:  styleguide
lean-bem
A leaner, cleaner & prettier adaptation of BEM
Stars: ✭ 12 (-96.08%)
Mutual labels:  standards
140stories
140Stories: Collaborative stories 140 chars at a time.
Stars: ✭ 14 (-95.42%)
Mutual labels:  writing
Http Extensions
HTTP Extensions in progress
Stars: ✭ 264 (-13.73%)
Mutual labels:  standards
sass-common
Common Sass mixins and files
Stars: ✭ 13 (-95.75%)
Mutual labels:  styleguide
Overview
中文编程的历史、现状和展望。issue 中进行相关问题的讨论.
Stars: ✭ 282 (-7.84%)
Mutual labels:  styleguide
flake8-cognitive-complexity
An extension for flake8 that validates cognitive functions complexity
Stars: ✭ 44 (-85.62%)
Mutual labels:  styleguide
Vuejs Component Style Guide
Vue.js Component Style Guide
Stars: ✭ 2,796 (+813.73%)
Mutual labels:  styleguide
Yarneditor
A tool for writing interactive dialogue in games!
Stars: ✭ 292 (-4.58%)
Mutual labels:  writing
Fountain Mode
Emacs major mode for screenwriting in Fountain plain-text markup
Stars: ✭ 288 (-5.88%)
Mutual labels:  writing
Calver
📅 The web's go-to resource for Calendar Versioning info.
Stars: ✭ 271 (-11.44%)
Mutual labels:  standards

To Title Case for JavaScript

Intelligently format your headlines into title case.

Installation

  • Browser: Add the script to your page with something like <script src="to-title-case.js"></script>
  • Node: npm install @gouch/to-title-case and then add require('@gouch/to-title-case') to your script

Usage

Use the .toTitleCase() method on strings you want converted to title case:

'Make me a headline'.toTitleCase() // returns: Make Me a Headline

The script assumes input is either sentence case (e.g. To title case for JavaScript) or every-word “title case” (e.g. To Title Case For JavaScript). In both cases, the script will convert the text to To Title Case for JavaScript.

What is Title Case?

Title case (or headline case) is a convention for formatting the titles of things. It’s often used for the title of articles, but also matters if you mention the title of something in paragraph.

The Capitalization Rules

  1. By default, capitalize all words
  2. Always capitalize the first and last word in titles and subtitles
  3. Capitalize both parts of hyphenated words
  4. Lowercase articles: a, an, the
  5. Lowercase conjunctions: and, but, or, nor
  6. Lowercase short prepositions: as, at, by, for, in, of, on, per, to, via
  7. Lowercase versus: vs., vs, v., v
  8. Lowercase NYT words*: en, if
  9. Let intentional capitalization stand

These rules are based on style guides from APA, Chicago, and modern conventions. The result will match general expectations for what a title should look like. Some style guides might state special rules depending on contextual use, but these decisions rely on grammatical understanding, which is beyond the scope of a small script. Your titles will at least be consistent.

* Treating these as small words was inherited from Gruber's implementation. They're likely based on New York Times style. Opinions are welcome on whether these should be removed in a future version.

FAQ: Dealing With Uppercase and ALL CAPS Input

If you’re stuck with uppercase input, you can get to title case by changing to lowercase first:

'CAPSLOCK FOREVER'.toLowerCase().toTitleCase() // returns: Capslock Forever

// Don’t actually do this until you read the notes below!

Think hard before doing this! As frustrating as all uppercase input can be, acronyms are very common. Turning genuine abbreviations into blatant typos is a worse look than all caps. As an example, this was a real headline from CNN:

PETA: Turkey, TX, change your name

If you brute forced that into title case, you'd wind up with Peta and Tx, which would make Cnn look pretty amateur.

History/Changelog

2.2.1 / 2018-09-07

  • Publish to npm

2.2 / 2018-08-28

  • Rewrite to use split instead of replace. This makes it easier to follow what the script is doing.
  • Add additional tests
  • Document the actual rules used

2.1 / 2013-11-03

  • Acknowledge characters outside of US-ASCII
  • Fix bug related to hyphenated small words
  • Replace baby's first testing script with the QUnit framework

2.0.1 / 2012-01-06

  • Fixed IE 7 breakage introduced in 2.0. Don't treat strings like character arrays.

2.0 / 2012-01-06

  • 15% less code and 35% easier to understand.
  • Small words list moved to variable for easy modification.
  • Test titles rewritten to focus on a single issue per title.
  • More braces to make style guides and JSLint happier.

Inspiration

I built this after reading John Gruber’s explanation of title case.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].