slimjson 1.0.3 → 1.1.0

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.
@@ -1,42 +1,42 @@
1
- /**
2
- * 用法: node decompress-file.js <压缩文件> [输出.json]
3
- *
4
- * 默认输出文件名: <输入名>.json(去掉 .slim 后缀)
5
- */
6
- const fs = require('fs');
7
- const path = require('path');
8
- const { decompress, parse } = require('./compress');
9
-
10
- const input = process.argv[2];
11
- if (!input) {
12
- console.error('用法: node decompress-file.js <压缩文件> [输出.json]');
13
- process.exit(1);
14
- }
15
- if (!fs.existsSync(input)) {
16
- console.error(`文件不存在: ${input}`);
17
- process.exit(1);
18
- }
19
-
20
- const output = process.argv[3] || input.replace(/\.json\.slim$/i, '.json');
21
-
22
- let text;
23
- try {
24
- text = fs.readFileSync(input, 'utf8');
25
- } catch (e) {
26
- console.error(`读取文件失败: ${e.message}`);
27
- process.exit(1);
28
- }
29
-
30
- let compressed;
31
- try {
32
- compressed = parse(text);
33
- } catch (e) {
34
- console.error(`解析失败: ${e.message}`);
35
- process.exit(1);
36
- }
37
-
38
- const data = decompress(compressed);
39
- fs.writeFileSync(output, JSON.stringify(data, null, 2), 'utf8');
40
-
41
- console.log(`输入: ${path.basename(input)}`);
42
- console.log(`输出: ${path.basename(output)} (${data.length} 条)`);
1
+ /**
2
+ * 用法: node decompress-file.js <压缩文件> [输出.json]
3
+ *
4
+ * 默认输出文件名: <输入名>.json(去掉 .slim 后缀)
5
+ */
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const { decompress, parse } = require('./compress');
9
+
10
+ const input = process.argv[2];
11
+ if (!input) {
12
+ console.error('用法: node decompress-file.js <压缩文件> [输出.json]');
13
+ process.exit(1);
14
+ }
15
+ if (!fs.existsSync(input)) {
16
+ console.error(`文件不存在: ${input}`);
17
+ process.exit(1);
18
+ }
19
+
20
+ const output = process.argv[3] || input.replace(/\.json\.slim$/i, '.json');
21
+
22
+ let text;
23
+ try {
24
+ text = fs.readFileSync(input, 'utf8');
25
+ } catch (e) {
26
+ console.error(`读取文件失败: ${e.message}`);
27
+ process.exit(1);
28
+ }
29
+
30
+ let compressed;
31
+ try {
32
+ compressed = parse(text);
33
+ } catch (e) {
34
+ console.error(`解析失败: ${e.message}`);
35
+ process.exit(1);
36
+ }
37
+
38
+ const data = decompress(compressed);
39
+ fs.writeFileSync(output, JSON.stringify(data, null, 2), 'utf8');
40
+
41
+ console.log(`输入: ${path.basename(input)}`);
42
+ console.log(`输出: ${path.basename(output)} (${data.length} 条)`);
package/esm.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { createRequire } from 'node:module';
2
- const require = createRequire(import.meta.url);
3
- const { compress, decompress, stringify, parse } = require('./compress.js');
4
- export { compress, decompress, stringify, parse };
1
+ import { createRequire } from 'node:module';
2
+ const require = createRequire(import.meta.url);
3
+ const { compress, decompress, stringify, parse } = require('./compress.js');
4
+ export { compress, decompress, stringify, parse };
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
- {
2
- "name": "slimjson",
3
- "version": "1.0.3",
4
- "main": "compress.js",
5
- "exports": {
6
- ".": {
7
- "import": "./esm.mjs",
8
- "require": "./compress.js"
9
- }
10
- },
11
- "scripts": {
12
- "test": "jest"
13
- },
14
- "author": "lastheaven",
15
- "license": "MIT",
16
- "description": "轻量级对象数组压缩工具",
17
- "devDependencies": {
18
- "jest": "^30.4.2"
19
- },
20
- "repository": {
21
- "type": "git",
22
- "url": "https://github.com/LastHeaven/slimjson.git"
23
- }
24
- }
1
+ {
2
+ "name": "slimjson",
3
+ "version": "1.1.0",
4
+ "main": "compress.js",
5
+ "exports": {
6
+ ".": {
7
+ "import": "./esm.mjs",
8
+ "require": "./compress.js"
9
+ }
10
+ },
11
+ "scripts": {
12
+ "test": "jest"
13
+ },
14
+ "author": "lastheaven",
15
+ "license": "MIT",
16
+ "description": "轻量级对象数组压缩工具",
17
+ "devDependencies": {
18
+ "jest": "^30.4.2"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/LastHeaven/slimjson.git"
23
+ }
24
+ }