officeparser 6.1.0 → 7.0.0

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.
Files changed (70) hide show
  1. package/README.md +284 -86
  2. package/dist/OfficeConverter.d.ts +46 -0
  3. package/dist/OfficeConverter.js +72 -0
  4. package/dist/OfficeGenerator.d.ts +19 -0
  5. package/dist/OfficeGenerator.js +48 -0
  6. package/dist/OfficeParser.d.ts +6 -0
  7. package/dist/OfficeParser.js +55 -28
  8. package/dist/cli.d.ts +3 -1
  9. package/dist/cli.js +107 -22
  10. package/dist/defaults.d.ts +41 -0
  11. package/dist/defaults.js +172 -0
  12. package/dist/generators/BaseGenerator.d.ts +58 -0
  13. package/dist/generators/BaseGenerator.js +107 -0
  14. package/dist/generators/ChunkingGenerator.d.ts +81 -0
  15. package/dist/generators/ChunkingGenerator.js +683 -0
  16. package/dist/generators/CsvGenerator.d.ts +30 -0
  17. package/dist/generators/CsvGenerator.js +233 -0
  18. package/dist/generators/HtmlGenerator.d.ts +37 -0
  19. package/dist/generators/HtmlGenerator.js +1013 -0
  20. package/dist/generators/MarkdownGenerator.d.ts +59 -0
  21. package/dist/generators/MarkdownGenerator.js +481 -0
  22. package/dist/generators/PdfGenerator.d.ts +22 -0
  23. package/dist/generators/PdfGenerator.js +118 -0
  24. package/dist/generators/RtfGenerator.d.ts +15 -0
  25. package/dist/generators/RtfGenerator.js +208 -0
  26. package/dist/generators/TextGenerator.d.ts +13 -0
  27. package/dist/generators/TextGenerator.js +108 -0
  28. package/dist/index.d.ts +11 -3
  29. package/dist/index.js +17 -2
  30. package/dist/index.mjs +2 -2
  31. package/dist/officeparser.browser.d.ts +878 -5
  32. package/dist/officeparser.browser.iife.js +703 -49
  33. package/dist/officeparser.browser.mjs +703 -49
  34. package/dist/parsers/CsvParser.d.ts +9 -0
  35. package/dist/parsers/CsvParser.js +110 -0
  36. package/dist/parsers/ExcelParser.d.ts +2 -2
  37. package/dist/parsers/ExcelParser.js +145 -114
  38. package/dist/parsers/HtmlParser.d.ts +2 -0
  39. package/dist/parsers/HtmlParser.js +539 -0
  40. package/dist/parsers/MarkdownParser.d.ts +2 -0
  41. package/dist/parsers/MarkdownParser.js +360 -0
  42. package/dist/parsers/OpenOfficeParser.d.ts +2 -2
  43. package/dist/parsers/OpenOfficeParser.js +237 -128
  44. package/dist/parsers/PdfParser.d.ts +2 -2
  45. package/dist/parsers/PdfParser.js +52 -49
  46. package/dist/parsers/PowerPointParser.d.ts +2 -2
  47. package/dist/parsers/PowerPointParser.js +132 -123
  48. package/dist/parsers/RtfParser.d.ts +22 -2
  49. package/dist/parsers/RtfParser.js +1398 -1282
  50. package/dist/parsers/WordParser.d.ts +3 -2
  51. package/dist/parsers/WordParser.js +333 -115
  52. package/dist/sbom.cdx.json +103 -103
  53. package/dist/types.d.ts +833 -5
  54. package/dist/types.js +71 -0
  55. package/dist/utils/astUtils.d.ts +16 -0
  56. package/dist/utils/astUtils.js +32 -0
  57. package/dist/utils/configUtils.d.ts +26 -0
  58. package/dist/utils/configUtils.js +140 -0
  59. package/dist/utils/envUtils.js +56 -2
  60. package/dist/utils/errorUtils.d.ts +17 -29
  61. package/dist/utils/errorUtils.js +109 -52
  62. package/dist/utils/moduleLoader.js +15 -9
  63. package/dist/utils/ocrUtils.js +2 -1
  64. package/dist/utils/sheetUtils.d.ts +7 -0
  65. package/dist/utils/sheetUtils.js +35 -0
  66. package/dist/utils/styleMapper.d.ts +36 -0
  67. package/dist/utils/styleMapper.js +224 -0
  68. package/dist/utils/xmlUtils.d.ts +0 -8
  69. package/dist/utils/xmlUtils.js +2 -1
  70. package/package.json +28 -9
package/dist/types.js CHANGED
@@ -1,2 +1,73 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OfficeWarningType = exports.OfficeErrorType = void 0;
4
+ /**
5
+ * Standard error types for OfficeParser.
6
+ * Use these to identify the kind of error being reported.
7
+ */
8
+ var OfficeErrorType;
9
+ (function (OfficeErrorType) {
10
+ /** Unsupported file extension */
11
+ OfficeErrorType["EXTENSION_UNSUPPORTED"] = "EXTENSION_UNSUPPORTED";
12
+ /** File appears to be corrupted or malformed */
13
+ OfficeErrorType["FILE_CORRUPTED"] = "FILE_CORRUPTED";
14
+ /** File could not be found at the specified path */
15
+ OfficeErrorType["FILE_DOES_NOT_EXIST"] = "FILE_DOES_NOT_EXIST";
16
+ /** Specified location/directory is not reachable or is a directory */
17
+ OfficeErrorType["LOCATION_NOT_FOUND"] = "LOCATION_NOT_FOUND";
18
+ /** Arguments passed to the function are missing or invalid */
19
+ OfficeErrorType["IMPROPER_ARGUMENTS"] = "IMPROPER_ARGUMENTS";
20
+ /** Error occurred while reading or processing file buffers */
21
+ OfficeErrorType["IMPROPER_BUFFERS"] = "IMPROPER_BUFFERS";
22
+ /** Input type is not a supported type (string, Buffer, ArrayBuffer) */
23
+ OfficeErrorType["INVALID_INPUT"] = "INVALID_INPUT";
24
+ /** PDF worker source is missing (required in browser) */
25
+ OfficeErrorType["PDF_WORKER_MISSING"] = "PDF_WORKER_MISSING";
26
+ /** Attempted to use Node.js-only features in a browser environment */
27
+ OfficeErrorType["FEATURE_NOT_SUPPORTED_IN_BROWSER"] = "FEATURE_NOT_SUPPORTED_IN_BROWSER";
28
+ /** Style mapping string is malformed */
29
+ OfficeErrorType["INVALID_STYLE_MAPPING"] = "INVALID_STYLE_MAPPING";
30
+ /** Selector in style mapping is invalid */
31
+ OfficeErrorType["INVALID_SELECTOR"] = "INVALID_SELECTOR";
32
+ /** Output mapping in style mapping is invalid */
33
+ OfficeErrorType["INVALID_OUTPUT_MAPPING"] = "INVALID_OUTPUT_MAPPING";
34
+ /** Semantic chunking strategy is selected but no embedding function is provided */
35
+ OfficeErrorType["MISSING_EMBEDDING_FUNCTION"] = "MISSING_EMBEDDING_FUNCTION";
36
+ })(OfficeErrorType || (exports.OfficeErrorType = OfficeErrorType = {}));
37
+ /**
38
+ * Standard warning types for OfficeParser.
39
+ * Use these for reporting non-fatal issues or performance tips.
40
+ */
41
+ var OfficeWarningType;
42
+ (function (OfficeWarningType) {
43
+ /** Performance advice (e.g., Rosetta translation on Mac) */
44
+ OfficeWarningType["PERFORMANCE_TIP"] = "PERFORMANCE_TIP";
45
+ /** OCR processing failed for an attachment */
46
+ OfficeWarningType["OCR_FAILED"] = "OCR_FAILED";
47
+ /** Extraction of structured chart data failed */
48
+ OfficeWarningType["CHART_DATA_EXTRACTION_FAILED"] = "CHART_DATA_EXTRACTION_FAILED";
49
+ /** Automatic worker path failed, falling back to CDN */
50
+ OfficeWarningType["PDF_WORKER_FALLBACK"] = "PDF_WORKER_FALLBACK";
51
+ /** General attachment extraction failure */
52
+ OfficeWarningType["ATTACHMENT_EXTRACTION_FAILED"] = "ATTACHMENT_EXTRACTION_FAILED";
53
+ /** Failed to load a specific page in a multi-page document */
54
+ OfficeWarningType["PAGE_LOAD_FAILED"] = "PAGE_LOAD_FAILED";
55
+ /** Failed to load a required dynamic dependency */
56
+ OfficeWarningType["DEPENDENCY_LOAD_FAILED"] = "DEPENDENCY_LOAD_FAILED";
57
+ /** Failed to extract images from a source */
58
+ OfficeWarningType["IMAGE_EXTRACTION_FAILED"] = "IMAGE_EXTRACTION_FAILED";
59
+ /** Failed to extract annotations from a document */
60
+ OfficeWarningType["ANNOTATION_EXTRACTION_FAILED"] = "ANNOTATION_EXTRACTION_FAILED";
61
+ /** Failed to process an extracted image bitmap */
62
+ OfficeWarningType["IMAGE_PROCESSING_FAILED"] = "IMAGE_PROCESSING_FAILED";
63
+ /** Warning about limitations of browser-based generation */
64
+ OfficeWarningType["BROWSER_GENERATION_LIMITATION"] = "BROWSER_GENERATION_LIMITATION";
65
+ /** Specified sheet range in Excel/ODS export was not found */
66
+ OfficeWarningType["SHEET_RANGE_NOT_FOUND"] = "SHEET_RANGE_NOT_FOUND";
67
+ /** Buffer content type does not match the provided or expected file extension */
68
+ OfficeWarningType["BUFFER_TYPE_MISMATCH"] = "BUFFER_TYPE_MISMATCH";
69
+ /** No chunks were generated for the document given the current strategy */
70
+ OfficeWarningType["EMPTY_CHUNK_GENERATED"] = "EMPTY_CHUNK_GENERATED";
71
+ /** A node was skipped because it only contained whitespace */
72
+ OfficeWarningType["WHITESPACE_NODE_SKIPPED"] = "WHITESPACE_NODE_SKIPPED";
73
+ })(OfficeWarningType || (exports.OfficeWarningType = OfficeWarningType = {}));
@@ -0,0 +1,16 @@
1
+ import { OfficeParserAST, OfficeContentNode, OfficeMetadata, OfficeAttachment, SupportedFileType, OfficeParserConfig } from '../types.js';
2
+ /**
3
+ * Creates a fully-featured OfficeParserAST object with conversion methods.
4
+ *
5
+ * This helper ensures that all ASTs returned by officeParser have the latest
6
+ * conversion methods (.to()) and maintain backward compatibility (.toText()).
7
+ *
8
+ * @param type - The detected file type
9
+ * @param metadata - Document metadata
10
+ * @param content - Parsed content nodes
11
+ * @param attachments - Extracted attachments
12
+ * @param config - Original parser configuration
13
+ * @param toTextSync - Synchronous text extraction logic (for backward compatibility)
14
+ * @returns An object conforming to OfficeParserAST
15
+ */
16
+ export declare function createAST(type: SupportedFileType, metadata: OfficeMetadata, content: OfficeContentNode[], attachments: OfficeAttachment[], config: OfficeParserConfig, toTextSync: () => string): OfficeParserAST;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAST = createAST;
4
+ const OfficeGenerator_js_1 = require("../OfficeGenerator.js");
5
+ /**
6
+ * Creates a fully-featured OfficeParserAST object with conversion methods.
7
+ *
8
+ * This helper ensures that all ASTs returned by officeParser have the latest
9
+ * conversion methods (.to()) and maintain backward compatibility (.toText()).
10
+ *
11
+ * @param type - The detected file type
12
+ * @param metadata - Document metadata
13
+ * @param content - Parsed content nodes
14
+ * @param attachments - Extracted attachments
15
+ * @param config - Original parser configuration
16
+ * @param toTextSync - Synchronous text extraction logic (for backward compatibility)
17
+ * @returns An object conforming to OfficeParserAST
18
+ */
19
+ function createAST(type, metadata, content, attachments, config, toTextSync) {
20
+ return {
21
+ config,
22
+ type,
23
+ metadata,
24
+ content,
25
+ attachments,
26
+ warnings: [],
27
+ toText: toTextSync,
28
+ async to(destination, genConfig) {
29
+ return OfficeGenerator_js_1.OfficeGenerator.generate(this, destination, genConfig);
30
+ }
31
+ };
32
+ }
@@ -0,0 +1,26 @@
1
+ import { FullGeneratorConfig, FullOfficeParserConfig, GeneratorConfig, OfficeParserConfig } from '../types.js';
2
+ /**
3
+ * Checks if a configuration object is a FullGeneratorConfig.
4
+ */
5
+ export declare function isFullGeneratorConfig(config: any): config is FullGeneratorConfig;
6
+ /**
7
+ * Checks if a configuration object is a FullOfficeParserConfig.
8
+ */
9
+ export declare function isFullParserConfig(config: any): config is FullOfficeParserConfig;
10
+ /**
11
+ * Resolves a full parser configuration by merging defaults and user-provided overrides.
12
+ *
13
+ * @param userConfig - Optional configuration provided by the user
14
+ * @returns A fully populated configuration object
15
+ */
16
+ export declare function resolveParserConfig(userConfig?: OfficeParserConfig | FullOfficeParserConfig): FullOfficeParserConfig;
17
+ /**
18
+ * Resolves a full, destination-specific configuration by merging defaults,
19
+ * AST-level settings, and user-provided overrides.
20
+ *
21
+ * @param destination - The target format
22
+ * @param userConfig - Optional configuration provided by the user
23
+ * @param astConfig - Optional configuration from the source AST (for inheritance)
24
+ * @returns A fully populated configuration object
25
+ */
26
+ export declare function resolveGeneratorConfig<D extends string>(destination: D, astConfig?: OfficeParserConfig, userConfig?: GeneratorConfig<D> | FullGeneratorConfig): FullGeneratorConfig;
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isFullGeneratorConfig = isFullGeneratorConfig;
4
+ exports.isFullParserConfig = isFullParserConfig;
5
+ exports.resolveParserConfig = resolveParserConfig;
6
+ exports.resolveGeneratorConfig = resolveGeneratorConfig;
7
+ const defaults_js_1 = require("../defaults.js");
8
+ /**
9
+ * Deep clones an object, specifically handling arrays and plain objects.
10
+ */
11
+ function deepClone(obj) {
12
+ if (obj === null || typeof obj !== 'object') {
13
+ return obj;
14
+ }
15
+ if (Array.isArray(obj)) {
16
+ return obj.map((item) => deepClone(item));
17
+ }
18
+ const cloned = {};
19
+ for (const key in obj) {
20
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
21
+ cloned[key] = deepClone(obj[key]);
22
+ }
23
+ }
24
+ return cloned;
25
+ }
26
+ /**
27
+ * Checks if a configuration object is a FullGeneratorConfig.
28
+ */
29
+ function isFullGeneratorConfig(config) {
30
+ return !!(config &&
31
+ typeof config === 'object' &&
32
+ 'textConfig' in config &&
33
+ 'htmlConfig' in config &&
34
+ 'pdfConfig' in config &&
35
+ 'csvConfig' in config &&
36
+ 'onNode' in config);
37
+ }
38
+ /**
39
+ * Checks if a configuration object is a FullOfficeParserConfig.
40
+ */
41
+ function isFullParserConfig(config) {
42
+ return !!(config &&
43
+ typeof config === 'object' &&
44
+ 'ocrConfig' in config &&
45
+ typeof config.ocrConfig === 'object' &&
46
+ 'language' in config.ocrConfig &&
47
+ 'workerPath' in config.ocrConfig);
48
+ }
49
+ /**
50
+ * Resolves a full parser configuration by merging defaults and user-provided overrides.
51
+ *
52
+ * @param userConfig - Optional configuration provided by the user
53
+ * @returns A fully populated configuration object
54
+ */
55
+ function resolveParserConfig(userConfig) {
56
+ if (isFullParserConfig(userConfig)) {
57
+ return userConfig;
58
+ }
59
+ // 1. Start with full defaults (deep cloned)
60
+ const config = deepClone(defaults_js_1.DEFAULT_OFFICE_PARSER_CONFIG);
61
+ if (!userConfig) {
62
+ return config;
63
+ }
64
+ // 2. Merge user config
65
+ // We handle ocrConfig specially to avoid shallow-overwriting the whole object
66
+ const { ocrConfig, ...rest } = userConfig;
67
+ Object.assign(config, rest);
68
+ if (ocrConfig) {
69
+ config.ocrConfig = { ...config.ocrConfig, ...ocrConfig };
70
+ }
71
+ // 3. Handle legacy ocrLanguage mapping if not explicitly set in ocrConfig
72
+ if (userConfig.ocrLanguage && !userConfig.ocrConfig?.language) {
73
+ config.ocrConfig.language = userConfig.ocrLanguage;
74
+ }
75
+ return config;
76
+ }
77
+ /**
78
+ * Resolves a full, destination-specific configuration by merging defaults,
79
+ * AST-level settings, and user-provided overrides.
80
+ *
81
+ * @param destination - The target format
82
+ * @param userConfig - Optional configuration provided by the user
83
+ * @param astConfig - Optional configuration from the source AST (for inheritance)
84
+ * @returns A fully populated configuration object
85
+ */
86
+ function resolveGeneratorConfig(destination, astConfig, userConfig) {
87
+ // If it's already a full config and we don't need to merge AST config, return it as is.
88
+ // We assume FullGeneratorConfig is already "safe" (references resolved).
89
+ if (isFullGeneratorConfig(userConfig) && !astConfig) {
90
+ return userConfig;
91
+ }
92
+ // 1. Start with full defaults (deep cloned to avoid reference sharing)
93
+ const config = deepClone(defaults_js_1.DEFAULT_GENERATOR_CONFIG);
94
+ // 2. Merge common properties and sub-configs
95
+ if (userConfig) {
96
+ // Extract sub-configs to avoid shallow-overwriting the whole sub-config objects
97
+ const { htmlConfig, mdConfig, pdfConfig, csvConfig, textConfig, chunksConfig, ...commonProps } = userConfig;
98
+ Object.assign(config, commonProps);
99
+ // Merge sub-configs individually, ignoring undefined properties to preserve defaults
100
+ const mergeSubConfig = (target, source) => {
101
+ if (!source)
102
+ return;
103
+ for (const key in source) {
104
+ if (source[key] !== undefined) {
105
+ target[key] = source[key];
106
+ }
107
+ }
108
+ };
109
+ if (htmlConfig)
110
+ mergeSubConfig(config.htmlConfig, htmlConfig);
111
+ if (mdConfig)
112
+ mergeSubConfig(config.mdConfig, mdConfig);
113
+ if (pdfConfig)
114
+ mergeSubConfig(config.pdfConfig, pdfConfig);
115
+ if (csvConfig)
116
+ mergeSubConfig(config.csvConfig, csvConfig);
117
+ if (textConfig)
118
+ mergeSubConfig(config.textConfig, textConfig);
119
+ if (chunksConfig)
120
+ mergeSubConfig(config.chunksConfig, chunksConfig);
121
+ }
122
+ // 3. Inherit from AST config if not explicitly provided
123
+ if (astConfig) {
124
+ if (userConfig?.onWarning === undefined) {
125
+ config.onWarning = astConfig.onWarning || config.onWarning;
126
+ }
127
+ // Inherit newlineDelimiter for text-based generators
128
+ const astNewline = astConfig.newlineDelimiter;
129
+ if (astNewline && ['text', 'md', 'rtf'].includes(destination)) {
130
+ // If user didn't specify a newline delimiter in their specific config, use AST's
131
+ if (destination === 'text' && userConfig?.textConfig?.newlineDelimiter === undefined) {
132
+ config.textConfig.newlineDelimiter = astNewline;
133
+ }
134
+ // For MD and RTF, they use common newline settings or internal defaults.
135
+ // We ensure the resolved config reflects this if possible, or generators can check astConfig directly.
136
+ // Since FullGeneratorConfig doesn't have an 'mdConfig', we rely on the generator implementation.
137
+ }
138
+ }
139
+ return config;
140
+ }
@@ -10,6 +10,8 @@ exports.ensureDomMatrix = ensureDomMatrix;
10
10
  * Detect if we are running in a browser environment.
11
11
  */
12
12
  exports.isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
13
+ const types_js_1 = require("../types.js");
14
+ const errorUtils_js_1 = require("./errorUtils.js");
13
15
  /**
14
16
  * Human-readable descriptions for Node-only features.
15
17
  */
@@ -26,7 +28,7 @@ const readableFeatures = {
26
28
  */
27
29
  function assertNode(feature) {
28
30
  if (exports.isBrowser) {
29
- throw new Error(`officeparser: '${readableFeatures[feature]}' is not supported in the browser. Browser users must pass file content as Buffer or ArrayBuffer directly.`);
31
+ throw (0, errorUtils_js_1.getOfficeError)(types_js_1.OfficeErrorType.FEATURE_NOT_SUPPORTED_IN_BROWSER, undefined, readableFeatures[feature]);
30
32
  }
31
33
  }
32
34
  /**
@@ -36,6 +38,7 @@ function assertNode(feature) {
36
38
  */
37
39
  function ensureDomMatrix() {
38
40
  if (typeof global !== 'undefined' && !global.DOMMatrix) {
41
+ // Node.js < 20 needs a polyfill for DOMMatrix used by pdf.js 5.x
39
42
  global.DOMMatrix = class DOMMatrix {
40
43
  a;
41
44
  b;
@@ -52,18 +55,69 @@ function ensureDomMatrix() {
52
55
  this.e = init[4];
53
56
  this.f = init[5];
54
57
  }
58
+ else if (typeof init === 'object' && init !== null) {
59
+ this.a = init.a;
60
+ this.b = init.b;
61
+ this.c = init.c;
62
+ this.d = init.d;
63
+ this.e = init.e;
64
+ this.f = init.f;
65
+ }
55
66
  else {
56
67
  this.a = this.d = 1;
57
68
  this.b = this.c = this.e = this.f = 0;
58
69
  }
59
70
  }
60
- // Map standard matrix properties for compatibility
71
+ // Standard matrix property aliases for compatibility
61
72
  get m11() { return this.a; }
62
73
  get m12() { return this.b; }
63
74
  get m21() { return this.c; }
64
75
  get m22() { return this.d; }
65
76
  get m41() { return this.e; }
66
77
  get m42() { return this.f; }
78
+ multiply(other) {
79
+ return new DOMMatrix([
80
+ this.a * other.a + this.c * other.b,
81
+ this.b * other.a + this.d * other.b,
82
+ this.a * other.c + this.c * other.d,
83
+ this.b * other.c + this.d * other.d,
84
+ this.a * other.e + this.c * other.f + this.e,
85
+ this.b * other.e + this.d * other.f + this.f
86
+ ]);
87
+ }
88
+ inverse() {
89
+ const det = this.a * this.d - this.b * this.c;
90
+ if (det === 0)
91
+ return new DOMMatrix();
92
+ return new DOMMatrix([
93
+ this.d / det,
94
+ -this.b / det,
95
+ -this.c / det,
96
+ this.a / det,
97
+ (this.c * this.f - this.d * this.e) / det,
98
+ (this.b * this.e - this.a * this.f) / det
99
+ ]);
100
+ }
101
+ transformPoint(point) {
102
+ const x = point?.x ?? 0;
103
+ const y = point?.y ?? 0;
104
+ return {
105
+ x: x * this.a + y * this.c + this.e,
106
+ y: x * this.b + y * this.d + this.f
107
+ };
108
+ }
109
+ };
110
+ }
111
+ if (typeof global !== 'undefined' && !global.ImageData) {
112
+ global.ImageData = class ImageData {
113
+ width;
114
+ height;
115
+ data;
116
+ constructor(data, width, height) {
117
+ this.data = data;
118
+ this.width = width;
119
+ this.height = height;
120
+ }
67
121
  };
68
122
  }
69
123
  }
@@ -5,38 +5,24 @@
5
5
  * It defines standard error types, messages, and handling logic to ensure
6
6
  * consistent error reporting across all parsers and the main entry point.
7
7
  */
8
- import { OfficeParserConfig } from '../types';
8
+ import { OfficeErrorType, OfficeParserConfig, OfficeWarningType } from '../types.js';
9
9
  /**
10
- * Standard error types for OfficeParser.
11
- * Use these to identify the kind of error being reported.
10
+ * Creates a formatted warning message for a specific warning type.
11
+ *
12
+ * @param type - The type of warning
13
+ * @param info - Optional additional information
14
+ * @returns The formatted warning message string
12
15
  */
13
- export declare enum OfficeErrorType {
14
- /** Unsupported file extension */
15
- EXTENSION_UNSUPPORTED = "EXTENSION_UNSUPPORTED",
16
- /** File appears to be corrupted or malformed */
17
- FILE_CORRUPTED = "FILE_CORRUPTED",
18
- /** File could not be found at the specified path */
19
- FILE_DOES_NOT_EXIST = "FILE_DOES_NOT_EXIST",
20
- /** Specified location/directory is not reachable or is a directory */
21
- LOCATION_NOT_FOUND = "LOCATION_NOT_FOUND",
22
- /** Arguments passed to the function are missing or invalid */
23
- IMPROPER_ARGUMENTS = "IMPROPER_ARGUMENTS",
24
- /** Error occurred while reading or processing file buffers */
25
- IMPROPER_BUFFERS = "IMPROPER_BUFFERS",
26
- /** Input type is not a supported type (string, Buffer, ArrayBuffer) */
27
- INVALID_INPUT = "INVALID_INPUT",
28
- /** PDF worker source is missing (required in browser) */
29
- PDF_WORKER_MISSING = "PDF_WORKER_MISSING"
30
- }
16
+ export declare const getWarningMessage: (type: OfficeWarningType, info?: any) => string;
31
17
  /**
32
18
  * Creates, optionally logs to console, and returns a formatted OfficeParser error.
33
19
  *
34
20
  * @param type - The type of error
35
- * @param config - Parser configuration (checks outputErrorToConsole)
21
+ * @param config - Optional parser configuration (checks outputErrorToConsole)
36
22
  * @param info - Optional additional information
37
23
  * @returns The Error object to be thrown
38
24
  */
39
- export declare const getOfficeError: (type: OfficeErrorType, config: OfficeParserConfig, info?: any) => Error;
25
+ export declare const getOfficeError: (type: OfficeErrorType, config?: OfficeParserConfig, info?: any) => Error;
40
26
  /**
41
27
  * Wraps an existing error with OfficeParser context and performs corruption detection.
42
28
  * Optionally logs the error to console.
@@ -48,11 +34,13 @@ export declare const getOfficeError: (type: OfficeErrorType, config: OfficeParse
48
34
  */
49
35
  export declare const getWrappedError: (error: any, config: OfficeParserConfig, filePath?: string) => Error;
50
36
  /**
51
- * Conditionally logs a warning message to the console.
52
- * Used for non-fatal errors that shouldn't stop the parsing process.
37
+ * Centralized logging utility for non-fatal warnings or issues.
38
+ * Routes messages to config.onWarning if provided, or console.warn/error
39
+ * if config.outputErrorToConsole is true.
53
40
  *
54
- * @param message - The warning message
55
- * @param config - Parser configuration
56
- * @param error - Optional original error object for more context
41
+ * @param messageOrType - The warning message or warning type
42
+ * @param config - Optional parser configuration
43
+ * @param info - Optional additional information for dynamic messages or context
44
+ * @param error - Optional original error object
57
45
  */
58
- export declare const logWarning: (message: string, config: OfficeParserConfig, error?: any) => void;
46
+ export declare const logWarning: (type: OfficeWarningType, config?: OfficeParserConfig, info?: any, error?: any) => void;