@js-ak/excel-toolbox 1.6.0 → 1.7.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 (33) hide show
  1. package/build/cjs/lib/merge-sheets-to-base-file-process-sync.js +105 -0
  2. package/build/cjs/lib/merge-sheets-to-base-file-process.js +3 -3
  3. package/build/cjs/lib/merge-sheets-to-base-file-sync.js +2 -2
  4. package/build/cjs/lib/merge-sheets-to-base-file.js +1 -1
  5. package/build/cjs/lib/template/template-fs.js +8 -8
  6. package/build/cjs/lib/template/template-memory.js +21 -21
  7. package/build/cjs/lib/xml/extract-rows-from-sheet-sync.js +67 -0
  8. package/build/cjs/lib/xml/extract-rows-from-sheet.js +4 -2
  9. package/build/cjs/lib/xml/extract-xml-from-sheet-sync.js +43 -0
  10. package/build/cjs/lib/xml/extract-xml-from-sheet.js +15 -15
  11. package/build/cjs/lib/xml/index.js +2 -1
  12. package/build/esm/lib/merge-sheets-to-base-file-process-sync.js +69 -0
  13. package/build/esm/lib/merge-sheets-to-base-file-process.js +3 -3
  14. package/build/esm/lib/merge-sheets-to-base-file-sync.js +2 -2
  15. package/build/esm/lib/merge-sheets-to-base-file.js +1 -1
  16. package/build/esm/lib/template/template-fs.js +8 -8
  17. package/build/esm/lib/template/template-memory.js +21 -21
  18. package/build/esm/lib/xml/extract-rows-from-sheet-sync.js +64 -0
  19. package/build/esm/lib/xml/extract-rows-from-sheet.js +4 -2
  20. package/build/esm/lib/xml/extract-xml-from-sheet-sync.js +40 -0
  21. package/build/esm/lib/xml/extract-xml-from-sheet.js +12 -15
  22. package/build/esm/lib/xml/index.js +2 -1
  23. package/build/types/lib/merge-sheets-to-base-file-process-sync.d.ts +27 -0
  24. package/build/types/lib/merge-sheets-to-base-file-process.d.ts +1 -1
  25. package/build/types/lib/xml/extract-rows-from-sheet-sync.d.ts +28 -0
  26. package/build/types/lib/xml/extract-rows-from-sheet.d.ts +2 -2
  27. package/build/types/lib/xml/extract-xml-from-sheet-sync.d.ts +14 -0
  28. package/build/types/lib/xml/extract-xml-from-sheet.d.ts +2 -2
  29. package/build/types/lib/xml/index.d.ts +2 -1
  30. package/package.json +1 -5
  31. package/build/cjs/lib/xml/extract-xml-from-system-content.js +0 -53
  32. package/build/esm/lib/xml/extract-xml-from-system-content.js +0 -49
  33. package/build/types/lib/xml/extract-xml-from-system-content.d.ts +0 -15
@@ -1,49 +0,0 @@
1
- import { inflateRaw } from "pako";
2
- /**
3
- * Extracts and decompresses XML content from Excel system files (e.g., workbook.xml, [Content_Types].xml).
4
- * Handles both compressed (raw DEFLATE) and uncompressed (plain XML) formats with comprehensive error handling.
5
- *
6
- * @param {Buffer} buffer - The file content to process, which may be:
7
- * - Raw XML text
8
- * - DEFLATE-compressed XML data (without zlib headers)
9
- * @param {string} name - The filename being processed (for error reporting)
10
- * @returns {string} - The extracted XML content as a sanitized UTF-8 string
11
- * @throws {Error} - With descriptive messages for various failure scenarios:
12
- * - Empty buffer
13
- * - Decompression failures
14
- * - Invalid XML content
15
- */
16
- export const extractXmlFromSystemContent = (buffer, name) => {
17
- // Validate input buffer
18
- if (!buffer || buffer.length === 0) {
19
- throw new Error(`Empty data buffer provided for file ${name}`);
20
- }
21
- let xml;
22
- // Check for XML declaration in first 5 bytes (<?xml)
23
- const startsWithXml = buffer.subarray(0, 5).toString("utf8").trim().startsWith("<?xml");
24
- if (startsWithXml) {
25
- // Case 1: Already uncompressed XML - convert directly to string
26
- xml = buffer.toString("utf8");
27
- }
28
- else {
29
- // Case 2: Attempt DEFLATE decompression
30
- try {
31
- const inflated = inflateRaw(buffer, { to: "string" });
32
- // Validate decompressed content contains XML declaration
33
- if (inflated && inflated.includes("<?xml")) {
34
- xml = inflated;
35
- }
36
- else {
37
- throw new Error(`Decompressed data doesn't contain valid XML in ${name}`);
38
- }
39
- }
40
- catch (error) {
41
- const message = error instanceof Error ? error.message : "Unknown error";
42
- throw new Error(`Failed to decompress ${name}: ${message}`);
43
- }
44
- }
45
- // Sanitize XML by removing illegal control characters (per XML 1.0 spec)
46
- // Preserves tabs (0x09), newlines (0x0A), and carriage returns (0x0D)
47
- xml = xml.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, "");
48
- return xml;
49
- };
@@ -1,15 +0,0 @@
1
- /**
2
- * Extracts and decompresses XML content from Excel system files (e.g., workbook.xml, [Content_Types].xml).
3
- * Handles both compressed (raw DEFLATE) and uncompressed (plain XML) formats with comprehensive error handling.
4
- *
5
- * @param {Buffer} buffer - The file content to process, which may be:
6
- * - Raw XML text
7
- * - DEFLATE-compressed XML data (without zlib headers)
8
- * @param {string} name - The filename being processed (for error reporting)
9
- * @returns {string} - The extracted XML content as a sanitized UTF-8 string
10
- * @throws {Error} - With descriptive messages for various failure scenarios:
11
- * - Empty buffer
12
- * - Decompression failures
13
- * - Invalid XML content
14
- */
15
- export declare const extractXmlFromSystemContent: (buffer: Buffer, name: string) => string;