xw-devtool-cli 1.0.3 → 1.0.4
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/package.json +2 -1
- package/src/commands/hashing.js +58 -0
- package/src/commands/qrcode.js +61 -0
- package/src/index.js +11 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xw-devtool-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "基于node的开发者助手cli",
|
|
6
6
|
"main": "index.js",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"inquirer": "^13.1.0",
|
|
52
52
|
"lorem-ipsum": "^2.0.8",
|
|
53
53
|
"pinyin": "^4.0.0",
|
|
54
|
+
"qrcode": "^1.5.4",
|
|
54
55
|
"sharp": "^0.33.5",
|
|
55
56
|
"tinycolor2": "^1.6.0",
|
|
56
57
|
"uuid": "^13.0.0"
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import crypto from 'node:crypto';
|
|
3
|
+
import { copy, read } from '../utils/clipboard.js';
|
|
4
|
+
import { selectFromMenu } from '../utils/menu.js';
|
|
5
|
+
|
|
6
|
+
export async function hashingHandler() {
|
|
7
|
+
const { input } = await inquirer.prompt([
|
|
8
|
+
{
|
|
9
|
+
type: 'input',
|
|
10
|
+
name: 'input',
|
|
11
|
+
message: 'Enter text to hash (Press Enter to paste from clipboard):',
|
|
12
|
+
}
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
let textToHash = input;
|
|
16
|
+
|
|
17
|
+
if (!textToHash || textToHash.length === 0) {
|
|
18
|
+
textToHash = await read();
|
|
19
|
+
if (!textToHash || textToHash.length === 0) {
|
|
20
|
+
console.log('Clipboard is empty or could not be read.');
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
console.log(`\nUsing clipboard content: "${textToHash}"`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const algorithms = [
|
|
27
|
+
{ name: 'MD5', algo: 'md5' },
|
|
28
|
+
{ name: 'SHA1', algo: 'sha1' },
|
|
29
|
+
{ name: 'SHA256', algo: 'sha256' },
|
|
30
|
+
{ name: 'SHA512', algo: 'sha512' },
|
|
31
|
+
{ name: 'SM3', algo: 'sm3' }
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
const results = [];
|
|
35
|
+
|
|
36
|
+
console.log('\n=== Hash Results ===');
|
|
37
|
+
for (const { name, algo } of algorithms) {
|
|
38
|
+
try {
|
|
39
|
+
const hash = crypto.createHash(algo).update(textToHash).digest('hex');
|
|
40
|
+
results.push({ name, value: hash });
|
|
41
|
+
console.log(`${name.padEnd(8)}: ${hash}`);
|
|
42
|
+
} catch (e) {
|
|
43
|
+
console.log(`${name.padEnd(8)}: Not supported in this environment`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
console.log('====================\n');
|
|
47
|
+
|
|
48
|
+
if (results.length === 0) return;
|
|
49
|
+
|
|
50
|
+
const copyChoice = await selectFromMenu('Select hash to copy',
|
|
51
|
+
results.map(r => ({
|
|
52
|
+
name: `${r.name} (${r.value.substring(0, 10)}...)`,
|
|
53
|
+
value: r.value
|
|
54
|
+
}))
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
await copy(copyChoice);
|
|
58
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import QRCode from 'qrcode';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import dayjs from 'dayjs';
|
|
6
|
+
import { read } from '../utils/clipboard.js';
|
|
7
|
+
import { selectFromMenu } from '../utils/menu.js';
|
|
8
|
+
|
|
9
|
+
export async function qrcodeHandler() {
|
|
10
|
+
const { input } = await inquirer.prompt([
|
|
11
|
+
{
|
|
12
|
+
type: 'input',
|
|
13
|
+
name: 'input',
|
|
14
|
+
message: 'Enter text to generate QR code (Press Enter to paste from clipboard):',
|
|
15
|
+
}
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
let textToEncode = input;
|
|
19
|
+
|
|
20
|
+
if (!textToEncode || textToEncode.length === 0) {
|
|
21
|
+
textToEncode = await read();
|
|
22
|
+
if (!textToEncode || textToEncode.length === 0) {
|
|
23
|
+
console.log('Clipboard is empty or could not be read.');
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
console.log(`\nUsing clipboard content: "${textToEncode}"`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
// Display in terminal
|
|
31
|
+
const string = await QRCode.toString(textToEncode, { type: 'terminal', small: true });
|
|
32
|
+
console.log('\n=== QR Code ===\n');
|
|
33
|
+
console.log(string);
|
|
34
|
+
console.log('===============\n');
|
|
35
|
+
|
|
36
|
+
// Ask if user wants to save to file
|
|
37
|
+
const action = await selectFromMenu('What would you like to do next?', [
|
|
38
|
+
{ name: 'Back to menu', value: 'back' },
|
|
39
|
+
{ name: 'Save as PNG image', value: 'save' }
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
if (action === 'save') {
|
|
43
|
+
const defaultFilename = `qrcode_${dayjs().format('YYYYMMDD_HHmmss')}.png`;
|
|
44
|
+
const { filename } = await inquirer.prompt([
|
|
45
|
+
{
|
|
46
|
+
type: 'input',
|
|
47
|
+
name: 'filename',
|
|
48
|
+
message: `Enter filename (default: ${defaultFilename}):`,
|
|
49
|
+
default: defaultFilename
|
|
50
|
+
}
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
const outputPath = path.resolve(process.cwd(), filename);
|
|
54
|
+
await QRCode.toFile(outputPath, textToEncode);
|
|
55
|
+
console.log(`\nQR Code saved to: ${outputPath}\n`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
} catch (err) {
|
|
59
|
+
console.error('Error generating QR code:', err.message);
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/index.js
CHANGED
|
@@ -10,6 +10,8 @@ import { uuidHandler } from './commands/uuid.js';
|
|
|
10
10
|
import { pinyinHandler } from './commands/pinyin.js';
|
|
11
11
|
import { colorHandler } from './commands/color.js';
|
|
12
12
|
import { variableFormatHandler } from './commands/variableFormat.js';
|
|
13
|
+
import { hashingHandler } from './commands/hashing.js';
|
|
14
|
+
import { qrcodeHandler } from './commands/qrcode.js';
|
|
13
15
|
|
|
14
16
|
process.on('SIGINT', () => {
|
|
15
17
|
console.log('\nBye!');
|
|
@@ -36,7 +38,9 @@ const features = [
|
|
|
36
38
|
{ name: 'Get UUID', value: 'uuid' },
|
|
37
39
|
{ name: 'Chinese to Pinyin', value: 'pinyin' },
|
|
38
40
|
{ name: 'Color Converter (Hex <-> RGB)', value: 'color' },
|
|
39
|
-
{ name: 'Variable Format Converter', value: 'variableFormat' }
|
|
41
|
+
{ name: 'Variable Format Converter', value: 'variableFormat' },
|
|
42
|
+
{ name: 'Hash Calculator (MD5/SHA/SM3)', value: 'hashing' },
|
|
43
|
+
{ name: 'QR Code Generator', value: 'qrcode' }
|
|
40
44
|
];
|
|
41
45
|
|
|
42
46
|
async function main() {
|
|
@@ -145,6 +149,12 @@ async function handleAction(action) {
|
|
|
145
149
|
case 'variableFormat':
|
|
146
150
|
await variableFormatHandler();
|
|
147
151
|
break;
|
|
152
|
+
case 'hashing':
|
|
153
|
+
await hashingHandler();
|
|
154
|
+
break;
|
|
155
|
+
case 'qrcode':
|
|
156
|
+
await qrcodeHandler();
|
|
157
|
+
break;
|
|
148
158
|
default:
|
|
149
159
|
console.log('Feature not implemented yet.');
|
|
150
160
|
}
|