limace 0.1.1

Slugify some strings
Documentation
  • Coverage
  • 100%
    5 out of 5 items documented5 out of 5 items with examples
  • Size
  • Source code size: 10.81 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.47 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jdrouet

limace

limace is a fast and minimal slugification utility for Rust. It converts strings into clean, URL-friendly slugs using ASCII characters only. It handles Unicode characters via transliteration and supports customizable separator characters.

Features

  • Transliterates Unicode to ASCII using deunicode
  • Strips punctuation and special characters
  • Converts to lowercase
  • Customizable separator (default is -)
  • No heap allocations beyond the result String

Example

use limace::Slugifier;

fn main() {
    let slugifier = Slugifier::default();

    assert_eq!(slugifier.slugify("Hello, World!"), "hello-world");
    assert_eq!(slugifier.slugify("Crème brûlée"), "creme-brulee");

    let custom = Slugifier::default().with_separator('_');
    assert_eq!(custom.slugify("Hello, World!"), "hello_world");
}

Usage

Add this to your Cargo.toml:

[dependencies]
limace = "0.1"

Then use it in your code:

use limace::Slugifier;

let slug = Slugifier::default().slugify("Rust 2024: Fast & Fearless!");
assert_eq!(slug, "rust-2024-fast-fearless");

Custom separator

You can change the separator using with_separator():

use limace::Slugifier;

let slug = Slugifier::default()
    .with_separator('_')
    .slugify("Hello, World!");
assert_eq!(slug, "hello_world");

How it works

  1. Unicode characters are transliterated to ASCII using deunicode_char().
  2. Uppercase letters are manually lowercased.
  3. Alphanumeric ASCII characters are kept.
  4. All other characters are replaced by a separator.
  5. Consecutive separators are collapsed into one.

License

Licensed under MIT