@e-mc/compress 0.9.3 → 0.9.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.
Files changed (3) hide show
  1. package/README.md +4 -4
  2. package/index.js +45 -48
  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.9.3/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.4/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { CompressLevel } from "./squared";
@@ -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.9.3/lib/squared.d.ts
124
- - https://www.unpkg.com/@e-mc/types@0.9.3/lib/compress.d.ts
125
- - https://www.unpkg.com/@e-mc/types@0.9.3/lib/settings.d.ts
123
+ - https://www.unpkg.com/@e-mc/types@0.9.4/lib/squared.d.ts
124
+ - https://www.unpkg.com/@e-mc/types@0.9.4/lib/compress.d.ts
125
+ - https://www.unpkg.com/@e-mc/types@0.9.4/lib/settings.d.ts
126
126
 
127
127
  * https://www.npmjs.com/package/@types/node
128
128
 
package/index.js CHANGED
@@ -65,7 +65,7 @@ function setCacheData(index) {
65
65
  catch {
66
66
  }
67
67
  }
68
- removeFile(pathname);
68
+ fs.unlink(pathname, () => { });
69
69
  }
70
70
  else if (item.isDirectory()) {
71
71
  recurse(paths.concat(filename));
@@ -79,7 +79,6 @@ function setCacheData(index) {
79
79
  }
80
80
  return CACHE_INIT[index] = true;
81
81
  }
82
- const removeFile = (pathname) => fs.unlink(pathname, () => { });
83
82
  class Compress extends module_1 {
84
83
  static singleton() {
85
84
  if (!SINGLETON_INSTANCE) {
@@ -119,7 +118,7 @@ class Compress extends module_1 {
119
118
  }
120
119
  register(format, callback, level) {
121
120
  this.compressors[format = format.toLowerCase()] = callback;
122
- if (level !== undefined) {
121
+ if (typeof level === 'number') {
123
122
  this.level[format] = level;
124
123
  }
125
124
  }
@@ -128,7 +127,7 @@ class Compress extends module_1 {
128
127
  if (!isNaN(result)) {
129
128
  return result;
130
129
  }
131
- if (fallback !== undefined) {
130
+ if (typeof fallback === 'number') {
132
131
  return fallback;
133
132
  }
134
133
  switch (value) {
@@ -376,29 +375,28 @@ class Compress extends module_1 {
376
375
  }
377
376
  });
378
377
  };
379
- module_1.resolveMime(data).then(font => {
380
- try {
381
- switch (font?.mime) {
382
- case "font/woff":
383
- if (cache) {
384
- CACHE_FONTFROM[hash] = 'woff';
385
- }
386
- checkResult(toSfnt(data), 'woff');
387
- break;
388
- case "font/woff2":
389
- if (cache) {
390
- CACHE_FONTFROM[hash] = 'woff2';
391
- }
392
- wawoff2.decompress(data).then(woff => checkResult(woff, 'woff2'));
393
- break;
394
- default:
395
- errorResponse(font);
396
- break;
397
- }
398
- }
399
- catch (err) {
400
- endProcess(err);
378
+ module_1.resolveMime(data)
379
+ .then(font => {
380
+ switch (font?.mime) {
381
+ case "font/woff":
382
+ if (cache) {
383
+ CACHE_FONTFROM[hash] = 'woff';
384
+ }
385
+ checkResult(toSfnt(data), 'woff');
386
+ break;
387
+ case "font/woff2":
388
+ if (cache) {
389
+ CACHE_FONTFROM[hash] = 'woff2';
390
+ }
391
+ wawoff2.decompress(data).then(woff => checkResult(woff, 'woff2'));
392
+ break;
393
+ default:
394
+ errorResponse(font);
395
+ break;
401
396
  }
397
+ })
398
+ .catch((err) => {
399
+ endProcess(err);
402
400
  });
403
401
  break;
404
402
  }
@@ -418,29 +416,28 @@ class Compress extends module_1 {
418
416
  });
419
417
  };
420
418
  startProcess(true);
421
- module_1.resolveMime(data).then(font => {
422
- try {
423
- switch (font?.mime) {
424
- case "font/ttf":
425
- if (cache) {
426
- CACHE_FONTFROM[hash] = 'ttf';
427
- }
428
- wawoff2.compress(data).then(result => checkResult(result, "font/woff2", 'ttf'));
429
- break;
430
- case "font/otf":
431
- if (cache) {
432
- CACHE_FONTFROM[hash] = 'otf';
433
- }
434
- checkResult(toWoff(data), "font/woff", 'otf');
435
- break;
436
- default:
437
- errorResponse(font);
438
- break;
439
- }
440
- }
441
- catch (err) {
442
- endProcess(err);
419
+ module_1.resolveMime(data)
420
+ .then(font => {
421
+ switch (font?.mime) {
422
+ case "font/ttf":
423
+ if (cache) {
424
+ CACHE_FONTFROM[hash] = 'ttf';
425
+ }
426
+ wawoff2.compress(data).then(result => checkResult(result, "font/woff2", 'ttf'));
427
+ break;
428
+ case "font/otf":
429
+ if (cache) {
430
+ CACHE_FONTFROM[hash] = 'otf';
431
+ }
432
+ checkResult(toWoff(data), "font/woff", 'otf');
433
+ break;
434
+ default:
435
+ errorResponse(font);
436
+ break;
443
437
  }
438
+ })
439
+ .catch((err) => {
440
+ endProcess(err);
444
441
  });
445
442
  break;
446
443
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/compress",
3
- "version": "0.9.3",
3
+ "version": "0.9.4",
4
4
  "description": "Compress constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -23,8 +23,8 @@
23
23
  "license": "BSD 3-Clause",
24
24
  "homepage": "https://github.com/anpham6/e-mc#readme",
25
25
  "dependencies": {
26
- "@e-mc/module": "0.9.3",
27
- "@e-mc/types": "0.9.3",
26
+ "@e-mc/module": "0.9.4",
27
+ "@e-mc/types": "0.9.4",
28
28
  "tinify": "^1.7.1",
29
29
  "wawoff2": "^2.0.1",
30
30
  "woff2sfnt-sfnt2woff": "^1.0.0"