xw-devtool-cli 1.0.25 → 1.0.26

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
@@ -15,7 +15,11 @@
15
15
  - **图片分割**:支持网格等分(自定义行/列数)或自定义分割线(像素/百分比),自动生成分割后的图片文件。
16
16
  - **图片主色识别**:提取图片主色调(Hex/RGB/HSL/HSV),默认复制 Hex 到剪贴板,支持保存详细信息到文件。
17
17
  - **颜色吸取**:从图片中吸取单像素颜色或区域平均颜色,支持 px/% 坐标输入,结果显示颜色条并自动复制 Hex/Hex8。
18
- - **屏幕取色**:无需选择图片,直接在屏幕上将鼠标移动到目标位置按回车即可取色,支持透明度显示和预览。
18
+ - **屏幕取色**:直接在屏幕上将鼠标移动到目标位置按 **空格键** 即可取色。
19
+ > **注意事项**:
20
+ > 1. 使用前请确保命令行窗口处于 **激活状态** (Focus)。
21
+ > 2. 由于涉及跨进程通信,按下空格后可能存在轻微延时,请耐心等待结果。
22
+ > 3. 取色模式下会显示全屏十字辅助线,按 **回车键** 退出模式。
19
23
  - **占位图生成**:快速生成指定尺寸、颜色、文字的占位图片 (Placeholder Image)。
20
24
  - **Mock 数据生成**:
21
25
  - 支持生成:英文段落 (Lorem Ipsum)、中文字符、中国居民身份证号、电子邮箱、URL、订单号、手机号、座机号。
@@ -29,6 +33,7 @@
29
33
  - **Unicode 编解码**:文本与 Unicode 转义序列 (\uXXXX) 互转。
30
34
  - **UUID**:生成 UUID v4。
31
35
  - **中文转拼音**:将汉字转换为不带声调的拼音。
36
+ - **进制转换**:支持二进制、八进制、十进制、十六进制之间的互相转换。
32
37
  - **颜色转换**:Hex <-> RGB 互转,并在结果中显示颜色条预览(支持透明度棋盘背景),自动复制 Hex。
33
38
  - **颜色预览**:输入颜色并在终端显示颜色条,便于快速视觉确认,同时自动复制 Hex 到剪贴板。
34
39
  - **变量格式转换**:支持 CamelCase, PascalCase, SnakeCase, KebabCase, ConstantCase 互转。
@@ -297,6 +302,12 @@ Key features include: Base64 encoding/decoding, image format conversion, image <
297
302
  - **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.
298
303
  - **Image ↔ Base64**: Convert images to Base64 strings and vice versa.
299
304
  - **Image Dominant Color**: Extract dominant color (Hex/RGB/HSL/HSV), copy Hex to clipboard by default, or save details to file.
305
+ - **Image Color Picker**: Pick color from image (single pixel or average), supports px/% coordinates, shows color bar and auto-copies Hex/Hex8.
306
+ - **Screen Color Picker**: Pick color directly from screen by moving mouse and pressing **Space**.
307
+ > **Note**:
308
+ > 1. Ensure the terminal window is **Focused** before use.
309
+ > 2. There might be a slight delay after pressing Space due to system calls.
310
+ > 3. A full-screen crosshair is shown in picking mode; press **Enter** to exit.
300
311
  - **Placeholder Image**: Quickly generate placeholder images with custom size, color, and text.
301
312
  - **Mock Data**:
302
313
  - Generate: Lorem Ipsum, Chinese characters, ID cards, Emails, URLs, Order IDs, Phone numbers.
package/README_EN.md CHANGED
@@ -28,6 +28,7 @@ Key features include: Base64 encoding/decoding, image format conversion, image <
28
28
  - **Unicode Encode/Decode**: Text <-> Unicode escape sequences (\uXXXX).
29
29
  - **UUID**: Generate UUID v4.
30
30
  - **Pinyin**: Convert Chinese characters to Pinyin (without tone).
31
+ - **Base Converter**: Convert between Binary, Octal, Decimal, and Hexadecimal.
31
32
  - **Color Converter**: Hex <-> RGB, and shows a color bar preview in results (with checkerboard alpha simulation); Hex auto-copied.
32
33
  - **Color Preview**: Enter a color and display a color bar in terminal for quick visual confirmation; Hex is auto-copied to clipboard.
33
34
  - **Variable Format**: CamelCase, PascalCase, SnakeCase, KebabCase, ConstantCase.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xw-devtool-cli",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
4
4
  "type": "module",
5
5
  "description": "基于node的开发者助手cli",
6
6
  "main": "index.js",
@@ -0,0 +1,111 @@
1
+ import inquirer from 'inquirer';
2
+ import { copy } from '../utils/clipboard.js';
3
+ import { selectFromMenu } from '../utils/menu.js';
4
+ import i18next from '../i18n.js';
5
+
6
+ function cleanInput(input, base) {
7
+ input = input.trim();
8
+ if (base === 16 && (input.startsWith('0x') || input.startsWith('0X'))) {
9
+ return input.slice(2);
10
+ }
11
+ if (base === 2 && (input.startsWith('0b') || input.startsWith('0B'))) {
12
+ return input.slice(2);
13
+ }
14
+ if (base === 8 && (input.startsWith('0o') || input.startsWith('0O'))) {
15
+ return input.slice(2);
16
+ }
17
+ return input;
18
+ }
19
+
20
+ function isValid(input, base) {
21
+ const regexMap = {
22
+ 10: /^-?\d+$/,
23
+ 16: /^-?[0-9a-fA-F]+$/,
24
+ 2: /^-?[01]+$/,
25
+ 8: /^-?[0-7]+$/
26
+ };
27
+ return regexMap[base] ? regexMap[base].test(input) : false;
28
+ }
29
+
30
+ export async function baseConvertHandler() {
31
+ const { rawInput } = await inquirer.prompt([
32
+ {
33
+ type: 'input',
34
+ name: 'rawInput',
35
+ message: i18next.t('baseConvert.inputPrompt'),
36
+ validate: (input) => input.trim().length > 0 || i18next.t('baseConvert.invalidInput')
37
+ }
38
+ ]);
39
+
40
+ const inputBase = await selectFromMenu(i18next.t('baseConvert.selectBase'), [
41
+ { name: i18next.t('baseConvert.auto'), value: 'auto' },
42
+ { name: 'Decimal (10)', value: 10 },
43
+ { name: 'Hexadecimal (16)', value: 16 },
44
+ { name: 'Binary (2)', value: 2 },
45
+ { name: 'Octal (8)', value: 8 }
46
+ ], true, i18next.t('common.back'));
47
+
48
+ if (inputBase === '__BACK__') {
49
+ return;
50
+ }
51
+
52
+ let decimalValue;
53
+ let base = inputBase;
54
+ let inputToParse = rawInput.trim();
55
+
56
+ try {
57
+ if (inputBase === 'auto') {
58
+ if (inputToParse.startsWith('0x') || inputToParse.startsWith('0X')) {
59
+ base = 16;
60
+ inputToParse = inputToParse.slice(2);
61
+ } else if (inputToParse.startsWith('0b') || inputToParse.startsWith('0B')) {
62
+ base = 2;
63
+ inputToParse = inputToParse.slice(2);
64
+ } else if (inputToParse.startsWith('0o') || inputToParse.startsWith('0O')) {
65
+ base = 8;
66
+ inputToParse = inputToParse.slice(2);
67
+ } else {
68
+ base = 10;
69
+ }
70
+ } else {
71
+ inputToParse = cleanInput(inputToParse, base);
72
+ }
73
+
74
+ if (!isValid(inputToParse, base)) {
75
+ console.error(`\n${i18next.t('baseConvert.error')} (Base: ${base})`);
76
+ return;
77
+ }
78
+
79
+ decimalValue = parseInt(inputToParse, base);
80
+
81
+ if (isNaN(decimalValue)) {
82
+ throw new Error('Invalid number');
83
+ }
84
+ } catch (e) {
85
+ console.error(`\n${i18next.t('baseConvert.error')}`);
86
+ return;
87
+ }
88
+
89
+ const results = [];
90
+ results.push(`Decimal (10): ${decimalValue.toString(10)}`);
91
+ results.push(`Hexadecimal (16): 0x${decimalValue.toString(16).toUpperCase()}`);
92
+ results.push(`Binary (2): 0b${decimalValue.toString(2)}`);
93
+ results.push(`Octal (8): 0o${decimalValue.toString(8)}`);
94
+
95
+ console.log(`\n=== ${i18next.t('baseConvert.result')} ===`);
96
+ results.forEach(res => console.log(res));
97
+ console.log('==========================\n');
98
+
99
+ const copyChoice = await selectFromMenu(i18next.t('baseConvert.copyPrompt'), [
100
+ { name: 'Decimal', value: decimalValue.toString(10) },
101
+ { name: 'Hexadecimal', value: decimalValue.toString(16).toUpperCase() },
102
+ { name: 'Binary', value: decimalValue.toString(2) },
103
+ { name: 'Octal', value: decimalValue.toString(8) }
104
+ ], true, i18next.t('common.back'));
105
+
106
+ if (copyChoice === '__BACK__') {
107
+ return;
108
+ }
109
+
110
+ await copy(copyChoice);
111
+ }
package/src/index.js CHANGED
@@ -4,6 +4,7 @@ import i18next from './i18n.js';
4
4
  import { saveConfig } from './utils/config.js';
5
5
 
6
6
  import { urlHandler } from './commands/url.js';
7
+ import { baseConvertHandler } from './commands/baseConvert.js';
7
8
  import { base64Handler } from './commands/base64.js';
8
9
  import { unicodeHandler } from './commands/unicode.js';
9
10
  import { imgBase64Handler } from './commands/imgBase64.js';
@@ -57,6 +58,7 @@ function getFeatures() {
57
58
 
58
59
  // Encode/Decode & Formatting
59
60
  { name: i18next.t('menu.features.url'), value: 'url' },
61
+ { name: i18next.t('menu.features.baseConvert'), value: 'baseConvert' },
60
62
  { name: i18next.t('menu.features.base64'), value: 'base64' },
61
63
  { name: i18next.t('menu.features.unicode'), value: 'unicode' },
62
64
  { name: i18next.t('menu.features.htmlEntities'), value: 'htmlEntities' },
@@ -168,6 +170,9 @@ async function handleAction(action) {
168
170
  case 'url':
169
171
  await urlHandler();
170
172
  break;
173
+ case 'baseConvert':
174
+ await baseConvertHandler();
175
+ break;
171
176
  case 'base64':
172
177
  await base64Handler();
173
178
  break;
package/src/locales/en.js CHANGED
@@ -1,8 +1,11 @@
1
1
  export default {
2
+ common: {
3
+ back: 'Back to previous step'
4
+ },
2
5
  menu: {
3
6
  title: 'xw-devtool-cli Menu',
4
7
  exit: 'Exit',
5
- prompt: 'Please enter the feature key (0-9, a-z):',
8
+ prompt: 'Please enter feature key',
6
9
  invalid: 'Invalid selection. Please enter a valid menu key.',
7
10
  bye: 'Bye!',
8
11
  features: {
@@ -14,6 +17,7 @@ export default {
14
17
  placeholderImg: 'Placeholder Image Generator',
15
18
  qrcode: 'QR Code Generator',
16
19
  url: 'URL Encode/Decode',
20
+ baseConvert: 'Number Base Converter',
17
21
  base64: 'String Encode/Decode (Base64)',
18
22
  unicode: 'Unicode Encode/Decode',
19
23
  htmlEntities: 'HTML Entity Encode/Decode',
@@ -78,6 +82,15 @@ export default {
78
82
  result: 'Result:',
79
83
  error: 'Error processing URL:'
80
84
  },
85
+ baseConvert: {
86
+ inputPrompt: 'Enter number:',
87
+ invalidInput: 'Please enter a valid number',
88
+ selectBase: 'Select input base:',
89
+ auto: 'Auto-detect',
90
+ result: 'Conversion Results',
91
+ error: 'Invalid number for the selected base.',
92
+ copyPrompt: 'Select format to copy'
93
+ },
81
94
  imgSplit: {
82
95
  mode: 'Select split mode',
83
96
  modeGrid: 'Grid Split (Equal parts)',
package/src/locales/zh.js CHANGED
@@ -1,8 +1,11 @@
1
1
  export default {
2
+ common: {
3
+ back: '返回上一步'
4
+ },
2
5
  menu: {
3
6
  title: 'xw-devtool-cli 菜单',
4
7
  exit: '退出',
5
- prompt: '请输入功能键 (0-9, a-z):',
8
+ prompt: '请输入功能键',
6
9
  invalid: '无效选择,请输入有效的菜单键。',
7
10
  bye: '再见!',
8
11
  features: {
@@ -14,6 +17,7 @@ export default {
14
17
  placeholderImg: '占位图生成器',
15
18
  qrcode: '二维码生成器',
16
19
  url: 'URL 编码/解码',
20
+ baseConvert: '进制转换工具',
17
21
  base64: '字符串 编码/解码 (Base64)',
18
22
  unicode: 'Unicode 编码/解码',
19
23
  htmlEntities: 'HTML 实体 编码/解码',
@@ -78,6 +82,15 @@ export default {
78
82
  result: '结果:',
79
83
  error: '处理 URL 时出错:'
80
84
  },
85
+ baseConvert: {
86
+ inputPrompt: '请输入数字:',
87
+ invalidInput: '请输入有效的数字',
88
+ selectBase: '选择输入进制:',
89
+ auto: '自动检测',
90
+ result: '转换结果',
91
+ error: '输入的数字对于所选进制无效。',
92
+ copyPrompt: '选择要复制的格式'
93
+ },
81
94
  imgSplit: {
82
95
  mode: '选择分割模式',
83
96
  modeGrid: '网格分割 (等分)',