libreoffice-convert 1.7.0 → 1.8.1
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/index.d.ts +1 -0
- package/index.js +3 -1
- package/package.json +1 -1
- package/tests/convert.test.js +8 -1
package/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ declare module "libreoffice-convert" {
|
|
|
14
14
|
tmpOptions?: Record<string | number | symbol, unknown>;
|
|
15
15
|
asyncOptions?: { times?: number; interval?: number };
|
|
16
16
|
sofficeBinaryPaths?: string[];
|
|
17
|
+
sofficeAdditionalArgs?: string[];
|
|
17
18
|
fileName?: string;
|
|
18
19
|
},
|
|
19
20
|
callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void
|
package/index.js
CHANGED
|
@@ -12,6 +12,7 @@ const convertWithOptions = (document, format, filter, options, callback) => {
|
|
|
12
12
|
const asyncOptions = (options || {}).asyncOptions || {};
|
|
13
13
|
const execOptions = (options || {}).execOptions || {};
|
|
14
14
|
const fileName = (options || {}).fileName || 'source';
|
|
15
|
+
const sofficeAdditionalArgs = (options || {}).sofficeAdditionalArgs || [];
|
|
15
16
|
const tempDir = tmp.dirSync({prefix: 'libreofficeConvert_', unsafeCleanup: true, ...tmpOptions});
|
|
16
17
|
const installDir = tmp.dirSync({prefix: 'soffice', unsafeCleanup: true, ...tmpOptions});
|
|
17
18
|
return async.auto({
|
|
@@ -59,6 +60,7 @@ const convertWithOptions = (document, format, filter, options, callback) => {
|
|
|
59
60
|
args.push(fmt);
|
|
60
61
|
args.push('--outdir');
|
|
61
62
|
args.push(tempDir.name);
|
|
63
|
+
args.push(...sofficeAdditionalArgs);
|
|
62
64
|
args.push(path.join(tempDir.name, fileName));
|
|
63
65
|
|
|
64
66
|
return execFile(results.soffice, args, execOptions, (err, stdout, stderr) => {
|
|
@@ -72,7 +74,7 @@ const convertWithOptions = (document, format, filter, options, callback) => {
|
|
|
72
74
|
async.retry({
|
|
73
75
|
times: asyncOptions.times || 3,
|
|
74
76
|
interval: asyncOptions.interval || 200
|
|
75
|
-
}, (callback) => fs.readFile(path.join(tempDir.name, `${fileName}.${format.split(":")[0]}`), callback), callback)
|
|
77
|
+
}, (callback) => fs.readFile(path.join(tempDir.name, `${fileName.slice(0, fileName.length - path.extname(fileName).length)}.${format.split(":")[0]}`), callback), callback)
|
|
76
78
|
]
|
|
77
79
|
}).then( (res) => {
|
|
78
80
|
return callback(null, res.loadDestination);
|
package/package.json
CHANGED
package/tests/convert.test.js
CHANGED
|
@@ -2,7 +2,8 @@ var _jest = require('jest'),
|
|
|
2
2
|
_fs = require('fs'),
|
|
3
3
|
_path = require('path'),
|
|
4
4
|
{ exec } = require('child_process'),
|
|
5
|
-
convert = require('../index').convert
|
|
5
|
+
convert = require('../index').convert,
|
|
6
|
+
convertWithOptions = require('../index').convertWithOptions;
|
|
6
7
|
|
|
7
8
|
describe('convert', () => {
|
|
8
9
|
function expectHello(done) {
|
|
@@ -22,6 +23,12 @@ describe('convert', () => {
|
|
|
22
23
|
});
|
|
23
24
|
|
|
24
25
|
|
|
26
|
+
it('should convert a word document to text with options', (done) => {
|
|
27
|
+
const docx = _fs.readFileSync(_path.join(__dirname, '/resources/hello.docx'));
|
|
28
|
+
convertWithOptions(docx, 'txt', undefined, { fileName: 'hello.docx' }, expectHello(done));
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
|
|
25
32
|
it('if an another instance of soffice exists, should convert a word document to text', (done) => {
|
|
26
33
|
exec("soffice --headless")
|
|
27
34
|
// this command create an instance of soffice. This instance will get a failure "Error: source file could not be loaded"
|