node-poppler 7.0.1 → 7.0.2
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/package.json +1 -1
- package/src/index.js +16 -12
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -18,6 +18,10 @@ const errorMessages = {
|
|
|
18
18
|
3221226505: "Internal process error",
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
+
// Cache immutable regex as they are expensive to create and garbage collect
|
|
22
|
+
const popplerVersionRegex = /(\d{1,2}\.\d{1,2}\.\d{1,2})/u;
|
|
23
|
+
const pdfInfoFileSizesRegex = /(File\s+size:\s+)0(\s+)bytes/u;
|
|
24
|
+
|
|
21
25
|
/**
|
|
22
26
|
* @author Frazer Smith
|
|
23
27
|
* @description Checks each option provided is valid, of the correct type, and can be used by specified
|
|
@@ -36,7 +40,7 @@ function parseOptions(acceptedOptions, options, version) {
|
|
|
36
40
|
const invalidArgs = [];
|
|
37
41
|
Object.keys(options).forEach((key) => {
|
|
38
42
|
if (Object.hasOwn(acceptedOptions, key)) {
|
|
39
|
-
// eslint-disable-next-line valid-typeof
|
|
43
|
+
// eslint-disable-next-line valid-typeof -- `type` is a string
|
|
40
44
|
if (typeof options[key] === acceptedOptions[key].type) {
|
|
41
45
|
// Skip boolean options if false
|
|
42
46
|
|
|
@@ -222,7 +226,7 @@ class Poppler {
|
|
|
222
226
|
);
|
|
223
227
|
|
|
224
228
|
// @ts-ignore: parseOptions checks if falsy
|
|
225
|
-
const versionInfo =
|
|
229
|
+
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
226
230
|
|
|
227
231
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
228
232
|
|
|
@@ -327,7 +331,7 @@ class Poppler {
|
|
|
327
331
|
);
|
|
328
332
|
|
|
329
333
|
// @ts-ignore: parseOptions checks if falsy
|
|
330
|
-
const versionInfo =
|
|
334
|
+
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
331
335
|
|
|
332
336
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
333
337
|
|
|
@@ -451,7 +455,7 @@ class Poppler {
|
|
|
451
455
|
);
|
|
452
456
|
|
|
453
457
|
// @ts-ignore: parseOptions checks if falsy
|
|
454
|
-
const versionInfo =
|
|
458
|
+
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
455
459
|
|
|
456
460
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
457
461
|
|
|
@@ -496,7 +500,7 @@ class Poppler {
|
|
|
496
500
|
if (stdOut !== "") {
|
|
497
501
|
if (fileSize) {
|
|
498
502
|
stdOut = stdOut.replace(
|
|
499
|
-
|
|
503
|
+
pdfInfoFileSizesRegex,
|
|
500
504
|
`$1${fileSize}$2bytes`
|
|
501
505
|
);
|
|
502
506
|
}
|
|
@@ -570,7 +574,7 @@ class Poppler {
|
|
|
570
574
|
);
|
|
571
575
|
|
|
572
576
|
// @ts-ignore: parseOptions checks if falsy
|
|
573
|
-
const versionInfo =
|
|
577
|
+
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
574
578
|
|
|
575
579
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
576
580
|
args.push(file);
|
|
@@ -748,7 +752,7 @@ class Poppler {
|
|
|
748
752
|
);
|
|
749
753
|
|
|
750
754
|
// @ts-ignore: parseOptions checks if falsy
|
|
751
|
-
const versionInfo =
|
|
755
|
+
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
752
756
|
|
|
753
757
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
754
758
|
|
|
@@ -896,7 +900,7 @@ class Poppler {
|
|
|
896
900
|
);
|
|
897
901
|
|
|
898
902
|
// @ts-ignore: parseOptions checks if falsy
|
|
899
|
-
const versionInfo =
|
|
903
|
+
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
900
904
|
|
|
901
905
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
902
906
|
|
|
@@ -1101,7 +1105,7 @@ class Poppler {
|
|
|
1101
1105
|
);
|
|
1102
1106
|
|
|
1103
1107
|
// @ts-ignore: parseOptions checks if falsy
|
|
1104
|
-
const versionInfo =
|
|
1108
|
+
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
1105
1109
|
|
|
1106
1110
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
1107
1111
|
|
|
@@ -1339,7 +1343,7 @@ class Poppler {
|
|
|
1339
1343
|
);
|
|
1340
1344
|
|
|
1341
1345
|
// @ts-ignore: parseOptions checks if falsy
|
|
1342
|
-
const versionInfo =
|
|
1346
|
+
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
1343
1347
|
|
|
1344
1348
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
1345
1349
|
|
|
@@ -1496,7 +1500,7 @@ class Poppler {
|
|
|
1496
1500
|
);
|
|
1497
1501
|
|
|
1498
1502
|
// @ts-ignore: parseOptions checks if falsy
|
|
1499
|
-
const versionInfo =
|
|
1503
|
+
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
1500
1504
|
|
|
1501
1505
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
1502
1506
|
|
|
@@ -1582,7 +1586,7 @@ class Poppler {
|
|
|
1582
1586
|
);
|
|
1583
1587
|
|
|
1584
1588
|
// @ts-ignore: parseOptions checks if falsy
|
|
1585
|
-
const versionInfo =
|
|
1589
|
+
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
1586
1590
|
|
|
1587
1591
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
1588
1592
|
files.forEach((element) => {
|