#snake #inflector #pluralize #inflection #camel

str_inflector

Adds String based inflections for Rust. Snake, kebab, camel, sentence, class, title and table cases as well as ordinalize, deordinalize, demodulize, foreign key, and pluralize/singularize are supported as both traits and pure functions acting on String types.

1 unstable release

Uses old Rust 2015

0.12.0 Jan 30, 2022

#405 in Text processing

Download history 6326/week @ 2024-07-21 8343/week @ 2024-07-28 6767/week @ 2024-08-04 7452/week @ 2024-08-11 7834/week @ 2024-08-18 8856/week @ 2024-08-25 7924/week @ 2024-09-01 7841/week @ 2024-09-08 6025/week @ 2024-09-15 7444/week @ 2024-09-22 7401/week @ 2024-09-29 7027/week @ 2024-10-06 6871/week @ 2024-10-13 8459/week @ 2024-10-20 6872/week @ 2024-10-27 8753/week @ 2024-11-03

31,377 downloads per month
Used in 21 crates (3 directly)

BSD-2-Clause

175KB
2.5K SLoC

Rust (i)nflector

Adds String based inflections for Rust. Snake, kebab, train, camel, sentence, class, and title cases as well as ordinalize, deordinalize, demodulize, deconstantize, foreign key, table case, and pluralize/singularize are supported as both traits and pure functions acting on &str and String types. forked from: https://github.com/whatisinternet/Inflector


Documentation:

Documentation can be found here at the README or via rust docs below.

Rust docs with examples


Installation:

As a crate

[dependencies]
inflector = "*"

Compile yourself:

  1. Install Rust and cargo
  2. git clone https://github.com/abumni/inflector
  3. Library: cd inflector && cargo build --release --lib
  4. You can find the library in target/release

Usage / Example:

...
// to use methods like String.to_lower_case();
extern crate inflector;
use inflector::inflector;
...
fn main() {
...
  let camel_case_string: String = "some_string".to_camel_case();
...
}

Or

...
// to use methods like to_snake_case(&str);
extern crate inflector;

// use inflector::cases::classcase::to_class_case;
// use inflector::cases::classcase::is_class_case;

// use inflector::cases::camelcase::to_camel_case;
// use inflector::cases::camelcase::is_camel_case;

// use inflector::cases::pascalcase::to_pascal_case;
// use inflector::cases::pascalcase::is_pascal_case;

// use inflector::cases::screamingsnakecase::to_screamingsnake_case;
// use inflector::cases::screamingsnakecase::is_screamingsnake_case;

// use inflector::cases::snakecase::to_snake_case;
// use inflector::cases::snakecase::is_snake_case;

// use inflector::cases::kebabcase::to_kebab_case;
// use inflector::cases::kebabcase::is_kebab_case;

// use inflector::cases::traincase::to_train_case;
// use inflector::cases::traincase::is_train_case;

// use inflector::cases::sentencecase::to_sentence_case;
// use inflector::cases::sentencecase::is_sentence_case;

// use inflector::cases::titlecase::to_title_case;
// use inflector::cases::titlecase::is_title_case;

// use inflector::cases::tablecase::to_table_case;
// use inflector::cases::tablecase::is_table_case;

// use inflector::numbers::ordinalize::ordinalize;
// use inflector::numbers::deordinalize::deordinalize;

// use inflector::suffix::foreignkey::to_foreign_key;
// use inflector::suffix::foreignkey::is_foreign_key;

// use inflector::string::demodulize::demodulize;
// use inflector::string::deconstantize::deconstantize;

// use inflector::string::pluralize::to_plural;
// use inflector::string::singularize::to_singular;
...
fn main() {
...
  let camel_case_string: String = to_camel_case("some_string");
...
}

Advanced installation and usage:

If the project doesn't require singularize, pluralize, class, table, demodulize, deconstantize. Then in your cargo.toml you may wish to specify:

[dependencies.inflector]
version = "*"
default-features = false

Or

inflector = {version="*", default-features=false}

To test this crate locally with features off try:

cargo test --no-default-features

Contributing

This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Dependencies

~0–520KB