chromiumly 2.5.1 → 2.6.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/dist/chromium/converters/html.converter.d.ts +5 -1
- package/dist/chromium/converters/html.converter.js +4 -1
- package/dist/chromium/converters/html.converter.js.map +1 -1
- package/package.json +13 -13
- package/src/chromium/converters/html.converter.ts +6 -0
- package/src/chromium/converters/tests/html.converter.test.ts +21 -2
|
@@ -32,8 +32,12 @@ export declare class HtmlConverter extends Converter {
|
|
|
32
32
|
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
|
|
33
33
|
* @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
|
|
34
34
|
*/
|
|
35
|
-
convert({ html, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnConsoleExceptions, }: {
|
|
35
|
+
convert({ html, assets, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnConsoleExceptions, }: {
|
|
36
36
|
html: PathLikeOrReadStream;
|
|
37
|
+
assets?: {
|
|
38
|
+
file: PathLikeOrReadStream;
|
|
39
|
+
name: string;
|
|
40
|
+
}[];
|
|
37
41
|
header?: PathLikeOrReadStream;
|
|
38
42
|
footer?: PathLikeOrReadStream;
|
|
39
43
|
properties?: PageProperties;
|
|
@@ -39,10 +39,13 @@ class HtmlConverter extends converter_1.Converter {
|
|
|
39
39
|
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
|
|
40
40
|
* @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
|
|
41
41
|
*/
|
|
42
|
-
convert({ html, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnConsoleExceptions, }) {
|
|
42
|
+
convert({ html, assets, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnConsoleExceptions, }) {
|
|
43
43
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
44
44
|
const data = new form_data_1.default();
|
|
45
45
|
yield converter_utils_1.ConverterUtils.addFile(data, html, "index.html");
|
|
46
|
+
if (assets === null || assets === void 0 ? void 0 : assets.length) {
|
|
47
|
+
yield Promise.all(assets.map(({ file, name }) => converter_utils_1.ConverterUtils.addFile(data, file, name)));
|
|
48
|
+
}
|
|
46
49
|
yield converter_utils_1.ConverterUtils.customize(data, {
|
|
47
50
|
header,
|
|
48
51
|
footer,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.converter.js","sourceRoot":"","sources":["../../../src/chromium/converters/html.converter.ts"],"names":[],"mappings":";;;;AAAA,kEAAiC;AAEjC,yCAA6E;AAK7E,8DAAwD;AACxD,2CAAsC;AACtC,mDAAgD;AAEhD;;;;;GAKG;AACH,MAAa,aAAc,SAAQ,qBAAS;IACxC;;;OAGG;IACH;QACI,KAAK,CAAC,2BAAa,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACG,OAAO,CAAC,EACI,IAAI,EACJ,MAAM,EACN,MAAM,EACN,UAAU,EACV,SAAS,EACT,KAAK,EACL,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,uBAAuB,
|
|
1
|
+
{"version":3,"file":"html.converter.js","sourceRoot":"","sources":["../../../src/chromium/converters/html.converter.ts"],"names":[],"mappings":";;;;AAAA,kEAAiC;AAEjC,yCAA6E;AAK7E,8DAAwD;AACxD,2CAAsC;AACtC,mDAAgD;AAEhD;;;;;GAKG;AACH,MAAa,aAAc,SAAQ,qBAAS;IACxC;;;OAGG;IACH;QACI,KAAK,CAAC,2BAAa,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACG,OAAO,CAAC,EACI,IAAI,EACJ,MAAM,EACN,MAAM,EACN,MAAM,EACN,UAAU,EACV,SAAS,EACT,KAAK,EACL,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,uBAAuB,GAexC;;YACG,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAE5B,MAAM,gCAAc,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;YAEvD,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,EAAE,CAAC;gBACjB,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,gCAAc,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;YAC/F,CAAC;YAED,MAAM,gCAAc,CAAC,SAAS,CAAC,IAAI,EAAE;gBACjC,MAAM;gBACN,MAAM;gBACN,UAAU;gBACV,SAAS;gBACT,KAAK;gBACL,iBAAiB;gBACjB,SAAS;gBACT,iBAAiB;gBACjB,SAAS;gBACT,gBAAgB;gBAChB,uBAAuB;aAC1B,CAAC,CAAC;YAEH,OAAO,uBAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;KAAA;CACJ;AAhFD,sCAgFC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chromiumly",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "A lightweight Typescript library that interacts with Gotenberg's different modules to convert a variety of document formats to PDF files.",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"types": "dist/main.d.ts",
|
|
@@ -47,26 +47,26 @@
|
|
|
47
47
|
"@types/config": "3.3.3",
|
|
48
48
|
"@types/dotenv": "8.2.0",
|
|
49
49
|
"@types/form-data": "2.5.0",
|
|
50
|
-
"@types/jest": "29.5.
|
|
51
|
-
"@types/node": "20.
|
|
52
|
-
"@types/node-fetch": "2.6.
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "
|
|
54
|
-
"@typescript-eslint/parser": "
|
|
50
|
+
"@types/jest": "29.5.12",
|
|
51
|
+
"@types/node": "20.11.19",
|
|
52
|
+
"@types/node-fetch": "2.6.11",
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "7.0.1",
|
|
54
|
+
"@typescript-eslint/parser": "7.0.1",
|
|
55
55
|
"commitizen": "4.3.0",
|
|
56
|
-
"eslint": "8.
|
|
57
|
-
"husky": "
|
|
56
|
+
"eslint": "8.56.0",
|
|
57
|
+
"husky": "9.0.11",
|
|
58
58
|
"inquirer": "8",
|
|
59
59
|
"jest": "29.7.0",
|
|
60
60
|
"jest-junit": "16.0.0",
|
|
61
|
-
"release-it": "17.0.
|
|
62
|
-
"ts-jest": "29.1.
|
|
63
|
-
"ts-node": "10.9.
|
|
61
|
+
"release-it": "17.0.5",
|
|
62
|
+
"ts-jest": "29.1.2",
|
|
63
|
+
"ts-node": "10.9.2",
|
|
64
64
|
"tslib": "2.6.2",
|
|
65
65
|
"typescript": "5.3.3"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"config": "3.3.
|
|
69
|
-
"dotenv": "16.
|
|
68
|
+
"config": "3.3.11",
|
|
69
|
+
"dotenv": "16.4.4",
|
|
70
70
|
"file-type": "16.5.4",
|
|
71
71
|
"form-data": "4.0.0",
|
|
72
72
|
"node-fetch": "2.7.0"
|
|
@@ -44,6 +44,7 @@ export class HtmlConverter extends Converter {
|
|
|
44
44
|
*/
|
|
45
45
|
async convert({
|
|
46
46
|
html,
|
|
47
|
+
assets,
|
|
47
48
|
header,
|
|
48
49
|
footer,
|
|
49
50
|
properties,
|
|
@@ -57,6 +58,7 @@ export class HtmlConverter extends Converter {
|
|
|
57
58
|
failOnConsoleExceptions,
|
|
58
59
|
}: {
|
|
59
60
|
html: PathLikeOrReadStream;
|
|
61
|
+
assets?: { file: PathLikeOrReadStream, name: string }[]
|
|
60
62
|
header?: PathLikeOrReadStream;
|
|
61
63
|
footer?: PathLikeOrReadStream;
|
|
62
64
|
properties?: PageProperties;
|
|
@@ -73,6 +75,10 @@ export class HtmlConverter extends Converter {
|
|
|
73
75
|
|
|
74
76
|
await ConverterUtils.addFile(data, html, "index.html");
|
|
75
77
|
|
|
78
|
+
if (assets?.length) {
|
|
79
|
+
await Promise.all(assets.map(({ file, name }) => ConverterUtils.addFile(data, file, name)))
|
|
80
|
+
}
|
|
81
|
+
|
|
76
82
|
await ConverterUtils.customize(data, {
|
|
77
83
|
header,
|
|
78
84
|
footer,
|
|
@@ -25,7 +25,12 @@ describe("HtmlConverter", () => {
|
|
|
25
25
|
const mockPromisesAccess = jest.spyOn(promises, "access");
|
|
26
26
|
const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
|
|
27
27
|
const mockFormDataAppend = jest.spyOn(FormData.prototype, "append");
|
|
28
|
-
|
|
28
|
+
|
|
29
|
+
const assets = [
|
|
30
|
+
{ file: Buffer.from('asset1'), name: 'asset1' },
|
|
31
|
+
{ file: Buffer.from('asset2'), name: 'asset2' }
|
|
32
|
+
]
|
|
33
|
+
|
|
29
34
|
beforeEach(() => {
|
|
30
35
|
(createReadStream as jest.Mock) = jest.fn()
|
|
31
36
|
});
|
|
@@ -92,6 +97,19 @@ describe("HtmlConverter", () => {
|
|
|
92
97
|
});
|
|
93
98
|
});
|
|
94
99
|
|
|
100
|
+
describe("when assets parameter is passed", () => {
|
|
101
|
+
it("should return a buffer", async () => {
|
|
102
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
103
|
+
const buffer = await converter.convert({
|
|
104
|
+
html: Buffer.from("data"),
|
|
105
|
+
assets,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
|
|
109
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
95
113
|
describe("when emulatedMediaType parameter is passed", () => {
|
|
96
114
|
it("should return a buffer", async () => {
|
|
97
115
|
mockFetch.mockResolvedValue(new Response("content"));
|
|
@@ -110,13 +128,14 @@ describe("HtmlConverter", () => {
|
|
|
110
128
|
mockFetch.mockResolvedValue(new Response("content"));
|
|
111
129
|
const buffer = await converter.convert({
|
|
112
130
|
html: Buffer.from("data"),
|
|
131
|
+
assets,
|
|
113
132
|
header: Buffer.from("header"),
|
|
114
133
|
footer: Buffer.from("footer"),
|
|
115
134
|
pdfFormat: PdfFormat.A_1a,
|
|
116
135
|
emulatedMediaType: "screen",
|
|
117
136
|
properties: {size: {width: 8.3, height: 11.7}},
|
|
118
137
|
});
|
|
119
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(
|
|
138
|
+
expect(mockFormDataAppend).toHaveBeenCalledTimes(9);
|
|
120
139
|
expect(buffer).toEqual(Buffer.from("content"));
|
|
121
140
|
});
|
|
122
141
|
});
|