6 个版本
| 0.3.0 | 2024年7月29日 |
|---|---|
| 0.2.1 | 2024年7月29日 |
| 0.2.0 | 2024年1月7日 |
| 0.1.2 | 2023年10月6日 |
251 在 模板引擎 中排名
每月下载 249 次
在 ctgen 中使用
17KB
269 行(不包括注释)
handlebars-inflector
handlebars-rust 的字符串屈折词助手
快速开始
使用 handlebars-rust v4.4.0 和 Inflector v0.11.4 开发和测试。
版本 0.1.* 与 handlebars 4 兼容。
版本 0.2.* 与 handlebars 5 兼容。(感谢 campeis)版本 0.3.* 与 handlebars 6 兼容。
注册
use handlebars::Handlebars;
use handlebars_inflector::HandlebarsInflector;
let mut h = Handlebars::new();
h.register_helper("inflect", Box::new(HandlebarsInflector));
用法
助手查找恰好一个字符串类型的参数。操作可以堆叠,但执行顺序为特定预定义的顺序。操作参数值不重要,只要参数存在即可。
。
。
{{inflect param to_singular=true to_sentence_case=true to_lower_case=true }}
操作
执行顺序中可能操作列表
to_camel_case: product_images to productImages
to_pascal_case: product_images to ProductImages
to_snake_case: ProductImages to product_images
to_screaming_snake_case: ProductImages to PRODUCT_IMAGES
to_kebab_case: product_images to product-images
to_train_case: product_images to Product-Images
to_sentence_case: product_images to Product images
to_title_case: product_images to Product Images
ordinalize: July 1 to July 1st
deordinalize:从 July 1st 到 July 1
to_foreign_key:从 Product image 到 product_image_id
demodulize:从 std::io 到 Io
deconstantize:从 std::io 到 Std
to_class_case:从 product_images 到 ProductImage
to_table_case:从 ProductImage 到 product_images
to_plural:从 ProductImage 到 ProductImages
to_singular:从 product_images 到 product_image
to_upper_case:从 product_images 到 PRODUCT_IMAGES
to_lower_case:从 ProductImages 到 productimages
请注意,某些组合可能不相互兼容。
如果您仍然绝对需要执行此类组合,您可以嵌套操作,如下所示
Bars::Foos 到 Bar
{{inflect (inflect param deconstantize=true) to_singular=true}}
致谢
这基本上是对Inflector crate的一个薄包装。向它的开发者表示敬意。
许可证
此库(handlebars-inflector)是在BSD 2许可证下开源的。
顺便说一下:我对许可证并不真正关心,所以我选择了我的依赖项中的一个许可证。 :)
依赖项
~3–4MB
~83K SLoC