
Security News
PodRocket Podcast: Inside the Recent npm Supply Chain Attacks
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
to-title-cased
Advanced tools
Converts the specified string to title case (except for words that are entirely in uppercase, which are considered to be acronyms).
to-title-cased
is a function that takes a string and converts it to title case using various style guidelines, including the American Psychological Association (APA), American Psychological Association 7th edition (APA 7), Associated Press (AP), Chicago Manual of Style, New York Times (NYT), Wikipedia, and British styles. The function capitalizes the first letter of each word, except for articles, coordinating conjunctions, and prepositions, unless they are the first word of the string. The function also ensures that certain abbreviations and acronyms are in the correct format according to the style guidelines.
This package supports custom options to further refine the conversion, including words that should never be capitalized, words or phrases to ignore, short conjunctions, short prepositions, and more. These options allow for greater customization and flexibility when converting strings to title case.
You can install title-case
using npm:
npm install to-title-cased
Alternatively, you can also install it using yarn:
yarn add to-title-cased
After installing the package, you can use it in your code by importing it:
const toTitleCase = require('to-title-cased');
Or if you're using ES6 syntax:
import { toTitleCase } from 'to-title-cased';
String.prototype.toTitleCase(style, options);
shortConjunctions
: short conjunctions that should not be capitalized, such as "and", "but", and "if"articles
: articles that should not be capitalized, such as "a", "an", and "the".shortPrepositions
: short prepositions that should not be capitalized, such as "of", "to", and "by".neverCapitalized
: words that should never be capitalized, such as "etc.", "i.e.", and "vs.".UNIQUE_WORDS
is a list of words that should never be capitalized, such as "etc.", "i.e.", and "vs.".CORRECTED_TITLE_CASE_TERMS
is a list of words that should be capitalized differently than the default title case rules, such as "Front-End" and "Back-End".UPPERCASE_COMMON_WORDS
is a list of abbreviations and acronyms that should be capitalized, such as "API" and "HTML".A new string with the original string converted to title case.
"Back-End Web Development: Building Scalable APIs with Node.js".toTitleCase();
"Exploring Back-End Frameworks: Comparing Django, Ruby on Rails, and Laravel".toTitleCase({ style: 'chicago' });
"Mastering Front-End Web Design: Tips and Tricks for Creating Responsive Layouts".toTitleCase({ style: 'nyt' });
"Back-End Security: Best Practices for Securing Your Web Applications".toTitleCase({ style: 'wikipedia' });
"Advanced jQuery Techniques: Tips and Tricks for Experienced Front-End Developers".toTitleCase({ style: 'british' });
"The Future of Back-End Development: Trends and Technologies to Watch".toTitleCase({ style: 'ap' });
"Front-End Performance Optimization: Tools and Techniques for Faster Websites".toTitleCase({ style: 'apa' });
// Example 1: Default title case
const input = "the quick brown fox jumps over the lazy dog";
const output = input.toTitleCase(); // "The Quick Brown Fox Jumps Over the Lazy Dog"
// Example 2: Title case with small words not capitalized
const input = "to be or not to be";
const output = input.toTitleCase(); // "To Be or Not to Be"
// Example 3: Title case with specific words not capitalized
const input = "the name of the musical is The Musical";
const output = input.toTitleCase( { neverCapitalized: ["The Musical"] }); // "The Name of the Musical Is The Musical"
// Example 4: Chicago style title case
const input = "the quick rabbit together with the brown fox jumped over the dog";
const output = input.toTitleCase({ style: "chicago" }); // "The Quick Rabbit Together with the Brown Fox Jumped Over the Dog"
"JQuery Plugins for Front-End Developers: A Comprehensive Guide".toTitleCase({ style: 'apa' });
// converts JQuery to jQuery, even if it's the first word,
// replaces Front-End with Frontend (see correctCapitalization)
npm test
String.prototype.toTitleCase
✓ throws TypeError if input is not a string (4 ms)
✓ throws TypeError if options is not an object
✓ AP style (1 ms)
✓ Chicago style (1 ms)
✓ APA style (1 ms)
✓ NYT style (2 ms)
✓ Wikipedia style
✓ Reserved keyword (jQuery, Frontend)
✓ Reserved keyword, correct capitalization (Back-End > Backend) (1 ms)
✓ Complex title with various formatting (1 ms)
✓ Colonization of mars with mixed case and possessive (1 ms)
✓ Cryptocurrencies with all caps and ampersand (2 ms)
✓ Technology and mental health with question mark and quotes (1 ms)
✓ Fashion with acronym and hyphen (1 ms)
✓ Nutrition with colon and apostrophe
✓ Correct capitalization for special terms (1 ms)
✓ Correct capitalization for special terms
Test Suites: 1 passed, 1 total
Tests: 11 passed, 11 total
Snapshots: 0 total
Time: 0.124 s, estimated 1 s
FAQs
Converts the specified string to title case (except for words that are entirely in uppercase, which are considered to be acronyms).
The npm package to-title-cased receives a total of 0 weekly downloads. As such, to-title-cased popularity was classified as not popular.
We found that to-title-cased demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.