str_slug
generates url friendly slug
from the given string.
slug
, slug_hash
, slag_hash_len
StrSlug::new
For more examples please check the Documentation
NORMAL
```rust use str_slug::slug;
let slug = slug("hello world"); assert_eq!(slug, "hello-world"); ```
WITH HASH
```rust use strslug::slughash;
let slug = slughashlen("Hello, world ;-)", 6); asserteq!("hello-worldea1ac5", slug); ```
```rust pub struct StrSlug { pub use_hash: bool,
/// if its set to false the hash will be prepended
pub append_hash: bool,
/// use full hash if `hash_len` = 0
pub hash_len: usize,
/// separator to use to separate slug and hash
pub hash_separator: char,
pub separator: char,
pub remove_duplicate_separators: bool,
pub trim_separator_start: bool,
pub trim_separator_end: bool,
pub trim_separator_both: bool,
} ```
```rust pub fn new() -> Self { Self { usehash: false, appendhash: true, hashlen: 6, hashseparator: '_',
separator: '-',
remove_duplicate_separators: true,
trim_whitespace: true,
trim_whitespace_start: false,
trim_whitespace_end: false,
trim_separator: true,
trim_separator_start: false,
trim_separator_end: false,
}
} ```
trim_whitespace
and trim_separator
will take precedence when set to true
.
```rust let sentence = "quick brown fox jumps over the lazy dog"; let slug = str_slug::slug(sentence);
// quick-brown-fox-jumps-over-the-lazy-dog ```
with a hash
```rust let sentence = "quick brown fox jumps over the lazy dog"; let slug = strslug::slughash(sentence);
// quick-brown-fox-jumps-over-the-lazy-dog_ce2907 ```