xw-devtool-cli 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,6 +26,7 @@
26
26
  - **二维码生成**:终端直接显示二维码,支持保存为 PNG 图片(带时间戳文件名)。
27
27
  - **特殊符号大全**:包含常用符号、箭头、数学符号、货币、希腊字母等 170+ 个符号,支持一键复制。
28
28
  - **Emoji 输入**:支持分类查看和选择常用 Emoji,一键复制到剪贴板。
29
+ - **HTML 实体工具**:支持 HTML 实体编码与解码 (如 `&` <-> `&amp;`)。
29
30
  - **便捷操作**:
30
31
  - 支持文件选择对话框 (Windows)。
31
32
  - 结果自动复制到剪贴板。
@@ -72,6 +73,7 @@ b. Hash Calculator (MD5/SHA/SM3)
72
73
  c. QR Code Generator
73
74
  d. Special Characters (Symbols)
74
75
  e. Emoji Picker
76
+ f. HTML Entity Encode/Decode
75
77
  0. Exit
76
78
  =================================
77
79
  ```
@@ -158,6 +160,14 @@ e. Emoji Picker
158
160
  - 分类展示常用 Emoji (表情、手势、动物、食物等)。
159
161
  - 输入编号选择并复制 Emoji 到剪贴板。
160
162
 
163
+ ### 15. HTML 实体编码/解码
164
+ - 选择 `f` 进入。
165
+ - 支持两种编码模式:
166
+ - **Standard**: 仅编码特殊字符(如 `<` `>` `&` 及非 ASCII 字符)。
167
+ - **Everything**: 编码所有字符(包括 ASCII 字母数字)。
168
+ - 支持直接回车读取剪贴板内容。
169
+ - 结果自动复制到剪贴板。
170
+
161
171
  ## 📄 License
162
172
 
163
173
  ISC
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xw-devtool-cli",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "type": "module",
5
5
  "description": "基于node的开发者助手cli",
6
6
  "main": "index.js",
@@ -48,6 +48,7 @@
48
48
  "clipboardy": "^5.0.2",
49
49
  "commander": "^14.0.2",
50
50
  "dayjs": "^1.11.19",
51
+ "he": "^1.2.0",
51
52
  "inquirer": "^13.1.0",
52
53
  "lorem-ipsum": "^2.0.8",
53
54
  "pinyin": "^4.0.0",
@@ -0,0 +1,57 @@
1
+ import inquirer from 'inquirer';
2
+ import he from 'he';
3
+ import { copy, read } from '../utils/clipboard.js';
4
+ import { selectFromMenu } from '../utils/menu.js';
5
+
6
+ export async function htmlEntitiesHandler() {
7
+ const mode = await selectFromMenu('HTML Entity Encode/Decode', [
8
+ { name: 'Encode (Standard - Special chars only)', value: 'encode' },
9
+ { name: 'Encode (Everything - All chars)', value: 'encodeAll' },
10
+ { name: 'Decode (HTML Entities -> Text)', value: 'decode' }
11
+ ]);
12
+
13
+ const actionName = mode.startsWith('encode') ? 'encode' : 'decode';
14
+
15
+ const { input } = await inquirer.prompt([
16
+ {
17
+ type: 'input',
18
+ name: 'input',
19
+ message: `Enter text to ${actionName} (Press Enter to paste from clipboard):`
20
+ }
21
+ ]);
22
+
23
+ let textToProcess = input;
24
+
25
+ if (!textToProcess || textToProcess.trim().length === 0) {
26
+ textToProcess = await read();
27
+ if (!textToProcess || textToProcess.trim().length === 0) {
28
+ console.log('Clipboard is empty or could not be read.');
29
+ return;
30
+ }
31
+ console.log(`\nUsing clipboard content: "${textToProcess.length > 50 ? textToProcess.substring(0, 47) + '...' : textToProcess}"`);
32
+ }
33
+
34
+ let result;
35
+ try {
36
+ if (mode === 'encode') {
37
+ // Standard encode: only special chars like < > & " ' and non-ASCII
38
+ result = he.encode(textToProcess, { encodeEverything: false });
39
+ } else if (mode === 'encodeAll') {
40
+ // Encode everything: includes ASCII alphanumeric
41
+ result = he.encode(textToProcess, { encodeEverything: true });
42
+ } else {
43
+ result = he.decode(textToProcess);
44
+ }
45
+
46
+ console.log(`\nResult:\n${result}\n`);
47
+
48
+ if (mode === 'encode' && result === textToProcess) {
49
+ console.log('(Note: No special characters were found to encode. Use "Encode (Everything)" if you want to encode standard letters.)\n');
50
+ }
51
+
52
+ await copy(result);
53
+ console.log('Result copied to clipboard!');
54
+ } catch (e) {
55
+ console.error(`Error processing HTML entities (${mode}):`, e.message);
56
+ }
57
+ }
package/src/index.js CHANGED
@@ -14,6 +14,7 @@ import { hashingHandler } from './commands/hashing.js';
14
14
  import { qrcodeHandler } from './commands/qrcode.js';
15
15
  import { specialCharsHandler } from './commands/specialChars.js';
16
16
  import { emojiHandler } from './commands/emoji.js';
17
+ import { htmlEntitiesHandler } from './commands/htmlEntities.js';
17
18
 
18
19
  process.on('SIGINT', () => {
19
20
  console.log('\nBye!');
@@ -44,7 +45,8 @@ const features = [
44
45
  { name: 'Hash Calculator (MD5/SHA/SM3)', value: 'hashing' },
45
46
  { name: 'QR Code Generator', value: 'qrcode' },
46
47
  { name: 'Special Characters (Symbols)', value: 'specialChars' },
47
- { name: 'Emoji Picker', value: 'emoji' }
48
+ { name: 'Emoji Picker', value: 'emoji' },
49
+ { name: 'HTML Entity Encode/Decode', value: 'htmlEntities' }
48
50
  ];
49
51
 
50
52
  async function main() {
@@ -165,6 +167,9 @@ async function handleAction(action) {
165
167
  case 'emoji':
166
168
  await emojiHandler();
167
169
  break;
170
+ case 'htmlEntities':
171
+ await htmlEntitiesHandler();
172
+ break;
168
173
  default:
169
174
  console.log('Feature not implemented yet.');
170
175
  }