officeparser 6.1.1 → 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.
Files changed (71) hide show
  1. package/README.md +301 -26
  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 +74 -31
  8. package/dist/cli.d.ts +3 -1
  9. package/dist/cli.js +106 -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 +828 -5
  32. package/dist/officeparser.browser.iife.js +703 -52
  33. package/dist/officeparser.browser.mjs +703 -52
  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 +140 -79
  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 +20 -23
  48. package/dist/parsers/RtfParser.d.ts +2 -2
  49. package/dist/parsers/RtfParser.js +1291 -1240
  50. package/dist/parsers/WordParser.d.ts +2 -2
  51. package/dist/parsers/WordParser.js +232 -97
  52. package/dist/sbom.cdx.json +99 -99
  53. package/dist/types.d.ts +783 -5
  54. package/dist/types.js +73 -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.d.ts +8 -3
  60. package/dist/utils/envUtils.js +117 -34
  61. package/dist/utils/errorUtils.d.ts +17 -29
  62. package/dist/utils/errorUtils.js +110 -52
  63. package/dist/utils/moduleLoader.js +19 -11
  64. package/dist/utils/ocrUtils.js +2 -1
  65. package/dist/utils/sheetUtils.d.ts +7 -0
  66. package/dist/utils/sheetUtils.js +35 -0
  67. package/dist/utils/styleMapper.d.ts +36 -0
  68. package/dist/utils/styleMapper.js +224 -0
  69. package/dist/utils/xmlUtils.d.ts +0 -8
  70. package/dist/utils/xmlUtils.js +2 -1
  71. package/package.json +26 -7
@@ -24,6 +24,8 @@
24
24
  */
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.parsePowerPoint = void 0;
27
+ const types_js_1 = require("../types.js");
28
+ const astUtils_js_1 = require("../utils/astUtils.js");
27
29
  const chartUtils_js_1 = require("../utils/chartUtils.js");
28
30
  const errorUtils_js_1 = require("../utils/errorUtils.js");
29
31
  const imageUtils_js_1 = require("../utils/imageUtils.js");
@@ -704,10 +706,10 @@ const parsePowerPoint = async (buffer, config) => {
704
706
  if (config.ocr) {
705
707
  if (attachment.mimeType.startsWith('image/')) {
706
708
  try {
707
- attachment.ocrText = (await (0, ocrUtils_js_1.performOcr)(media.content, { language: config.ocrLanguage, ...config.ocrConfig })).trim();
709
+ attachment.ocrText = (await (0, ocrUtils_js_1.performOcr)(media.content, { ...config.ocrConfig })).trim();
708
710
  }
709
711
  catch (e) {
710
- (0, errorUtils_js_1.logWarning)(`OCR failed for ${attachment.name}:`, config, e);
712
+ (0, errorUtils_js_1.logWarning)(types_js_1.OfficeWarningType.OCR_FAILED, config, attachment.name, e);
711
713
  }
712
714
  }
713
715
  }
@@ -729,7 +731,7 @@ const parsePowerPoint = async (buffer, config) => {
729
731
  attachment.chartData = chartData;
730
732
  }
731
733
  catch (e) {
732
- (0, errorUtils_js_1.logWarning)(`Failed to extract text from chart ${chart.path}:`, config, e);
734
+ (0, errorUtils_js_1.logWarning)(types_js_1.OfficeWarningType.CHART_DATA_EXTRACTION_FAILED, config, chart.path, e);
733
735
  }
734
736
  }
735
737
  // Loop through nodes to find images and charts and link their text and chartData
@@ -745,7 +747,7 @@ const parsePowerPoint = async (buffer, config) => {
745
747
  node.text = attachment.ocrText;
746
748
  }
747
749
  if (node.type === 'chart') {
748
- node.text = attachment.chartData?.rawTexts.join(config.newlineDelimiter || '\n');
750
+ node.text = attachment.chartData?.rawTexts.join(config.newlineDelimiter);
749
751
  }
750
752
  }
751
753
  }
@@ -764,24 +766,19 @@ const parsePowerPoint = async (buffer, config) => {
764
766
  return aIsNote - bIsNote;
765
767
  });
766
768
  }
767
- return {
768
- type: 'pptx',
769
- metadata: metadata,
770
- content: content,
771
- attachments: attachments,
772
- toText: () => content.map(c => {
773
- // Recursive text extraction
774
- const getText = (node) => {
775
- let t = '';
776
- if (node.children) {
777
- t += node.children.map(getText).filter(t => t != '').join(!node.children[0]?.children ? '' : config.newlineDelimiter ?? '\n');
778
- }
779
- else
780
- t += node.text || '';
781
- return t;
782
- };
783
- return getText(c);
784
- }).filter(t => t != '').join(config.newlineDelimiter ?? '\n')
785
- };
769
+ const toTextSync = () => content.map(c => {
770
+ // Recursive text extraction
771
+ const getText = (node) => {
772
+ let t = '';
773
+ if (node.children) {
774
+ t += node.children.map(getText).filter(t => t != '').join(!node.children[0]?.children ? '' : config.newlineDelimiter);
775
+ }
776
+ else
777
+ t += node.text || '';
778
+ return t;
779
+ };
780
+ return getText(c);
781
+ }).filter(t => t != '').join(config.newlineDelimiter);
782
+ return (0, astUtils_js_1.createAST)('pptx', metadata, content, attachments, config, toTextSync);
786
783
  };
787
784
  exports.parsePowerPoint = parsePowerPoint;
@@ -39,7 +39,7 @@
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
- import { OfficeParserAST, OfficeParserConfig } from '../types.js';
42
+ import { FullOfficeParserConfig, OfficeParserAST } from '../types.js';
43
43
  /**
44
44
  * Represents an RTF group (content enclosed in braces).
45
45
  * Groups create formatting scopes and can contain other groups, control words, or text.
@@ -184,4 +184,4 @@ export declare class SimpleRtfParser {
184
184
  * @param config The parser configuration.
185
185
  * @returns The parsed AST.
186
186
  */
187
- export declare const parseRtf: (buffer: Buffer, config: OfficeParserConfig) => Promise<OfficeParserAST>;
187
+ export declare const parseRtf: (buffer: Buffer, config: FullOfficeParserConfig) => Promise<OfficeParserAST>;