@e-mc/compress 0.8.11 → 0.8.12

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 -47
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- - https://www.unpkg.com/@e-mc/types@0.8.11/lib/index.d.ts
12
+ - https://www.unpkg.com/@e-mc/types@0.8.12/lib/index.d.ts
13
13
 
14
14
  ```typescript
15
15
  import type { CompressLevel } from "./squared";
@@ -51,9 +51,9 @@ interface CompressConstructor extends ModuleConstructor {
51
51
 
52
52
  ## References
53
53
 
54
- - https://www.unpkg.com/@e-mc/types@0.8.11/lib/squared.d.ts
55
- - https://www.unpkg.com/@e-mc/types@0.8.11/lib/compress.d.ts
56
- - https://www.unpkg.com/@e-mc/types@0.8.11/lib/settings.d.ts
54
+ - https://www.unpkg.com/@e-mc/types@0.8.12/lib/squared.d.ts
55
+ - https://www.unpkg.com/@e-mc/types@0.8.12/lib/compress.d.ts
56
+ - https://www.unpkg.com/@e-mc/types@0.8.12/lib/settings.d.ts
57
57
 
58
58
  ## LICENSE
59
59
 
package/index.js CHANGED
@@ -122,7 +122,7 @@ class Compress extends module_1.default {
122
122
  }
123
123
  register(format, callback, level) {
124
124
  this.compressors[format = format.toLowerCase()] = callback;
125
- if (level !== undefined) {
125
+ if (typeof level === 'number') {
126
126
  this.level[format] = level;
127
127
  }
128
128
  }
@@ -132,7 +132,7 @@ class Compress extends module_1.default {
132
132
  if (!isNaN(result)) {
133
133
  return result;
134
134
  }
135
- if (fallback !== undefined) {
135
+ if (typeof fallback === 'number') {
136
136
  return fallback;
137
137
  }
138
138
  switch (value) {
@@ -371,29 +371,28 @@ class Compress extends module_1.default {
371
371
  }
372
372
  });
373
373
  };
374
- module_1.default.resolveMime(data).then(font => {
375
- try {
376
- switch (font === null || font === void 0 ? void 0 : font.mime) {
377
- case "font/woff":
378
- if (cache) {
379
- CACHE_FONTFROM[hash] = 'woff';
380
- }
381
- checkResult(toSfnt(data), 'woff');
382
- break;
383
- case "font/woff2":
384
- if (cache) {
385
- CACHE_FONTFROM[hash] = 'woff2';
386
- }
387
- wawoff2.decompress(data).then(woff => checkResult(woff, 'woff2'));
388
- break;
389
- default:
390
- errorResponse(font);
391
- break;
392
- }
393
- }
394
- catch (err) {
395
- endProcess(err);
374
+ module_1.default.resolveMime(data)
375
+ .then(font => {
376
+ switch (font === null || font === void 0 ? void 0 : font.mime) {
377
+ case "font/woff":
378
+ if (cache) {
379
+ CACHE_FONTFROM[hash] = 'woff';
380
+ }
381
+ checkResult(toSfnt(data), 'woff');
382
+ break;
383
+ case "font/woff2":
384
+ if (cache) {
385
+ CACHE_FONTFROM[hash] = 'woff2';
386
+ }
387
+ wawoff2.decompress(data).then(woff => checkResult(woff, 'woff2'));
388
+ break;
389
+ default:
390
+ errorResponse(font);
391
+ break;
396
392
  }
393
+ })
394
+ .catch(err => {
395
+ endProcess(err);
397
396
  });
398
397
  break;
399
398
  }
@@ -413,29 +412,28 @@ class Compress extends module_1.default {
413
412
  });
414
413
  };
415
414
  startProcess(true);
416
- module_1.default.resolveMime(data).then(font => {
417
- try {
418
- switch (font === null || font === void 0 ? void 0 : font.mime) {
419
- case "font/ttf":
420
- if (cache) {
421
- CACHE_FONTFROM[hash] = 'ttf';
422
- }
423
- wawoff2.compress(data).then(result => checkResult(result, "font/woff2", 'ttf'));
424
- break;
425
- case "font/otf":
426
- if (cache) {
427
- CACHE_FONTFROM[hash] = 'otf';
428
- }
429
- checkResult(toWoff(data), "font/woff", 'otf');
430
- break;
431
- default:
432
- errorResponse(font);
433
- break;
434
- }
435
- }
436
- catch (err) {
437
- endProcess(err);
415
+ module_1.default.resolveMime(data)
416
+ .then(font => {
417
+ switch (font === null || font === void 0 ? void 0 : font.mime) {
418
+ case "font/ttf":
419
+ if (cache) {
420
+ CACHE_FONTFROM[hash] = 'ttf';
421
+ }
422
+ wawoff2.compress(data).then(result => checkResult(result, "font/woff2", 'ttf'));
423
+ break;
424
+ case "font/otf":
425
+ if (cache) {
426
+ CACHE_FONTFROM[hash] = 'otf';
427
+ }
428
+ checkResult(toWoff(data), "font/woff", 'otf');
429
+ break;
430
+ default:
431
+ errorResponse(font);
432
+ break;
438
433
  }
434
+ })
435
+ .catch(err => {
436
+ endProcess(err);
439
437
  });
440
438
  break;
441
439
  }
@@ -524,7 +522,6 @@ class Compress extends module_1.default {
524
522
  if (callback) {
525
523
  callback(err, result);
526
524
  }
527
- resolve(result);
528
525
  if (!ctime && hash && cacheKey && TEMP_DIR) {
529
526
  const pathname = path.join(TEMP_DIR, plugin, hash);
530
527
  if (module_1.default.createDir(pathname)) {
@@ -536,6 +533,7 @@ class Compress extends module_1.default {
536
533
  });
537
534
  }
538
535
  }
536
+ resolve(result);
539
537
  };
540
538
  if (output) {
541
539
  fs.writeFile(output, result, err => complete(err));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/compress",
3
- "version": "0.8.11",
3
+ "version": "0.8.12",
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": "MIT",
24
24
  "homepage": "https://github.com/anpham6/e-mc#readme",
25
25
  "dependencies": {
26
- "@e-mc/module": "0.8.11",
27
- "@e-mc/types": "0.8.11",
26
+ "@e-mc/module": "0.8.12",
27
+ "@e-mc/types": "0.8.12",
28
28
  "tinify": "^1.7.1",
29
29
  "wawoff2": "^2.0.1",
30
30
  "woff2sfnt-sfnt2woff": "^1.0.0"