Slugify-rs

A utility macro for flexible slug genereation that handles unicode.

The slugify! macro implements a flexible slug generator, allowing for stop words, custom separator and maximum length options. The macro provides both a simple interface with sane default parameters but also allows the parameters to be overriden when needed.

Features:

Usage

This crate is on crates.io and can be used by adding slugify to the dependencies in your project’s Cargo.toml toml [dependencies] slugify-rs = "0.0.1" Examples Basic slug generation ```rust assert_eq!(slugify!("hello world"), "hello-world");

// Using a custom separator asserteq!(slugify!("hello world", separator = "."), "hello.world"); asserteq!(slugify!("hello world", separator = " "), "hello world"); assert_eq!(slugify!("hello world", separator = ""), "helloworld");

// Stop words filtering asserteq!(slugify!("the quick brown fox jumps over the lazy dog", stopwords = "the,fox"), "quick-brown-jumps-over-lazy-dog");

// Maximum length asserteq!(slugify!("hello world", maxlength = 5), "hello"); asserteq!(slugify!("the hello world", stopwords = "the", max_length = 5), "hello");

// Random values added to string through nanoid asserteq!(slugify!("hello world", randomness=true).len(), "hello-world".len()+6); asserteq!(slugify!("hello world", randomness=true,randomness_length=8).len(), "hello-world".len()+9);

// Phonetic Conversion and accented text asserteq!(slugify!("影師嗎"), "ying-shi-ma"); asserteq!(slugify!("Æúű--cool?"), "aeuu-cool"); assert_eq!(slugify!("Nín hǎo. Wǒ shì zhōng guó rén"), "nin-hao-wo-shi-zhong-guo-ren");

// Passing multiple optional parameters. // NOTE: the order of optional parameters matters: stopwords, separator and then maxlength. All of them are optional, however when specifying more than one optional parameter, this order must be adhered.

asserteq!(slugify!("the hello world", stopwords = "the", separator = "-"), "hello-world"); asserteq!(slugify!("the hello world", separator = ".", maxlength = 10), "the.hello"); asserteq!(slugify!("the hello world", stopwords = "the", maxlength = 5), "hello"); asserteq!(slugify!("the hello world", stopwords = "the", separator = "-", maxlength = 20), "hello-world"); ```

Info

This slug was forked from the original slugify crate by @mattgathu