@e-mc/compress 0.8.7 → 0.8.8
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 +3 -7
- package/README.md +6 -6
- package/index.js +19 -14
- package/package.json +4 -4
package/LICENSE
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
6
|
|
|
7
|
-
|
|
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
|
-
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.
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @e-mc/compress
|
|
2
2
|
|
|
3
3
|
* NodeJS 14
|
|
4
|
-
*
|
|
4
|
+
* ES2019
|
|
5
5
|
|
|
6
6
|
## General Usage
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
12
|
+
- https://www.unpkg.com/@e-mc/types@0.8.8/lib/index.d.ts
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { CompressLevel } from "./squared";
|
|
@@ -51,10 +51,10 @@ interface CompressConstructor extends ModuleConstructor {
|
|
|
51
51
|
|
|
52
52
|
## References
|
|
53
53
|
|
|
54
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
55
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
56
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
54
|
+
- https://www.unpkg.com/@e-mc/types@0.8.8/lib/squared.d.ts
|
|
55
|
+
- https://www.unpkg.com/@e-mc/types@0.8.8/lib/compress.d.ts
|
|
56
|
+
- https://www.unpkg.com/@e-mc/types@0.8.8/lib/settings.d.ts
|
|
57
57
|
|
|
58
58
|
## LICENSE
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
MIT
|
package/index.js
CHANGED
|
@@ -127,7 +127,8 @@ class Compress extends module_1.default {
|
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
getLevel(value, fallback) {
|
|
130
|
-
|
|
130
|
+
var _a;
|
|
131
|
+
const result = (_a = this.level[value = value.toLowerCase()]) !== null && _a !== void 0 ? _a : this.level[value = path.extname(value).substring(1)];
|
|
131
132
|
if (!isNaN(result)) {
|
|
132
133
|
return result;
|
|
133
134
|
}
|
|
@@ -145,6 +146,7 @@ class Compress extends module_1.default {
|
|
|
145
146
|
return file instanceof Buffer ? stream.Readable.from(file) : fs.createReadStream(file);
|
|
146
147
|
}
|
|
147
148
|
createGzip(file, options) {
|
|
149
|
+
var _a, _b, _c;
|
|
148
150
|
let algorithm, level, chunkSize;
|
|
149
151
|
if (options) {
|
|
150
152
|
({ algorithm, level, chunkSize } = options);
|
|
@@ -156,7 +158,7 @@ class Compress extends module_1.default {
|
|
|
156
158
|
zopfli.numiterations = level;
|
|
157
159
|
}
|
|
158
160
|
else {
|
|
159
|
-
zopfli.numiterations
|
|
161
|
+
(_a = zopfli.numiterations) !== null && _a !== void 0 ? _a : (zopfli.numiterations = this.level.zopfli);
|
|
160
162
|
}
|
|
161
163
|
return this.getReadable(file).pipe(GZIP_ZOPFLI.createGzip(zopfli));
|
|
162
164
|
}
|
|
@@ -168,22 +170,23 @@ class Compress extends module_1.default {
|
|
|
168
170
|
gzip.level = level;
|
|
169
171
|
}
|
|
170
172
|
else {
|
|
171
|
-
gzip.level
|
|
173
|
+
(_b = gzip.level) !== null && _b !== void 0 ? _b : (gzip.level = this.level.gz);
|
|
172
174
|
}
|
|
173
175
|
if (checkChunkSize(chunkSize)) {
|
|
174
176
|
gzip.chunkSize = chunkSize;
|
|
175
177
|
}
|
|
176
178
|
else {
|
|
177
|
-
gzip.chunkSize
|
|
179
|
+
(_c = gzip.chunkSize) !== null && _c !== void 0 ? _c : (gzip.chunkSize = this.chunkSize);
|
|
178
180
|
}
|
|
179
181
|
return this.getReadable(file).pipe(zlib.createGzip(gzip));
|
|
180
182
|
}
|
|
181
183
|
createBrotliCompress(file, options) {
|
|
184
|
+
var _a;
|
|
182
185
|
let level, chunkSize, mimeType;
|
|
183
186
|
if (options) {
|
|
184
187
|
({ level, chunkSize, mimeType } = options);
|
|
185
188
|
}
|
|
186
|
-
const params = { [zlib.constants.BROTLI_PARAM_QUALITY]: level
|
|
189
|
+
const params = { [zlib.constants.BROTLI_PARAM_QUALITY]: level !== null && level !== void 0 ? level : this.level.br };
|
|
187
190
|
let brotli = this.module.brotli;
|
|
188
191
|
if ((0, types_1.isPlainObject)(brotli)) {
|
|
189
192
|
brotli = (0, types_1.isPlainObject)(brotli.params) ? { ...brotli, params: Object.assign(params, brotli.params) } : { ...brotli, params };
|
|
@@ -197,7 +200,7 @@ class Compress extends module_1.default {
|
|
|
197
200
|
brotli.chunkSize = chunkSize;
|
|
198
201
|
}
|
|
199
202
|
else {
|
|
200
|
-
brotli.chunkSize
|
|
203
|
+
(_a = brotli.chunkSize) !== null && _a !== void 0 ? _a : (brotli.chunkSize = this.chunkSize);
|
|
201
204
|
}
|
|
202
205
|
return this.getReadable(file).pipe(zlib.createBrotliCompress(brotli));
|
|
203
206
|
}
|
|
@@ -228,6 +231,7 @@ class Compress extends module_1.default {
|
|
|
228
231
|
let hash = config.etag;
|
|
229
232
|
const cache = this.settings.cache ? !!(hash && (hash = module_1.default.asHash(hash)) || Buffer.isBuffer(file) && (hash = module_1.default.asHash(file))) : false;
|
|
230
233
|
return new Promise((resolve, reject) => {
|
|
234
|
+
var _a;
|
|
231
235
|
let timer = null, aborted;
|
|
232
236
|
const endProcess = (err, data = null, ext, result, fromCache) => {
|
|
233
237
|
if (timer) {
|
|
@@ -356,7 +360,7 @@ class Compress extends module_1.default {
|
|
|
356
360
|
startProcess(false);
|
|
357
361
|
const checkResult = (result, from) => {
|
|
358
362
|
module_1.default.resolveMime(result).then(font => {
|
|
359
|
-
switch (font
|
|
363
|
+
switch (font === null || font === void 0 ? void 0 : font.mime) {
|
|
360
364
|
case "font/ttf":
|
|
361
365
|
case "font/otf":
|
|
362
366
|
writeFont(result, font.ext, from);
|
|
@@ -369,7 +373,7 @@ class Compress extends module_1.default {
|
|
|
369
373
|
};
|
|
370
374
|
module_1.default.resolveMime(data).then(font => {
|
|
371
375
|
try {
|
|
372
|
-
switch (font
|
|
376
|
+
switch (font === null || font === void 0 ? void 0 : font.mime) {
|
|
373
377
|
case "font/woff":
|
|
374
378
|
if (cache) {
|
|
375
379
|
CACHE_FONTFROM[hash] = 'woff';
|
|
@@ -400,7 +404,7 @@ class Compress extends module_1.default {
|
|
|
400
404
|
}
|
|
401
405
|
const checkResult = (result, mimeType, from) => {
|
|
402
406
|
module_1.default.resolveMime(result).then(font => {
|
|
403
|
-
if (font
|
|
407
|
+
if ((font === null || font === void 0 ? void 0 : font.mime) === mimeType) {
|
|
404
408
|
writeFont(result, font.ext, from);
|
|
405
409
|
}
|
|
406
410
|
else {
|
|
@@ -411,7 +415,7 @@ class Compress extends module_1.default {
|
|
|
411
415
|
startProcess(true);
|
|
412
416
|
module_1.default.resolveMime(data).then(font => {
|
|
413
417
|
try {
|
|
414
|
-
switch (font
|
|
418
|
+
switch (font === null || font === void 0 ? void 0 : font.mime) {
|
|
415
419
|
case "font/ttf":
|
|
416
420
|
if (cache) {
|
|
417
421
|
CACHE_FONTFROM[hash] = 'ttf';
|
|
@@ -436,7 +440,7 @@ class Compress extends module_1.default {
|
|
|
436
440
|
break;
|
|
437
441
|
}
|
|
438
442
|
default: {
|
|
439
|
-
const compressor = this.compressors[format]
|
|
443
|
+
const compressor = (_a = this.compressors[format]) === null || _a === void 0 ? void 0 : _a.bind(this);
|
|
440
444
|
if (typeof compressor === 'function') {
|
|
441
445
|
startProcess(true);
|
|
442
446
|
if (compressor.toString().startsWith('async')) {
|
|
@@ -486,6 +490,7 @@ class Compress extends module_1.default {
|
|
|
486
490
|
const ext = output ? path.extname(output).substring(1) : config.format || "Unknown";
|
|
487
491
|
const format = config.format || ext;
|
|
488
492
|
return new Promise((resolve, reject) => {
|
|
493
|
+
var _a, _b;
|
|
489
494
|
let timer = null, hash, cacheKey, aborted, apiKey;
|
|
490
495
|
const failed = (err) => {
|
|
491
496
|
aborted = true;
|
|
@@ -546,7 +551,7 @@ class Compress extends module_1.default {
|
|
|
546
551
|
case 'jpg':
|
|
547
552
|
case 'jpeg':
|
|
548
553
|
case 'webp':
|
|
549
|
-
apiKey = config.options
|
|
554
|
+
apiKey = ((_a = config.options) === null || _a === void 0 ? void 0 : _a.apiKey) || (module_1.default.enabled("process.env.apply") ? process.env.TINIFY_KEY : '');
|
|
550
555
|
break;
|
|
551
556
|
default:
|
|
552
557
|
failed((0, types_1.errorMessage)(plugin, 'Unsupported MIME', format));
|
|
@@ -579,7 +584,7 @@ class Compress extends module_1.default {
|
|
|
579
584
|
try {
|
|
580
585
|
stored = (CACHE_IMAGE[plugin] || (CACHE_IMAGE[plugin] = {}))[hash = module_1.default.asHash(data)];
|
|
581
586
|
cacheKey = module_1.default.asHash(plugin + ':' + (apiKey ? format + apiKey : module_1.default.asString(options) || 'unknown'), 'md5');
|
|
582
|
-
const ctime = stored
|
|
587
|
+
const ctime = stored === null || stored === void 0 ? void 0 : stored[cacheKey];
|
|
583
588
|
if (ctime) {
|
|
584
589
|
success(fs.readFileSync(path.join(TEMP_DIR, plugin, hash, cacheKey)), ctime);
|
|
585
590
|
return;
|
|
@@ -596,7 +601,7 @@ class Compress extends module_1.default {
|
|
|
596
601
|
timer = setTimeout(() => failed((0, types_1.errorMessage)(plugin, "Timeout was exceeded")), timeout);
|
|
597
602
|
}
|
|
598
603
|
if (apiKey) {
|
|
599
|
-
const apiProxy = proxyUrl && (typeof proxyUrl === 'function' ? proxyUrl("https://api.tinify.com") : proxyUrl) || this.module.tinify
|
|
604
|
+
const apiProxy = proxyUrl && (typeof proxyUrl === 'function' ? proxyUrl("https://api.tinify.com") : proxyUrl) || ((_b = this.module.tinify) === null || _b === void 0 ? void 0 : _b.proxy) || module_1.default.enabled("process.env.apply") && process.env.TINIFY_PROXY || '';
|
|
600
605
|
const key = apiKey + apiProxy;
|
|
601
606
|
let tinypng = CACHE_TINIFY[key];
|
|
602
607
|
const validate = () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/compress",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.8",
|
|
4
4
|
"description": "Compress constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"name": "An Pham",
|
|
21
21
|
"email": "anpham6@gmail.com"
|
|
22
22
|
},
|
|
23
|
-
"license": "
|
|
23
|
+
"license": "MIT",
|
|
24
24
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@e-mc/module": "0.8.
|
|
27
|
-
"@e-mc/types": "0.8.
|
|
26
|
+
"@e-mc/module": "0.8.8",
|
|
27
|
+
"@e-mc/types": "0.8.8",
|
|
28
28
|
"tinify": "^1.7.1",
|
|
29
29
|
"wawoff2": "^2.0.1",
|
|
30
30
|
"woff2sfnt-sfnt2woff": "^1.0.0"
|