@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.
- package/README.md +4 -4
- package/index.js +45 -48
- 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.
|
|
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.
|
|
124
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
125
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
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
|
-
|
|
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
|
|
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
|
|
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)
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
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)
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
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
|
+
"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.
|
|
27
|
-
"@e-mc/types": "0.9.
|
|
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"
|