officeparser 6.0.3 → 6.0.6
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 +2 -2
- package/dist/OfficeParser.d.ts +0 -1
- package/dist/OfficeParser.js +20 -9
- package/dist/officeparser.browser.js +86 -85
- package/dist/officeparser.browser.js.map +4 -4
- package/dist/parsers/ExcelParser.d.ts +0 -1
- package/dist/parsers/ExcelParser.js +2 -2
- package/dist/parsers/OpenOfficeParser.d.ts +0 -1
- package/dist/parsers/OpenOfficeParser.js +5 -5
- package/dist/parsers/PdfParser.d.ts +0 -1
- package/dist/parsers/PdfParser.js +4 -44
- package/dist/parsers/PowerPointParser.d.ts +0 -1
- package/dist/parsers/PowerPointParser.js +2 -2
- package/dist/parsers/RtfParser.d.ts +0 -1
- package/dist/parsers/RtfParser.js +28 -28
- package/dist/parsers/WordParser.d.ts +0 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils/chartUtils.d.ts +0 -1
- package/dist/utils/errorUtils.js +1 -1
- package/dist/utils/imageUtils.d.ts +0 -1
- package/dist/utils/imageUtils.js +4 -4
- package/dist/utils/moduleLoader.d.ts +17 -0
- package/dist/utils/moduleLoader.js +84 -0
- package/dist/utils/ocrUtils.d.ts +0 -1
- package/dist/utils/zipUtils.d.ts +0 -1
- package/package.json +16 -13
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
* @module ExcelParser
|
|
22
22
|
* @see https://www.ecma-international.org/publications-and-standards/standards/ecma-376/
|
|
23
23
|
*/
|
|
24
|
-
/// <reference types="node" />
|
|
25
24
|
import { OfficeParserAST, OfficeParserConfig } from '../types';
|
|
26
25
|
/**
|
|
27
26
|
* Parses an Excel spreadsheet (.xlsx) and extracts sheets, rows, and cells.
|
|
@@ -542,7 +542,7 @@ const parseExcel = async (buffer, config) => {
|
|
|
542
542
|
if (attachment) {
|
|
543
543
|
const imageNode = {
|
|
544
544
|
type: 'image',
|
|
545
|
-
text: '',
|
|
545
|
+
text: '', // Will be populated by assignAttachmentData
|
|
546
546
|
children: [],
|
|
547
547
|
metadata: {
|
|
548
548
|
attachmentName: attachment.name || 'unknown',
|
|
@@ -562,7 +562,7 @@ const parseExcel = async (buffer, config) => {
|
|
|
562
562
|
if (attachment) {
|
|
563
563
|
const chartNode = {
|
|
564
564
|
type: 'chart',
|
|
565
|
-
text: '',
|
|
565
|
+
text: '', // Will be populated by assignAttachmentData
|
|
566
566
|
children: [],
|
|
567
567
|
metadata: {
|
|
568
568
|
attachmentName: chartName
|
|
@@ -1009,10 +1009,10 @@ const parseOpenOffice = async (buffer, config) => {
|
|
|
1009
1009
|
// logic for image node
|
|
1010
1010
|
const imageNode = {
|
|
1011
1011
|
type: 'image',
|
|
1012
|
-
text: '',
|
|
1012
|
+
text: '', // Will be populated by assignAttachmentData
|
|
1013
1013
|
children: [],
|
|
1014
1014
|
metadata: {
|
|
1015
|
-
attachmentName: imageHref,
|
|
1015
|
+
attachmentName: imageHref, // Might be empty, will resolve in assignAttachmentData
|
|
1016
1016
|
...(altText ? { altText } : {})
|
|
1017
1017
|
}
|
|
1018
1018
|
};
|
|
@@ -1024,7 +1024,7 @@ const parseOpenOffice = async (buffer, config) => {
|
|
|
1024
1024
|
else if (chartHref) {
|
|
1025
1025
|
const chartNode = {
|
|
1026
1026
|
type: 'chart',
|
|
1027
|
-
text: '',
|
|
1027
|
+
text: '', // Will be populated by assignAttachmentData
|
|
1028
1028
|
children: [],
|
|
1029
1029
|
metadata: {
|
|
1030
1030
|
attachmentName: chartHref
|
|
@@ -1058,7 +1058,7 @@ const parseOpenOffice = async (buffer, config) => {
|
|
|
1058
1058
|
for (let k = 0; k < rowsRepeated; k++) {
|
|
1059
1059
|
const rowNode = {
|
|
1060
1060
|
type: 'row',
|
|
1061
|
-
children: JSON.parse(JSON.stringify(cells)),
|
|
1061
|
+
children: JSON.parse(JSON.stringify(cells)), // Deep copy for repeated rows
|
|
1062
1062
|
metadata: undefined
|
|
1063
1063
|
};
|
|
1064
1064
|
// Fix row index in metadata for repeated rows
|
|
@@ -1173,7 +1173,7 @@ const parseOpenOffice = async (buffer, config) => {
|
|
|
1173
1173
|
const objectId = objFile.path.split('/')[0];
|
|
1174
1174
|
const attachment = {
|
|
1175
1175
|
type: 'chart',
|
|
1176
|
-
mimeType: 'application/vnd.oasis.opendocument.chart',
|
|
1176
|
+
mimeType: 'application/vnd.oasis.opendocument.chart', // Accurate ODF chart type
|
|
1177
1177
|
data: objFile.content.toString('base64'),
|
|
1178
1178
|
name: objectId,
|
|
1179
1179
|
extension: 'xml'
|
|
@@ -56,7 +56,6 @@
|
|
|
56
56
|
* @see https://mozilla.github.io/pdf.js/ PDF.js documentation
|
|
57
57
|
* @see https://www.adobe.com/devnet/pdf/pdf_reference.html PDF Reference
|
|
58
58
|
*/
|
|
59
|
-
/// <reference types="node" />
|
|
60
59
|
import { OfficeParserAST, OfficeParserConfig } from '../types';
|
|
61
60
|
/**
|
|
62
61
|
* Parses a PDF file and extracts content.
|
|
@@ -57,34 +57,12 @@
|
|
|
57
57
|
* @see https://mozilla.github.io/pdf.js/ PDF.js documentation
|
|
58
58
|
* @see https://www.adobe.com/devnet/pdf/pdf_reference.html PDF Reference
|
|
59
59
|
*/
|
|
60
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
61
|
-
if (k2 === undefined) k2 = k;
|
|
62
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
63
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
64
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
65
|
-
}
|
|
66
|
-
Object.defineProperty(o, k2, desc);
|
|
67
|
-
}) : (function(o, m, k, k2) {
|
|
68
|
-
if (k2 === undefined) k2 = k;
|
|
69
|
-
o[k2] = m[k];
|
|
70
|
-
}));
|
|
71
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
72
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
73
|
-
}) : function(o, v) {
|
|
74
|
-
o["default"] = v;
|
|
75
|
-
});
|
|
76
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
77
|
-
if (mod && mod.__esModule) return mod;
|
|
78
|
-
var result = {};
|
|
79
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
80
|
-
__setModuleDefault(result, mod);
|
|
81
|
-
return result;
|
|
82
|
-
};
|
|
83
60
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
84
61
|
exports.parsePdf = void 0;
|
|
85
62
|
const errorUtils_1 = require("../utils/errorUtils");
|
|
86
63
|
const imageUtils_1 = require("../utils/imageUtils");
|
|
87
64
|
const ocrUtils_1 = require("../utils/ocrUtils");
|
|
65
|
+
const moduleLoader_1 = require("../utils/moduleLoader");
|
|
88
66
|
/**
|
|
89
67
|
* Parses PDF creation/modification date strings.
|
|
90
68
|
* PDF dates are in format: D:YYYYMMDDHHmmSSOHH'mm'
|
|
@@ -329,25 +307,7 @@ function convertToRgbaBuffer(data, width, height, kind) {
|
|
|
329
307
|
* @returns Promise resolving to the parsed AST
|
|
330
308
|
*/
|
|
331
309
|
const parsePdf = async (buffer, config) => {
|
|
332
|
-
|
|
333
|
-
// Check if we are in a Node.js environment
|
|
334
|
-
// @ts-ignore
|
|
335
|
-
if (typeof window === 'undefined') {
|
|
336
|
-
// Helper to bypass TS/Webpack/Other transpilers converting import() to require() when compiling to CJS
|
|
337
|
-
// Defined here to avoid CSP 'unsafe-eval' issues in browser environments
|
|
338
|
-
const dynamicImport = new Function('specifier', 'return import(specifier)');
|
|
339
|
-
try {
|
|
340
|
-
// Use legacy build for Node.js (required for pdfjs-dist v5+)
|
|
341
|
-
pdfjs = await dynamicImport('pdfjs-dist/legacy/build/pdf.mjs');
|
|
342
|
-
}
|
|
343
|
-
catch (e) {
|
|
344
|
-
// Fallback to standard if legacy not found (e.g. older versions)
|
|
345
|
-
pdfjs = await dynamicImport('pdfjs-dist');
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
pdfjs = await Promise.resolve().then(() => __importStar(require('pdfjs-dist')));
|
|
350
|
-
}
|
|
310
|
+
const pdfjs = await (0, moduleLoader_1.loadPdfJs)();
|
|
351
311
|
// Configure worker
|
|
352
312
|
if (config.pdfWorkerSrc) {
|
|
353
313
|
pdfjs.GlobalWorkerOptions.workerSrc = config.pdfWorkerSrc;
|
|
@@ -357,7 +317,7 @@ const parsePdf = async (buffer, config) => {
|
|
|
357
317
|
// @ts-ignore
|
|
358
318
|
if (typeof window !== 'undefined') {
|
|
359
319
|
// Browser: Default to CDN
|
|
360
|
-
pdfjs.GlobalWorkerOptions.workerSrc =
|
|
320
|
+
pdfjs.GlobalWorkerOptions.workerSrc = `https://unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`;
|
|
361
321
|
}
|
|
362
322
|
else {
|
|
363
323
|
// Node.js: Try to auto-resolve local worker path to avoid remote fetch errors
|
|
@@ -407,7 +367,7 @@ const parsePdf = async (buffer, config) => {
|
|
|
407
367
|
title: info?.Title || undefined,
|
|
408
368
|
author: info?.Author || undefined,
|
|
409
369
|
subject: info?.Subject || undefined,
|
|
410
|
-
description: info?.Keywords || undefined,
|
|
370
|
+
description: info?.Keywords || undefined, // Map Keywords to description as closest match
|
|
411
371
|
created: parsePdfDate(info?.CreationDate),
|
|
412
372
|
modified: parsePdfDate(info?.ModDate),
|
|
413
373
|
// Note: lastModifiedBy is not available in PDF format - there's no concept of "last modifier"
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
* @module PowerPointParser
|
|
22
22
|
* @see https://www.ecma-international.org/publications-and-standards/standards/ecma-376/
|
|
23
23
|
*/
|
|
24
|
-
/// <reference types="node" />
|
|
25
24
|
import { OfficeParserAST, OfficeParserConfig } from '../types';
|
|
26
25
|
/**
|
|
27
26
|
* Parses a PowerPoint presentation (.pptx) and extracts slides and notes.
|
|
@@ -239,7 +239,7 @@ const parsePowerPoint = async (buffer, config) => {
|
|
|
239
239
|
// Step 6: Build AST node
|
|
240
240
|
const chartNode = {
|
|
241
241
|
type: "chart",
|
|
242
|
-
text: "",
|
|
242
|
+
text: "", // chart text gets filled later
|
|
243
243
|
metadata: {
|
|
244
244
|
attachmentName // name used to link to attachments & chartData
|
|
245
245
|
}
|
|
@@ -707,7 +707,7 @@ const parsePowerPoint = async (buffer, config) => {
|
|
|
707
707
|
for (const chart of chartFiles) {
|
|
708
708
|
const attachment = {
|
|
709
709
|
type: 'chart',
|
|
710
|
-
mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
710
|
+
mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', // Generic XML type for now
|
|
711
711
|
data: chart.content.toString('base64'),
|
|
712
712
|
name: chart.path.split('/').pop() || '',
|
|
713
713
|
extension: 'xml'
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
* @see https://www.biblioscape.com/rtf15_spec.htm RTF 1.5 Specification
|
|
40
40
|
* @see https://latex2rtf.sourceforge.net/RTF-Spec-1.2.pdf RTF 1.2 Specification
|
|
41
41
|
*/
|
|
42
|
-
/// <reference types="node" />
|
|
43
42
|
import { OfficeParserAST, OfficeParserConfig } from '../types';
|
|
44
43
|
/**
|
|
45
44
|
* Represents an RTF group (content enclosed in braces).
|
|
@@ -151,32 +151,32 @@ class SimpleRtfParser {
|
|
|
151
151
|
// Characters 0x80-0x9F in Windows-1252 don't map directly to Unicode
|
|
152
152
|
// We need to convert them properly
|
|
153
153
|
const windows1252ToUnicode = {
|
|
154
|
-
0x80: 0x20AC,
|
|
155
|
-
0x82: 0x201A,
|
|
156
|
-
0x83: 0x0192,
|
|
157
|
-
0x84: 0x201E,
|
|
158
|
-
0x85: 0x2026,
|
|
159
|
-
0x86: 0x2020,
|
|
160
|
-
0x87: 0x2021,
|
|
161
|
-
0x88: 0x02C6,
|
|
162
|
-
0x89: 0x2030,
|
|
163
|
-
0x8A: 0x0160,
|
|
164
|
-
0x8B: 0x2039,
|
|
165
|
-
0x8C: 0x0152,
|
|
166
|
-
0x8E: 0x017D,
|
|
167
|
-
0x91: 0x2018,
|
|
168
|
-
0x92: 0x2019,
|
|
169
|
-
0x93: 0x201C,
|
|
170
|
-
0x94: 0x201D,
|
|
171
|
-
0x95: 0x2022,
|
|
172
|
-
0x96: 0x2013,
|
|
173
|
-
0x97: 0x2014,
|
|
174
|
-
0x98: 0x02DC,
|
|
175
|
-
0x99: 0x2122,
|
|
176
|
-
0x9A: 0x0161,
|
|
177
|
-
0x9B: 0x203A,
|
|
178
|
-
0x9C: 0x0153,
|
|
179
|
-
0x9E: 0x017E,
|
|
154
|
+
0x80: 0x20AC, // €
|
|
155
|
+
0x82: 0x201A, // ‚
|
|
156
|
+
0x83: 0x0192, // ƒ
|
|
157
|
+
0x84: 0x201E, // „
|
|
158
|
+
0x85: 0x2026, // …
|
|
159
|
+
0x86: 0x2020, // †
|
|
160
|
+
0x87: 0x2021, // ‡
|
|
161
|
+
0x88: 0x02C6, // ˆ
|
|
162
|
+
0x89: 0x2030, // ‰
|
|
163
|
+
0x8A: 0x0160, // Š
|
|
164
|
+
0x8B: 0x2039, // ‹
|
|
165
|
+
0x8C: 0x0152, // Œ
|
|
166
|
+
0x8E: 0x017D, // Ž
|
|
167
|
+
0x91: 0x2018, // '
|
|
168
|
+
0x92: 0x2019, // '
|
|
169
|
+
0x93: 0x201C, // "
|
|
170
|
+
0x94: 0x201D, // "
|
|
171
|
+
0x95: 0x2022, // •
|
|
172
|
+
0x96: 0x2013, // –
|
|
173
|
+
0x97: 0x2014, // —
|
|
174
|
+
0x98: 0x02DC, // ˜
|
|
175
|
+
0x99: 0x2122, // ™
|
|
176
|
+
0x9A: 0x0161, // š
|
|
177
|
+
0x9B: 0x203A, // ›
|
|
178
|
+
0x9C: 0x0153, // œ
|
|
179
|
+
0x9E: 0x017E, // ž
|
|
180
180
|
0x9F: 0x0178 // Ÿ
|
|
181
181
|
};
|
|
182
182
|
const unicodeCode = windows1252ToUnicode[code] || code;
|
|
@@ -557,7 +557,7 @@ const parseRtf = async (buffer, config) => {
|
|
|
557
557
|
tableId++;
|
|
558
558
|
const tableNode = {
|
|
559
559
|
type: 'table',
|
|
560
|
-
text: ctx.rows.map(r => r.text).join('\n'),
|
|
560
|
+
text: ctx.rows.map(r => r.text).join('\n'), // Aggregate text from rows
|
|
561
561
|
children: [...ctx.rows]
|
|
562
562
|
};
|
|
563
563
|
// If we have a parent table, add this table to the parent's current cell
|
|
@@ -1566,7 +1566,7 @@ const parseRtf = async (buffer, config) => {
|
|
|
1566
1566
|
// RTF Limitation: No style map available (RTF uses inline styles)
|
|
1567
1567
|
},
|
|
1568
1568
|
content: content,
|
|
1569
|
-
attachments: attachments,
|
|
1569
|
+
attachments: attachments, // PNG and JPEG images extracted from \\pict groups
|
|
1570
1570
|
toText: () => {
|
|
1571
1571
|
let text = content.map(c => c.text).join(config.newlineDelimiter ?? '\n');
|
|
1572
1572
|
if (config.putNotesAtLast && notes.length > 0) {
|
|
@@ -58,7 +58,6 @@
|
|
|
58
58
|
* @see https://www.ecma-international.org/publications-and-standards/standards/ecma-376/ OOXML Standard
|
|
59
59
|
* @see https://learn.microsoft.com/en-us/openspecs/office_standards/ms-docx/ [MS-DOCX] Specification
|
|
60
60
|
*/
|
|
61
|
-
/// <reference types="node" />
|
|
62
61
|
import { OfficeParserAST, OfficeParserConfig } from '../types';
|
|
63
62
|
/**
|
|
64
63
|
* Parses a Word document (.docx) and extracts content, formatting, and metadata.
|
package/dist/types.d.ts
CHANGED
|
@@ -54,7 +54,7 @@ export interface OfficeParserConfig {
|
|
|
54
54
|
* The URL/path to the PDF.js worker script.
|
|
55
55
|
*
|
|
56
56
|
* **Mandatory** when using PDF parsing in browser environments to avoid worker configuration errors.
|
|
57
|
-
* If not provided, it defaults to `https://unpkg.com/pdfjs-dist@5.
|
|
57
|
+
* If not provided, it defaults to `https://unpkg.com/pdfjs-dist@5.5.207/build/pdf.worker.min.mjs`.
|
|
58
58
|
* You can override this with your own local path or a different CDN link.
|
|
59
59
|
*/
|
|
60
60
|
pdfWorkerSrc?: string;
|
package/dist/utils/errorUtils.js
CHANGED
|
@@ -32,7 +32,7 @@ var OfficeErrorType;
|
|
|
32
32
|
OfficeErrorType["INVALID_INPUT"] = "INVALID_INPUT";
|
|
33
33
|
/** PDF worker source is missing (required in browser) */
|
|
34
34
|
OfficeErrorType["PDF_WORKER_MISSING"] = "PDF_WORKER_MISSING";
|
|
35
|
-
})(OfficeErrorType
|
|
35
|
+
})(OfficeErrorType || (exports.OfficeErrorType = OfficeErrorType = {}));
|
|
36
36
|
/**
|
|
37
37
|
* Lookup table for error messages.
|
|
38
38
|
* Some entries are functions that take parameters to build dynamic messages.
|
package/dist/utils/imageUtils.js
CHANGED
|
@@ -123,10 +123,10 @@ const createAttachment = (name, content) => {
|
|
|
123
123
|
}
|
|
124
124
|
// Step 4: Create and return the attachment object
|
|
125
125
|
return {
|
|
126
|
-
type: 'image',
|
|
127
|
-
mimeType: mime,
|
|
128
|
-
data: content.toString('base64'),
|
|
129
|
-
name: name,
|
|
126
|
+
type: 'image', // All attachments created here are images
|
|
127
|
+
mimeType: mime, // Cast to our supported MIME types
|
|
128
|
+
data: content.toString('base64'), // Convert buffer to Base64 string
|
|
129
|
+
name: name, // Original filename
|
|
130
130
|
extension: ext // File extension for reference
|
|
131
131
|
};
|
|
132
132
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module Loader Utility
|
|
3
|
+
*
|
|
4
|
+
* Centralizes dynamic imports for ESM-only packages (like file-type and pdfjs-dist)
|
|
5
|
+
* to maintain CommonJS compatibility while supporting modern ESM dependencies.
|
|
6
|
+
*
|
|
7
|
+
* This approach prevents TypeScript from transpiling dynamic import()
|
|
8
|
+
* into require() when targeting CommonJS.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Specialized loader for file-type
|
|
12
|
+
*/
|
|
13
|
+
export declare function loadFileType(): Promise<typeof import('file-type')>;
|
|
14
|
+
/**
|
|
15
|
+
* Specialized loader for pdfjs-dist
|
|
16
|
+
*/
|
|
17
|
+
export declare function loadPdfJs(): Promise<any>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Module Loader Utility
|
|
4
|
+
*
|
|
5
|
+
* Centralizes dynamic imports for ESM-only packages (like file-type and pdfjs-dist)
|
|
6
|
+
* to maintain CommonJS compatibility while supporting modern ESM dependencies.
|
|
7
|
+
*
|
|
8
|
+
* This approach prevents TypeScript from transpiling dynamic import()
|
|
9
|
+
* into require() when targeting CommonJS.
|
|
10
|
+
*/
|
|
11
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
15
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(o, k2, desc);
|
|
18
|
+
}) : (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
}));
|
|
22
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
23
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
24
|
+
}) : function(o, v) {
|
|
25
|
+
o["default"] = v;
|
|
26
|
+
});
|
|
27
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
28
|
+
var ownKeys = function(o) {
|
|
29
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
+
var ar = [];
|
|
31
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
+
return ar;
|
|
33
|
+
};
|
|
34
|
+
return ownKeys(o);
|
|
35
|
+
};
|
|
36
|
+
return function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
+
__setModuleDefault(result, mod);
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.loadFileType = loadFileType;
|
|
46
|
+
exports.loadPdfJs = loadPdfJs;
|
|
47
|
+
/**
|
|
48
|
+
* Dynamically loads an ESM module in a Node.js CJS context.
|
|
49
|
+
*
|
|
50
|
+
* @param specifier - The module specifier to load
|
|
51
|
+
* @returns The loaded module
|
|
52
|
+
*/
|
|
53
|
+
async function loadNodeEsmModule(specifier) {
|
|
54
|
+
// We use 'new Function' to bypass static analysis of tsc and some bundlers.
|
|
55
|
+
// This ensures that Node.js sees a real 'import()' at runtime, even in a CJS file.
|
|
56
|
+
return new Function('s', 'return import(s)')(specifier);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Specialized loader for file-type
|
|
60
|
+
*/
|
|
61
|
+
async function loadFileType() {
|
|
62
|
+
if (typeof window === 'undefined') {
|
|
63
|
+
// Node.js path
|
|
64
|
+
return loadNodeEsmModule('file-type');
|
|
65
|
+
}
|
|
66
|
+
// Browser path: esbuild handles standard dynamic import()
|
|
67
|
+
return Promise.resolve().then(() => __importStar(require('file-type')));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Specialized loader for pdfjs-dist
|
|
71
|
+
*/
|
|
72
|
+
async function loadPdfJs() {
|
|
73
|
+
if (typeof window === 'undefined') {
|
|
74
|
+
// Node.js environment: require legacy build for stability with ESM-only main
|
|
75
|
+
try {
|
|
76
|
+
return await loadNodeEsmModule('pdfjs-dist/legacy/build/pdf.mjs');
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return await loadNodeEsmModule('pdfjs-dist');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Browser environment: esbuild handles standard static-looking dynamic import()
|
|
83
|
+
return Promise.resolve().then(() => __importStar(require('pdfjs-dist')));
|
|
84
|
+
}
|
package/dist/utils/ocrUtils.d.ts
CHANGED
package/dist/utils/zipUtils.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "officeparser",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.6",
|
|
4
4
|
"description": "A robust, strictly-typed Node.js and Browser library for parsing office files (.docx, .pptx, .xlsx, .odt, .odp, .ods, .pdf, .rtf) into structured AST with rich metadata, formatting, and attachment support.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,9 +12,10 @@
|
|
|
12
12
|
"dist"
|
|
13
13
|
],
|
|
14
14
|
"scripts": {
|
|
15
|
-
"build": "
|
|
15
|
+
"build": "npm run sync:versions && npm run build:node && npm run build:browser",
|
|
16
16
|
"build:node": "tsc",
|
|
17
17
|
"build:browser": "node build_browser.js && npm run sync:docs",
|
|
18
|
+
"sync:versions": "node scripts/sync-pdfjs-versions.js",
|
|
18
19
|
"sync:docs": "mkdir -p docs/dist && cp dist/officeparser.browser.js docs/dist/",
|
|
19
20
|
"test": "npm run test:clean && npm run build && npx tsx test/testOfficeParser.ts",
|
|
20
21
|
"test:clean": "rm -rf test/results",
|
|
@@ -26,7 +27,9 @@
|
|
|
26
27
|
"type": "git",
|
|
27
28
|
"url": "git+https://github.com/harshankur/officeParser.git"
|
|
28
29
|
},
|
|
29
|
-
"bin":
|
|
30
|
+
"bin": {
|
|
31
|
+
"officeparser": "dist/index.js"
|
|
32
|
+
},
|
|
30
33
|
"keywords": [
|
|
31
34
|
"office",
|
|
32
35
|
"docx",
|
|
@@ -64,24 +67,24 @@
|
|
|
64
67
|
"bugs": {
|
|
65
68
|
"url": "https://github.com/harshankur/officeParser/issues"
|
|
66
69
|
},
|
|
67
|
-
"homepage": "https://github.
|
|
70
|
+
"homepage": "https://harshankur.github.io/officeParser/",
|
|
68
71
|
"dependencies": {
|
|
69
|
-
"@xmldom/xmldom": "^0.8.
|
|
72
|
+
"@xmldom/xmldom": "^0.8.11",
|
|
70
73
|
"concat-stream": "^2.0.0",
|
|
71
|
-
"file-type": "^
|
|
72
|
-
"pdfjs-dist": "5.
|
|
73
|
-
"tesseract.js": "^
|
|
74
|
-
"yauzl": "^3.1
|
|
74
|
+
"file-type": "^19.6.0",
|
|
75
|
+
"pdfjs-dist": "^5.5.207",
|
|
76
|
+
"tesseract.js": "^7.0.0",
|
|
77
|
+
"yauzl": "^3.2.1"
|
|
75
78
|
},
|
|
76
79
|
"devDependencies": {
|
|
77
80
|
"@types/concat-stream": "^2.0.3",
|
|
78
|
-
"@types/node": "^
|
|
79
|
-
"@types/xmldom": "^0.1.
|
|
81
|
+
"@types/node": "^22.13.10",
|
|
82
|
+
"@types/xmldom": "^0.1.34",
|
|
80
83
|
"@types/yauzl": "^2.10.3",
|
|
81
|
-
"esbuild": "^0.27.
|
|
84
|
+
"esbuild": "^0.27.4",
|
|
82
85
|
"esbuild-plugin-polyfill-node": "^0.3.0",
|
|
83
86
|
"husky": "^9.1.7",
|
|
84
87
|
"tsx": "^4.21.0",
|
|
85
|
-
"typescript": "^5.
|
|
88
|
+
"typescript": "^5.9.3"
|
|
86
89
|
}
|
|
87
90
|
}
|