chromiumly 2.6.0 → 2.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.
Files changed (111) hide show
  1. package/README.md +147 -42
  2. package/dist/chromium/converters/converter.d.ts +1 -1
  3. package/dist/chromium/converters/converter.js +1 -1
  4. package/dist/chromium/converters/converter.js.map +1 -1
  5. package/dist/chromium/converters/html.converter.d.ts +9 -4
  6. package/dist/chromium/converters/html.converter.js +7 -3
  7. package/dist/chromium/converters/html.converter.js.map +1 -1
  8. package/dist/chromium/converters/markdown.converter.d.ts +9 -4
  9. package/dist/chromium/converters/markdown.converter.js +7 -3
  10. package/dist/chromium/converters/markdown.converter.js.map +1 -1
  11. package/dist/chromium/converters/url.converter.d.ts +9 -4
  12. package/dist/chromium/converters/url.converter.js +6 -2
  13. package/dist/chromium/converters/url.converter.js.map +1 -1
  14. package/dist/chromium/index.d.ts +6 -3
  15. package/dist/chromium/index.js +7 -1
  16. package/dist/chromium/index.js.map +1 -1
  17. package/dist/chromium/interfaces/common.types.d.ts +13 -0
  18. package/dist/chromium/interfaces/common.types.js +3 -0
  19. package/dist/chromium/interfaces/common.types.js.map +1 -0
  20. package/dist/chromium/interfaces/converter.types.d.ts +4 -10
  21. package/dist/chromium/interfaces/screenshot.types.d.ts +10 -0
  22. package/dist/chromium/interfaces/screenshot.types.js +3 -0
  23. package/dist/chromium/interfaces/screenshot.types.js.map +1 -0
  24. package/dist/chromium/screenshots/html.screenshot.d.ts +54 -0
  25. package/dist/chromium/screenshots/html.screenshot.js +67 -0
  26. package/dist/chromium/screenshots/html.screenshot.js.map +1 -0
  27. package/dist/chromium/screenshots/markdown.screenshot.d.ts +52 -0
  28. package/dist/chromium/screenshots/markdown.screenshot.js +66 -0
  29. package/dist/chromium/screenshots/markdown.screenshot.js.map +1 -0
  30. package/dist/chromium/screenshots/screenshot.d.ts +18 -0
  31. package/dist/chromium/screenshots/screenshot.js +21 -0
  32. package/dist/chromium/screenshots/screenshot.js.map +1 -0
  33. package/dist/chromium/screenshots/url.screenshot.d.ts +50 -0
  34. package/dist/chromium/screenshots/url.screenshot.js +66 -0
  35. package/dist/chromium/screenshots/url.screenshot.js.map +1 -0
  36. package/dist/chromium/utils/converter.utils.d.ts +2 -12
  37. package/dist/chromium/utils/converter.utils.js +36 -50
  38. package/dist/chromium/utils/converter.utils.js.map +1 -1
  39. package/dist/chromium/utils/screenshot.utils.d.ts +22 -0
  40. package/dist/chromium/utils/screenshot.utils.js +75 -0
  41. package/dist/chromium/utils/screenshot.utils.js.map +1 -0
  42. package/dist/common/gotenberg.utils.d.ts +11 -1
  43. package/dist/common/gotenberg.utils.js +25 -2
  44. package/dist/common/gotenberg.utils.js.map +1 -1
  45. package/dist/common/index.d.ts +3 -3
  46. package/dist/common/index.js.map +1 -1
  47. package/dist/common/types.d.ts +1 -1
  48. package/dist/gotenberg.js +4 -3
  49. package/dist/gotenberg.js.map +1 -1
  50. package/dist/libre-office/index.d.ts +2 -2
  51. package/dist/libre-office/index.js.map +1 -1
  52. package/dist/libre-office/utils/constants.js +80 -76
  53. package/dist/libre-office/utils/constants.js.map +1 -1
  54. package/dist/libre-office/utils/libre-office.utils.d.ts +3 -3
  55. package/dist/libre-office/utils/libre-office.utils.js +5 -5
  56. package/dist/libre-office/utils/libre-office.utils.js.map +1 -1
  57. package/dist/main.config.d.ts +6 -1
  58. package/dist/main.config.js +11 -6
  59. package/dist/main.config.js.map +1 -1
  60. package/dist/main.d.ts +3 -3
  61. package/dist/main.js +4 -1
  62. package/dist/main.js.map +1 -1
  63. package/dist/pdf-engines/index.d.ts +1 -1
  64. package/dist/pdf-engines/index.js.map +1 -1
  65. package/dist/pdf-engines/pdf.engine.d.ts +3 -3
  66. package/dist/pdf-engines/pdf.engine.js +5 -5
  67. package/dist/pdf-engines/pdf.engine.js.map +1 -1
  68. package/dist/pdf-engines/utils/engine.utils.d.ts +2 -2
  69. package/dist/pdf-engines/utils/engine.utils.js +3 -3
  70. package/dist/pdf-engines/utils/engine.utils.js.map +1 -1
  71. package/package.json +20 -12
  72. package/src/.prettierrc.yml +4 -0
  73. package/src/chromium/converters/converter.ts +2 -2
  74. package/src/chromium/converters/html.converter.ts +37 -27
  75. package/src/chromium/converters/markdown.converter.ts +32 -26
  76. package/src/chromium/converters/tests/html.converter.test.ts +97 -73
  77. package/src/chromium/converters/tests/markdown.converter.test.ts +102 -77
  78. package/src/chromium/converters/tests/url.converter.test.ts +90 -66
  79. package/src/chromium/converters/url.converter.ts +31 -25
  80. package/src/chromium/index.ts +6 -3
  81. package/src/chromium/interfaces/common.types.ts +15 -0
  82. package/src/chromium/interfaces/converter.types.ts +4 -12
  83. package/src/chromium/interfaces/screenshot.types.ts +12 -0
  84. package/src/chromium/screenshots/html.screenshot.ts +100 -0
  85. package/src/chromium/screenshots/markdown.screenshot.ts +95 -0
  86. package/src/chromium/screenshots/screenshot.ts +22 -0
  87. package/src/chromium/screenshots/tests/html.screenshot.test.ts +192 -0
  88. package/src/chromium/screenshots/tests/markdown.screenshot.test.ts +176 -0
  89. package/src/chromium/screenshots/tests/url.screenshot.test.ts +166 -0
  90. package/src/chromium/screenshots/url.screenshot.ts +91 -0
  91. package/src/chromium/utils/converter.utils.ts +67 -60
  92. package/src/chromium/utils/screenshot.utils.ts +115 -0
  93. package/src/chromium/utils/tests/converter.utils.test.ts +250 -168
  94. package/src/chromium/utils/tests/screenshot.utils.test.ts +284 -0
  95. package/src/common/constants.ts +3 -3
  96. package/src/common/gotenberg.utils.ts +39 -8
  97. package/src/common/index.ts +3 -3
  98. package/src/common/tests/gotenberg.utils.test.ts +84 -31
  99. package/src/common/types.ts +2 -2
  100. package/src/gotenberg.ts +9 -9
  101. package/src/libre-office/index.ts +2 -2
  102. package/src/libre-office/utils/constants.ts +80 -76
  103. package/src/libre-office/utils/libre-office.utils.ts +21 -18
  104. package/src/libre-office/utils/tests/libre-office.utils.test.ts +58 -49
  105. package/src/main.config.ts +19 -13
  106. package/src/main.ts +10 -3
  107. package/src/pdf-engines/index.ts +1 -1
  108. package/src/pdf-engines/pdf.engine.ts +23 -19
  109. package/src/pdf-engines/tests/pdf.engine.test.ts +52 -49
  110. package/src/pdf-engines/utils/engine.utils.ts +12 -9
  111. package/src/pdf-engines/utils/tests/engine.utils.test.ts +23 -23
@@ -1,78 +1,82 @@
1
1
  export const LIBRE_OFFICE_EXTENSIONS = [
2
- "bib",
3
- "doc",
4
- "xml",
5
- "docx",
6
- "fodt",
7
- "html",
8
- "ltx",
9
- "txt",
10
- "odt",
11
- "ott",
12
- "pdb",
13
- "pdf",
14
- "psw",
15
- "rtf",
16
- "sdw",
17
- "stw",
18
- "sxw",
19
- "uot",
20
- "vor",
21
- "wps",
22
- "epub",
23
- "png",
24
- "bmp",
25
- "emf",
26
- "eps",
27
- "fodg",
28
- "gif",
29
- "jpg",
30
- "met",
31
- "odd",
32
- "otg",
33
- "pbm",
34
- "pct",
35
- "pgm",
36
- "ppm",
37
- "ras",
38
- "std",
39
- "svg",
40
- "svm",
41
- "swf",
42
- "sxd",
43
- "sxw",
44
- "tiff",
45
- "xhtml",
46
- "xpm",
47
- "fodp",
48
- "potm",
49
- "pot",
50
- "pptx",
51
- "pps",
52
- "ppt",
53
- "pwp",
54
- "sda",
55
- "sdd",
56
- "sti",
57
- "sxi",
58
- "uop",
59
- "wmf",
60
- "csv",
61
- "dbf",
62
- "dif",
63
- "fods",
64
- "ods",
65
- "ots",
66
- "pxl",
67
- "sdc",
68
- "slk",
69
- "stc",
70
- "sxc",
71
- "uos",
72
- "xls",
73
- "xlt",
74
- "xlsx",
75
- "tif",
76
- "jpeg",
77
- "odp",
2
+ 'bib',
3
+ 'doc',
4
+ 'xml',
5
+ 'docx',
6
+ 'fodt',
7
+ 'html',
8
+ 'ltx',
9
+ 'txt',
10
+ 'odt',
11
+ 'ott',
12
+ 'pdb',
13
+ 'pdf',
14
+ 'psw',
15
+ 'rtf',
16
+ 'sdw',
17
+ 'stw',
18
+ 'sxw',
19
+ 'uot',
20
+ 'vor',
21
+ 'wps',
22
+ 'epub',
23
+ 'png',
24
+ 'bmp',
25
+ 'emf',
26
+ 'eps',
27
+ 'fodg',
28
+ 'gif',
29
+ 'jpg',
30
+ 'met',
31
+ 'odd',
32
+ 'otg',
33
+ 'pbm',
34
+ 'pct',
35
+ 'pgm',
36
+ 'ppm',
37
+ 'ras',
38
+ 'std',
39
+ 'svg',
40
+ 'svm',
41
+ 'swf',
42
+ 'sxd',
43
+ 'sxw',
44
+ 'tiff',
45
+ 'xhtml',
46
+ 'xpm',
47
+ 'fodp',
48
+ 'pages',
49
+ 'potm',
50
+ 'pot',
51
+ 'pptx',
52
+ 'pps',
53
+ 'ppt',
54
+ 'pwp',
55
+ 'sda',
56
+ 'sdd',
57
+ 'sti',
58
+ 'sxi',
59
+ 'uop',
60
+ 'wmf',
61
+ 'csv',
62
+ 'dbf',
63
+ 'dif',
64
+ 'fods',
65
+ 'ods',
66
+ 'ots',
67
+ 'pxl',
68
+ 'sdc',
69
+ 'slk',
70
+ 'stc',
71
+ 'sxc',
72
+ 'uos',
73
+ 'xls',
74
+ 'xlt',
75
+ 'xlsx',
76
+ 'tif',
77
+ 'jpeg',
78
+ 'odp',
79
+ 'odg',
80
+ 'dotx',
81
+ 'xltx'
78
82
  ];
@@ -1,13 +1,13 @@
1
- import {constants, createReadStream, promises, ReadStream} from "fs";
2
- import path from "path";
1
+ import { constants, createReadStream, promises, ReadStream } from 'fs';
2
+ import path from 'path';
3
3
 
4
- import {fromStream, fromBuffer} from "file-type";
4
+ import { fromStream, fromBuffer } from 'file-type';
5
5
 
6
- import FormData from "form-data";
6
+ import FormData from 'form-data';
7
7
 
8
- import {GotenbergUtils, PathLikeOrReadStream} from "../../common";
9
- import {LIBRE_OFFICE_EXTENSIONS} from "./constants";
10
- import {PageProperties} from "../interfaces/libre-office.types";
8
+ import { GotenbergUtils, PathLikeOrReadStream } from '../../common';
9
+ import { LIBRE_OFFICE_EXTENSIONS } from './constants';
10
+ import { PageProperties } from '../interfaces/libre-office.types';
11
11
 
12
12
  /**
13
13
  * Utility class for handling common tasks related to LibreOffice conversions.
@@ -20,7 +20,10 @@ export class LibreOfficeUtils {
20
20
  * @param {FormData} data - The FormData object to which files will be added.
21
21
  * @throws {Error} Throws an error if the file extension is not supported.
22
22
  */
23
- public static async addFiles(files: PathLikeOrReadStream[], data: FormData) {
23
+ public static async addFiles(
24
+ files: PathLikeOrReadStream[],
25
+ data: FormData
26
+ ) {
24
27
  for (const [key, value] of files.entries()) {
25
28
  let file = value;
26
29
  let fileInfo;
@@ -32,18 +35,18 @@ export class LibreOfficeUtils {
32
35
  } else {
33
36
  await promises.access(value, constants.R_OK);
34
37
  const filename = path.basename(value.toString());
35
- fileInfo = {ext: path.extname(filename).slice(1)};
36
- file = createReadStream(value)
38
+ fileInfo = { ext: path.extname(filename).slice(1) };
39
+ file = createReadStream(value);
37
40
  }
38
41
 
39
42
  if (!fileInfo) {
40
- throw new Error("File type could not be determined");
43
+ throw new Error('File type could not be determined');
41
44
  }
42
45
 
43
46
  const extension = fileInfo.ext;
44
47
 
45
48
  if (LIBRE_OFFICE_EXTENSIONS.includes(extension)) {
46
- data.append("files", file, `${key}.${extension}`);
49
+ data.append('files', file, `${key}.${extension}`);
47
50
  } else {
48
51
  throw new Error(`${extension} is not supported`);
49
52
  }
@@ -61,20 +64,20 @@ export class LibreOfficeUtils {
61
64
  pageProperties: PageProperties
62
65
  ): void {
63
66
  if (pageProperties.landscape) {
64
- data.append("landscape", String(pageProperties.landscape));
67
+ data.append('landscape', String(pageProperties.landscape));
65
68
  }
66
69
 
67
70
  if (pageProperties.nativePageRanges) {
68
71
  GotenbergUtils.assert(
69
72
  pageProperties.nativePageRanges.from > 0 &&
70
- pageProperties.nativePageRanges.to > 0 &&
71
- pageProperties.nativePageRanges.to >=
72
- pageProperties.nativePageRanges.from,
73
- "page ranges syntax error"
73
+ pageProperties.nativePageRanges.to > 0 &&
74
+ pageProperties.nativePageRanges.to >=
75
+ pageProperties.nativePageRanges.from,
76
+ 'page ranges syntax error'
74
77
  );
75
78
 
76
79
  data.append(
77
- "nativePageRanges",
80
+ 'nativePageRanges',
78
81
  `${pageProperties.nativePageRanges.from}-${pageProperties.nativePageRanges.to}`
79
82
  );
80
83
  }
@@ -1,14 +1,14 @@
1
1
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
- import {promises, createReadStream} from "fs";
3
- import {LibreOfficeUtils} from "../libre-office.utils";
2
+ import { promises, createReadStream } from 'fs';
3
+ import { LibreOfficeUtils } from '../libre-office.utils';
4
4
 
5
- import FormData from "form-data";
6
- import FileType from "file-type";
5
+ import FormData from 'form-data';
6
+ import FileType from 'file-type';
7
7
 
8
- describe("LibreOfficeUtils", () => {
9
- const mockPromisesAccess = jest.spyOn(promises, "access");
10
- const mockFormDataAppend = jest.spyOn(FormData.prototype, "append");
11
- const mockFromBuffer = jest.spyOn(FileType, "fromBuffer");
8
+ describe('LibreOfficeUtils', () => {
9
+ const mockPromisesAccess = jest.spyOn(promises, 'access');
10
+ const mockFormDataAppend = jest.spyOn(FormData.prototype, 'append');
11
+ const mockFromBuffer = jest.spyOn(FileType, 'fromBuffer');
12
12
 
13
13
  const data = new FormData();
14
14
 
@@ -22,67 +22,70 @@ describe("LibreOfficeUtils", () => {
22
22
  jest.resetAllMocks();
23
23
  });
24
24
 
25
- describe("addFiles", () => {
26
- describe("when files exist", () => {
27
- describe("when files parameter contains paths", () => {
28
- it("should append each file to data", async () => {
25
+ describe('addFiles', () => {
26
+ describe('when files exist', () => {
27
+ describe('when files parameter contains paths', () => {
28
+ it('should append each file to data', async () => {
29
29
  mockPromisesAccess.mockResolvedValue();
30
30
  await LibreOfficeUtils.addFiles(
31
- ["path/to/file.docx", "path/to/file.bib"],
31
+ ['path/to/file.docx', 'path/to/file.bib'],
32
32
  data
33
33
  );
34
34
  expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
35
35
  });
36
- })
37
- describe("when files parameter contains a buffer", () => {
38
- it("should append each file to data", async () => {
36
+ });
37
+ describe('when files parameter contains a buffer', () => {
38
+ it('should append each file to data', async () => {
39
39
  mockPromisesAccess.mockResolvedValueOnce();
40
40
  mockFromBuffer.mockResolvedValueOnce({
41
- ext: "docx",
42
- mime: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
43
- })
41
+ ext: 'docx',
42
+ mime: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
43
+ });
44
44
  await LibreOfficeUtils.addFiles(
45
- [Buffer.from("data"), "path/to/file.bib"],
45
+ [Buffer.from('data'), 'path/to/file.bib'],
46
46
  data
47
47
  );
48
48
  expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
49
49
  });
50
- })
50
+ });
51
51
  });
52
52
 
53
- describe("when one of the files has undetermined format", () => {
54
- it("should throw an error", async () => {
53
+ describe('when one of the files has undetermined format', () => {
54
+ it('should throw an error', async () => {
55
55
  mockPromisesAccess.mockResolvedValueOnce();
56
- mockFromBuffer.mockResolvedValueOnce(undefined
57
- )
56
+ mockFromBuffer.mockResolvedValueOnce(undefined);
58
57
 
59
- await expect(LibreOfficeUtils.addFiles(
60
- [Buffer.from("data"), "path/to/file.bib"],
61
- data
62
- )).rejects.toThrow("File type could not be determined");
58
+ await expect(
59
+ LibreOfficeUtils.addFiles(
60
+ [Buffer.from('data'), 'path/to/file.bib'],
61
+ data
62
+ )
63
+ ).rejects.toThrow('File type could not be determined');
63
64
  });
64
- })
65
+ });
65
66
 
66
- describe("when one of the files has unsupported format", () => {
67
- it("should throw an error", async () => {
67
+ describe('when one of the files has unsupported format', () => {
68
+ it('should throw an error', async () => {
68
69
  mockPromisesAccess.mockResolvedValueOnce();
69
70
  await expect(() =>
70
71
  LibreOfficeUtils.addFiles(
71
- ["path/to/file.rar", "path/to/file.pdf"],
72
+ ['path/to/file.rar', 'path/to/file.pdf'],
72
73
  data
73
74
  )
74
- ).rejects.toThrow("rar is not supported");
75
+ ).rejects.toThrow('rar is not supported');
75
76
  });
76
77
  });
77
78
 
78
- describe("when one of the files does not exist", () => {
79
- it("should throw an error", async () => {
79
+ describe('when one of the files does not exist', () => {
80
+ it('should throw an error', async () => {
80
81
  const errorMessage =
81
82
  "ENOENT: no such file or directory, access 'path/to/index.html'";
82
- mockPromisesAccess.mockRejectedValueOnce(new Error(errorMessage));
83
+ mockPromisesAccess.mockRejectedValueOnce(
84
+ new Error(errorMessage)
85
+ );
83
86
  await expect(() =>
84
87
  LibreOfficeUtils.addFiles(
85
- ["path/to/file.pdf", "path/to/another-file.pdf"],
88
+ ['path/to/file.pdf', 'path/to/another-file.pdf'],
86
89
  data
87
90
  )
88
91
  ).rejects.toThrow(errorMessage);
@@ -90,27 +93,33 @@ describe("LibreOfficeUtils", () => {
90
93
  });
91
94
  });
92
95
 
93
- describe("addPageProperties", () => {
94
- describe("Page landscape", () => {
95
- describe("when landscape parameter is set", () => {
96
- it("should append landscape to data", () => {
96
+ describe('addPageProperties', () => {
97
+ describe('Page landscape', () => {
98
+ describe('when landscape parameter is set', () => {
99
+ it('should append landscape to data', () => {
97
100
  LibreOfficeUtils.addPageProperties(data, {
98
- landscape: true,
101
+ landscape: true
99
102
  });
100
103
  expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
101
- expect(data.append).toHaveBeenCalledWith("landscape", "true");
104
+ expect(data.append).toHaveBeenCalledWith(
105
+ 'landscape',
106
+ 'true'
107
+ );
102
108
  });
103
109
  });
104
110
  });
105
111
 
106
- describe("Page ranges", () => {
107
- describe("when nativePageRanges is valid", () => {
108
- it("should append nativePageRanges to data", () => {
112
+ describe('Page ranges', () => {
113
+ describe('when nativePageRanges is valid', () => {
114
+ it('should append nativePageRanges to data', () => {
109
115
  LibreOfficeUtils.addPageProperties(data, {
110
- nativePageRanges: {from: 1, to: 6},
116
+ nativePageRanges: { from: 1, to: 6 }
111
117
  });
112
118
  expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
113
- expect(data.append).toHaveBeenCalledWith("nativePageRanges", "1-6");
119
+ expect(data.append).toHaveBeenCalledWith(
120
+ 'nativePageRanges',
121
+ '1-6'
122
+ );
114
123
  });
115
124
  });
116
125
  });
@@ -1,13 +1,13 @@
1
- import {Gotenberg} from "./gotenberg";
1
+ import { Gotenberg } from './gotenberg';
2
2
 
3
3
  /**
4
4
  * Enum representing the available Chromium routes for conversion.
5
5
  * @enum {string}
6
6
  */
7
7
  export enum ChromiumRoute {
8
- URL = "url",
9
- HTML = "html",
10
- MARKDOWN = "markdown",
8
+ URL = 'url',
9
+ HTML = 'html',
10
+ MARKDOWN = 'markdown'
11
11
  }
12
12
 
13
13
  /**
@@ -15,7 +15,7 @@ export enum ChromiumRoute {
15
15
  * @enum {string}
16
16
  */
17
17
  enum PdfEngineRoute {
18
- MERGE = "merge",
18
+ MERGE = 'merge'
19
19
  }
20
20
 
21
21
  /**
@@ -23,7 +23,7 @@ enum PdfEngineRoute {
23
23
  * @enum {string}
24
24
  */
25
25
  enum LibreOfficeRoute {
26
- CONVERT = "convert",
26
+ CONVERT = 'convert'
27
27
  }
28
28
 
29
29
  /**
@@ -40,19 +40,25 @@ export class Chromiumly {
40
40
  * The path for Chromium-related conversions.
41
41
  * @type {string}
42
42
  */
43
- public static readonly CHROMIUM_PATH = "forms/chromium/convert";
43
+ public static readonly CHROMIUM_CONVERT_PATH = 'forms/chromium/convert';
44
44
 
45
+ /**
46
+ * The path for Chromium-related screenshots.
47
+ * @type {string}
48
+ */
49
+ public static readonly CHROMIUM_SCREENSHOT_PATH =
50
+ 'forms/chromium/screenshot';
45
51
  /**
46
52
  * The path for PDF engine-related operations.
47
53
  * @type {string}
48
54
  */
49
- public static readonly PDF_ENGINES_PATH = "forms/pdfengines";
55
+ public static readonly PDF_ENGINES_PATH = 'forms/pdfengines';
50
56
 
51
57
  /**
52
58
  * The path for LibreOffice-related conversions.
53
59
  * @type {string}
54
60
  */
55
- public static readonly LIBRE_OFFICE_PATH = "forms/libreoffice";
61
+ public static readonly LIBRE_OFFICE_PATH = 'forms/libreoffice';
56
62
 
57
63
  /**
58
64
  * Routes for Chromium conversions.
@@ -61,7 +67,7 @@ export class Chromiumly {
61
67
  public static readonly CHROMIUM_ROUTES = {
62
68
  url: ChromiumRoute.URL,
63
69
  html: ChromiumRoute.HTML,
64
- markdown: ChromiumRoute.MARKDOWN,
70
+ markdown: ChromiumRoute.MARKDOWN
65
71
  };
66
72
 
67
73
  /**
@@ -69,7 +75,7 @@ export class Chromiumly {
69
75
  * @type {Object}
70
76
  */
71
77
  public static readonly PDF_ENGINE_ROUTES = {
72
- merge: PdfEngineRoute.MERGE,
78
+ merge: PdfEngineRoute.MERGE
73
79
  };
74
80
 
75
81
  /**
@@ -77,6 +83,6 @@ export class Chromiumly {
77
83
  * @type {Object}
78
84
  */
79
85
  public static readonly LIBRE_OFFICE_ROUTES = {
80
- convert: LibreOfficeRoute.CONVERT,
86
+ convert: LibreOfficeRoute.CONVERT
81
87
  };
82
- }
88
+ }
package/src/main.ts CHANGED
@@ -1,3 +1,10 @@
1
- export {PdfFormat} from "./common/constants";
2
- export {HtmlConverter, MarkdownConverter, UrlConverter} from "./chromium";
3
- export {PDFEngine} from "./pdf-engines";
1
+ export { PdfFormat } from './common/constants';
2
+ export {
3
+ HtmlConverter,
4
+ HtmlScreenshot,
5
+ MarkdownConverter,
6
+ MarkdownScreenshot,
7
+ UrlConverter,
8
+ UrlScreenshot
9
+ } from './chromium';
10
+ export { PDFEngine } from './pdf-engines';
@@ -1 +1 @@
1
- export {PDFEngine} from "./pdf.engine";
1
+ export { PDFEngine } from './pdf.engine';
@@ -1,12 +1,12 @@
1
- import {promises} from "fs";
2
- import path from "path";
1
+ import { promises } from 'fs';
2
+ import path from 'path';
3
3
 
4
- import FormData from "form-data";
4
+ import FormData from 'form-data';
5
5
 
6
- import {Chromiumly} from "../main.config";
7
- import {GotenbergUtils, PathLikeOrReadStream, PdfFormat} from "../common";
8
- import {LibreOfficeUtils, PageProperties} from "../libre-office";
9
- import {PDFEngineUtils} from "./utils/engine.utils";
6
+ import { Chromiumly } from '../main.config';
7
+ import { GotenbergUtils, PathLikeOrReadStream, PdfFormat } from '../common';
8
+ import { LibreOfficeUtils, PageProperties } from '../libre-office';
9
+ import { PDFEngineUtils } from './utils/engine.utils';
10
10
 
11
11
  /**
12
12
  * Class representing a PDF engine for various operations such as merging and conversion.
@@ -19,7 +19,11 @@ export class PDFEngine {
19
19
  * @param {PathLikeOrReadStream[]} options.files - An array of PathLikes or ReadStreams to the PDF files to be merged.
20
20
  * @returns {Promise<Buffer>} A Promise resolving to the merged PDF content as a Buffer.
21
21
  */
22
- public static async merge({files}: { files: PathLikeOrReadStream[] }): Promise<Buffer> {
22
+ public static async merge({
23
+ files
24
+ }: {
25
+ files: PathLikeOrReadStream[];
26
+ }): Promise<Buffer> {
23
27
  const data = new FormData();
24
28
  await PDFEngineUtils.addFiles(files, data);
25
29
  const endpoint = `${Chromiumly.GOTENBERG_ENDPOINT}/${Chromiumly.PDF_ENGINES_PATH}/${Chromiumly.PDF_ENGINE_ROUTES.merge}`;
@@ -38,12 +42,12 @@ export class PDFEngine {
38
42
  * @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
39
43
  */
40
44
  public static async convert({
41
- files,
42
- properties,
43
- pdfFormat,
44
- pdfUA,
45
- merge,
46
- }: {
45
+ files,
46
+ properties,
47
+ pdfFormat,
48
+ pdfUA,
49
+ merge
50
+ }: {
47
51
  files: PathLikeOrReadStream[];
48
52
  properties?: PageProperties;
49
53
  pdfFormat?: PdfFormat;
@@ -53,15 +57,15 @@ export class PDFEngine {
53
57
  const data = new FormData();
54
58
 
55
59
  if (pdfFormat) {
56
- data.append("pdfa", pdfFormat);
60
+ data.append('pdfa', pdfFormat);
57
61
  }
58
62
 
59
63
  if (pdfUA) {
60
- data.append("pdfUA", String(pdfUA));
64
+ data.append('pdfUA', String(pdfUA));
61
65
  }
62
66
 
63
67
  if (merge) {
64
- data.append("merge", String(merge));
68
+ data.append('merge', String(merge));
65
69
  }
66
70
 
67
71
  if (properties) {
@@ -86,8 +90,8 @@ export class PDFEngine {
86
90
  filename: string,
87
91
  buffer: Buffer
88
92
  ): Promise<void> {
89
- const __generated__ = path.resolve(process.cwd(), "__generated__");
90
- await promises.mkdir(path.resolve(__generated__), {recursive: true});
93
+ const __generated__ = path.resolve(process.cwd(), '__generated__');
94
+ await promises.mkdir(path.resolve(__generated__), { recursive: true });
91
95
  await promises.writeFile(path.resolve(__generated__, filename), buffer);
92
96
  }
93
97
  }