#string #case #casing

case-switcher

用于更改字符串大小写的库

3个稳定版本

1.0.2 2023年3月4日

#6 in #casing

Apache-2.0

8KB
69 行代码(不含注释)

Case Switcher

Crates.io Apache 2.0

此库提供更改字符串大小写约定的函数。

支持的格式

  • camelCase
  • dot.case
  • kebab-case
  • PascalCase
  • path/case
  • snake_case
  • Title Case

安装

cargo add case-switcher

示例

use case_switcher as cs;

fn main() {
    let sample = "avocado bagel-coffeeDONUTEclair_food.gravy";

    let result = cs::to_camel(sample);
    assert_eq!(result, "avocadoBagelCoffeeDONUTEclairFoodGravy");

    let result = cs::to_dot(sample);
    assert_eq!(result, "avocado.bagel.coffee.donut.eclair.food.gravy");

    let result = cs::to_kebab(sample);
    assert_eq!(result, "avocado-bagel-coffee-donut-eclair-food-gravy");

    let result = cs::to_pascal(sample);
    assert_eq!(result, "AvocadoBagelCoffeeDONUTEclairFoodGravy");

    let result = cs::to_path(sample);
    assert_eq!(result, "avocado/bagel/coffee/donut/eclair/food/gravy");

    let result = cs::to_snake(sample);
    assert_eq!(result, "avocado_bagel_coffee_donut_eclair_food_gravy");

    let result = cs::to_title(sample);
    assert_eq!(result, "Avocado Bagel Coffee DONUT Eclair Food Gravy");
}

支持开发者

Buy Me A Coffee

依赖项

~2.2–3MB
~53K SLoC