#title #case #capitalization #text-style #capitalize #capitalisation

bin+lib titlecase

Capitalize text according to a style defined by John Gruber for Daring Fireball

9 releases (stable)

3.0.0 Apr 1, 2024
2.2.1 Oct 6, 2022
2.2.0 Sep 3, 2022
2.1.0 Aug 30, 2022
0.9.1 Jun 19, 2017

#44 in Text processing

Download history 3770/week @ 2023-12-24 4917/week @ 2023-12-31 5847/week @ 2024-01-07 5598/week @ 2024-01-14 5676/week @ 2024-01-21 5913/week @ 2024-01-28 5630/week @ 2024-02-04 5637/week @ 2024-02-11 5480/week @ 2024-02-18 5782/week @ 2024-02-25 5969/week @ 2024-03-03 5785/week @ 2024-03-10 5736/week @ 2024-03-17 5584/week @ 2024-03-24 6511/week @ 2024-03-31 4694/week @ 2024-04-07

22,886 downloads per month
Used in 35 crates (17 directly)

MIT license

19KB
369 lines

Title Case (titlecase)

titlecase is a small tool and library (crate) that capitalizes English text according to a style defined by John Gruber for post titles on his website Daring Fireball. titlecase should run on all platforms supported by Rust including Linux, macOS, FreeBSD, NetBSD, OpenBSD, and Windows.

Build Status crates.io Documentation License

Command Line Usage

titlecase reads lines of text from stdin and prints title cased versions to stdout.

Examples

% echo 'Being productive on linux' | titlecase
Being Productive on Linux

% echo 'Finding an alternative to Mac OS X — part 2' | titlecase
Finding an Alternative to Mac OS X — Part 2

% echo 'an example with small words and sub-phrases: "the example"' | titlecase
An Example With Small Words and Sub-Phrases: "The Example"

Install

Pre-compiled binaries

Pre-compiled binaries are available for a some platforms:

Example to download and extract a binary:

curl https://releases.wezm.net/titlecase/3.0.0/titlecase-3.0.0-x86_64-unknown-linux-musl.tar.gz | tar zxf -

From Source

If you have a stable Rust compiler toolchain installed you can install the most recently released titlecase with cargo:

cargo install titlecase

Usage as a Rust Crate

Minimum Supported Rust Version: 1.70.0

See the crate documentation.

Style

Instead of simply capitalizing each word titlecase does the following (amongst other things):

  • Lower case small words like an, of, or in.
  • Don't capitalize words like iPhone.
  • Don't interfere with file paths, URLs, domains, and email addresses.
  • Always capitalize the first and last words, even if they are small words or surrounded by quotes.
  • Don't interfere with terms like "Q&A", or "AT&T".
  • Capitalize small words after a colon.

Credits

This tool makes use of prior work by John Gruber, Aristotle Pagaltzis, and David Gouch.

Dependencies

~2.8–4MB
~67K SLoC