@e-mc/compress 0.7.1 → 0.8.0
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/LICENSE +10 -10
- package/index.d.ts +4 -4
- package/index.js +16 -16
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
Copyright 2023 An Pham
|
|
2
|
-
|
|
3
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
-
|
|
5
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
-
|
|
7
|
-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
1
|
+
Copyright 2023 An Pham
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
+
|
|
9
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
+
|
|
11
11
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CompressConstructor } from '../types/lib';
|
|
2
|
-
|
|
3
|
-
declare const Compress: CompressConstructor;
|
|
4
|
-
|
|
1
|
+
import type { CompressConstructor } from '../types/lib';
|
|
2
|
+
|
|
3
|
+
declare const Compress: CompressConstructor;
|
|
4
|
+
|
|
5
5
|
export = Compress;
|
package/index.js
CHANGED
|
@@ -207,7 +207,7 @@ class Compress extends module_1.default {
|
|
|
207
207
|
createWriteStreamAsBrotli(file, output, options) {
|
|
208
208
|
return this.createBrotliCompress(file, options).pipe(fs.createWriteStream(output));
|
|
209
209
|
}
|
|
210
|
-
tryFile(file, output, config, callback) {
|
|
210
|
+
async tryFile(file, output, config, callback) {
|
|
211
211
|
if (typeof config === 'function') {
|
|
212
212
|
callback = config;
|
|
213
213
|
config = undefined;
|
|
@@ -244,7 +244,7 @@ class Compress extends module_1.default {
|
|
|
244
244
|
}
|
|
245
245
|
else {
|
|
246
246
|
if (!fromCache) {
|
|
247
|
-
this.writeTimeProcess(ext || format, (0, types_1.isString)(result) ? path.basename(result) : filename ||
|
|
247
|
+
this.writeTimeProcess(ext || format, (0, types_1.isString)(result) ? path.basename(result) : filename || "Completed" /* VAL_MESSAGE.COMPLETED */, startTime, { type: 8 /* LOG_TYPE.COMPRESS */, sessionId, broadcastId });
|
|
248
248
|
}
|
|
249
249
|
if (callback) {
|
|
250
250
|
callback(null, result || data, ext);
|
|
@@ -311,7 +311,7 @@ class Compress extends module_1.default {
|
|
|
311
311
|
else {
|
|
312
312
|
endProcess(null, data, to, '', true);
|
|
313
313
|
}
|
|
314
|
-
this.formatMessage(8 /* LOG_TYPE.COMPRESS */, from, [pathname ? path.basename(pathname) :
|
|
314
|
+
this.formatMessage(8 /* LOG_TYPE.COMPRESS */, from, [pathname ? path.basename(pathname) : "Completed" /* VAL_MESSAGE.COMPLETED */ + ` -> font/${to}`, 'cache'], tempFont[1].toLocaleString(), { ...module_1.default.LOG_STYLE_NOTICE, hintBold: true, sessionId, broadcastId });
|
|
315
315
|
return true;
|
|
316
316
|
}
|
|
317
317
|
catch {
|
|
@@ -357,8 +357,8 @@ class Compress extends module_1.default {
|
|
|
357
357
|
const checkResult = (result, from) => {
|
|
358
358
|
module_1.default.resolveMime(result).then(font => {
|
|
359
359
|
switch (font?.mime) {
|
|
360
|
-
case
|
|
361
|
-
case
|
|
360
|
+
case "font/ttf" /* MIME_TYPE.TTF */:
|
|
361
|
+
case "font/otf" /* MIME_TYPE.OTF */:
|
|
362
362
|
writeFont(result, font.ext, from);
|
|
363
363
|
break;
|
|
364
364
|
default:
|
|
@@ -370,13 +370,13 @@ class Compress extends module_1.default {
|
|
|
370
370
|
module_1.default.resolveMime(data).then(font => {
|
|
371
371
|
try {
|
|
372
372
|
switch (font?.mime) {
|
|
373
|
-
case
|
|
373
|
+
case "font/woff" /* MIME_TYPE.WOFF */:
|
|
374
374
|
if (cache) {
|
|
375
375
|
CACHE_FONTFROM[hash] = 'woff';
|
|
376
376
|
}
|
|
377
377
|
checkResult(toSfnt(data), 'woff');
|
|
378
378
|
break;
|
|
379
|
-
case
|
|
379
|
+
case "font/woff2" /* MIME_TYPE.WOFF2 */:
|
|
380
380
|
if (cache) {
|
|
381
381
|
CACHE_FONTFROM[hash] = 'woff2';
|
|
382
382
|
}
|
|
@@ -412,17 +412,17 @@ class Compress extends module_1.default {
|
|
|
412
412
|
module_1.default.resolveMime(data).then(font => {
|
|
413
413
|
try {
|
|
414
414
|
switch (font?.mime) {
|
|
415
|
-
case
|
|
415
|
+
case "font/ttf" /* MIME_TYPE.TTF */:
|
|
416
416
|
if (cache) {
|
|
417
417
|
CACHE_FONTFROM[hash] = 'ttf';
|
|
418
418
|
}
|
|
419
|
-
wawoff2.compress(data).then(result => checkResult(result,
|
|
419
|
+
wawoff2.compress(data).then(result => checkResult(result, "font/woff2" /* MIME_TYPE.WOFF2 */, 'ttf'));
|
|
420
420
|
break;
|
|
421
|
-
case
|
|
421
|
+
case "font/otf" /* MIME_TYPE.OTF */:
|
|
422
422
|
if (cache) {
|
|
423
423
|
CACHE_FONTFROM[hash] = 'otf';
|
|
424
424
|
}
|
|
425
|
-
checkResult(toWoff(data),
|
|
425
|
+
checkResult(toWoff(data), "font/woff" /* MIME_TYPE.WOFF */, 'otf');
|
|
426
426
|
break;
|
|
427
427
|
default:
|
|
428
428
|
errorResponse(font);
|
|
@@ -467,7 +467,7 @@ class Compress extends module_1.default {
|
|
|
467
467
|
}
|
|
468
468
|
});
|
|
469
469
|
}
|
|
470
|
-
tryImage(file, output, config, callback) {
|
|
470
|
+
async tryImage(file, output, config, callback) {
|
|
471
471
|
if (typeof config === 'function') {
|
|
472
472
|
callback = config;
|
|
473
473
|
config = undefined;
|
|
@@ -509,7 +509,7 @@ class Compress extends module_1.default {
|
|
|
509
509
|
}
|
|
510
510
|
const complete = (err) => {
|
|
511
511
|
const value = output ? path.basename(output) : filename || (0, types_1.isString)(file) && path.basename(file);
|
|
512
|
-
const status = value ? plugin + ' -> ' + value :
|
|
512
|
+
const status = value ? plugin + ' -> ' + value : "Completed" /* VAL_MESSAGE.COMPLETED */;
|
|
513
513
|
if (ctime) {
|
|
514
514
|
this.formatMessage(8 /* LOG_TYPE.COMPRESS */, value ? path.extname(value).substring(1) : '', [status, 'cache'], ctime.toLocaleString(), { ...module_1.default.LOG_STYLE_NOTICE, hintBold: true, sessionId, broadcastId });
|
|
515
515
|
}
|
|
@@ -557,9 +557,9 @@ class Compress extends module_1.default {
|
|
|
557
557
|
return;
|
|
558
558
|
}
|
|
559
559
|
switch (module_1.default.lookupMime(ext)) {
|
|
560
|
-
case
|
|
561
|
-
case
|
|
562
|
-
case
|
|
560
|
+
case "image/jpeg" /* MIME_TYPE.JPEG */:
|
|
561
|
+
case "image/png" /* MIME_TYPE.PNG */:
|
|
562
|
+
case "image/webp" /* MIME_TYPE.WEBP */:
|
|
563
563
|
break;
|
|
564
564
|
default:
|
|
565
565
|
failed((0, types_1.errorMessage)(plugin, 'Unsupported format', getFormat()));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/compress",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
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.
|
|
27
|
-
"@e-mc/types": "0.
|
|
26
|
+
"@e-mc/module": "0.8.0",
|
|
27
|
+
"@e-mc/types": "0.8.0",
|
|
28
28
|
"tinify": "^1.7.1",
|
|
29
29
|
"wawoff2": "^2.0.1",
|
|
30
30
|
"woff2sfnt-sfnt2woff": "^1.0.0"
|