xw-devtool-cli 1.0.7 → 1.0.9
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 +22 -0
- package/package.json +2 -1
- package/src/commands/htmlEntities.js +57 -0
- package/src/commands/placeholderImg.js +88 -0
- package/src/index.js +11 -1
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
- **图片工具**:
|
|
11
11
|
- **图片格式转换**:支持 PNG、JPG、WebP 格式互转,可调整压缩质量。
|
|
12
12
|
- **图片 ↔ Base64**:支持图片转 Base64 字符串,以及 Base64 还原为图片文件。
|
|
13
|
+
- **占位图生成**:快速生成指定尺寸、颜色、文字的占位图片 (Placeholder Image)。
|
|
13
14
|
- **Mock 数据生成**:
|
|
14
15
|
- 支持生成:英文段落 (Lorem Ipsum)、中文字符、中国居民身份证号、电子邮箱、URL、订单号、手机号、座机号。
|
|
15
16
|
- 支持批量生成。
|
|
@@ -26,6 +27,8 @@
|
|
|
26
27
|
- **二维码生成**:终端直接显示二维码,支持保存为 PNG 图片(带时间戳文件名)。
|
|
27
28
|
- **特殊符号大全**:包含常用符号、箭头、数学符号、货币、希腊字母等 170+ 个符号,支持一键复制。
|
|
28
29
|
- **Emoji 输入**:支持分类查看和选择常用 Emoji,一键复制到剪贴板。
|
|
30
|
+
- **HTML 实体工具**:支持 HTML 实体编码与解码 (如 `&` <-> `&`)。
|
|
31
|
+
- **占位图生成**:自定义尺寸、背景色、文字颜色和格式生成占位图。
|
|
29
32
|
- **便捷操作**:
|
|
30
33
|
- 支持文件选择对话框 (Windows)。
|
|
31
34
|
- 结果自动复制到剪贴板。
|
|
@@ -72,6 +75,8 @@ b. Hash Calculator (MD5/SHA/SM3)
|
|
|
72
75
|
c. QR Code Generator
|
|
73
76
|
d. Special Characters (Symbols)
|
|
74
77
|
e. Emoji Picker
|
|
78
|
+
f. HTML Entity Encode/Decode
|
|
79
|
+
g. Placeholder Image Generator
|
|
75
80
|
0. Exit
|
|
76
81
|
=================================
|
|
77
82
|
```
|
|
@@ -158,6 +163,23 @@ e. Emoji Picker
|
|
|
158
163
|
- 分类展示常用 Emoji (表情、手势、动物、食物等)。
|
|
159
164
|
- 输入编号选择并复制 Emoji 到剪贴板。
|
|
160
165
|
|
|
166
|
+
### 15. HTML 实体编码/解码
|
|
167
|
+
- 选择 `f` 进入。
|
|
168
|
+
- 支持两种编码模式:
|
|
169
|
+
- **Standard**: 仅编码特殊字符(如 `<` `>` `&` 及非 ASCII 字符)。
|
|
170
|
+
- **Everything**: 编码所有字符(包括 ASCII 字母数字)。
|
|
171
|
+
- 支持直接回车读取剪贴板内容。
|
|
172
|
+
- 结果自动复制到剪贴板。
|
|
173
|
+
|
|
174
|
+
### 16. 占位图生成 (Placeholder Image)
|
|
175
|
+
- 选择 `g` 进入。
|
|
176
|
+
- 支持自定义:
|
|
177
|
+
- **尺寸**: 宽度和高度 (px)。
|
|
178
|
+
- **颜色**: 背景色和文字颜色(支持 Hex 或颜色名)。
|
|
179
|
+
- **内容**: 自定义图片中间的文字(默认显示尺寸)。
|
|
180
|
+
- **格式**: 输出 PNG, JPG, WebP, GIF。
|
|
181
|
+
- 文件名默认包含时间戳,避免覆盖。
|
|
182
|
+
|
|
161
183
|
## 📄 License
|
|
162
184
|
|
|
163
185
|
ISC
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xw-devtool-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
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
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import sharp from 'sharp';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
export async function placeholderImgHandler() {
|
|
6
|
+
console.log('\n--- Generate Placeholder Image ---\n');
|
|
7
|
+
|
|
8
|
+
const answers = await inquirer.prompt([
|
|
9
|
+
{
|
|
10
|
+
type: 'input',
|
|
11
|
+
name: 'width',
|
|
12
|
+
message: 'Width (px):',
|
|
13
|
+
default: '300',
|
|
14
|
+
validate: (input) => {
|
|
15
|
+
const val = parseInt(input);
|
|
16
|
+
return !isNaN(val) && val > 0 ? true : 'Please enter a valid positive number';
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
type: 'input',
|
|
21
|
+
name: 'height',
|
|
22
|
+
message: 'Height (px):',
|
|
23
|
+
default: '200',
|
|
24
|
+
validate: (input) => {
|
|
25
|
+
const val = parseInt(input);
|
|
26
|
+
return !isNaN(val) && val > 0 ? true : 'Please enter a valid positive number';
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: 'input',
|
|
31
|
+
name: 'bgColor',
|
|
32
|
+
message: 'Background Color (Hex/Name):',
|
|
33
|
+
default: '#cccccc'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
type: 'input',
|
|
37
|
+
name: 'textColor',
|
|
38
|
+
message: 'Text Color (Hex/Name):',
|
|
39
|
+
default: '#333333'
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
type: 'input',
|
|
43
|
+
name: 'text',
|
|
44
|
+
message: 'Text (leave empty for size):',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: 'list',
|
|
48
|
+
name: 'format',
|
|
49
|
+
message: 'Output Format:',
|
|
50
|
+
choices: ['png', 'jpg', 'webp', 'gif'],
|
|
51
|
+
default: 'png'
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
type: 'input',
|
|
55
|
+
name: 'filename',
|
|
56
|
+
message: 'Filename (without extension):',
|
|
57
|
+
default: () => `placeholder-${Date.now()}`
|
|
58
|
+
}
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
const width = parseInt(answers.width);
|
|
62
|
+
const height = parseInt(answers.height);
|
|
63
|
+
const text = answers.text || `${width}x${height}`;
|
|
64
|
+
const fontSize = Math.floor(Math.min(width, height) / 5); // Heuristic for font size
|
|
65
|
+
|
|
66
|
+
// Create SVG buffer
|
|
67
|
+
const svgImage = `
|
|
68
|
+
<svg width="${width}" height="${height}" version="1.1" xmlns="http://www.w3.org/2000/svg">
|
|
69
|
+
<rect width="100%" height="100%" fill="${answers.bgColor}" />
|
|
70
|
+
<text x="50%" y="50%" font-size="${fontSize}" fill="${answers.textColor}" text-anchor="middle" dy=".3em" font-family="Arial, sans-serif">${text}</text>
|
|
71
|
+
</svg>
|
|
72
|
+
`;
|
|
73
|
+
|
|
74
|
+
const buffer = Buffer.from(svgImage);
|
|
75
|
+
|
|
76
|
+
const outputFilename = `${answers.filename}.${answers.format}`;
|
|
77
|
+
const outputPath = path.resolve(process.cwd(), outputFilename);
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
await sharp(buffer)
|
|
81
|
+
.toFormat(answers.format)
|
|
82
|
+
.toFile(outputPath);
|
|
83
|
+
|
|
84
|
+
console.log(`\nImage generated successfully: ${outputPath}`);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
console.error(`\nFailed to generate image: ${error.message}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
package/src/index.js
CHANGED
|
@@ -14,6 +14,8 @@ 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';
|
|
18
|
+
import { placeholderImgHandler } from './commands/placeholderImg.js';
|
|
17
19
|
|
|
18
20
|
process.on('SIGINT', () => {
|
|
19
21
|
console.log('\nBye!');
|
|
@@ -44,7 +46,9 @@ const features = [
|
|
|
44
46
|
{ name: 'Hash Calculator (MD5/SHA/SM3)', value: 'hashing' },
|
|
45
47
|
{ name: 'QR Code Generator', value: 'qrcode' },
|
|
46
48
|
{ name: 'Special Characters (Symbols)', value: 'specialChars' },
|
|
47
|
-
{ name: 'Emoji Picker', value: 'emoji' }
|
|
49
|
+
{ name: 'Emoji Picker', value: 'emoji' },
|
|
50
|
+
{ name: 'HTML Entity Encode/Decode', value: 'htmlEntities' },
|
|
51
|
+
{ name: 'Placeholder Image Generator', value: 'placeholderImg' }
|
|
48
52
|
];
|
|
49
53
|
|
|
50
54
|
async function main() {
|
|
@@ -165,6 +169,12 @@ async function handleAction(action) {
|
|
|
165
169
|
case 'emoji':
|
|
166
170
|
await emojiHandler();
|
|
167
171
|
break;
|
|
172
|
+
case 'htmlEntities':
|
|
173
|
+
await htmlEntitiesHandler();
|
|
174
|
+
break;
|
|
175
|
+
case 'placeholderImg':
|
|
176
|
+
await placeholderImgHandler();
|
|
177
|
+
break;
|
|
168
178
|
default:
|
|
169
179
|
console.log('Feature not implemented yet.');
|
|
170
180
|
}
|