libreoffice-convert 1.3.4 → 1.3.7

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/Readme.md CHANGED
@@ -1,33 +1,38 @@
1
- # libreoffice-convert #
1
+ # libreoffice-convert
2
2
 
3
3
  A simple and fast node.js module for converting office documents to different formats.
4
4
 
5
- ## Dependency ##
5
+ ## Dependency
6
6
 
7
7
  Please install libreoffice in /Applications (Mac), with your favorite package manager (Linux), or with the msi (Windows).
8
8
 
9
+ ## Usage example
9
10
 
10
- ## Usage example ##
11
11
  ```javascript
12
- const libre = require('libreoffice-convert');
12
+ 'use strict';
13
13
 
14
14
  const path = require('path');
15
- const fs = require('fs');
16
-
17
- const extend = '.pdf'
18
- const enterPath = path.join(__dirname, '/resources/example.docx');
19
- const outputPath = path.join(__dirname, `/resources/example${extend}`);
20
-
21
- // Read file
22
- const file = fs.readFileSync(enterPath);
23
- // Convert it to pdf format with undefined filter (see Libreoffice doc about filter)
24
- libre.convert(file, extend, undefined, (err, done) => {
25
- if (err) {
26
- console.log(`Error converting file: ${err}`);
27
- }
15
+ const fs = require('fs').promises;
16
+
17
+ const libre = require('libreoffice-convert');
18
+ libre.convertAsync = require('util').promisify(libre.convert);
19
+
20
+ async function main() {
21
+ const ext = '.pdf'
22
+ const inputPath = path.join(__dirname, '/resources/example.docx');
23
+ const outputPath = path.join(__dirname, `/resources/example${ext}`);
24
+
25
+ // Read file
26
+ const docxBuf = await fs.readFile(inputPath);
27
+
28
+ // Convert it to pdf format with undefined filter (see Libreoffice docs about filter)
29
+ let pdfBuf = await libre.convertAsync(docxBuf, ext, undefined);
28
30
 
29
31
  // Here in done you have pdf file which you can save or transfer in another stream
30
- fs.writeFileSync(outputPath, done);
32
+ await fs.writeFile(outputPath, pdfBuf);
33
+ }
34
+
35
+ main().catch(function (err) {
36
+ console.log(`Error converting file: ${err}`);
31
37
  });
32
38
  ```
33
-
package/index.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ /// <reference types="node" />
2
+ declare module "libreoffice-convert" {
3
+ function convert(
4
+ document: Buffer,
5
+ format: string,
6
+ filter: string | undefined,
7
+ callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void
8
+ ): void;
9
+ function convertWithOptions(
10
+ document: Buffer,
11
+ format: string,
12
+ filter: string | undefined,
13
+ options: {
14
+ tmpOptions?: Record<string | number | symbol, unknown>;
15
+ asyncOptions?: { times?: number; interval?: number };
16
+ },
17
+ callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void
18
+ ): void;
19
+ }
package/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
+ const url = require('url');
5
6
  const async = require('async');
6
7
  const tmp = require('tmp');
7
8
  const { execFile } = require('child_process');
@@ -43,7 +44,7 @@ const convertWithOptions = (document, format, filter, options, callback) => {
43
44
  },
44
45
  saveSource: callback => fs.writeFile(path.join(tempDir.name, 'source'), document, callback),
45
46
  convert: ['soffice', 'saveSource', (results, callback) => {
46
- let command = `-env:UserInstallation=file://${installDir.name} --headless --convert-to ${format}`;
47
+ let command = `-env:UserInstallation=${url.pathToFileURL(installDir.name)} --headless --convert-to ${format}`;
47
48
  if (filter !== undefined) {
48
49
  command += `:"${filter}"`;
49
50
  }
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "libreoffice-convert",
3
- "version": "1.3.4",
3
+ "version": "1.3.7",
4
4
  "description": "A simple and fast node.js module for converting office documents to different formats",
5
5
  "main": "index.js",
6
+ "types": "index.d.ts",
6
7
  "repository": "https://github.com/elwerene/libreoffice-convert",
7
8
  "keywords": [
8
9
  "Libreoffice",
@@ -27,6 +28,7 @@
27
28
  "tmp": "^0.2.1"
28
29
  },
29
30
  "devDependencies": {
31
+ "@types/node": "^17.0.23",
30
32
  "jest": "^24.7.1"
31
33
  },
32
34
  "engines": {