#snake #inflector #inflection #camel #pluralize

str_inflector

为Rust添加基于String的词形变化。支持蛇形、短横线、驼峰、句子、类、标题和表格形式,以及序数化、非序数化、去模块化、外键、复数化/单数化等功能,这些功能可以作为特性和对String类型执行操作的纯函数。

1 个不稳定版本

使用旧的Rust 2015

0.12.0 2022年1月30日

文本处理类别中排名第413

Download history 9389/week @ 2024-04-22 6845/week @ 2024-04-29 5814/week @ 2024-05-06 6213/week @ 2024-05-13 6601/week @ 2024-05-20 6939/week @ 2024-05-27 7540/week @ 2024-06-03 11239/week @ 2024-06-10 8042/week @ 2024-06-17 6627/week @ 2024-06-24 6912/week @ 2024-07-01 5716/week @ 2024-07-08 5090/week @ 2024-07-15 6586/week @ 2024-07-22 8071/week @ 2024-07-29 6998/week @ 2024-08-05

每月下载量26,975
16个crate中(3个直接)使用

BSD-2-Clause

175KB
2.5K SLoC

Rust (i)nflector

为Rust添加基于String的词形变化。支持蛇形、短横线、下划线、驼峰、句子、类和标题形式,以及序数化、非序数化、去模块化、去常量化、外键、表格形式和复数化/单数化等功能,这些功能可以作为特性和对&str和String类型执行操作的纯函数。源自:https://github.com/whatisinternet/Inflector


文档

文档可以在README中找到,或者通过下面的rust文档查看。

Rust文档及示例


安装

作为crate

[dependencies]
inflector = "*"

自行编译

  1. 安装Rust和cargo
  2. git clone https://github.com/abumni/inflector
  3. 库:cd inflector && cargo build --release --lib
  4. 您可以在target/release中找到库

使用/示例

...
// 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();
...
}

或者

...
// 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");
...
}

高级安装和使用

如果项目不需要单复数化、类、表格、去模块化、去常量化。那么在你的cargo.toml中,你可能希望指定

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

或者

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

要本地测试此crate而不启用功能,请尝试

cargo test --no-default-features

贡献

本项目旨在成为一个安全、欢迎的协作空间,贡献者应遵守贡献者守则

依赖

~0–500KB