Socket
Book a DemoInstallSign in
Socket

apa-title-case

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

apa-title-case

Converts a string to title case in APA or Chicago style

1.0.5
unpublished
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

toTitleCase()

Converts a string to title case APA (default) or Chicago style

apa-title-case is a Node.js package that converts a string to APA or Chicago-style title case. APA follows the first letter of each major word capitalized while Chicago capitalizes every word except for short conjunctions and prepositions.

Installation

You can install title-case using npm:

npm install apa-title-case

Alternatively, you can also install it using yarn:

yarn add apa-title-case

After installing the package, you can use it in your code by importing it:

const toTitleCase = require('apa-title-case');

Or if you're using ES6 syntax:

import { toTitleCase } from 'apa-title-case';
String.prototype.toTitleCase(style, options);

Parameters

  • 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.".

Return value

A new string with the original string converted to title case.

Examples

// 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"

Tests

npm test
  String.prototype.toTitleCase
    ✓ throws TypeError if input is not a string (3 ms)
    ✓ throws TypeError if options is not an object (3 ms)
    ✓ capitalizes the first letter of each word in a sentence
    ✓ capitalizes the first letter of the first word in a sentence (2 ms)
    ✓ handles hyphenated words and last words in a sentence
    ✓ capitalizes the first word of a sentence
    ✓ capitalizes all significant words in a sentence
    ✓ excludes specific words from capitalization
    ✓ capitalizes significant words with Chicago style
    ✓ does not modify already capitalized words (1 ms)
    ✓ returns an empty string for empty input

Test Suites: 1 passed, 1 total
Tests:       11 passed, 11 total
Snapshots:   0 total
Time:        0.134 s, estimated 1 s

Resources

  • APA Style Grammar Guidelines: Capitalization
  • Chicago Manual of Style: Capitalization
  • Wikipedia: Letter case
  • Grammarly Handbook: Title Case - an overview of title case and its rules
  • Title Capitalization Rules for Writers - a guide to title case with examples and exceptions.

Notes

  • The toTitleCase() function correctly capitalizes the first letter of each word in a string, while handling various exceptions and rules.
  • The function supports several optional configuration options, such as specifying words that should never be capitalized, short conjunctions that should not be capitalized, and short prepositions that should not be capitalized.
  • The function also supports two style options: APA style and Chicago style.
  • The function is optimized to improve performance by memoizing capitalized versions of words and avoiding unnecessary work when checking for ignored words, intentionally uppercase words, URLs, hashtags, and handles.
  • The function correctly handles multi-word small words and hyphenated words, as well as non-ASCII characters.
  • The function includes unit tests to ensure proper functionality and prevent regressions.

Keywords

title

FAQs

Package last updated on 05 Mar 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.