str_slug

Crates.iostr_slug
lib.rsstr_slug
version0.1.3
sourcesrc
created_at2020-04-10 02:34:59.600779
updated_at2020-04-10 13:13:38.332881
descriptionGenerate a URL friendly slug from the given string
homepage
repositoryhttps://github.com/OussamaElgoumri/str_slug
max_upload_size
id228206
size11,756
(OussamaElgoumri)

documentation

https://docs.rs/str_slug

README

Generate a URL friendly 'slug' from the given string

str_slug generates url friendly slug from the given string.

Features

  • correct unicode support.
  • ability to append/prepend a hash of the given value to the generated slug.
  • provide a simple to use apis slug, slug_hash, slag_hash_len
  • fully customizable when you need it via StrSlug::new

Examples

For more examples please check the Documentation

Simple usage

NORMAL

use str_slug::slug;

let slug = slug("hello world");
assert_eq!(slug, "hello-world");

WITH HASH

use str_slug::slug_hash;

let slug = slug_hash_len("Hello, world ;-)", 6);
assert_eq!("hello-world_ea1ac5", slug);

Options

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,

    /// Trim leading and trailing separators after slugifying the given string.
    pub trim_separator: bool,
    pub trim_separator_start: bool,
    pub trim_separator_end: bool,
}

Defaults

pub fn new() -> Self {
    Self {
        use_hash: false,
        append_hash: true,
        hash_len: 6,
        hash_separator: '_',

        separator: '-',
        remove_duplicate_separators: true,

        trim_separator: true,
        trim_separator_start: false,
        trim_separator_end: false,
    }
}

trim_separator will take precedence when set to true.

Commit count: 0

cargo fmt