Skip to main content

A CLI utility and library to cast strings to title-case according to locale specific style guides including Turkish support

Project description

decasify

Rust Test Status Rust Lint Status Flake Run Status Lua Lint Status Lua Test Status
GitHub tag (latest) Crates.io (latest) LuaRocks (latest) PyPi (latest) NPM Version

A CLI utility, Rust crate, Lua Rock, Python module, JavaScript module, and Neovim plugin to cast strings to title-case (and other cases) according to locale specific style guides including Turkish support.

This project was born out of frustration with ALL CAPS TITLES in Markdown that no tooling seemed to properly support casting to title-cased strings, particularly coming from Turkish. Many tools can handle casing single words, some programmer specific tools can recaseing tokens and identifiers, and yet a few others can handle English strings, but nothing seemed to be out there for changing the case of full Turkish strings.

The CLI defaults to titlecase and English, but lower, upper, and sentence case options are also available. The Rust, Lua, Python, and JavaScript library APIs have functions specific to each operation. Where possible the APIs currently default to English rules and (for English) the Gruber style guide, but others are available.

The Turkish style follows the Turkish Language Institute's guidelines.

For English, three style guides are known: Associated Press (AP), Chicago Manual of Style (CMOS), and John Grubber's Daring Fireball (Gruber). The Gruber style is by far the most complete, being implemented by the titlecase crate. The CMOS style handles a number of parts of speech but has punctuation related issues. The AP style is largely unimplemented.

Contributions are welcome for better style guide support or further languages.

$ decasify -l tr ILIK SU VE İTEN RÜZGARLAR
Ilık Su ve İten Rüzgarlar
$ echo ILIK SU VE İTEN RÜZGARLAR | decasify -l tr
Ilık Su ve İten Rüzgarlar
$ echo foo BAR AND baz: an alter ego | decasify -l en -s gruber
Foo BAR and Baz: An Alter Ego

Use as a CLI tool

Use of the CLI is pretty simple. Input may be either shell arguments or STDIN.

$ decasify --help
A CLI tool to convert all-caps strings to title-case or other less aggressive tones that supports
Turkish input

Usage: decasify [OPTIONS] [INPUT]...

Arguments:
  [INPUT]...  Input string

Options:
  -l, --locale <LOCALE>  Locale [default: EN] [possible values: EN, TR]
  -c, --case <CASE>      Target case [default: Title] [possible values: Lower, Sentence, Title,
                         Upper]
  -s, --style <STYLE>    Style Guide [possible values: ap, cmos, gruber]
  -h, --help             Print help
  -V, --version          Print version

First, check your distro for packages, e.g. for Arch Linux get it from the AUR.

Otherwise for many platforms you can run it directly or install it to a shell using Nix Flakes:

$ nix run github:alerque/decasify

To do a full install from source, grab the tarball attached to the latest release or use Git to clone the repository. Don't use the "source code" zip/tar.gz files linked from releases, go for the tar.zst source file. If you use a Git close, first run ./bootstrap.sh after checkout. This isn't needed in the source release tarballs. Next, configure and install with:

$ ./configure
$ make
$ sudo make install

Note that installing from source has the advantage of include a man page and shell completions. All the usual autotools options apply, see --help for details. The most commonly used option especially for distro packagers is probably --prefix /usr to change the install location from the default of /usr/local.

Of course the bare binary can also be installed directly with Cargo:

$ cargo install --features cli decasify

Use as a Rust crate

In your Cargo.toml file.

[dependencies]
decasify = "0.6"

Then use the crate functions and types in your project something like this:

use decasify::to_titlecase;
use decasify::{InputLocale, StyleGuide};

fn demo() {
    let input = "ILIK SU VE İTEN RÜZGARLAR";
    let output = to_titlecase(input, InputLocale::TR, None);
    eprintln! {"{output}"};
    let input = "title with a twist: a colon";
    let output = to_titlecase(input, InputLocale::EN, Some(StyleGuide::DaringFireball));
    eprintln! {"{output}"};
}

Use as a Lua Rock

Depend on the LuaRock in your project or install with luarocks install decasify:

dependencies = {
   "decasify"
}

Then import and use the provided functions:

local decasify = require("decasify")
local input = "ILIK SU VE İTEN RÜZGARLAR"
local output = decasify.titlecase(input, "tr")
print(output)
input = "title with a twist: a colon"
output  = decasify.titlecase(input, "en", "gruber")
print(output)

Use as a Python Module

Depend on the Python module in your project or install with pip install decasify:

[project]
dependencies = [
  "decasify"
]

Then import and use the provided functions and type classes:

from decasify import *

input = "ILIK SU VE İTEN RÜZGARLAR"
output = titlecase(input, InputLocale.TR)
print(output)
input = "title with a twist: a colon"
output  = titlecase(input, InputLocale.EN, StyleGuide.DaringFireball)
print(output)

Use as a JavaScript (WASM) Module

Depend on the WASM based JavaScript module in your project with npm add decasify:

Then import and use the provided functions and classes:

import { titlecase, uppercase, lowercase, InputLocale, StyleGuide } from 'decasify';

var input = "ILIK SU VE İTEN RÜZGARLAR"
var output = titlecase(input, InputLocale.TR)
console.log(output)

var input = "title with a twist: a colon"
var output = titlecase(input, InputLocale.EN, StyleGuide.DaringFireball)
console.log(output)

Use as a Neovim plugin

  • Using rocks.nvim, simply run :Rocks install decasify.nvim dev.

  • Using lazy.nvim, simply add { "alerque/decasify" }

  • Using other plugin managers that don't automatically detect dependencies, you will need to manually specify the dependency and/or make sure the Lua Rock for decasify is available, then use this repository as a plugin however your plugin manager handles that.

    -- for packer.nvim
    use {
       "alerque/decasify",
       rocks = { "decasify" },
    }
    
  • Using no plugin manager, make sure the decasify Rock is installed matching the version of Lua NeoVIM is built with, then copy plugin/decasify.lua to wherever your user's plugin directory is.

A new command :Decasify will become available (with optional subcommands for cases other than title case) that transforms the current line or any range of lines. The default case, locale, and style guide can be changed (before or after loading) with global or buffer local variables:

-- Set the default target case globally
vim.g.decasify_case = "title"
-- Change the locale for the current buffer
vim.b.decasify_locale = "tr"
-- Change the default style guide globally
vim.g.decasify_style = "gruber"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

decasify-0.6.1.tar.gz (47.0 kB view details)

Uploaded Source

Built Distribution

decasify-0.6.1-cp312-cp312-manylinux_2_34_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.34+ x86-64

File details

Details for the file decasify-0.6.1.tar.gz.

File metadata

  • Download URL: decasify-0.6.1.tar.gz
  • Upload date:
  • Size: 47.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.7.4

File hashes

Hashes for decasify-0.6.1.tar.gz
Algorithm Hash digest
SHA256 d3dd813c36158595b48a813a235cd63895b4c9a85f6b49b58d6f21cf6e4dcf9a
MD5 5f5126ac7e3abe234d80a0edf3472880
BLAKE2b-256 054de342f53e609e40bd15c9ee808be1db9dcbe62e48bf04d5fd2fc03879e6fd

See more details on using hashes here.

File details

Details for the file decasify-0.6.1-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for decasify-0.6.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 abfa613d1404bd9863b86a842ca5ccbeeaf6315a6fda7af00511b859199c4da7
MD5 fa5fb46b32406fa5106ba2e5c313ffa9
BLAKE2b-256 fe4b9e2a2cb7df5e0aee23b6b4bd97ccb484b147f7ef5095d33672e5fde5795e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page