@e-mc/compress 0.12.7 → 0.12.9

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 +5 -5
  2. package/index.js +14 -3
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.12.7/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.12.9/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { IModule, ModuleConstructor } from "./index";
@@ -32,7 +32,7 @@ interface ICompress extends IModule {
32
32
  createGzip(file: string | Buffer, options?: CompressLevel): Gzip;
33
33
  createBrotliCompress(file: string | Buffer, options?: BrotliCompressLevel): BrotliCompress;
34
34
  createWriteStreamAsGzip(file: string | Buffer, output: string, options?: CompressLevel): WriteStream;
35
- createWriteStreamAsBrotli(file: string | Buffer, output: string, options?: CompressLevel): WriteStream;
35
+ createWriteStreamAsBrotli(file: string | Buffer, output: string, options?: BrotliCompressLevel): WriteStream;
36
36
  intoGzipStream(output: string, options?: ZlibOptions): WriteStream;
37
37
  intoBrotliStream(output: string, options?: BrotliOptions): WriteStream;
38
38
  writeGzip(file: string | Buffer, output: string, options?: CompressLevel): Promise<void>;
@@ -120,9 +120,9 @@ instance.tryImage("/tmp/image.png", "/path/output/compressed.png", options)
120
120
 
121
121
  ## References
122
122
 
123
- - https://www.unpkg.com/@e-mc/types@0.12.7/lib/squared.d.ts
124
- - https://www.unpkg.com/@e-mc/types@0.12.7/lib/compress.d.ts
125
- - https://www.unpkg.com/@e-mc/types@0.12.7/lib/settings.d.ts
123
+ - https://www.unpkg.com/@e-mc/types@0.12.9/lib/squared.d.ts
124
+ - https://www.unpkg.com/@e-mc/types@0.12.9/lib/compress.d.ts
125
+ - https://www.unpkg.com/@e-mc/types@0.12.9/lib/settings.d.ts
126
126
 
127
127
  * https://www.npmjs.com/package/@types/node
128
128
 
package/index.js CHANGED
@@ -219,10 +219,15 @@ class Compress extends core_1.Module {
219
219
  if (options) {
220
220
  ({ level, chunkSize, mimeType } = options);
221
221
  }
222
- const params = { [zlib.constants.BROTLI_PARAM_QUALITY]: level ?? this.level.br };
223
- let brotli = this.module.brotli;
222
+ let brotli = this.module.brotli, params = {};
224
223
  if ((0, types_1.isPlainObject)(brotli)) {
225
- brotli = (0, types_1.isPlainObject)(brotli.params) ? { ...brotli, params: Object.assign(params, brotli.params) } : { ...brotli, params };
224
+ if ((0, types_1.isPlainObject)(brotli.params)) {
225
+ brotli = (0, types_1.cloneObject)(brotli, true);
226
+ params = brotli.params;
227
+ }
228
+ else {
229
+ brotli = { ...brotli, params };
230
+ }
226
231
  }
227
232
  else {
228
233
  brotli = { params };
@@ -239,6 +244,12 @@ class Compress extends core_1.Module {
239
244
  else {
240
245
  brotli.chunkSize ??= this.chunkSize;
241
246
  }
247
+ if (typeof level === 'number') {
248
+ params[zlib.constants.BROTLI_PARAM_QUALITY] = level;
249
+ }
250
+ else {
251
+ params[zlib.constants.BROTLI_PARAM_QUALITY] ??= this.level.br;
252
+ }
242
253
  return this.getReadable(file, options).pipe(zlib.createBrotliCompress(brotli));
243
254
  }
244
255
  createWriteStreamAsGzip(file, output, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/compress",
3
- "version": "0.12.7",
3
+ "version": "0.12.9",
4
4
  "description": "Compress constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -22,8 +22,8 @@
22
22
  "license": "BSD-3-Clause",
23
23
  "homepage": "https://github.com/anpham6/e-mc#readme",
24
24
  "dependencies": {
25
- "@e-mc/core": "0.12.7",
26
- "@e-mc/types": "0.12.7",
25
+ "@e-mc/core": "0.12.9",
26
+ "@e-mc/types": "0.12.9",
27
27
  "wawoff2": "^2.0.1",
28
28
  "woff2sfnt-sfnt2woff": "^1.0.0"
29
29
  }