Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion plugins/text-case-converter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# 更新日志

## 1.1.0

- 新增首字母大写、小驼峰、大驼峰、蛇形命名、尖叫蛇形命名
- 支持符号分隔与中文参与蛇形命名,五种命名风格可互转
- 补充 node --test 用例与异常通知

## 1.0.0
- 剪贴板智能大小写转换

- 剪贴板智能大小写转换
66 changes: 47 additions & 19 deletions plugins/text-case-converter/README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,61 @@
# text-case-converter

ZTools 插件:选中文本或剪贴板中的英文内容,一键智能/手动转换大小写
智能大小写转换。支持智能转大小写、转大写、转小写、大小写反转、首字母大写、小驼峰命名、大驼峰命名、蛇形命名、尖叫蛇形命名

## 功能

| 功能 | 触发关键字 | 选中有效文本时 |
| ----- | -------------------------- | ------- |
| 智能大小写 | `大小写` / `智能大小写` / `case` | 「智能大小写」 |
| 转大写 | `转大写` / `uppercase` | 「转大写」 |
| 转小写 | `转小写` / `lowercase` | 「转小写」 |
| 大小写反转 | `大小写反转` / `invert case` | 「大小写反转」 |
| 首字母大写 | `首字母大写` / `title case` | 「首字母大写」 |
| 小驼峰 | `小驼峰` / `camelCase` | 「小驼峰」 |
| 大驼峰 | `大驼峰` / `PascalCase` | 「大驼峰」 |
| 蛇形命名 | `蛇形命名` / `snake_case` | 「蛇形命名」 |
| 尖叫蛇形 | `尖叫蛇形` / `SCREAMING_SNAKE` | 「尖叫蛇形」 |

| 功能 | 触发关键字 | 选中有效文本时 |
| ----- | ------------------------ | ------------- |
| 智能大小写 | `大小写` / `智能大小写` / `case` | 超级面板显示「智能大小写」 |
| 转大写 | `转大写` / `uppercase` | 「转大写」 |
| 转小写 | `转小写` / `lowercase` | 「转小写」 |
| 大小写反转 | `大小写反转` / `invert case` | 「大小写反转」 |
**智能大小写**(只统计英文字母):大写多于小写则整段转小写,否则转大写。


**智能规则**(只统计英文字母 `[A-Za-z]`):大写字母数多于小写则整段转小写,否则(含相等)转大写。
**命名风格**:先按符号切开(保留符号),再智能分词后套用目标风格。蛇形/尖叫蛇形允许中文作为命名一段(`xxx_中文_xxx`);其余命名风格将中文视为分隔符。

**输出**:

- 选中文本触发 → 转换后粘贴回原选区,系统通知后退出
- 关键字触发 → 读取剪贴板,写回剪贴板并通知后退出
- 无英文字母 → 提示「未检测到有效英文字母」,直接退出
- 选中文本触发 → 粘贴回选区后退出
- 关键字触发 → 写回剪贴板后退出
- 无效或异常 → 系统通知提示后退出

## 示例

- 以插件名称为例:

| 指令 | 输入示例 | 输出示例 |
| ----- | ------------------- | ------------------- |
| 智能大小写 | `TextCaseConverter` | 按大小写计数转全大或全小 |
| 转大写 | `textCaseConverter` | `TEXTCASECONVERTER` |
| 转小写 | `TextCaseConverter` | `textcaseconverter` |
| 大小写反转 | `TextCase` | `tEXTcASE` |
| 首字母大写 | `textCaseConverter` | `Text Case Converter` |
| 小驼峰 | `Text Case Converter` | `textCaseConverter` |
| 大驼峰 | `text_case_converter` | `TextCaseConverter` |
| 蛇形命名 | `textCaseConverter` | `text_case_converter` |
| 尖叫蛇形 | `textCaseConverter` | `TEXT_CASE_CONVERTER` |
| 蛇形+中文 | `text转换Converter` | `text_转换_converter` |

> 可在 **插件详情-指令列表** 设置 **全局快捷键** 或 **禁用无用指令**

## 开发

```bash
pnpm install
pnpm run build # tsc → 生成 public/*.png → 组装 dist/
pnpm run icons # 仅生成 public/*.png(不提交,已 gitignore)
pnpm run dev # tsc -w(改完后需再 pnpm run build)
pnpm run test
pnpm run icons
pnpm run dev
```

本地调试请加载 `dist/`。图标由 `scripts/svg-to-png.cjs` 在构建时生成,仓库不提交 PNG;示例字母见脚本顶部 `SAMPLE_LETTER`。
本地调试请加载 `dist/`。图标由构建生成,仓库不提交 `public/`

## 构建产物(CI zip 根)

Expand All @@ -39,20 +64,23 @@ dist/
├── plugin.json
├── preload.js
├── case-convert.js
├── naming.js
└── public/
├── logo.png
├── smart.png
├── upper.png
├── lower.png
└── invert.png
├── invert.png
├── title.png
├── camel.png
├── pascal.png
├── snake.png
└── screaming.png
```



## 相关文档

- [第一个插件](https://ztoolscenter.github.io/ZTools-doc/first-plugin.html)
- [preload-js](https://ztoolscenter.github.io/ZTools-doc/preload-js.html)
- [plugin.json 配置](https://ztoolscenter.github.io/ZTools-doc/plugin-json.html)
- [插件 API](https://ztoolscenter.github.io/ZTools-doc/plugin-api.html)

11 changes: 7 additions & 4 deletions plugins/text-case-converter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
"name": "UCPr",
"url": "https://github.com/UCPr251"
},
"version": "1.0.0",
"version": "1.1.0",
"type": "commonjs",
"description": "剪贴板智能大小写转换",
"description": "智能大小写转换。支持智能转大小写、转大写、转小写、大小写反转、首字母大写、小驼峰命名、大驼峰命名、蛇形命名、尖叫蛇形命名\n可在 插件详情-指令列表 设置全局快捷键或禁用无用指令",
"scripts": {
"build": "tsc && node scripts/svg-to-png.cjs && node scripts/assemble-dist.cjs",
"prebuild": "pnpm icons",
"build": "tsc",
"postbuild": "node scripts/assemble-dist.cjs",
"icons": "node scripts/svg-to-png.cjs",
"dev": "tsc -w --preserveWatchOutput"
"dev": "tsc -w --preserveWatchOutput",
"test": "pnpm run build && node --test \"test/*.test.cjs\""
},
"devDependencies": {
"@resvg/resvg-js": "^2.6.2",
Expand Down
84 changes: 82 additions & 2 deletions plugins/text-case-converter/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"$schema": "node_modules/@ztools-center/ztools-api-types/resource/ztools.schema.json",
"name": "text-case-converter",
"title": "大小写转换",
"description": "剪贴板智能大小写转换",
"description": "智能大小写转换。支持智能转大小写、转大写、转小写、大小写反转、首字母大写、小驼峰命名、大驼峰命名、蛇形命名、尖叫蛇形命名。可在 插件详情-指令列表 设置全局快捷键或禁用无用指令",
"author": "UCPr",
"version": "1.0.0",
"version": "1.1.0",
"preload": "preload.js",
"logo": "public/logo.png",
"features": [
Expand Down Expand Up @@ -72,6 +72,86 @@
"minLength": 1
}
]
},
{
"code": "title",
"explain": "转为首字母大写(按词分割并空格连接)",
"icon": "public/title.png",
"mainHide": true,
"cmds": [
"首字母大写",
"title case",
{
"type": "regex",
"label": "首字母大写",
"match": "/[A-Za-z]/",
"minLength": 1
}
]
},
{
"code": "camel",
"explain": "转为小驼峰命名",
"icon": "public/camel.png",
"mainHide": true,
"cmds": [
"小驼峰",
"camelCase",
{
"type": "regex",
"label": "小驼峰",
"match": "/[A-Za-z]/",
"minLength": 1
}
]
},
{
"code": "pascal",
"explain": "转为大驼峰命名",
"icon": "public/pascal.png",
"mainHide": true,
"cmds": [
"大驼峰",
"PascalCase",
{
"type": "regex",
"label": "大驼峰",
"match": "/[A-Za-z]/",
"minLength": 1
}
]
},
{
"code": "snake",
"explain": "转为蛇形命名(下划线连接,可含中文)",
"icon": "public/snake.png",
"mainHide": true,
"cmds": [
"蛇形命名",
"snake_case",
{
"type": "regex",
"label": "蛇形命名",
"match": "/[A-Za-z]/",
"minLength": 1
}
]
},
{
"code": "screaming",
"explain": "转为尖叫蛇形命名(大写下划线)",
"icon": "public/screaming.png",
"mainHide": true,
"cmds": [
"尖叫蛇形",
"SCREAMING_SNAKE",
{
"type": "regex",
"label": "尖叫蛇形",
"match": "/[A-Za-z]/",
"minLength": 1
}
]
}
]
}
2 changes: 1 addition & 1 deletion plugins/text-case-converter/scripts/assemble-dist.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (!fs.existsSync(distDir)) {
process.exit(1)
}

const requiredJs = ['preload.js', 'case-convert.js']
const requiredJs = ['preload.js', 'case-convert.js', 'naming.js']
for (const file of requiredJs) {
if (!fs.existsSync(path.join(distDir, file))) {
console.error(`Missing dist/${file} — run tsc first`)
Expand Down
Loading
Loading