xw-devtool-cli 1.0.39 → 1.0.40

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
@@ -4,7 +4,7 @@
4
4
 
5
5
  一个基于 Node.js 的开发者命令行工具箱,旨在提供开箱即用的常用开发工具,帮助开发者快速处理日常任务。
6
6
 
7
- 主要功能包括:Base64 编解码、图片格式转换、图片与 Base64 互转、Mock 数据生成、时间戳/日期格式化、时间计算、URL 编解码、UUID 生成、汉字转拼音、颜色转换、变量格式转换、哈希计算、二维码生成、特殊符号大全、Markdown 语法工具、VS Code 代码段生成、当前目录树生成等。所有结果均自动复制到剪贴板,极大提升开发效率。
7
+ 主要功能包括:Base64 编解码、图片格式转换、图片与 Base64 互转、Mock 数据生成、时间戳/日期格式化、时间计算、URL 编解码、UUID 生成、汉字转拼音、颜色转换、变量格式转换、哈希计算、二维码生成、特殊符号大全、Markdown 语法工具、VS Code 代码段生成、当前目录树生成等。大部分结果可一键复制到剪贴板,极大提升开发效率。
8
8
 
9
9
  ## ✨ 功能特性
10
10
 
@@ -51,7 +51,7 @@
51
51
  - **Markdown 语法工具**:提供常用 Markdown 语法模板 (Headers, Lists, Tables, Code 等),一键复制。
52
52
  - **VS Code 代码段生成器**:将代码转换为 VS Code Snippet JSON,自动生成语法速查表注释。
53
53
  - **Git 助手**: 标准化生成 Git 分支名 (feature/bugfix/custom) 和 Conventional Commits 提交日志。
54
- - **当前目录树生成**:生成当前目录的文件树结构,支持指定层级,默认输出全部层级并自动复制到剪贴板。
54
+ - **当前目录树生成**:生成当前目录的文件树结构,支持指定层级,输出可选复制到剪贴板或导出为 txt 文件。
55
55
  - **占位图生成**:自定义尺寸、背景色、文字颜色和格式生成占位图。
56
56
  - **便捷操作**:
57
57
  - 支持文件选择对话框 (Windows)。
@@ -133,8 +133,8 @@ s. Emoji 选择器
133
133
  t. Markdown 片段
134
134
  u. VS Code 代码片段生成
135
135
  v. Git 助手 (分支/提交模板)
136
- w. 当前目录树生成
137
- x. 设置 / 语言 (Settings)
136
+ w. 当前目录树生成
137
+ x. 设置 / 语言 (Settings)
138
138
  0. 退出
139
139
  =================================
140
140
  ```
@@ -171,13 +171,15 @@ x. 设置 / 语言 (Settings)
171
171
  - 默认输出到源目录下的 `compressed_YYYYMMDD_HHmmss` 文件夹。
172
172
  - 自动复制输出目录路径。
173
173
  - 完成后可选直接打开输出目录。
174
-
175
- ### 当前目录树生成
176
- - 选择 `w` 进入。
177
- - 先选择层级模式:
178
- - **所有层级**:从当前目录递归到最深层。
179
- - **指定层级**:输入层级数字(`0` 表示仅根目录,`1` 表示包含第一层子项)。
180
- - 生成后的目录树会自动复制到剪贴板,便于粘贴到文档或 Issue 中。
174
+
175
+ ### 当前目录树生成
176
+ - 选择 `w` 进入。
177
+ - 先选择层级模式:
178
+ - **所有层级**:从当前目录递归到最深层。
179
+ - **指定层级**:输入层级数字(`0` 表示仅根目录,`1` 表示包含第一层子项)。
180
+ - 再选择输出方式:
181
+ - **复制到剪贴板**:自动复制结果,便于粘贴到文档或 Issue 中。
182
+ - **输出为 txt 文件**:可选择保存位置,默认文件名带时间戳,避免覆盖旧文件。
181
183
 
182
184
  ### 3. 占位图生成 (Placeholder Image)
183
185
  - 选择 `3` 进入。
@@ -243,13 +245,16 @@ x. 设置 / 语言 (Settings)
243
245
 
244
246
  ### 10. JSON 格式化
245
247
  - 选择 `a` 进入。
246
- - 支持三种模式:
247
- - **Minify**: 压缩 JSON (去除空格和换行)。
248
- - **Prettify (2 spaces)**: 美化 JSON (2 空格缩进)。
249
- - **Prettify (4 spaces)**: 美化 JSON (4 空格缩进)。
250
- - 支持自动修复简单的非标准 JSON (如 key 缺少引号的 JS 对象)。
251
- - 支持从剪贴板、文件或手动输入读取。
252
- - **注意**:为防止长文本刷屏,结果**仅自动复制到剪贴板**,不会在终端打印。
248
+ - 支持两种输入来源:
249
+ - **从剪贴板读取**:自动读取当前剪贴板内容。
250
+ - **从本地文件读取**:支持文件对话框选择或手动输入路径。
251
+ - 优先按标准 JSON 解析;若遇到常见非标准写法(如代码块包裹、单引号、未加引号的 key、尾随逗号、HTML 实体),会自动修正常见问题后再格式化。
252
+ - 统一转换为 2 空格缩进的标准 JSON 格式。
253
+ - 支持在各选项列表中返回上一步。
254
+ - 输出支持:
255
+ - **复制到剪贴板**(默认推荐)。
256
+ - **保存到文件**(默认文件名带时间戳,避免覆盖旧文件)。
257
+ - **注意**:为防止长文本刷屏,结果不会在终端完整打印。
253
258
 
254
259
  ### 11. 中文转拼音
255
260
  - 选择 `b` 进入。
@@ -517,8 +522,11 @@ v. Git Helper (Branch/Commit Template) w. Settings / Language
517
522
 
518
523
  #### 10. JSON Format
519
524
  - Select `a`.
520
- - **Minify**: Remove whitespace.
521
- - **Prettify (2/4 spaces)**.
525
+ - Supports two input sources:
526
+ - **Clipboard**: Read content directly from clipboard.
527
+ - **Local file**: Pick by file dialog or enter file path manually.
528
+ - Strictly parses standard JSON and converts to canonical JSON with 2-space indentation.
529
+ - Supports going back to previous step in option lists.
522
530
  - **Note**: Results copied to clipboard only (to avoid flooding terminal).
523
531
 
524
532
  #### 11. Chinese to Pinyin
package/README_EN.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  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.
6
6
 
7
- 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, current directory tree generation, etc. All results are automatically copied to the clipboard, greatly improving development efficiency.
7
+ 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, current directory tree generation, etc. Most results can be copied to the clipboard in one step, greatly improving development efficiency.
8
8
 
9
9
  ## ✨ Features
10
10
 
@@ -45,7 +45,7 @@ Key features include: Base64 encoding/decoding, image format conversion, image <
45
45
  - **Markdown Snippets**: Common Markdown templates.
46
46
  - **VS Code Snippets**: Generate VS Code snippet JSON from code.
47
47
  - **Git Helper**: Generate standardized Git branch names (feature/bugfix) and Conventional Commits messages.
48
- - **Current Directory Tree**: Generate the file tree for the current directory, with optional depth limit (default: all levels), and copy result to clipboard.
48
+ - **Current Directory Tree**: Generate the file tree for the current directory with optional depth limit, then choose to copy to clipboard or export as a `.txt` file.
49
49
  - **Convenience**:
50
50
  - File selection dialog (Windows).
51
51
  - Auto-copy results to clipboard.
@@ -189,9 +189,16 @@ s. Settings (Language)
189
189
 
190
190
  ### 10. JSON Format
191
191
  - Select `a`.
192
- - **Minify**: Remove whitespace.
193
- - **Prettify (2/4 spaces)**.
194
- - **Note**: Results copied to clipboard only (to avoid flooding terminal).
192
+ - Supports two input sources:
193
+ - **Clipboard**: Read content directly from clipboard.
194
+ - **Local file**: Pick by file dialog or enter file path manually.
195
+ - Parses standard JSON first; if it detects common non-standard patterns (code fences, single quotes, unquoted keys, trailing commas, HTML entities), it auto-fixes and then formats.
196
+ - Converts to canonical JSON with 2-space indentation.
197
+ - Supports going back to previous step in option lists.
198
+ - Output supports:
199
+ - **Copy to clipboard** (recommended).
200
+ - **Save to file** (default filename includes timestamp to avoid overwriting old files).
201
+ - **Note**: Full output is not printed to terminal to avoid flooding.
195
202
 
196
203
  ### 11. Chinese to Pinyin
197
204
  - Select `b`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xw-devtool-cli",
3
- "version": "1.0.39",
3
+ "version": "1.0.40",
4
4
  "type": "module",
5
5
  "description": "基于node的开发者助手cli",
6
6
  "main": "index.js",
@@ -43,6 +43,7 @@
43
43
  "placeholder-image",
44
44
  "qrcode",
45
45
  "json-format",
46
+ "json-formatter",
46
47
  "variable-case",
47
48
  "hash",
48
49
  "encryption",
@@ -3,7 +3,8 @@ import path from 'path';
3
3
  import inquirer from 'inquirer';
4
4
  import i18next from '../i18n.js';
5
5
  import { selectFromMenu } from '../utils/menu.js';
6
- import { copy } from '../utils/clipboard.js';
6
+ import { saveFile } from '../utils/fileDialog.js';
7
+ import { defaultFileName, outputText } from '../utils/output.js';
7
8
 
8
9
  export async function fileTreeHandler() {
9
10
  const mode = await selectFromMenu(
@@ -39,14 +40,48 @@ export async function fileTreeHandler() {
39
40
  maxDepth = Number.parseInt(depth, 10);
40
41
  }
41
42
 
43
+ const outputMode = await selectFromMenu(
44
+ i18next.t('fileTree.outputMode'),
45
+ [
46
+ { name: i18next.t('fileTree.outputClipboard'), value: 'clipboard' },
47
+ { name: i18next.t('fileTree.outputFile'), value: 'file' }
48
+ ],
49
+ true,
50
+ i18next.t('common.back')
51
+ );
52
+ if (outputMode === '__BACK__') {
53
+ return;
54
+ }
55
+
42
56
  const cwd = process.cwd();
43
57
  const tree = buildTree(cwd, maxDepth);
44
58
  const depthText = Number.isFinite(maxDepth) ? String(maxDepth) : i18next.t('fileTree.allDepth');
45
59
 
46
- console.log(i18next.t('fileTree.generated', { path: cwd, depth: depthText }));
47
- const preview = tree.length > 2000 ? `${tree.slice(0, 1000)}\n...\n${tree.slice(-800)}` : tree;
48
- console.log(`\n${preview}\n`);
49
- await copy(tree);
60
+ if (outputMode === 'file') {
61
+ const defaultName = defaultFileName('file-tree', 'txt');
62
+ let savePath = saveFile(defaultName, 'Text Files|*.txt|All Files|*.*') || '';
63
+ if (!savePath) {
64
+ const answer = await inquirer.prompt([
65
+ {
66
+ type: 'input',
67
+ name: 'path',
68
+ message: i18next.t('fileTree.enterOutputPath'),
69
+ default: defaultName,
70
+ validate: (value) => value.trim() ? true : i18next.t('fileTree.outputPathRequired')
71
+ }
72
+ ]);
73
+ savePath = answer.path;
74
+ }
75
+
76
+ await outputText(tree, { showPreview: false, savePath, copyToClipboard: false });
77
+ console.log(i18next.t('fileTree.generatedFile', { path: cwd, depth: depthText, savePath }));
78
+ return;
79
+ }
80
+
81
+ console.log(i18next.t('fileTree.generatedClipboard', { path: cwd, depth: depthText }));
82
+ const preview = tree.length > 2000 ? `${tree.slice(0, 1000)}\n...\n${tree.slice(-800)}` : tree;
83
+ console.log(`\n${preview}\n`);
84
+ await outputText(tree, { showPreview: false });
50
85
  }
51
86
 
52
87
  export function buildTree(rootPath, maxDepth) {
@@ -1,83 +1,161 @@
1
+ import fs from 'fs';
2
+ import he from 'he';
1
3
  import inquirer from 'inquirer';
2
- import { copy } from '../utils/clipboard.js';
4
+ import i18next from '../i18n.js';
5
+ import { read } from '../utils/clipboard.js';
6
+ import { saveFile, selectFile } from '../utils/fileDialog.js';
3
7
  import { selectFromMenu } from '../utils/menu.js';
4
- import fs from 'fs';
8
+ import { defaultFileName, outputText } from '../utils/output.js';
5
9
 
6
- export async function jsonFormatHandler() {
7
- const mode = await selectFromMenu('JSON Format', [
8
- { name: 'Minify (Compact)', value: 'minify' },
9
- { name: 'Prettify (2 spaces)', value: 'prettify-2' },
10
- { name: 'Prettify (4 spaces)', value: 'prettify-4' }
11
- ]);
10
+ function stripCodeFence(text) {
11
+ const match = text.match(/^```(?:json|javascript|js)?\s*([\s\S]*?)\s*```$/i);
12
+ return match ? match[1] : text;
13
+ }
12
14
 
13
- const inputSource = await selectFromMenu('Select Input Source', [
14
- { name: 'Clipboard (Paste automatically)', value: 'clipboard' },
15
- { name: 'Manual Input', value: 'manual' },
16
- { name: 'File', value: 'file' }
17
- ]);
15
+ function normalizeQuotes(text) {
16
+ return text.replace(/[“”]/g, '"').replace(/[‘’]/g, "'");
17
+ }
18
18
 
19
- let input = '';
20
- if (inputSource === 'clipboard') {
21
- const clipboardy = (await import('clipboardy')).default;
22
- input = await clipboardy.read();
23
- } else if (inputSource === 'file') {
24
- const { filePath } = await inquirer.prompt([
25
- {
26
- type: 'input',
27
- name: 'filePath',
28
- message: 'Enter file path:'
29
- }
30
- ]);
19
+ function relaxJsonLike(text) {
20
+ let result = text;
21
+ result = result.replace(/([{,]\s*)([a-zA-Z_$][\w$-]*)(\s*:)/g, '$1"$2"$3');
22
+ result = result.replace(/'([^'\\]*(?:\\.[^'\\]*)*)'/g, (_, value) => `"${value.replace(/"/g, '\\"')}"`);
23
+ result = result.replace(/,\s*([}\]])/g, '$1');
24
+ return result;
25
+ }
26
+
27
+ function parseJsonInput(text) {
28
+ const candidates = new Set();
29
+ const trimmed = text.replace(/^\uFEFF/, '').trim();
30
+ const decoded = he.decode(trimmed);
31
+
32
+ [trimmed, decoded].forEach((raw) => {
33
+ if (!raw) return;
34
+ const noFence = stripCodeFence(raw).trim();
35
+ const normalized = normalizeQuotes(noFence);
36
+ const relaxed = relaxJsonLike(normalized);
37
+ candidates.add(noFence);
38
+ candidates.add(normalized);
39
+ candidates.add(relaxed);
40
+ });
41
+
42
+ let lastError = new Error('Invalid JSON');
43
+ for (const candidate of candidates) {
44
+ if (!candidate) continue;
31
45
  try {
32
- input = fs.readFileSync(filePath.replace(/"/g, ''), 'utf-8');
33
- } catch (e) {
34
- console.error('Error reading file:', e.message);
46
+ return JSON.parse(candidate);
47
+ } catch (error) {
48
+ lastError = error;
49
+ }
50
+ }
51
+ throw lastError;
52
+ }
53
+
54
+ export async function jsonFormatHandler() {
55
+ const inputSource = await selectFromMenu(
56
+ i18next.t('jsonFormat.selectSource'),
57
+ [
58
+ { name: i18next.t('jsonFormat.sourceClipboard'), value: 'clipboard' },
59
+ { name: i18next.t('jsonFormat.sourceFile'), value: 'file' }
60
+ ],
61
+ true,
62
+ i18next.t('common.back')
63
+ );
64
+ if (inputSource === '__BACK__') {
65
+ return;
66
+ }
67
+
68
+ let inputText = '';
69
+ if (inputSource === 'clipboard') {
70
+ inputText = await read();
71
+ if (!inputText.trim()) {
72
+ console.log(i18next.t('jsonFormat.clipboardEmpty'));
35
73
  return;
36
74
  }
37
75
  } else {
38
- const { manualInput } = await inquirer.prompt([
39
- {
40
- type: 'input',
41
- name: 'manualInput',
42
- message: 'Enter JSON string:'
76
+ const inputMethod = await selectFromMenu(
77
+ i18next.t('jsonFormat.fileInputMethod'),
78
+ [
79
+ { name: i18next.t('jsonFormat.fileInputDialog'), value: 'dialog' },
80
+ { name: i18next.t('jsonFormat.fileInputManual'), value: 'manual' }
81
+ ],
82
+ true,
83
+ i18next.t('common.back')
84
+ );
85
+ if (inputMethod === '__BACK__') {
86
+ return;
87
+ }
88
+
89
+ let filePath = '';
90
+ if (inputMethod === 'dialog') {
91
+ filePath = selectFile('JSON Files|*.json|Text Files|*.txt;*.log|All Files|*.*') || '';
92
+ if (!filePath) {
93
+ console.log(i18next.t('jsonFormat.dialogUnavailable'));
43
94
  }
44
- ]);
45
- input = manualInput;
95
+ }
96
+ if (!filePath) {
97
+ const answer = await inquirer.prompt([
98
+ {
99
+ type: 'input',
100
+ name: 'path',
101
+ message: i18next.t('jsonFormat.enterFilePath'),
102
+ validate: (value) => (fs.existsSync(value) ? true : i18next.t('jsonFormat.fileNotFound'))
103
+ }
104
+ ]);
105
+ filePath = answer.path;
106
+ }
107
+
108
+ try {
109
+ inputText = fs.readFileSync(filePath, 'utf-8');
110
+ } catch (error) {
111
+ console.error(i18next.t('jsonFormat.readFileError', { message: error.message }));
112
+ return;
113
+ }
114
+ }
115
+
116
+ const normalizedInput = inputText.replace(/^\uFEFF/, '').trim();
117
+ if (!normalizedInput) {
118
+ console.log(i18next.t('jsonFormat.emptyInput'));
119
+ return;
46
120
  }
47
121
 
48
122
  try {
49
- // Try to parse relaxed JSON (like JS objects) if possible, but standard JSON.parse is safer for strict JSON
50
- // We can try to evaluate if it fails parsing, but that's risky.
51
- // Let's stick to standard JSON parsing first.
52
- let jsonObj;
53
- try {
54
- jsonObj = JSON.parse(input);
55
- } catch (e) {
56
- // If strict parse fails, try to be more lenient if it's a JS object string
57
- // e.g. { a: 1 } instead of { "a": 1 }
58
- // Using Function constructor is safer than eval but still risky.
59
- // For a dev tool, it might be acceptable if warned.
60
- // Let's try a simple regex fix for common cases (keys without quotes)
61
- try {
62
- // This is a very basic attempt to fix unquoted keys
63
- const fixed = input.replace(/([{,]\s*)([a-zA-Z0-9_]+?)\s*:/g, '$1"$2":');
64
- jsonObj = JSON.parse(fixed);
65
- } catch (e2) {
66
- throw new Error('Invalid JSON format');
67
- }
123
+ const parsed = parseJsonInput(normalizedInput);
124
+ const formatted = JSON.stringify(parsed, null, 2);
125
+ const outputMode = await selectFromMenu(
126
+ i18next.t('jsonFormat.outputMode'),
127
+ [
128
+ { name: i18next.t('jsonFormat.outputClipboard'), value: 'clipboard' },
129
+ { name: i18next.t('jsonFormat.outputFile'), value: 'file' }
130
+ ],
131
+ true,
132
+ i18next.t('common.back')
133
+ );
134
+ if (outputMode === '__BACK__') {
135
+ return;
68
136
  }
69
137
 
70
- let output = '';
71
- if (mode === 'minify') {
72
- output = JSON.stringify(jsonObj);
73
- } else if (mode === 'prettify-2') {
74
- output = JSON.stringify(jsonObj, null, 2);
75
- } else {
76
- output = JSON.stringify(jsonObj, null, 4);
138
+ if (outputMode === 'file') {
139
+ const defaultName = defaultFileName('json-format', 'json');
140
+ let savePath = saveFile(defaultName, 'JSON Files|*.json|Text Files|*.txt|All Files|*.*') || '';
141
+ if (!savePath) {
142
+ const answer = await inquirer.prompt([
143
+ {
144
+ type: 'input',
145
+ name: 'path',
146
+ message: i18next.t('jsonFormat.enterOutputPath'),
147
+ default: defaultName,
148
+ validate: (value) => value.trim() ? true : i18next.t('jsonFormat.outputPathRequired')
149
+ }
150
+ ]);
151
+ savePath = answer.path;
152
+ }
153
+ await outputText(formatted, { showPreview: false, savePath });
154
+ return;
77
155
  }
78
-
79
- await copy(output);
80
- } catch (e) {
81
- console.error('Error processing JSON:', e.message);
156
+
157
+ await outputText(formatted, { showPreview: false });
158
+ } catch (error) {
159
+ console.error(i18next.t('jsonFormat.invalidJson', { message: error.message }));
82
160
  }
83
161
  }
package/src/i18n.js CHANGED
@@ -37,6 +37,9 @@ if (language.toLowerCase().startsWith('zh')) {
37
37
  await i18next.init({
38
38
  lng: language,
39
39
  fallbackLng: 'en',
40
+ interpolation: {
41
+ escapeValue: false
42
+ },
40
43
  resources: {
41
44
  en: { translation: en },
42
45
  zh: { translation: zh }
package/src/locales/en.js CHANGED
@@ -50,7 +50,7 @@ export default {
50
50
  unicode: 'Unicode Encode/Decode',
51
51
  htmlEntities: 'HTML Entity Encode/Decode',
52
52
  variableFormat: 'Variable Format Converter',
53
- jsonFormat: 'JSON Format (Minify/Prettify)',
53
+ jsonFormat: 'JSON Standard Formatter',
54
54
  pinyin: 'Chinese to Pinyin',
55
55
  timeFormat: 'Time Format / Timestamp',
56
56
  timeCalc: 'Time Calculation (Diff/Offset)',
@@ -121,6 +121,26 @@ export default {
121
121
  error: 'Invalid number for the selected base.',
122
122
  copyPrompt: 'Select format to copy'
123
123
  },
124
+ jsonFormat: {
125
+ selectSource: 'Select JSON input source',
126
+ sourceClipboard: 'Read from clipboard',
127
+ sourceFile: 'Read from local file',
128
+ fileInputMethod: 'Select file input method',
129
+ fileInputDialog: 'Select file (dialog)',
130
+ fileInputManual: 'Enter file path manually',
131
+ dialogUnavailable: 'File dialog is unavailable or canceled. Please enter the file path manually.',
132
+ enterFilePath: 'Enter JSON file path:',
133
+ fileNotFound: 'File does not exist.',
134
+ readFileError: 'Failed to read file: {{message}}',
135
+ clipboardEmpty: 'Clipboard is empty. Please copy JSON content first.',
136
+ emptyInput: 'Input content is empty.',
137
+ invalidJson: 'Invalid JSON format: {{message}}',
138
+ outputMode: 'Select output method',
139
+ outputClipboard: 'Copy to clipboard',
140
+ outputFile: 'Save to file',
141
+ enterOutputPath: 'Enter output file path:',
142
+ outputPathRequired: 'Output file path cannot be empty.'
143
+ },
124
144
  imgSplit: {
125
145
  mode: 'Select split mode',
126
146
  modeGrid: 'Grid Split (Equal parts)',
@@ -165,7 +185,13 @@ export default {
165
185
  customDepth: 'Specify depth',
166
186
  depthPrompt: 'Enter depth (0 means root only):',
167
187
  depthInvalid: 'Please enter an integer greater than or equal to 0',
168
- generated: 'Directory tree generated (path: {{path}}, depth: {{depth}}) and copied to clipboard',
188
+ outputMode: 'Select output method',
189
+ outputClipboard: 'Copy to clipboard',
190
+ outputFile: 'Export as txt file',
191
+ enterOutputPath: 'Enter output file path:',
192
+ outputPathRequired: 'Output file path is required',
193
+ generatedClipboard: 'Directory tree generated (path: {{path}}, depth: {{depth}}) and copied to clipboard',
194
+ generatedFile: 'Directory tree generated (path: {{path}}, depth: {{depth}}) and saved to file: {{savePath}}',
169
195
  readFailed: 'Failed to read directory'
170
196
  }
171
197
  };
package/src/locales/zh.js CHANGED
@@ -50,7 +50,7 @@ export default {
50
50
  unicode: 'Unicode 编码/解码',
51
51
  htmlEntities: 'HTML 实体 编码/解码',
52
52
  variableFormat: '变量命名格式转换',
53
- jsonFormat: 'JSON 格式化 (压缩/美化)',
53
+ jsonFormat: 'JSON 标准格式化',
54
54
  pinyin: '汉字转拼音',
55
55
  timeFormat: '时间格式化 / 时间戳',
56
56
  timeCalc: '时间计算 (差值/偏移)',
@@ -121,6 +121,26 @@ export default {
121
121
  error: '输入的数字对于所选进制无效。',
122
122
  copyPrompt: '选择要复制的格式'
123
123
  },
124
+ jsonFormat: {
125
+ selectSource: '选择 JSON 输入来源',
126
+ sourceClipboard: '从剪贴板读取',
127
+ sourceFile: '从本地文件读取',
128
+ fileInputMethod: '选择文件读取方式',
129
+ fileInputDialog: '选择文件(对话框)',
130
+ fileInputManual: '手动输入文件路径',
131
+ dialogUnavailable: '文件对话框不可用或已取消,请手动输入文件路径。',
132
+ enterFilePath: '请输入 JSON 文件路径:',
133
+ fileNotFound: '文件不存在。',
134
+ readFileError: '读取文件失败: {{message}}',
135
+ clipboardEmpty: '剪贴板为空,请先复制 JSON 内容。',
136
+ emptyInput: '输入内容为空。',
137
+ invalidJson: 'JSON 格式无效: {{message}}',
138
+ outputMode: '选择输出方式',
139
+ outputClipboard: '复制到剪贴板',
140
+ outputFile: '保存到文件',
141
+ enterOutputPath: '请输入输出文件路径:',
142
+ outputPathRequired: '输出文件路径不能为空。'
143
+ },
124
144
  imgSplit: {
125
145
  mode: '选择分割模式',
126
146
  modeGrid: '网格分割 (等分)',
@@ -166,7 +186,13 @@ export default {
166
186
  customDepth: '指定层级',
167
187
  depthPrompt: '请输入层级(0 表示仅根目录):',
168
188
  depthInvalid: '请输入大于等于 0 的整数',
169
- generated: '目录树已生成(路径: {{path}},层级: {{depth}}),已复制到剪贴板',
189
+ outputMode: '请选择输出方式',
190
+ outputClipboard: '复制到剪贴板',
191
+ outputFile: '输出为 txt 文件',
192
+ enterOutputPath: '请输入输出文件路径:',
193
+ outputPathRequired: '输出文件路径不能为空',
194
+ generatedClipboard: '目录树已生成(路径: {{path}},层级: {{depth}}),已复制到剪贴板',
195
+ generatedFile: '目录树已生成(路径: {{path}},层级: {{depth}}),已输出到文件: {{savePath}}',
170
196
  readFailed: '读取目录失败'
171
197
  }
172
198
  };
@@ -7,7 +7,8 @@ export async function outputText(text, options = {}) {
7
7
  previewHead = 50,
8
8
  previewTail = 50,
9
9
  threshold = 500,
10
- savePath
10
+ savePath,
11
+ copyToClipboard = true
11
12
  } = options;
12
13
 
13
14
  if (savePath) {
@@ -26,7 +27,9 @@ export async function outputText(text, options = {}) {
26
27
  }
27
28
  }
28
29
 
29
- await copy(text);
30
+ if (copyToClipboard) {
31
+ await copy(text);
32
+ }
30
33
  }
31
34
 
32
35
  export function defaultFileName(tool, ext = 'txt') {