xw-devtool-cli 1.0.19 → 1.0.21

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
@@ -1,6 +1,6 @@
1
1
  # xw-devtool-cli
2
2
 
3
- **中文** | [English Documentation](https://unpkg.com/xw-devtool-cli@latest/README_EN.md)
3
+ **中文** | [English](#english)
4
4
 
5
5
  一个基于 Node.js 的开发者命令行工具箱,旨在提供开箱即用的常用开发工具,帮助开发者快速处理日常任务。
6
6
 
@@ -10,7 +10,7 @@
10
10
 
11
11
  - **Base64 工具**:支持字符串与 Base64 互转,支持从剪贴板、文件或手动输入读取。
12
12
  - **图片工具**:
13
- - **图片格式转换**:支持 PNG、JPG、WebP 格式互转,可调整压缩质量。
13
+ - **图片格式转换**:支持 PNG、JPG、WebP、ICO 格式互转,可调整压缩质量。生成 ICO 时支持自定义尺寸(逗号分隔),留空则默认生成 `256` 尺寸。输出文件名默认带时间戳,避免覆盖。
14
14
  - **图片 ↔ Base64**:支持图片转 Base64 字符串,以及 Base64 还原为图片文件。
15
15
  - **占位图生成**:快速生成指定尺寸、颜色、文字的占位图片 (Placeholder Image)。
16
16
  - **Mock 数据生成**:
@@ -74,31 +74,31 @@ xw-devtool --en # 英文启动 (Start in English)
74
74
 
75
75
  ```text
76
76
  =================================
77
- xw-devtool-cli Menu
77
+ xw-devtool-cli 菜单
78
78
  =================================
79
- 1. Image <-> Base64
80
- 2. Image Format Convert
81
- 3. Placeholder Image Generator
82
- 4. QR Code Generator
83
- 5. URL Encode/Decode
84
- 6. String Encode/Decode (Base64)
85
- 7. Unicode Encode/Decode
86
- 8. HTML Entity Encode/Decode
87
- 9. Variable Format Converter
88
- a. JSON Format (Minify/Prettify)
89
- b. Chinese to Pinyin
90
- c. Time Format / Timestamp
91
- d. Time Calculation (Diff/Offset)
92
- e. Color Converter (Hex <-> RGB)
93
- f. Get UUID
94
- g. Hash Calculator (MD5/SHA/SM3)
95
- h. Mock Text
96
- i. Special Characters (Symbols)
97
- j. Emoji Picker
98
- k. Markdown Snippets
99
- l. VS Code Snippet Generator
100
- s. Settings (Language)
101
- 0. Exit
79
+ 1. 图片 Base64
80
+ 2. 图片格式转换
81
+ 3. 占位图生成
82
+ 4. 二维码生成
83
+ 5. URL 编解码
84
+ 6. 字符串 Base64 转换
85
+ 7. Unicode 编解码
86
+ 8. HTML 实体 编码/解码
87
+ 9. 变量格式转换
88
+ a. JSON 格式 (压缩/美化)
89
+ b. 中文转拼音
90
+ c. 时间格式 / 时间戳
91
+ d. 时间计算 (差值/偏移)
92
+ e. 颜色转换 (Hex RGB)
93
+ f. 获取 UUID
94
+ g. 哈希计算 (MD5/SHA/SM3)
95
+ h. Mock 文本
96
+ i. 特殊符号大全
97
+ j. Emoji 输入
98
+ k. Markdown 语法工具
99
+ l. VS Code 代码段生成器
100
+ s. 设置 (语言)
101
+ 0. 退出
102
102
  =================================
103
103
  ```
104
104
 
@@ -116,9 +116,10 @@ s. Settings (Language)
116
116
  ### 2. 图片格式转换
117
117
  - 选择 `2` 进入。
118
118
  - 选择源图片文件。
119
- - 选择目标格式 (PNG / JPG / WebP)。
119
+ - 选择目标格式 (PNG / JPG / WebP / ICO)。
120
120
  - 设置压缩参数(如 JPG 质量 1-100,PNG 压缩等级 0-9)。
121
121
  - 生成的新图片将保存在源文件同级目录。
122
+ - 生成 ICO 时可自定义尺寸,留空默认生成 `256` 尺寸;输出文件名包含时间戳。
122
123
 
123
124
  ### 3. 占位图生成 (Placeholder Image)
124
125
  - 选择 `3` 进入。
@@ -269,6 +270,230 @@ s. Settings (Language)
269
270
  - **注意**:为防止长文本刷屏,结果**仅自动复制到剪贴板**,不会在终端打印。
270
271
  - **提示**:生成的代码段会自动包含语法速查表 (Syntax Cheatsheet) 作为注释,方便参考。
271
272
 
272
- ## 📄 License
273
+ ## 📄 License
274
+
275
+ ISC
276
+
277
+ ---
278
+
279
+ ## English
280
+
281
+ **English** | [中文](#xw-devtool-cli)
282
+
283
+ A Node.js-based developer command-line toolbox designed to provide out-of-the-box common development tools to help developers handle daily tasks quickly.
284
+
285
+ Key features include: Base64 encoding/decoding, image format conversion, image <-> Base64, Mock data generation, timestamp/date formatting, time calculation, URL encoding/decoding, UUID generation, Chinese pinyin conversion, color conversion, variable format conversion, hash calculation, QR code generation, special symbols, Markdown snippets, VS Code snippet generation, etc. All results are automatically copied to the clipboard, greatly improving development efficiency.
286
+
287
+ ### ✨ Features
288
+
289
+ - **Base64 Tools**: Convert strings to/from Base64, supports reading from clipboard, file, or manual input.
290
+ - **Image Tools**:
291
+ - **Format Conversion**: Convert between PNG, JPG, WebP, ICO, with adjustable compression quality. For ICO, you can specify sizes (comma-separated); leave empty to generate `256` size by default. Output filenames include timestamps to avoid overwriting.
292
+ - **Image ↔ Base64**: Convert images to Base64 strings and vice versa.
293
+ - **Placeholder Image**: Quickly generate placeholder images with custom size, color, and text.
294
+ - **Mock Data**:
295
+ - Generate: Lorem Ipsum, Chinese characters, ID cards, Emails, URLs, Order IDs, Phone numbers.
296
+ - Supports batch generation.
297
+ - **Time Tools**:
298
+ - **Formatting**: Timestamp/Date string -> `YYYY-MM-DD HH:mm:ss`.
299
+ - **Timestamp**: Quickly get current millisecond timestamp.
300
+ - **Calculation**: Calculate date differences or offsets (Add/Subtract).
301
+ - **Dev Tools**:
302
+ - **URL Encode/Decode**
303
+ - **Unicode Encode/Decode**: Text <-> Unicode escape sequences (\uXXXX).
304
+ - **UUID**: Generate UUID v4.
305
+ - **Pinyin**: Convert Chinese characters to Pinyin (without tone).
306
+ - **Color Converter**: Hex <-> RGB.
307
+ - **Variable Format**: CamelCase, PascalCase, SnakeCase, KebabCase, ConstantCase.
308
+ - **Hash Calculator**: MD5, SHA1, SHA256, SHA512, SM3.
309
+ - **QR Code**: Display QR codes in terminal, save as PNG.
310
+ - **Special Symbols**: 170+ symbols, arrows, math symbols, etc.
311
+ - **Emoji Picker**: Browse and copy emojis.
312
+ - **HTML Entity**: Encode/Decode HTML entities.
313
+ - **Markdown Snippets**: Common Markdown templates.
314
+ - **VS Code Snippets**: Generate VS Code snippet JSON from code.
315
+ - **Convenience**:
316
+ - File selection dialog (Windows).
317
+ - Auto-copy results to clipboard.
318
+ - Auto-read from clipboard.
319
+ - Save large results to file.
320
+ - **Internationalization (i18n)**:
321
+ - Support **English** and **Chinese**.
322
+ - Switch via **Settings** in the menu or use CLI flags: `xw-devtool --en` / `xw-devtool --zh`.
323
+
324
+ ### 📦 Installation
325
+
326
+ #### Global Installation (Recommended)
327
+ ```bash
328
+ npm install -g xw-devtool-cli
329
+ ```
330
+ After installation, use `xw-devtool` or `xw-dev` command.
331
+
332
+ #### Run via npx
333
+ ```bash
334
+ npx xw-devtool-cli@latest
335
+ ```
273
336
 
274
- ISC
337
+ ### 🚀 Quick Start
338
+
339
+ Run in terminal:
340
+ ```bash
341
+ xw-devtool
342
+ ```
343
+
344
+ Or specify language directly:
345
+ ```bash
346
+ xw-devtool --en # Start in English
347
+ xw-devtool --zh # Start in Chinese
348
+ ```
349
+
350
+ The interactive menu will appear:
351
+
352
+ ```text
353
+ =================================
354
+ xw-devtool-cli Menu
355
+ =================================
356
+ 1. Image <-> Base64
357
+ 2. Image Format Convert
358
+ 3. Placeholder Image Generator
359
+ 4. QR Code Generator
360
+ 5. URL Encode/Decode
361
+ 6. String Encode/Decode (Base64)
362
+ 7. Unicode Encode/Decode
363
+ 8. HTML Entity Encode/Decode
364
+ 9. Variable Format Converter
365
+ a. JSON Format (Minify/Prettify)
366
+ b. Chinese to Pinyin
367
+ c. Time Format / Timestamp
368
+ d. Time Calculation (Diff/Offset)
369
+ e. Color Converter (Hex <-> RGB)
370
+ f. Get UUID
371
+ g. Hash Calculator (MD5/SHA/SM3)
372
+ h. Mock Text
373
+ i. Special Characters (Symbols)
374
+ j. Emoji Picker
375
+ k. Markdown Snippets
376
+ l. VS Code Snippet Generator
377
+ s. Settings (Language)
378
+ 0. Exit
379
+ =================================
380
+ ```
381
+
382
+ ### 📖 Detailed Usage
383
+
384
+ #### 1. Image <-> Base64
385
+ - Select `1`.
386
+ - **Image -> Base64**:
387
+ - Select image file.
388
+ - Output Base64 string (can save to `.txt`).
389
+ - **Base64 -> Image**:
390
+ - Input Base64 string (file or clipboard).
391
+ - Auto-detect format and save as file.
392
+
393
+ #### 2. Image Format Convert
394
+ - Select `2`.
395
+ - Select source image.
396
+ - Select target format (PNG / JPG / WebP).
397
+ - Set quality/compression.
398
+ - Saved in the same directory.
399
+
400
+ #### 3. Placeholder Image Generator
401
+ - Select `3`.
402
+ - **Mode 1: Local Image File**
403
+ - Generate file locally.
404
+ - Customize: Size, Colors, Text, Format.
405
+ - **Mode 2: Remote Image URL**
406
+ - Generate URL and copy to clipboard.
407
+ - Supports: Picsum Photos, DummyImage, Via Placeholder, Placehold.jp, DevTool Tech, FPO Img.
408
+
409
+ #### 4. QR Code Generator
410
+ - Select `4`.
411
+ - Input text or URL.
412
+ - Preview in terminal.
413
+ - Option to save as PNG.
414
+
415
+ #### 5. URL Encode/Decode
416
+ - Select `5`.
417
+ - Select `Encode` or `Decode`.
418
+ - Input URL, result auto-copied.
419
+
420
+ #### 6. String Base64
421
+ - Select `6`.
422
+ - Input sources: Clipboard, File, Manual.
423
+ - Output: Copy, Save to file.
424
+
425
+ #### 7. Unicode Encode/Decode
426
+ - Select `7`.
427
+ - **Encode**: Text to Unicode escape sequences.
428
+ - **Non-ASCII Only**: Recommended.
429
+ - **All Characters**.
430
+ - **Decode**: Unicode to Text.
431
+
432
+ #### 8. HTML Entity Encode/Decode
433
+ - Select `8`.
434
+ - **Standard**: Special chars only.
435
+ - **Everything**: All chars.
436
+
437
+ #### 9. Variable Format Converter
438
+ - Select `9`.
439
+ - Input variable name.
440
+ - Shows CamelCase, PascalCase, SnakeCase, KebabCase, ConstantCase.
441
+ - Select one to copy.
442
+
443
+ #### 10. JSON Format
444
+ - Select `a`.
445
+ - **Minify**: Remove whitespace.
446
+ - **Prettify (2/4 spaces)**.
447
+ - **Note**: Results copied to clipboard only (to avoid flooding terminal).
448
+
449
+ #### 11. Chinese to Pinyin
450
+ - Select `b`.
451
+ - Input Chinese string.
452
+ - Output Pinyin (no tone).
453
+
454
+ #### 12. Time Format
455
+ - Select `c`.
456
+ - Timestamp <-> Date String.
457
+ - Enter to get current timestamp.
458
+
459
+ #### 13. Time Calculation
460
+ - Select `d`.
461
+ - **Diff**: Calculate difference between two dates.
462
+ - **Offset**: Calculate date after add/subtract time units.
463
+
464
+ #### 14. Color Converter
465
+ - Select `e`.
466
+ - Hex <-> RGB.
467
+
468
+ #### 15. Get UUID
469
+ - Select `f`.
470
+ - Generate UUID v4.
471
+
472
+ #### 16. Hash Calculator
473
+ - Select `g`.
474
+ - Input text.
475
+ - Shows MD5, SHA1, SHA256, SHA512, SM3.
476
+
477
+ #### 17. Mock Data
478
+ - Select `h`.
479
+ - Generate Lorem Ipsum, Names, IDs, Emails, Phones, etc.
480
+
481
+ #### 18. Special Symbols
482
+ - Select `i`.
483
+ - Grid view of symbols.
484
+ - Select index to copy.
485
+
486
+ #### 19. Emoji Picker
487
+ - Select `j`.
488
+ - Categorized emojis.
489
+ - Select to copy.
490
+
491
+ #### 20. Markdown Snippets
492
+ - Select `k`.
493
+ - Templates for Headers, Lists, Tables, Links, etc.
494
+
495
+ #### 21. VS Code Snippet Generator
496
+ - Select `l`.
497
+ - Convert code to `.code-snippets` JSON body.
498
+ - Auto-escapes quotes/newlines.
499
+ - Copied to clipboard.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xw-devtool-cli",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "type": "module",
5
5
  "description": "基于node的开发者助手cli",
6
6
  "main": "index.js",
@@ -75,6 +75,7 @@
75
75
  "qrcode": "^1.5.4",
76
76
  "sharp": "^0.33.5",
77
77
  "tinycolor2": "^1.6.0",
78
- "uuid": "^13.0.0"
78
+ "uuid": "^13.0.0",
79
+ "to-ico": "^1.1.5"
79
80
  }
80
81
  }
@@ -2,6 +2,7 @@ import inquirer from 'inquirer';
2
2
  import fs from 'fs';
3
3
  import path from 'path';
4
4
  import sharp from 'sharp';
5
+ import toIco from 'to-ico';
5
6
  import { selectFromMenu } from '../utils/menu.js';
6
7
  import { selectFile, saveFile } from '../utils/fileDialog.js';
7
8
  import { defaultFileName } from '../utils/output.js';
@@ -15,7 +16,8 @@ function getExt(p) {
15
16
  function suggestOutputPath(inputPath, targetExt) {
16
17
  const dir = path.dirname(inputPath);
17
18
  const base = path.basename(inputPath, path.extname(inputPath));
18
- return path.join(dir, `${base}.${targetExt}`);
19
+ const ts = Date.now();
20
+ return path.join(dir, `${base}-${ts}.${targetExt}`);
19
21
  }
20
22
 
21
23
  async function pickInputFile() {
@@ -48,7 +50,8 @@ async function pickTargetFormat(currentExt) {
48
50
  const options = [
49
51
  { name: 'png', value: 'png' },
50
52
  { name: 'jpg', value: 'jpg' },
51
- { name: 'webp', value: 'webp' }
53
+ { name: 'webp', value: 'webp' },
54
+ { name: 'ico', value: 'ico' }
52
55
  ].filter(o => o.value !== currentExt);
53
56
  return await selectFromMenu('Target format', options);
54
57
  }
@@ -69,6 +72,18 @@ async function pickQuality(targetExt) {
69
72
  { type: 'number', name: 'quality', message: 'WebP quality (1-100):', default: 80, validate: n => (n >= 1 && n <= 100) ? true : '1-100' }
70
73
  ]);
71
74
  return { webpQuality: quality };
75
+ } else if (targetExt === 'ico') {
76
+ const { sizesStr } = await inquirer.prompt([
77
+ { type: 'input', name: 'sizesStr', message: 'Enter ICO sizes (comma-separated). Leave empty for default 256:', default: '' }
78
+ ]);
79
+ const defaultSizes = [256];
80
+ const allowed = new Set([16, 24, 32, 48, 64, 128, 256]);
81
+ const parsed = (sizesStr || '')
82
+ .split(',')
83
+ .map(s => parseInt(s.trim()))
84
+ .filter(n => Number.isFinite(n) && allowed.has(n));
85
+ const uniq = Array.from(new Set(parsed));
86
+ return { icoSizes: uniq.length ? uniq : defaultSizes };
72
87
  }
73
88
  return {};
74
89
  }
@@ -82,7 +97,7 @@ export async function imgConvertHandler() {
82
97
  console.log(`Target format: ${targetExt}`);
83
98
  const opts = await pickQuality(targetExt);
84
99
 
85
- let outPath = saveFile(suggestOutputPath(inputPath, targetExt), 'Image Files|*.png;*.jpg;*.jpeg;*.webp|All Files|*.*');
100
+ let outPath = saveFile(suggestOutputPath(inputPath, targetExt), 'Image Files|*.png;*.jpg;*.jpeg;*.webp;*.ico|All Files|*.*');
86
101
  if (!outPath) {
87
102
  const def = suggestOutputPath(inputPath, targetExt);
88
103
  const ans = await inquirer.prompt([
@@ -93,19 +108,27 @@ export async function imgConvertHandler() {
93
108
 
94
109
  try {
95
110
  fs.mkdirSync(path.dirname(outPath), { recursive: true });
96
- let pipeline = sharp(inputPath);
97
- if (targetExt === 'png') {
98
- pipeline = pipeline.png({ compressionLevel: opts.pngCompressionLevel ?? 6 });
99
- } else if (targetExt === 'jpg') {
100
- pipeline = pipeline.jpeg({ quality: opts.jpegQuality ?? 80 });
101
- if (inputExt !== 'jpg') {
102
- pipeline = pipeline.flatten({ background: { r: 255, g: 255, b: 255 } });
111
+ if (targetExt === 'ico') {
112
+ const basePng = await sharp(inputPath).ensureAlpha().png().toBuffer();
113
+ const sizes = opts.icoSizes ?? [16, 24, 32, 48, 64, 128, 256];
114
+ const icoBuffer = await toIco([basePng], { resize: true, sizes });
115
+ fs.writeFileSync(outPath, icoBuffer);
116
+ console.log(`Converted to ICO: ${inputPath} -> ${outPath}`);
117
+ } else {
118
+ let pipeline = sharp(inputPath);
119
+ if (targetExt === 'png') {
120
+ pipeline = pipeline.png({ compressionLevel: opts.pngCompressionLevel ?? 6 });
121
+ } else if (targetExt === 'jpg') {
122
+ pipeline = pipeline.jpeg({ quality: opts.jpegQuality ?? 80 });
123
+ if (inputExt !== 'jpg') {
124
+ pipeline = pipeline.flatten({ background: { r: 255, g: 255, b: 255 } });
125
+ }
126
+ } else if (targetExt === 'webp') {
127
+ pipeline = pipeline.webp({ quality: opts.webpQuality ?? 80 });
103
128
  }
104
- } else if (targetExt === 'webp') {
105
- pipeline = pipeline.webp({ quality: opts.webpQuality ?? 80 });
129
+ await pipeline.toFile(outPath);
130
+ console.log(`Converted: ${inputPath} -> ${outPath}`);
106
131
  }
107
- await pipeline.toFile(outPath);
108
- console.log(`Converted: ${inputPath} -> ${outPath}`);
109
132
  } catch (e) {
110
133
  console.error('Conversion error:', e.message);
111
134
  }