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

bin+lib titlecase

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

12 releases (stable)

3.3.0 Jul 12, 2024
3.0.0 Apr 1, 2024
2.2.1 Oct 6, 2022
2.0.0 Jun 15, 2022
0.10.0 Jun 21, 2017

#49 in Text processing

Download history 7646/week @ 2024-07-29 6677/week @ 2024-08-05 7611/week @ 2024-08-12 6736/week @ 2024-08-19 6740/week @ 2024-08-26 6754/week @ 2024-09-02 7594/week @ 2024-09-09 6829/week @ 2024-09-16 6213/week @ 2024-09-23 6245/week @ 2024-09-30 6672/week @ 2024-10-07 7371/week @ 2024-10-14 7569/week @ 2024-10-21 6822/week @ 2024-10-28 6731/week @ 2024-11-04 8472/week @ 2024-11-11

29,985 downloads per month
Used in 44 crates (20 directly)

MIT license

21KB
376 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

Try Online

https://7bit.org/titlecase/

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 some platforms, check the latest release.

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.

Building for WebAssembly

Pre-requisites

  • Rust 1.73.0+
  • Rust wasm32-unknown-unknown target (rustup target add wasm32-unknown-unknown or rust-wasm package on Chimera Linux)
  • wasm-bindgen (wasm-bindgen package on Arch, or cargo install wasm-bindgen-cli --version 0.2.92)
  • make (GNU or BSD should work)

Building

There is a Makefile that automates building for WebAssembly.

make

The output is put into a wasm directory. See https://github.com/wezm/7bit.org/tree/main/public/titlecase for an example that uses the wasm build.

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–4.5MB
~71K SLoC