普贤教程 › 包参考
strcase 包
命名风格转换
| 项 | 值 |
|---|---|
| 包名 | strcase |
| 版本 | 0.2.0 |
| 可用版本 | 0.1.0 / 0.2.0 |
| 入口 | strcase.px |
| 分类 | 文本与中文处理 |
| 文件数 / 行数 | 1 / 275 |
安装与引入
bash
pxpkg init # 首次 pxpkg add strcase@0.2.0 pxpkg install
px
import strcase所属分类教程:文本与中文处理
公开接口
| 函数 | 参数 |
|---|---|
str_words | s |
str_snake | s |
str_kebab | s |
str_screaming_snake | s |
str_camel | s |
str_pascal | s |
str_title_words | s |
其余 24 个 def(内部与辅助,可直接调用但不属稳定接口)
| 函数 | 参数 |
|---|---|
sc_is_upper | c |
sc_is_lower | c |
sc_is_digit | c |
sc_is_space | c |
sc_is_sep | c |
sc_join | words, sep, mode |
sc_camel_join | words, pascal |
str_train | s |
str_dot | s |
str_path | s |
str_lower_words | s |
str_upper_words | s |
str_capitalize | s |
str_uncapitalize | s |
str_swap_case | s |
str_reverse | s |
str_repeat | s, n |
str_pad_left | s, width, ch = " " |
str_pad_right | s, width, ch = " " |
str_pad_center | s, width, ch = " " |
str_count | s, sub |
str_is_upper | s |
str_is_lower | s |
str_is_title | s |
包内说明(源码头注释)
text
============================================================ 普贤生态库:registry/strcase —— 命名风格转换 ------------------------------------------------------------ 纯函数库(无 IO、无状态),编译(px build)与解释(px run)双模式一致。 对齐 Rust heck / convert_case、Go iancoleman/strcase、Python inflection 心智: str_snake(s) → "FooBar" → "foo_bar" str_kebab(s) → "FooBar" → "foo-bar" str_camel(s) → "foo_bar" → "fooBar" str_pascal(s) → "foo_bar" → "FooBar" str_screaming_snake(s) → "FooBar" → "FOO_BAR" str_title_words(s) → "foo_bar" → "Foo Bar" str_words(s) → 分词结果 list(供自定义风格) 分词规则(heck 风格): - 分隔符(空格 / - / _ / . / / / \\\\ / 制表换行回车)断开 - lower/digit → upper 处断开(camelCase → camel + Case) - 连续大写后接小写时,在最后一个大写前断开(HTTPServer → HTTP + Server) - 数字并入相邻单词(sha256 → sha256) 说明:面向 ASCII 标识符;非 ASCII 字符按原字符并入当前词(不按字节切割)。 大小写判定用 to_upper/to_lower(m197 已有原生 ord;PX-DEF-013 为对方跳号不存在,勿引用)。 ============================================================ ---- 字符分类 ----