Crates.io | slugify |
lib.rs | slugify |
version | 0.1.0 |
source | src |
created_at | 2017-07-26 03:32:12.838629 |
updated_at | 2017-07-26 03:32:12.838629 |
description | Macro for flexible slug generation |
homepage | https://github.com/mattgathu/slugify |
repository | https://github.com/mattgathu/slugify |
max_upload_size | |
id | 25101 |
size | 16,431 |
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 call format that has sane default parameters
but also allows there default parameters to be overriden when needed.
Features:
Unicode strings support (phonetic conversion).
Support for custom slug separator.
Stop words filtering.
Slug maximum length support.
This crate is on crates.io and can be used by adding slugify
to the dependencies in your project's
Cargo.toml
[dependencies]
slugify = "0.1.0"
and this to your crate root:
#[macro_use] extern crate slugify;
use slugify::slugify;
assert_eq!(slugify!("hello world"), "hello-world");
assert_eq!(slugify!("hello world", separator = "."), "hello.world");
assert_eq!(slugify!("hello world", separator = " "), "hello world");
assert_eq!(slugify!("the quick brown fox jumps over the lazy dog", stop_words = "the,fox"), "quick-brown-jumps-over-lazy-dog");
assert_eq!(slugify!("the hello world", stop_words = "the", max_length = 5), "hello");
assert_eq!(slugify!("影師嗎"), "ying-shi-ma");
assert_eq!(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");
NOTE: the order of optional parameters matters: stop_words, separator and then max_length. All of them are optional, however when specifying more than one optional parameter, this order must be adhered.
assert_eq!(slugify!("the hello world", stop_words = "the", separator = "-"), "hello-world");
assert_eq!(slugify!("the hello world", separator = ".", max_length = 10), "the.hello");
assert_eq!(slugify!("the hello world", stop_words = "the", max_length = 5), "hello");
assert_eq!(slugify!("the hello world", stop_words = "the", separator = "-", max_length = 20), "hello-world");