@e-mc/compress 0.8.11 → 0.8.13
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 +6 -6
- package/README.md +59 -59
- package/index.d.ts +4 -4
- package/index.js +45 -47
- package/package.json +32 -32
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright 2024 An Pham
|
|
2
|
-
|
|
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
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
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,60 +1,60 @@
|
|
|
1
|
-
# @e-mc/compress
|
|
2
|
-
|
|
3
|
-
* NodeJS 14
|
|
4
|
-
* ES2019
|
|
5
|
-
|
|
6
|
-
## General Usage
|
|
7
|
-
|
|
8
|
-
* [Read the Docs](https://e-mc.readthedocs.io)
|
|
9
|
-
|
|
10
|
-
## Interface
|
|
11
|
-
|
|
12
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
13
|
-
|
|
14
|
-
```typescript
|
|
15
|
-
import type { CompressLevel } from "./squared";
|
|
16
|
-
|
|
17
|
-
import type { IModule, ModuleConstructor } from "./index";
|
|
18
|
-
import type { BufferResult, CompressFormat, TryFileCompressor, TryFileResult, TryImageResult } from "./compress";
|
|
19
|
-
import type { CompressModule, CompressSettings } from "./settings";
|
|
20
|
-
|
|
21
|
-
import type { WriteStream } from 'fs';
|
|
22
|
-
import type { Readable } from "stream";
|
|
23
|
-
import type { BrotliCompress, Gzip } from "zlib";
|
|
24
|
-
|
|
25
|
-
interface ICompress extends IModule {
|
|
26
|
-
module: CompressModule;
|
|
27
|
-
level: Record<string, number>;
|
|
28
|
-
compressors: Record<string, TryFileCompressor>;
|
|
29
|
-
chunkSize?: number;
|
|
30
|
-
init(...args: unknown[]): this;
|
|
31
|
-
register(format: string, callback: TryFileCompressor): void;
|
|
32
|
-
getLevel(value: string, fallback?: number): number | undefined;
|
|
33
|
-
getReadable(file: string | URL | Buffer): Readable;
|
|
34
|
-
createGzip(file: string | Buffer, options?: CompressLevel): Gzip;
|
|
35
|
-
createBrotliCompress(file: string | Buffer, options?: CompressLevel): BrotliCompress;
|
|
36
|
-
createWriteStreamAsGzip(file: string | Buffer, output: string, options?: CompressLevel): WriteStream;
|
|
37
|
-
createWriteStreamAsBrotli(file: string | Buffer, output: string, options?: CompressLevel): WriteStream;
|
|
38
|
-
tryFile(file: string | Buffer, config: CompressFormat, callback?: TryFileResult): Promise<BufferResult>;
|
|
39
|
-
tryFile(file: string | Buffer, output: string, config: CompressFormat, callback?: TryFileResult): Promise<BufferResult>;
|
|
40
|
-
tryImage(file: string, config: CompressFormat, callback?: TryImageResult): Promise<BufferResult>;
|
|
41
|
-
tryImage(file: string | Buffer, output: string, config: CompressFormat, callback?: TryImageResult): Promise<BufferResult>;
|
|
42
|
-
get settings(): CompressSettings;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
interface CompressConstructor extends ModuleConstructor {
|
|
46
|
-
singleton(): ICompress;
|
|
47
|
-
readonly prototype: ICompress;
|
|
48
|
-
new(module?: CompressModule): ICompress;
|
|
49
|
-
}
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## References
|
|
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.
|
|
57
|
-
|
|
58
|
-
## LICENSE
|
|
59
|
-
|
|
1
|
+
# @e-mc/compress
|
|
2
|
+
|
|
3
|
+
* NodeJS 14
|
|
4
|
+
* ES2019
|
|
5
|
+
|
|
6
|
+
## General Usage
|
|
7
|
+
|
|
8
|
+
* [Read the Docs](https://e-mc.readthedocs.io)
|
|
9
|
+
|
|
10
|
+
## Interface
|
|
11
|
+
|
|
12
|
+
- https://www.unpkg.com/@e-mc/types@0.8.13/lib/index.d.ts
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import type { CompressLevel } from "./squared";
|
|
16
|
+
|
|
17
|
+
import type { IModule, ModuleConstructor } from "./index";
|
|
18
|
+
import type { BufferResult, CompressFormat, TryFileCompressor, TryFileResult, TryImageResult } from "./compress";
|
|
19
|
+
import type { CompressModule, CompressSettings } from "./settings";
|
|
20
|
+
|
|
21
|
+
import type { WriteStream } from 'fs';
|
|
22
|
+
import type { Readable } from "stream";
|
|
23
|
+
import type { BrotliCompress, Gzip } from "zlib";
|
|
24
|
+
|
|
25
|
+
interface ICompress extends IModule {
|
|
26
|
+
module: CompressModule;
|
|
27
|
+
level: Record<string, number>;
|
|
28
|
+
compressors: Record<string, TryFileCompressor>;
|
|
29
|
+
chunkSize?: number;
|
|
30
|
+
init(...args: unknown[]): this;
|
|
31
|
+
register(format: string, callback: TryFileCompressor): void;
|
|
32
|
+
getLevel(value: string, fallback?: number): number | undefined;
|
|
33
|
+
getReadable(file: string | URL | Buffer): Readable;
|
|
34
|
+
createGzip(file: string | Buffer, options?: CompressLevel): Gzip;
|
|
35
|
+
createBrotliCompress(file: string | Buffer, options?: CompressLevel): BrotliCompress;
|
|
36
|
+
createWriteStreamAsGzip(file: string | Buffer, output: string, options?: CompressLevel): WriteStream;
|
|
37
|
+
createWriteStreamAsBrotli(file: string | Buffer, output: string, options?: CompressLevel): WriteStream;
|
|
38
|
+
tryFile(file: string | Buffer, config: CompressFormat, callback?: TryFileResult): Promise<BufferResult>;
|
|
39
|
+
tryFile(file: string | Buffer, output: string, config: CompressFormat, callback?: TryFileResult): Promise<BufferResult>;
|
|
40
|
+
tryImage(file: string, config: CompressFormat, callback?: TryImageResult): Promise<BufferResult>;
|
|
41
|
+
tryImage(file: string | Buffer, output: string, config: CompressFormat, callback?: TryImageResult): Promise<BufferResult>;
|
|
42
|
+
get settings(): CompressSettings;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface CompressConstructor extends ModuleConstructor {
|
|
46
|
+
singleton(): ICompress;
|
|
47
|
+
readonly prototype: ICompress;
|
|
48
|
+
new(module?: CompressModule): ICompress;
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## References
|
|
53
|
+
|
|
54
|
+
- https://www.unpkg.com/@e-mc/types@0.8.13/lib/squared.d.ts
|
|
55
|
+
- https://www.unpkg.com/@e-mc/types@0.8.13/lib/compress.d.ts
|
|
56
|
+
- https://www.unpkg.com/@e-mc/types@0.8.13/lib/settings.d.ts
|
|
57
|
+
|
|
58
|
+
## LICENSE
|
|
59
|
+
|
|
60
60
|
MIT
|
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
|
@@ -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
|
|
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
|
|
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)
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
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)
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
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,32 +1,32 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@e-mc/compress",
|
|
3
|
-
"version": "0.8.
|
|
4
|
-
"description": "Compress constructor for E-mc.",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"types": "index.d.ts",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
9
|
-
},
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/anpham6/e-mc.git",
|
|
13
|
-
"directory": "src/compress"
|
|
14
|
-
},
|
|
15
|
-
"keywords": [
|
|
16
|
-
"squared",
|
|
17
|
-
"squared-functions"
|
|
18
|
-
],
|
|
19
|
-
"author": {
|
|
20
|
-
"name": "An Pham",
|
|
21
|
-
"email": "anpham6@gmail.com"
|
|
22
|
-
},
|
|
23
|
-
"license": "MIT",
|
|
24
|
-
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"@e-mc/module": "0.8.
|
|
27
|
-
"@e-mc/types": "0.8.
|
|
28
|
-
"tinify": "^1.7.1",
|
|
29
|
-
"wawoff2": "^2.0.1",
|
|
30
|
-
"woff2sfnt-sfnt2woff": "^1.0.0"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@e-mc/compress",
|
|
3
|
+
"version": "0.8.13",
|
|
4
|
+
"description": "Compress constructor for E-mc.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/e-mc.git",
|
|
13
|
+
"directory": "src/compress"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"squared",
|
|
17
|
+
"squared-functions"
|
|
18
|
+
],
|
|
19
|
+
"author": {
|
|
20
|
+
"name": "An Pham",
|
|
21
|
+
"email": "anpham6@gmail.com"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@e-mc/module": "0.8.13",
|
|
27
|
+
"@e-mc/types": "0.8.13",
|
|
28
|
+
"tinify": "^1.7.1",
|
|
29
|
+
"wawoff2": "^2.0.1",
|
|
30
|
+
"woff2sfnt-sfnt2woff": "^1.0.0"
|
|
31
|
+
}
|
|
32
|
+
}
|