## slugrs
[](https://docs.rs/slugrs)
Fast, flexible, locale-aware slugify library for Rust. Mirrors the behavior of Node.js’s `slugify` package.
### Installation
On crates.io (after publishing):
```toml
[dependencies]
slugrs = "0.1"
```
Local path (during development):
```toml
[dependencies]
slugrs = { path = "../slugrs" }
```
### Quick Start
Recommended: Fluent `Slugifier`
```rust
use slugrs::{Slugifier, Locale};
let slug = Slugifier::new()
.separator("_")
.locale(Some(Locale::Tr))
.max_length(Some(24))
.slugify("İstanbul'a hoş geldiniz!");
assert_eq!(slug, "istanbula_hos_geldiniz");
```
Alternatives:
```rust
use slugrs::slugify;
// Defaults: separator "-", lowercase, trim, apostrophe removal, emoji removal
assert_eq!(slugify("Hello, World!"), "hello-world");
```
```rust
use slugrs::{slugify_with_options, Options, Locale};
// Simple customization (Options builder)
let slug = slugify_with_options(
"Füße lösen Ärger",
&Options::default().separator("_").locale(Some(Locale::De))
);
assert_eq!(slug, "fuesse_loesen_aerger");
let tr = Options::default().locale(Some(Locale::Tr));
assert_eq!(slugify_with_options("İstanbul'a hoş geldiniz!", &tr), "istanbula-hos-geldiniz");
```
### API
- `slugify(input: &str) -> String`: Slugify with default options.
- `slugify_with_options(input: &str, options: &Options) -> String`: Full control.
- `Options`: Behavior configuration.
- `Locale`: Language-specific conversions (`De`, `Tr`).
- `Slugifier`: Helper type for repeated calls with the same options.
### Options
| `separator` | `String` | `"-"` | Word separator. Consecutive separators are collapsed. |
| `locale` | `Option<Locale>` | `None` | Language-specific mappings like TR/DE. |
| `remove` | `Option<Regex>` | `None` | Custom removal regex applied before processing. |
| `lowercase` | `bool` | `true` | Convert output to lowercase. |
| `trim` | `bool` | `true` | Trim leading/trailing separators. |
| `max_length` | `Option<usize>` | `None` | Max length; trims trailing separator after truncation. |
| `drop_emoji` | `bool` | `true` | Drop emoji and most symbol characters pre-processing. |
| `drop_apostrophes` | `bool` | `true` | Drop apostrophes to avoid inserting separators. |
Notes:
- Emoji and similar symbols are removed by default.
- Non-ASCII characters are transliterated via `deunicode`.
- Apostrophes ("'", `’`) are removed by default to avoid extra separators.
### Locale Support
- `Locale::Tr`: `İ/ı -> I/i`, `ğ -> g`, `ş -> s`, `ç -> c`, `ö -> o`, `ü -> u`, etc.
- `Locale::De`: `ä -> ae`, `ö -> oe`, `ü -> ue`, `ß -> ss`, etc.
Locale transforms are applied before transliteration; remaining characters are then converted to ASCII.
### Examples
```rust
use regex::Regex;
use slugrs::{Slugifier, slugify, slugify_with_options, Options};
assert_eq!(slugify("Crème brûlée"), "creme-brulee");
assert_eq!(slugify("🔥 Rust & Friends"), "rust-friends");
let opts = Options::default().separator("_").remove(Some(Regex::new("[0-9]").unwrap()));
assert_eq!(slugify_with_options("A1 B2 C3", &opts), "a_b_c");
let s = Slugifier::new().separator("--").trim(true);
assert_eq!(s.slugify(" A--B__C "), "a--b--c");
let limited = Options::default().max_length(Some(10));
assert_eq!(slugify_with_options("this is a very long title", &limited), "this-is-a");
```
### Performance
- Minimized use of regex and `deunicode`.
- Typically uses single-allocation string operations for speed.
### Tests
```sh
cargo test
```
### License
MIT