@1-/minify_size 0.1.0 → 0.1.1

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.
Files changed (3) hide show
  1. package/README.md +16 -37
  2. package/file.js +6 -2
  3. package/package.json +6 -9
package/README.md CHANGED
@@ -3,9 +3,9 @@
3
3
  ---
4
4
 
5
5
  <a id="en"></a>
6
- # @1-/minify_size : Minify JS and output zstd compressed size
6
+ # @1-/minify_size : Minify JS and output brotli compressed size
7
7
 
8
- - [@1-/minify_size : Minify JS and output zstd compressed size](#1-minify_size-minify-js-and-output-zstd-compressed-size)
8
+ - [@1-/minify_size : Minify JS and output brotli compressed size](#1-minify_size-minify-js-and-output-brotli-compressed-size)
9
9
  - [1. Introduction](#1-introduction)
10
10
  - [2. Usage Demo](#2-usage-demo)
11
11
  - [3. Design Concept](#3-design-concept)
@@ -16,8 +16,8 @@
16
16
 
17
17
  ## 1. Introduction
18
18
 
19
- Minifies JS files in a specified directory and calculates their size after zstd compression.
20
- Evaluates JS library size under modern transmission environments supporting Zstd.
19
+ Minifies JavaScript files in a specified directory and calculates their size after Brotli compression.
20
+ Evaluates JavaScript library size under modern network transmission environments supporting Brotli.
21
21
 
22
22
  ## 2. Usage Demo
23
23
 
@@ -51,13 +51,13 @@ Total 650
51
51
 
52
52
  Execution process:
53
53
 
54
- ![](https://fastly.jsdelivr.net/gh/webc-fs/-@n-/Jsm3fz4EQSGdooVgJJCw.svg)
54
+ ![](https://fastly.jsdelivr.net/gh/webc-fs/-@RL/NUbVPqfWeEufBqPl_sqg.svg)
55
55
 
56
56
  ## 4. Tech Stack
57
57
 
58
58
  - **Runtime**: Node.js / Bun
59
59
  - **JS Minifier**: `oxc-minify` (JavaScript minifier implemented in Rust)
60
- - **Zstd Engine**: `@mongodb-js/zstd` (Zstandard binding)
60
+ - **Brotli Engine**: Built-in `node:zlib` (Brotli compression)
61
61
  - **Arg Parser**: `yargs`
62
62
  - **Encoding**: `@3-/utf8` (TextEncoder-based UTF-8 encoding)
63
63
  - **Output Formatting**: `cli-table3` (Formatted tabular output)
@@ -71,18 +71,12 @@ Execution process:
71
71
  src/
72
72
  ├── cli.js # CLI entrypoint, parses directory parameter and invokes main function
73
73
  ├── _.js # Directory traversal, concurrent file processing, aggregation and formatted output
74
- └── file.js # Single file processing: reading, oxc-minify compression, zstd compression and size calculation
74
+ └── file.js # Single file processing: reading, oxc-minify compression, brotli compression and size calculation
75
75
  ```
76
76
 
77
- Key configuration:
78
- - oxc-minify: `target: "esnext"`, `removeWhitespace: true`
79
- - zstd compression level: `3` (default)
80
- - Input validation: Directory parameter required
81
- - Error handling: Proper exit codes for missing parameters
82
-
83
77
  ## 6. History
84
78
 
85
- Zstandard (Zstd) was developed by Yann Collet at Facebook in 2015. Yann became interested in data compression while writing games for the HP 48 graphing calculator. He previously developed the LZ4 compression algorithm, which features high decompression speed. Subsequently, he designed Zstd to balance compression ratio and speed, which later became an industry standard (RFC 8478).
79
+ Brotli was developed by Jyrki Alakuijala and Zoltán Szabadka at Google in 2013. It was initially designed for compression of web fonts, and was later extended to become a general-purpose compression algorithm optimized for web transmission, becoming an industry standard (RFC 7932).
86
80
 
87
81
  ## About
88
82
 
@@ -94,9 +88,9 @@ This library is developed by [WebC.site](https://webc.site).
94
88
  ---
95
89
 
96
90
  <a id="zh"></a>
97
- # @1-/minify_size : 压缩 JS 并输出 zstd 压缩后大小
91
+ # @1-/minify_size : Minify JS and output brotli compressed size
98
92
 
99
- - [@1-/minify_size : 压缩 JS 并输出 zstd 压缩后大小](#1-minify_size-压缩-js-并输出-zstd-压缩后大小)
93
+ - [@1-/minify_size : Minify JS and output brotli compressed size](#1-minify_size-minify-js-and-output-brotli-compressed-size)
100
94
  - [1. 功能介绍](#1-功能介绍)
101
95
  - [2. 使用演示](#2-使用演示)
102
96
  - [3. 设计思路](#3-设计思路)
@@ -107,8 +101,8 @@ This library is developed by [WebC.site](https://webc.site).
107
101
 
108
102
  ## 1. 功能介绍
109
103
 
110
- 对指定目录中的 JS 文件进行压缩,并计算经 zstd 算法压缩后的体积。
111
- 用于评估 JS 库在支持 Zstd 的传输环境下的网络传输体积指标。
104
+ 压缩指定目录中的 JavaScript 文件,并计算经 Brotli 算法压缩后的体积。
105
+ 用于评估 JavaScript 库在支持 Brotli 的网络传输环境下的实际传输体积。
112
106
 
113
107
  ## 2. 使用演示
114
108
 
@@ -142,22 +136,13 @@ file.js 250
142
136
 
143
137
  系统执行流程如下:
144
138
 
145
- ```mermaid
146
- graph TD
147
- A[CLI 输入目录] --> B[读取目录下所有 JS 文件]
148
- B --> C[并发处理每个文件]
149
- C --> D[使用 oxc-minify 进行压缩]
150
- D --> E[将压缩代码转换为 UTF-8 编码]
151
- E --> F[通过 zstd 算法压缩 level 3]
152
- F --> G[计算压缩后字节长度]
153
- G --> H[使用 cli-table3 格式化输出结果]
154
- ```
139
+ ![](https://fastly.jsdelivr.net/gh/webc-fs/-@Eg/nKfDG6I2Cy7wB6zHgcjA.svg)
155
140
 
156
141
  ## 4. 技术栈
157
142
 
158
143
  - **Runtime**: Node.js / Bun
159
144
  - **JS Minifier**: `oxc-minify` (Rust 实现的 JavaScript 压缩器)
160
- - **Zstd Engine**: `@mongodb-js/zstd` (Zstandard 绑定实现)
145
+ - **Brotli Engine**: 内置 `node:zlib` (Brotli 压缩)
161
146
  - **Arg Parser**: `yargs`
162
147
  - **Encoding**: `@3-/utf8` (TextEncoder-based UTF-8 encoding)
163
148
  - **Output Formatting**: `cli-table3` (Formatted tabular output)
@@ -171,18 +156,12 @@ graph TD
171
156
  src/
172
157
  ├── cli.js # CLI 命令行入口,解析目录参数并调用主函数
173
158
  ├── _.js # 目录遍历、并发调度文件处理、汇总统计并格式化输出
174
- └── file.js # 单文件处理:读取、oxc-minify 压缩、zstd 压缩及大小计算
159
+ └── file.js # 单文件处理:读取、oxc-minify 压缩、brotli 压缩及大小计算
175
160
  ```
176
161
 
177
- 核心配置:
178
- - oxc-minify: `target: "esnext"`, `removeWhitespace: true`
179
- - zstd compression level: `3` (default)
180
- - Input validation: Directory parameter required
181
- - Error handling: Proper exit codes for missing parameters
182
-
183
162
  ## 6. 历史故事
184
163
 
185
- Zstandard(Zstd)由 Yann Collet 2015 年在 Facebook 主导开发。Yann 在为 HP 48 图形计算器编写游戏时对数据压缩产生兴趣。他此前开发了 LZ4 压缩算法,其解压速度极快。此后,他设计出 Zstd,均衡了压缩率与运行速度,并成为行业标准(RFC 8478)。
164
+ Brotli Google Jyrki Alakuijala Zoltán Szabadka 2013 年开发。它最初被设计用于压缩网页字体,后来发展为通用压缩算法,用于优化网页传输,并成为行业标准(RFC 7932)。
186
165
 
187
166
  ## 关于
188
167
 
package/file.js CHANGED
@@ -1,15 +1,19 @@
1
1
  import read from "@3-/read";
2
2
  import { minifySync } from "oxc-minify";
3
- import { compress } from "@mongodb-js/zstd";
3
+ import { promisify } from "node:util";
4
+ import { brotliCompress } from "node:zlib";
4
5
  import utf8e from "@3-/utf8";
5
6
  import { basename } from "node:path";
6
7
 
8
+ const brotli = promisify(brotliCompress);
9
+
10
+ // file_path: 文件路径;返回 minify 且 brotli 压缩后的字节数
7
11
  export default async (file_path) => {
8
12
  const code = read(file_path),
9
13
  { code: mini } = minifySync(basename(file_path), code, {
10
14
  compress: { target: "esnext" },
11
15
  codegen: { removeWhitespace: true },
12
16
  }),
13
- zip = await compress(utf8e(mini), 3);
17
+ zip = await brotli(utf8e(mini));
14
18
  return zip.length;
15
19
  };
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@1-/minify_size",
3
- "version": "0.1.0",
4
- "description": "Minify JS and output zstd compressed size | 压缩 JS 并输出 zstd 压缩后大小",
3
+ "version": "0.1.1",
4
+ "description": "Minify JS and output brotli compressed size | 压缩 JS 并输出 brotli 压缩后大小",
5
5
  "keywords": [
6
+ "br",
7
+ "brotli",
6
8
  "compression",
7
9
  "minify",
8
- "size",
9
- "zstd"
10
+ "size"
10
11
  ],
11
12
  "homepage": "https://github.com/webc-site/npm/tree/main/minify_size",
12
13
  "license": "MulanPSL-2.0",
@@ -26,12 +27,8 @@
26
27
  "dependencies": {
27
28
  "@3-/read": "^0.1.4",
28
29
  "@3-/utf8": "^0.1.1",
29
- "@mongodb-js/zstd": "^7.0.0",
30
30
  "cli-table3": "^0.6.5",
31
31
  "oxc-minify": "^0.135.0",
32
32
  "yargs": "^18.0.0"
33
- },
34
- "trustedDependencies": [
35
- "@mongodb-js/zstd"
36
- ]
33
+ }
37
34
  }