Crates.io | sluggify |
lib.rs | sluggify |
version | 0.1.0 |
source | src |
created_at | 2023-04-16 15:35:18.710002 |
updated_at | 2023-04-16 15:35:18.710002 |
description | Simple slug or clean url generator for rust. With default settings, you will get an hyphenized, lowercase, alphanumeric version of any string you please, with any diacritics removed, whitespace and dashes collapsed, and whitespace trimmed. |
homepage | |
repository | https://github.com/propenster/sluggify-rs |
max_upload_size | |
id | 840647 |
size | 19,910 |
Simple slug or clean url generator for Rust.
With new settings, you will get an hyphenized, lowercase, alphanumeric version of any string you please, with any diacritics removed, whitespace and dashes collapsed, and whitespace trimmed. If you are looking for a new feature or notice a bug open a PR or issue on the Github repository and I'll try to get to it as quickly as possible.
Please see the API documentation for available features and examples of how to use them.
We explain how to use sluggify step-by-step.
Users who already have experience with Rust can skip right to Step 3: Use sluggify in your project.
Users who already know sluggify
might want to jump right into the modules docs
Rust can be installed following the instruction for rustup.
Since sluggify is a library, you need to setup your own new Rust project to use sluggify. With Rust, projects and their dependencies are managed with the builtin package manager Cargo. To create a new Rust project, issue
cargo new hello_world --bin
cd hello_world
in your terminal. The flag --bin
tells Cargo to create an executable project instead of a library.
In this section of the Rust docs, you find details about what Cargo just created for you.
Your new project can be compiled with
cargo build
If dependencies in your project are out of date, update with
cargo update
Execute the compiled code with
cargo run
If you are new to Rust, we suggest to proceed with learning Rust via the Rust docs.
To use sluggify in your Rust project, add the following to your Cargo.toml
[dependencies]
sluggify = "0.1.0"
use sluggify::sluggify:: {SluggifyOptions, sluggify};
// Print a web page onto stdout
fn main() {
let raw_string = "Welcome to the party fellas!";
let cleaned_url = sluggify(raw_string, None);
println!("Sluggified version of raw string '{}' is '{}'", raw_string, cleaned_url);
Returns ``` r#Sluggified version of raw string 'Welcome to the party fellas!' is 'welcome-to-the-party-fellas'r# ```
}
use sluggify::sluggify:: {SluggifyOptions, sluggify};
// Print a web page onto stdout
//this replaces all whitespace characters with a hyphen '-'
fn main() {
let options = SluggifyOptions::new().set_collapse_whitespace(false); //it is true by new
let raw_string = "a #$b ** c \t \n d ! ... xyz...23";
let cleaned_url = sluggify(raw_string, Some(options));
println!("Sluggified version of raw string {} is {}", raw_string, cleaned_url);
}
use sluggify::sluggify:: {SluggifyOptions, sluggify};
// Print a web page onto stdout
fn main() {
let raw_string = "a #$b ** c \t \n d";
let bad_characters = vec!['*','$', '\t'];
let options = SluggifyOptions::new().set_disallowed_characters(bad_characters);
let cleaned_url = sluggify(raw_string, Some(options));
println!("Sluggified version of raw string {} is {}", raw_string, cleaned_url);
}
use sluggify::sluggify:: {SluggifyOptions, sluggify};
// Print a web page onto stdout
fn main() {
let raw_string = "a #$b ** c \t \n d";
let bad_characters = vec!['*','$', '\t'];
//don't collapse whitespaces and also look out for these bad characters...
let options = SluggifyOptions::new().set_collapse_whitespace(false).set_disallowed_characters(chars);
//pass this option to the sluggify helper
let cleaned_url = sluggify(raw_string, Some(options));
println!("Sluggified version of raw string {} is {}", raw_string, cleaned_url);
}
0.1.0:
Initial release.
MIT License
Copyright (c) 2023 propenster
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.