officeparser 7.0.0 → 7.0.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/README.md +86 -4
- package/dist/OfficeParser.js +26 -9
- package/dist/officeparser.browser.d.ts +2 -0
- package/dist/officeparser.browser.iife.js +28 -28
- package/dist/officeparser.browser.mjs +28 -28
- package/dist/sbom.cdx.json +98 -98
- package/dist/types.d.ts +2 -0
- package/dist/types.js +2 -0
- package/dist/utils/envUtils.d.ts +8 -3
- package/dist/utils/envUtils.js +113 -84
- package/dist/utils/errorUtils.js +2 -1
- package/dist/utils/moduleLoader.js +4 -2
- package/package.json +2 -2
package/dist/utils/envUtils.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* Environment detection and safe utility wrappers.
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isBrowser = void 0;
|
|
6
|
+
exports.ensureDomMatrix = exports.isBrowser = void 0;
|
|
7
7
|
exports.assertNode = assertNode;
|
|
8
|
-
exports.
|
|
8
|
+
exports.ensureEnvPolyfills = ensureEnvPolyfills;
|
|
9
9
|
/**
|
|
10
10
|
* Detect if we are running in a browser environment.
|
|
11
11
|
*/
|
|
@@ -32,92 +32,121 @@ function assertNode(feature) {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* Polyfills
|
|
35
|
+
* Polyfills environment features not available globally (required for Node.js < 20).
|
|
36
36
|
* This shim provides enough properties for pdfjs-dist 5.x to calculate
|
|
37
|
-
* text coordinates and transformations.
|
|
37
|
+
* text coordinates and transformations, and guards against modern RegExp flags.
|
|
38
38
|
*/
|
|
39
|
-
function
|
|
40
|
-
if (typeof global !== 'undefined'
|
|
41
|
-
//
|
|
42
|
-
global.DOMMatrix
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
39
|
+
function ensureEnvPolyfills() {
|
|
40
|
+
if (typeof global !== 'undefined') {
|
|
41
|
+
// 1. DOMMatrix Polyfill (Node.js < 20)
|
|
42
|
+
if (!global.DOMMatrix) {
|
|
43
|
+
global.DOMMatrix = class DOMMatrix {
|
|
44
|
+
a;
|
|
45
|
+
b;
|
|
46
|
+
c;
|
|
47
|
+
d;
|
|
48
|
+
e;
|
|
49
|
+
f;
|
|
50
|
+
constructor(init) {
|
|
51
|
+
if (Array.isArray(init) && init.length >= 6) {
|
|
52
|
+
this.a = init[0];
|
|
53
|
+
this.b = init[1];
|
|
54
|
+
this.c = init[2];
|
|
55
|
+
this.d = init[3];
|
|
56
|
+
this.e = init[4];
|
|
57
|
+
this.f = init[5];
|
|
58
|
+
}
|
|
59
|
+
else if (typeof init === 'object' && init !== null) {
|
|
60
|
+
this.a = init.a;
|
|
61
|
+
this.b = init.b;
|
|
62
|
+
this.c = init.c;
|
|
63
|
+
this.d = init.d;
|
|
64
|
+
this.e = init.e;
|
|
65
|
+
this.f = init.f;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
this.a = this.d = 1;
|
|
69
|
+
this.b = this.c = this.e = this.f = 0;
|
|
70
|
+
}
|
|
57
71
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
72
|
+
// Standard matrix property aliases for compatibility
|
|
73
|
+
get m11() { return this.a; }
|
|
74
|
+
get m12() { return this.b; }
|
|
75
|
+
get m21() { return this.c; }
|
|
76
|
+
get m22() { return this.d; }
|
|
77
|
+
get m41() { return this.e; }
|
|
78
|
+
get m42() { return this.f; }
|
|
79
|
+
multiply(other) {
|
|
80
|
+
return new DOMMatrix([
|
|
81
|
+
this.a * other.a + this.c * other.b,
|
|
82
|
+
this.b * other.a + this.d * other.b,
|
|
83
|
+
this.a * other.c + this.c * other.d,
|
|
84
|
+
this.b * other.c + this.d * other.d,
|
|
85
|
+
this.a * other.e + this.c * other.f + this.e,
|
|
86
|
+
this.b * other.e + this.d * other.f + this.f
|
|
87
|
+
]);
|
|
65
88
|
}
|
|
66
|
-
|
|
67
|
-
this.a
|
|
68
|
-
|
|
89
|
+
inverse() {
|
|
90
|
+
const det = this.a * this.d - this.b * this.c;
|
|
91
|
+
if (det === 0)
|
|
92
|
+
return new DOMMatrix();
|
|
93
|
+
return new DOMMatrix([
|
|
94
|
+
this.d / det,
|
|
95
|
+
-this.b / det,
|
|
96
|
+
-this.c / det,
|
|
97
|
+
this.a / det,
|
|
98
|
+
(this.c * this.f - this.d * this.e) / det,
|
|
99
|
+
(this.b * this.e - this.a * this.f) / det
|
|
100
|
+
]);
|
|
69
101
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
height;
|
|
115
|
-
data;
|
|
116
|
-
constructor(data, width, height) {
|
|
117
|
-
this.data = data;
|
|
118
|
-
this.width = width;
|
|
119
|
-
this.height = height;
|
|
120
|
-
}
|
|
121
|
-
};
|
|
102
|
+
transformPoint(point) {
|
|
103
|
+
const x = point?.x ?? 0;
|
|
104
|
+
const y = point?.y ?? 0;
|
|
105
|
+
return {
|
|
106
|
+
x: x * this.a + y * this.c + this.e,
|
|
107
|
+
y: x * this.b + y * this.d + this.f
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
// 2. ImageData Polyfill (Node.js < 20)
|
|
113
|
+
if (!global.ImageData) {
|
|
114
|
+
global.ImageData = class ImageData {
|
|
115
|
+
width;
|
|
116
|
+
height;
|
|
117
|
+
data;
|
|
118
|
+
constructor(data, width, height) {
|
|
119
|
+
this.data = data;
|
|
120
|
+
this.width = width;
|
|
121
|
+
this.height = height;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
// 3. RegExp 'v' flag Polyfill (Node.js < 20)
|
|
126
|
+
// Modern dependencies (file-type 22+, pdfjs-dist 5+) might use the 'v' flag.
|
|
127
|
+
// We wrap the constructor to downgrade 'v' to 'u' in Node 18.
|
|
128
|
+
const OriginalRegExp = global.RegExp;
|
|
129
|
+
try {
|
|
130
|
+
new OriginalRegExp('', 'v');
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
// 'v' flag is not supported (Node 18), apply fallback wrapper
|
|
134
|
+
const RegExpWrapper = function (pattern, flags) {
|
|
135
|
+
if (typeof flags === 'string' && flags.includes('v')) {
|
|
136
|
+
// Fallback 'v' to 'u' (Unicode sets to Unicode)
|
|
137
|
+
return new OriginalRegExp(pattern, flags.replace('v', 'u'));
|
|
138
|
+
}
|
|
139
|
+
return new OriginalRegExp(pattern, flags);
|
|
140
|
+
};
|
|
141
|
+
// Maintain prototype chain and static methods
|
|
142
|
+
RegExpWrapper.prototype = OriginalRegExp.prototype;
|
|
143
|
+
Object.setPrototypeOf(RegExpWrapper, OriginalRegExp);
|
|
144
|
+
global.RegExp = RegExpWrapper;
|
|
145
|
+
}
|
|
122
146
|
}
|
|
123
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Backward-compatible alias for ensureEnvPolyfills.
|
|
150
|
+
* @deprecated Use ensureEnvPolyfills instead.
|
|
151
|
+
*/
|
|
152
|
+
exports.ensureDomMatrix = ensureEnvPolyfills;
|
package/dist/utils/errorUtils.js
CHANGED
|
@@ -21,7 +21,7 @@ const ERROR_MESSAGES = {
|
|
|
21
21
|
[types_js_1.OfficeErrorType.FILE_DOES_NOT_EXIST]: (filepath) => `File ${filepath} could not be found! Check if the file exists or verify if the relative path to the file is correct from your terminal's location.`,
|
|
22
22
|
[types_js_1.OfficeErrorType.LOCATION_NOT_FOUND]: (location) => `Entered location ${location} is not reachable! Please make sure that the entered directory location exists. Check relative paths and reenter.`,
|
|
23
23
|
[types_js_1.OfficeErrorType.IMPROPER_ARGUMENTS]: `Improper arguments`,
|
|
24
|
-
[types_js_1.OfficeErrorType.IMPROPER_BUFFERS]: `
|
|
24
|
+
[types_js_1.OfficeErrorType.IMPROPER_BUFFERS]: `Auto-detection of file type from buffer failed. This can happen if the format lacks magic bytes (like md, html, or csv) or if the detection library is incompatible with your Node.js version. Please provide the 'fileType' hint in your configuration (e.g., { fileType: 'docx' }) to proceed.`,
|
|
25
25
|
[types_js_1.OfficeErrorType.INVALID_INPUT]: `Invalid input type: Expected a Buffer or a valid file path`,
|
|
26
26
|
[types_js_1.OfficeErrorType.PDF_WORKER_MISSING]: `Missing PDF worker configuration. PDF parsing in browser environments requires a worker source. Please provide "pdfWorkerSrc" in your configuration.`,
|
|
27
27
|
[types_js_1.OfficeErrorType.FEATURE_NOT_SUPPORTED_IN_BROWSER]: (feature) => `'${feature}' is not supported in the browser. Browser users must pass file content as Buffer or ArrayBuffer directly.`,
|
|
@@ -47,6 +47,7 @@ const WARNING_MESSAGES = {
|
|
|
47
47
|
[types_js_1.OfficeWarningType.BROWSER_GENERATION_LIMITATION]: (msg) => msg,
|
|
48
48
|
[types_js_1.OfficeWarningType.SHEET_RANGE_NOT_FOUND]: (range) => `No sheets found matching the range: ${range}`,
|
|
49
49
|
[types_js_1.OfficeWarningType.BUFFER_TYPE_MISMATCH]: (info) => `File content type mismatch: Detected '${info.detected}' but expected/provided '${info.expected}'. Parsing will proceed with '${info.expected}' as requested.`,
|
|
50
|
+
[types_js_1.OfficeWarningType.FILE_TYPE_DETECTION_FAILED]: `Auto-detection of file type failed. This can happen on older Node.js versions with modern file-type versions. Please provide the 'fileType' hint in the configuration if parsing fails.`,
|
|
50
51
|
[types_js_1.OfficeWarningType.EMPTY_CHUNK_GENERATED]: (strategy) => `No chunks generated for document. Check if the document content is compatible with the '${strategy}' strategy.`,
|
|
51
52
|
[types_js_1.OfficeWarningType.WHITESPACE_NODE_SKIPPED]: (nodeType) => `Skipped whitespace-only node of type: ${nodeType}`
|
|
52
53
|
};
|
|
@@ -34,6 +34,8 @@ async function loadNodeEsmModule(specifier) {
|
|
|
34
34
|
*/
|
|
35
35
|
async function loadFileType() {
|
|
36
36
|
if (!envUtils_js_1.isBrowser) {
|
|
37
|
+
// Ensure environment polyfills for Node.js 18 support
|
|
38
|
+
(0, envUtils_js_1.ensureEnvPolyfills)();
|
|
37
39
|
// Node.js path: Use dynamic import wrapper for CJS compatibility
|
|
38
40
|
return loadNodeEsmModule('file-type');
|
|
39
41
|
}
|
|
@@ -45,8 +47,8 @@ async function loadFileType() {
|
|
|
45
47
|
*/
|
|
46
48
|
async function loadPdfJs() {
|
|
47
49
|
if (!envUtils_js_1.isBrowser) {
|
|
48
|
-
// Ensure
|
|
49
|
-
(0, envUtils_js_1.
|
|
50
|
+
// Ensure environment polyfills for Node.js 18 support
|
|
51
|
+
(0, envUtils_js_1.ensureEnvPolyfills)();
|
|
50
52
|
// Node.js environment: require legacy build for stability with ESM-only main
|
|
51
53
|
try {
|
|
52
54
|
return await loadNodeEsmModule('pdfjs-dist/legacy/build/pdf.mjs');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "officeparser",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "A robust, strictly-typed Node.js and Browser library for parsing office files (.docx, .pptx, .xlsx, .odt, .odp, .ods, .pdf, .rtf, .csv, .md, .html) and generating high-fidelity outputs in Markdown, HTML, CSV, RTF, and RAG-focused chunks.",
|
|
5
5
|
"funding": "https://github.com/sponsors/harshankur",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -127,4 +127,4 @@
|
|
|
127
127
|
"tsx": "^4.21.0",
|
|
128
128
|
"typescript": "^6.0.2"
|
|
129
129
|
}
|
|
130
|
-
}
|
|
130
|
+
}
|