@js-ak/excel-toolbox 1.2.4 → 1.2.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/build/cjs/lib/merge-sheets-to-base-file-process.js +23 -14
- package/build/cjs/lib/merge-sheets-to-base-file-sync.js +18 -9
- package/build/cjs/lib/merge-sheets-to-base-file.js +18 -9
- package/build/cjs/lib/utils/get-max-row-number.js +1 -2
- package/build/cjs/lib/utils/is-same-buffer.js +1 -2
- package/build/cjs/lib/utils/remove-sheet-by-name.js +10 -9
- package/build/cjs/lib/utils/remove-sheet-from-content-types.js +1 -2
- package/build/cjs/lib/utils/remove-sheet-from-rels.js +1 -2
- package/build/cjs/lib/utils/remove-sheet-from-workbook.js +1 -2
- package/build/cjs/lib/utils/shift-cell-ref.js +1 -2
- package/build/cjs/lib/xml/build-merged-sheet.js +3 -4
- package/build/cjs/lib/xml/extract-rows-from-sheet.js +2 -2
- package/build/cjs/lib/xml/extract-xml-from-sheet.js +1 -2
- package/build/cjs/lib/xml/shift-row-indices.js +1 -2
- package/build/cjs/lib/zip/create-sync.js +1 -2
- package/build/cjs/lib/zip/create.js +1 -2
- package/build/cjs/lib/zip/read-sync.js +20 -21
- package/build/cjs/lib/zip/read.js +16 -20
- package/build/cjs/lib/zip/utils.js +3 -4
- package/build/cjs/package.json +3 -0
- package/build/esm/lib/merge-sheets-to-base-file-process.js +5 -5
- package/build/esm/lib/utils/remove-sheet-by-name.js +9 -7
- package/build/esm/lib/xml/build-merged-sheet.js +2 -2
- package/build/esm/lib/xml/extract-rows-from-sheet.js +1 -0
- package/build/esm/lib/zip/read-sync.js +16 -19
- package/build/esm/lib/zip/read.js +15 -18
- package/build/esm/package.json +3 -0
- package/build/types/lib/merge-sheets-to-base-file-process.d.ts +2 -2
- package/build/types/lib/merge-sheets-to-base-file-sync.d.ts +0 -2
- package/build/types/lib/merge-sheets-to-base-file.d.ts +0 -2
- package/build/types/lib/utils/is-same-buffer.d.ts +0 -2
- package/build/types/lib/utils/remove-sheet-by-name.d.ts +1 -1
- package/build/types/lib/xml/build-merged-sheet.d.ts +2 -2
- package/build/types/lib/xml/extract-rows-from-sheet.d.ts +1 -2
- package/build/types/lib/xml/extract-xml-from-sheet.d.ts +0 -2
- package/build/types/lib/xml/extract-xml-from-system-content.d.ts +0 -2
- package/build/types/lib/zip/constants.d.ts +3 -5
- package/build/types/lib/zip/create-sync.d.ts +0 -2
- package/build/types/lib/zip/create.d.ts +0 -2
- package/build/types/lib/zip/read-sync.d.ts +2 -4
- package/build/types/lib/zip/read.d.ts +2 -4
- package/build/types/lib/zip/utils.d.ts +0 -2
- package/package.json +9 -4
@@ -15,15 +15,25 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
15
15
|
}) : function(o, v) {
|
16
16
|
o["default"] = v;
|
17
17
|
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
};
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
exports.mergeSheetsToBaseFileProcess =
|
36
|
+
exports.mergeSheetsToBaseFileProcess = mergeSheetsToBaseFileProcess;
|
27
37
|
const Utils = __importStar(require("./utils/index.js"));
|
28
38
|
const Xml = __importStar(require("./xml/index.js"));
|
29
39
|
/**
|
@@ -48,7 +58,7 @@ function mergeSheetsToBaseFileProcess(data) {
|
|
48
58
|
if (!baseFiles[basePath]) {
|
49
59
|
throw new Error(`Base file does not contain ${basePath}`);
|
50
60
|
}
|
51
|
-
const { lastRowNumber, mergeCells: baseMergeCells, rows: baseRows, } = Xml.extractRowsFromSheet(baseFiles[basePath]);
|
61
|
+
const { lastRowNumber, mergeCells: baseMergeCells, rows: baseRows, xml, } = Xml.extractRowsFromSheet(baseFiles[basePath]);
|
52
62
|
const allRows = [...baseRows];
|
53
63
|
const allMergeCells = [...baseMergeCells];
|
54
64
|
let currentRowOffset = lastRowNumber + gap;
|
@@ -74,23 +84,22 @@ function mergeSheetsToBaseFileProcess(data) {
|
|
74
84
|
currentRowOffset += Utils.getMaxRowNumber(rows) + gap;
|
75
85
|
}
|
76
86
|
}
|
77
|
-
const mergedXml = Xml.buildMergedSheet(
|
87
|
+
const mergedXml = Xml.buildMergedSheet(xml, allRows, allMergeCells);
|
78
88
|
baseFiles[basePath] = mergedXml;
|
79
89
|
for (const sheetIndex of sheetsToRemove) {
|
80
90
|
const sheetPath = `xl/worksheets/sheet${sheetIndex}.xml`;
|
81
91
|
delete baseFiles[sheetPath];
|
82
92
|
if (baseFiles["xl/workbook.xml"]) {
|
83
|
-
baseFiles["xl/workbook.xml"] = Utils.removeSheetFromWorkbook(baseFiles["xl/workbook.xml"], sheetIndex);
|
93
|
+
baseFiles["xl/workbook.xml"] = Buffer.from(Utils.removeSheetFromWorkbook(baseFiles["xl/workbook.xml"].toString(), sheetIndex));
|
84
94
|
}
|
85
95
|
if (baseFiles["xl/_rels/workbook.xml.rels"]) {
|
86
|
-
baseFiles["xl/_rels/workbook.xml.rels"] = Utils.removeSheetFromRels(baseFiles["xl/_rels/workbook.xml.rels"], sheetIndex);
|
96
|
+
baseFiles["xl/_rels/workbook.xml.rels"] = Buffer.from(Utils.removeSheetFromRels(baseFiles["xl/_rels/workbook.xml.rels"].toString(), sheetIndex));
|
87
97
|
}
|
88
98
|
if (baseFiles["[Content_Types].xml"]) {
|
89
|
-
baseFiles["[Content_Types].xml"] = Utils.removeSheetFromContentTypes(baseFiles["[Content_Types].xml"], sheetIndex);
|
99
|
+
baseFiles["[Content_Types].xml"] = Buffer.from(Utils.removeSheetFromContentTypes(baseFiles["[Content_Types].xml"].toString(), sheetIndex));
|
90
100
|
}
|
91
101
|
}
|
92
102
|
for (const sheetName of sheetNamesToRemove) {
|
93
103
|
Utils.removeSheetByName(baseFiles, sheetName);
|
94
104
|
}
|
95
105
|
}
|
96
|
-
exports.mergeSheetsToBaseFileProcess = mergeSheetsToBaseFileProcess;
|
@@ -15,15 +15,25 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
15
15
|
}) : function(o, v) {
|
16
16
|
o["default"] = v;
|
17
17
|
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
};
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
exports.mergeSheetsToBaseFileSync =
|
36
|
+
exports.mergeSheetsToBaseFileSync = mergeSheetsToBaseFileSync;
|
27
37
|
const Utils = __importStar(require("./utils/index.js"));
|
28
38
|
const Zip = __importStar(require("./zip/index.js"));
|
29
39
|
const merge_sheets_to_base_file_process_js_1 = require("./merge-sheets-to-base-file-process.js");
|
@@ -65,4 +75,3 @@ function mergeSheetsToBaseFileSync(data) {
|
|
65
75
|
});
|
66
76
|
return Zip.createSync(baseFiles);
|
67
77
|
}
|
68
|
-
exports.mergeSheetsToBaseFileSync = mergeSheetsToBaseFileSync;
|
@@ -15,15 +15,25 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
15
15
|
}) : function(o, v) {
|
16
16
|
o["default"] = v;
|
17
17
|
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
};
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
19
|
+
var ownKeys = function(o) {
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
+
var ar = [];
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
+
return ar;
|
24
|
+
};
|
25
|
+
return ownKeys(o);
|
26
|
+
};
|
27
|
+
return function (mod) {
|
28
|
+
if (mod && mod.__esModule) return mod;
|
29
|
+
var result = {};
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
+
__setModuleDefault(result, mod);
|
32
|
+
return result;
|
33
|
+
};
|
34
|
+
})();
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
exports.mergeSheetsToBaseFile =
|
36
|
+
exports.mergeSheetsToBaseFile = mergeSheetsToBaseFile;
|
27
37
|
const Utils = __importStar(require("./utils/index.js"));
|
28
38
|
const Zip = __importStar(require("./zip/index.js"));
|
29
39
|
const merge_sheets_to_base_file_process_js_1 = require("./merge-sheets-to-base-file-process.js");
|
@@ -65,4 +75,3 @@ async function mergeSheetsToBaseFile(data) {
|
|
65
75
|
});
|
66
76
|
return Zip.create(baseFiles);
|
67
77
|
}
|
68
|
-
exports.mergeSheetsToBaseFile = mergeSheetsToBaseFile;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getMaxRowNumber =
|
3
|
+
exports.getMaxRowNumber = getMaxRowNumber;
|
4
4
|
/**
|
5
5
|
* Finds the maximum row number in a list of <row> elements.
|
6
6
|
* @param {string[]} rows - An array of strings, each representing a <row> element.
|
@@ -20,4 +20,3 @@ function getMaxRowNumber(rows) {
|
|
20
20
|
}
|
21
21
|
return max;
|
22
22
|
}
|
23
|
-
exports.getMaxRowNumber = getMaxRowNumber;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.isSameBuffer =
|
3
|
+
exports.isSameBuffer = isSameBuffer;
|
4
4
|
/**
|
5
5
|
* Checks if two Buffers are the same
|
6
6
|
* @param {Buffer} buf1 - the first Buffer
|
@@ -10,4 +10,3 @@ exports.isSameBuffer = void 0;
|
|
10
10
|
function isSameBuffer(buf1, buf2) {
|
11
11
|
return buf1.equals(buf2);
|
12
12
|
}
|
13
|
-
exports.isSameBuffer = isSameBuffer;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.removeSheetByName =
|
3
|
+
exports.removeSheetByName = removeSheetByName;
|
4
4
|
/**
|
5
5
|
* Removes a sheet from the Excel workbook by name.
|
6
6
|
* @param {Object.<string, string | Buffer>} files - The dictionary of files in the workbook.
|
@@ -8,8 +8,8 @@ exports.removeSheetByName = void 0;
|
|
8
8
|
* @returns {void}
|
9
9
|
*/
|
10
10
|
function removeSheetByName(files, sheetName) {
|
11
|
-
const workbookXml = files["xl/workbook.xml"];
|
12
|
-
const relsXml = files["xl/_rels/workbook.xml.rels"];
|
11
|
+
const workbookXml = files["xl/workbook.xml"]?.toString();
|
12
|
+
const relsXml = files["xl/_rels/workbook.xml.rels"]?.toString();
|
13
13
|
if (!workbookXml || !relsXml) {
|
14
14
|
return;
|
15
15
|
}
|
@@ -34,12 +34,13 @@ function removeSheetByName(files, sheetName) {
|
|
34
34
|
return;
|
35
35
|
}
|
36
36
|
const targetPath = `xl/${targetMatch[1]}`.replace(/\\/g, "/");
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
if (targetPath) {
|
38
|
+
delete files[targetPath];
|
39
|
+
}
|
40
|
+
files["xl/workbook.xml"] = Buffer.from(workbookXml.replace(sheetTag, ""));
|
41
|
+
files["xl/_rels/workbook.xml.rels"] = Buffer.from(relsXml.replace(relTag, ""));
|
42
|
+
const contentTypes = files["[Content_Types].xml"]?.toString();
|
41
43
|
if (contentTypes) {
|
42
|
-
files["[Content_Types].xml"] = contentTypes.replace(new RegExp(`<Override[^>]+PartName=["']/${targetPath}["'][^>]*/>`, "g"), "");
|
44
|
+
files["[Content_Types].xml"] = Buffer.from(contentTypes.replace(new RegExp(`<Override[^>]+PartName=["']/${targetPath}["'][^>]*/>`, "g"), ""));
|
43
45
|
}
|
44
46
|
}
|
45
|
-
exports.removeSheetByName = removeSheetByName;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.removeSheetFromContentTypes =
|
3
|
+
exports.removeSheetFromContentTypes = removeSheetFromContentTypes;
|
4
4
|
/**
|
5
5
|
* Removes the specified sheet from the Content_Types.xml file.
|
6
6
|
* @param {string} xml - The Content_Types.xml file contents as a string
|
@@ -10,4 +10,3 @@ exports.removeSheetFromContentTypes = void 0;
|
|
10
10
|
function removeSheetFromContentTypes(xml, sheetIndex) {
|
11
11
|
return xml.replace(new RegExp(`<Override[^>]+PartName=["']/xl/worksheets/sheet${sheetIndex}\\.xml["'][^>]*/>`, "g"), "");
|
12
12
|
}
|
13
|
-
exports.removeSheetFromContentTypes = removeSheetFromContentTypes;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.removeSheetFromRels =
|
3
|
+
exports.removeSheetFromRels = removeSheetFromRels;
|
4
4
|
/**
|
5
5
|
* Removes the specified sheet from the workbook relationships file (xl/_rels/workbook.xml.rels).
|
6
6
|
* @param {string} xml - The workbook relationships file contents as a string
|
@@ -10,4 +10,3 @@ exports.removeSheetFromRels = void 0;
|
|
10
10
|
function removeSheetFromRels(xml, sheetIndex) {
|
11
11
|
return xml.replace(new RegExp(`<Relationship[^>]+Target=["']worksheets/sheet${sheetIndex}\\.xml["'][^>]*/>`, "g"), "");
|
12
12
|
}
|
13
|
-
exports.removeSheetFromRels = removeSheetFromRels;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.removeSheetFromWorkbook =
|
3
|
+
exports.removeSheetFromWorkbook = removeSheetFromWorkbook;
|
4
4
|
/**
|
5
5
|
* Removes the specified sheet from the workbook (xl/workbook.xml).
|
6
6
|
* @param {string} xml - The workbook file contents as a string
|
@@ -10,4 +10,3 @@ exports.removeSheetFromWorkbook = void 0;
|
|
10
10
|
function removeSheetFromWorkbook(xml, sheetIndex) {
|
11
11
|
return xml.replace(new RegExp(`<sheet[^>]+sheetId=["']${sheetIndex}["'][^>]*/>`, "g"), "");
|
12
12
|
}
|
13
|
-
exports.removeSheetFromWorkbook = removeSheetFromWorkbook;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.shiftCellRef =
|
3
|
+
exports.shiftCellRef = shiftCellRef;
|
4
4
|
/**
|
5
5
|
* Shifts the row number in a cell reference by the specified number of rows.
|
6
6
|
* The function takes a cell reference string in the format "A1" and a row shift value.
|
@@ -23,4 +23,3 @@ function shiftCellRef(cellRef, rowShift) {
|
|
23
23
|
const row = parseInt(match[2], 10);
|
24
24
|
return `${col}${row + rowShift}`;
|
25
25
|
}
|
26
|
-
exports.shiftCellRef = shiftCellRef;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.buildMergedSheet =
|
3
|
+
exports.buildMergedSheet = buildMergedSheet;
|
4
4
|
/**
|
5
5
|
* Builds a new XML string for a merged Excel sheet by combining the original XML
|
6
6
|
* with merged rows and optional cell merge information.
|
@@ -12,7 +12,7 @@ exports.buildMergedSheet = void 0;
|
|
12
12
|
* @param {string[]} mergedRows - Array of XML strings representing each row in the merged sheet.
|
13
13
|
* @param {Object[]} [mergeCells] - Optional array of merge cell definitions.
|
14
14
|
* Each object should have a 'ref' property specifying the merge range (e.g., "A1:B2").
|
15
|
-
* @returns {
|
15
|
+
* @returns {Buffer} - The reconstructed XML string with merged content.
|
16
16
|
*/
|
17
17
|
function buildMergedSheet(originalXml, mergedRows, mergeCells = []) {
|
18
18
|
// Remove any existing <mergeCells> section from the XML
|
@@ -27,6 +27,5 @@ function buildMergedSheet(originalXml, mergedRows, mergeCells = []) {
|
|
27
27
|
// Insert <mergeCells> after </sheetData> and before the next XML tag
|
28
28
|
xmlData = xmlData.replace(/(<\/sheetData>)(\s*<)/, `$1\n${mergeCellsXml}\n$2`);
|
29
29
|
}
|
30
|
-
return xmlData;
|
30
|
+
return Buffer.from(xmlData);
|
31
31
|
}
|
32
|
-
exports.buildMergedSheet = buildMergedSheet;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.extractRowsFromSheet =
|
3
|
+
exports.extractRowsFromSheet = extractRowsFromSheet;
|
4
4
|
const extract_xml_from_sheet_js_1 = require("./extract-xml-from-sheet.js");
|
5
5
|
/**
|
6
6
|
* Parses a worksheet (either as Buffer or string) to extract row data,
|
@@ -60,6 +60,6 @@ function extractRowsFromSheet(sheet) {
|
|
60
60
|
lastRowNumber,
|
61
61
|
mergeCells,
|
62
62
|
rows,
|
63
|
+
xml,
|
63
64
|
};
|
64
65
|
}
|
65
|
-
exports.extractRowsFromSheet = extractRowsFromSheet;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.extractXmlFromSheet =
|
3
|
+
exports.extractXmlFromSheet = extractXmlFromSheet;
|
4
4
|
const pako_1 = require("pako");
|
5
5
|
/**
|
6
6
|
* Extracts and parses XML content from an Excel worksheet file (e.g., xl/worksheets/sheet1.xml).
|
@@ -46,4 +46,3 @@ function extractXmlFromSheet(buffer) {
|
|
46
46
|
xml = xml.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, "");
|
47
47
|
return xml;
|
48
48
|
}
|
49
|
-
exports.extractXmlFromSheet = extractXmlFromSheet;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.shiftRowIndices =
|
3
|
+
exports.shiftRowIndices = shiftRowIndices;
|
4
4
|
/**
|
5
5
|
* Adjusts row indices in Excel XML row elements by a specified offset.
|
6
6
|
* Handles both row element attributes and cell references within rows.
|
@@ -33,4 +33,3 @@ function shiftRowIndices(rows, offset) {
|
|
33
33
|
return adjustedRow;
|
34
34
|
});
|
35
35
|
}
|
36
|
-
exports.shiftRowIndices = shiftRowIndices;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.createSync =
|
3
|
+
exports.createSync = createSync;
|
4
4
|
const node_buffer_1 = require("node:buffer");
|
5
5
|
const node_zlib_1 = require("node:zlib");
|
6
6
|
const utils_js_1 = require("./utils.js");
|
@@ -81,4 +81,3 @@ function createSync(files) {
|
|
81
81
|
]);
|
82
82
|
return node_buffer_1.Buffer.concat(fileEntries.concat(centralDirectory).concat([endRecord]));
|
83
83
|
}
|
84
|
-
exports.createSync = createSync;
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.create =
|
6
|
+
exports.create = create;
|
7
7
|
const node_buffer_1 = require("node:buffer");
|
8
8
|
const node_util_1 = __importDefault(require("node:util"));
|
9
9
|
const node_zlib_1 = __importDefault(require("node:zlib"));
|
@@ -86,4 +86,3 @@ async function create(files) {
|
|
86
86
|
]);
|
87
87
|
return node_buffer_1.Buffer.concat(fileEntries.concat(centralDirectory).concat([endRecord]));
|
88
88
|
}
|
89
|
-
exports.create = create;
|
@@ -1,45 +1,45 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.readSync =
|
4
|
-
const node_zlib_1 = require("node:zlib");
|
6
|
+
exports.readSync = readSync;
|
7
|
+
const node_zlib_1 = __importDefault(require("node:zlib"));
|
5
8
|
/**
|
6
9
|
* Parses a ZIP archive from a buffer and extracts the files within.
|
7
10
|
*
|
8
11
|
* @param {Buffer} buffer - The buffer containing the ZIP archive data.
|
9
|
-
* @returns {Object.<string,
|
12
|
+
* @returns {Object.<string, Buffer>} - An object where keys are file names and values are file contents as Buffers.
|
10
13
|
* @throws {Error} - Throws an error if an unsupported compression method is encountered or if decompression fails.
|
11
14
|
*/
|
12
15
|
function readSync(buffer) {
|
13
16
|
const files = {};
|
14
17
|
let offset = 0;
|
15
|
-
while (offset +
|
18
|
+
while (offset + 30 <= buffer.length) {
|
16
19
|
const signature = buffer.readUInt32LE(offset);
|
17
20
|
if (signature !== 0x04034b50)
|
18
|
-
break;
|
21
|
+
break; // not a local file header
|
22
|
+
const generalPurposeBitFlag = buffer.readUInt16LE(offset + 6);
|
19
23
|
const compressionMethod = buffer.readUInt16LE(offset + 8);
|
20
24
|
const fileNameLength = buffer.readUInt16LE(offset + 26);
|
21
|
-
const
|
25
|
+
const extraFieldLength = buffer.readUInt16LE(offset + 28);
|
22
26
|
const fileNameStart = offset + 30;
|
23
27
|
const fileNameEnd = fileNameStart + fileNameLength;
|
24
28
|
const fileName = buffer.subarray(fileNameStart, fileNameEnd).toString();
|
25
|
-
const dataStart = fileNameEnd +
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
nextOffset++;
|
31
|
-
}
|
32
|
-
if (nextOffset + 4 > buffer.length) {
|
33
|
-
nextOffset = buffer.length;
|
29
|
+
const dataStart = fileNameEnd + extraFieldLength;
|
30
|
+
const compressedSize = buffer.readUInt32LE(offset + 18);
|
31
|
+
const useDataDescriptor = (generalPurposeBitFlag & 0x08) !== 0;
|
32
|
+
if (useDataDescriptor) {
|
33
|
+
throw new Error(`File ${fileName} uses data descriptor. Not supported in this minimal parser.`);
|
34
34
|
}
|
35
|
-
const compressedData = buffer.subarray(dataStart,
|
36
|
-
let content
|
35
|
+
const compressedData = buffer.subarray(dataStart, dataStart + compressedSize);
|
36
|
+
let content;
|
37
37
|
try {
|
38
38
|
if (compressionMethod === 0) {
|
39
|
-
content = compressedData
|
39
|
+
content = compressedData;
|
40
40
|
}
|
41
41
|
else if (compressionMethod === 8) {
|
42
|
-
content =
|
42
|
+
content = node_zlib_1.default.inflateRawSync(compressedData);
|
43
43
|
}
|
44
44
|
else {
|
45
45
|
throw new Error(`Unsupported compression method ${compressionMethod}`);
|
@@ -50,8 +50,7 @@ function readSync(buffer) {
|
|
50
50
|
throw new Error(`Error unpacking file ${fileName}: ${message}`);
|
51
51
|
}
|
52
52
|
files[fileName] = content;
|
53
|
-
offset =
|
53
|
+
offset = dataStart + compressedSize;
|
54
54
|
}
|
55
55
|
return files;
|
56
56
|
}
|
57
|
-
exports.readSync = readSync;
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.read =
|
6
|
+
exports.read = read;
|
7
7
|
const node_util_1 = __importDefault(require("node:util"));
|
8
8
|
const node_zlib_1 = __importDefault(require("node:zlib"));
|
9
9
|
const inflateRaw = node_util_1.default.promisify(node_zlib_1.default.inflateRaw);
|
@@ -11,40 +11,37 @@ const inflateRaw = node_util_1.default.promisify(node_zlib_1.default.inflateRaw)
|
|
11
11
|
* Parses a ZIP archive from a buffer and extracts the files within.
|
12
12
|
*
|
13
13
|
* @param {Buffer} buffer - The buffer containing the ZIP archive data.
|
14
|
-
* @returns {Object.<string,
|
14
|
+
* @returns {Object.<string, Buffer>} - An object where keys are file names and values are file contents as Buffers.
|
15
15
|
* @throws {Error} - Throws an error if an unsupported compression method is encountered or if decompression fails.
|
16
16
|
*/
|
17
17
|
async function read(buffer) {
|
18
18
|
const files = {};
|
19
19
|
let offset = 0;
|
20
|
-
while (offset +
|
20
|
+
while (offset + 30 <= buffer.length) {
|
21
21
|
const signature = buffer.readUInt32LE(offset);
|
22
22
|
if (signature !== 0x04034b50)
|
23
|
-
break;
|
23
|
+
break; // not a local file header
|
24
|
+
const generalPurposeBitFlag = buffer.readUInt16LE(offset + 6);
|
24
25
|
const compressionMethod = buffer.readUInt16LE(offset + 8);
|
25
26
|
const fileNameLength = buffer.readUInt16LE(offset + 26);
|
26
|
-
const
|
27
|
+
const extraFieldLength = buffer.readUInt16LE(offset + 28);
|
27
28
|
const fileNameStart = offset + 30;
|
28
29
|
const fileNameEnd = fileNameStart + fileNameLength;
|
29
30
|
const fileName = buffer.subarray(fileNameStart, fileNameEnd).toString();
|
30
|
-
const dataStart = fileNameEnd +
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
nextOffset++;
|
36
|
-
}
|
37
|
-
if (nextOffset + 4 > buffer.length) {
|
38
|
-
nextOffset = buffer.length;
|
31
|
+
const dataStart = fileNameEnd + extraFieldLength;
|
32
|
+
const compressedSize = buffer.readUInt32LE(offset + 18);
|
33
|
+
const useDataDescriptor = (generalPurposeBitFlag & 0x08) !== 0;
|
34
|
+
if (useDataDescriptor) {
|
35
|
+
throw new Error(`File ${fileName} uses data descriptor. Not supported in this minimal parser.`);
|
39
36
|
}
|
40
|
-
const compressedData = buffer.subarray(dataStart,
|
41
|
-
let content
|
37
|
+
const compressedData = buffer.subarray(dataStart, dataStart + compressedSize);
|
38
|
+
let content;
|
42
39
|
try {
|
43
40
|
if (compressionMethod === 0) {
|
44
|
-
content = compressedData
|
41
|
+
content = compressedData;
|
45
42
|
}
|
46
43
|
else if (compressionMethod === 8) {
|
47
|
-
content =
|
44
|
+
content = await inflateRaw(compressedData);
|
48
45
|
}
|
49
46
|
else {
|
50
47
|
throw new Error(`Unsupported compression method ${compressionMethod}`);
|
@@ -55,8 +52,7 @@ async function read(buffer) {
|
|
55
52
|
throw new Error(`Error unpacking file ${fileName}: ${message}`);
|
56
53
|
}
|
57
54
|
files[fileName] = content;
|
58
|
-
offset =
|
55
|
+
offset = dataStart + compressedSize;
|
59
56
|
}
|
60
57
|
return files;
|
61
58
|
}
|
62
|
-
exports.read = read;
|
@@ -1,6 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.crc32 = crc32;
|
4
|
+
exports.dosTime = dosTime;
|
5
|
+
exports.toBytes = toBytes;
|
4
6
|
const node_buffer_1 = require("node:buffer");
|
5
7
|
/**
|
6
8
|
* Precomputed CRC-32 lookup table for optimized checksum calculation.
|
@@ -75,7 +77,6 @@ function crc32(buf) {
|
|
75
77
|
*/
|
76
78
|
return ~crc >>> 0;
|
77
79
|
}
|
78
|
-
exports.crc32 = crc32;
|
79
80
|
/**
|
80
81
|
* Converts a JavaScript Date object to a 4-byte Buffer in MS-DOS date/time format
|
81
82
|
* as specified in the ZIP file format specification (PKZIP APPNOTE.TXT).
|
@@ -121,7 +122,6 @@ function dosTime(date) {
|
|
121
122
|
...toBytes(day, 2), // Convert date to 2 bytes (LSB first)
|
122
123
|
]);
|
123
124
|
}
|
124
|
-
exports.dosTime = dosTime;
|
125
125
|
/**
|
126
126
|
* Converts a numeric value into a fixed-length Buffer representation,
|
127
127
|
* storing the value in little-endian format with right-padding of zeros.
|
@@ -155,4 +155,3 @@ function toBytes(value, len) {
|
|
155
155
|
}
|
156
156
|
return buf;
|
157
157
|
}
|
158
|
-
exports.toBytes = toBytes;
|
@@ -22,7 +22,7 @@ export function mergeSheetsToBaseFileProcess(data) {
|
|
22
22
|
if (!baseFiles[basePath]) {
|
23
23
|
throw new Error(`Base file does not contain ${basePath}`);
|
24
24
|
}
|
25
|
-
const { lastRowNumber, mergeCells: baseMergeCells, rows: baseRows, } = Xml.extractRowsFromSheet(baseFiles[basePath]);
|
25
|
+
const { lastRowNumber, mergeCells: baseMergeCells, rows: baseRows, xml, } = Xml.extractRowsFromSheet(baseFiles[basePath]);
|
26
26
|
const allRows = [...baseRows];
|
27
27
|
const allMergeCells = [...baseMergeCells];
|
28
28
|
let currentRowOffset = lastRowNumber + gap;
|
@@ -48,19 +48,19 @@ export function mergeSheetsToBaseFileProcess(data) {
|
|
48
48
|
currentRowOffset += Utils.getMaxRowNumber(rows) + gap;
|
49
49
|
}
|
50
50
|
}
|
51
|
-
const mergedXml = Xml.buildMergedSheet(
|
51
|
+
const mergedXml = Xml.buildMergedSheet(xml, allRows, allMergeCells);
|
52
52
|
baseFiles[basePath] = mergedXml;
|
53
53
|
for (const sheetIndex of sheetsToRemove) {
|
54
54
|
const sheetPath = `xl/worksheets/sheet${sheetIndex}.xml`;
|
55
55
|
delete baseFiles[sheetPath];
|
56
56
|
if (baseFiles["xl/workbook.xml"]) {
|
57
|
-
baseFiles["xl/workbook.xml"] = Utils.removeSheetFromWorkbook(baseFiles["xl/workbook.xml"], sheetIndex);
|
57
|
+
baseFiles["xl/workbook.xml"] = Buffer.from(Utils.removeSheetFromWorkbook(baseFiles["xl/workbook.xml"].toString(), sheetIndex));
|
58
58
|
}
|
59
59
|
if (baseFiles["xl/_rels/workbook.xml.rels"]) {
|
60
|
-
baseFiles["xl/_rels/workbook.xml.rels"] = Utils.removeSheetFromRels(baseFiles["xl/_rels/workbook.xml.rels"], sheetIndex);
|
60
|
+
baseFiles["xl/_rels/workbook.xml.rels"] = Buffer.from(Utils.removeSheetFromRels(baseFiles["xl/_rels/workbook.xml.rels"].toString(), sheetIndex));
|
61
61
|
}
|
62
62
|
if (baseFiles["[Content_Types].xml"]) {
|
63
|
-
baseFiles["[Content_Types].xml"] = Utils.removeSheetFromContentTypes(baseFiles["[Content_Types].xml"], sheetIndex);
|
63
|
+
baseFiles["[Content_Types].xml"] = Buffer.from(Utils.removeSheetFromContentTypes(baseFiles["[Content_Types].xml"].toString(), sheetIndex));
|
64
64
|
}
|
65
65
|
}
|
66
66
|
for (const sheetName of sheetNamesToRemove) {
|
@@ -5,8 +5,8 @@
|
|
5
5
|
* @returns {void}
|
6
6
|
*/
|
7
7
|
export function removeSheetByName(files, sheetName) {
|
8
|
-
const workbookXml = files["xl/workbook.xml"];
|
9
|
-
const relsXml = files["xl/_rels/workbook.xml.rels"];
|
8
|
+
const workbookXml = files["xl/workbook.xml"]?.toString();
|
9
|
+
const relsXml = files["xl/_rels/workbook.xml.rels"]?.toString();
|
10
10
|
if (!workbookXml || !relsXml) {
|
11
11
|
return;
|
12
12
|
}
|
@@ -31,11 +31,13 @@ export function removeSheetByName(files, sheetName) {
|
|
31
31
|
return;
|
32
32
|
}
|
33
33
|
const targetPath = `xl/${targetMatch[1]}`.replace(/\\/g, "/");
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
if (targetPath) {
|
35
|
+
delete files[targetPath];
|
36
|
+
}
|
37
|
+
files["xl/workbook.xml"] = Buffer.from(workbookXml.replace(sheetTag, ""));
|
38
|
+
files["xl/_rels/workbook.xml.rels"] = Buffer.from(relsXml.replace(relTag, ""));
|
39
|
+
const contentTypes = files["[Content_Types].xml"]?.toString();
|
38
40
|
if (contentTypes) {
|
39
|
-
files["[Content_Types].xml"] = contentTypes.replace(new RegExp(`<Override[^>]+PartName=["']/${targetPath}["'][^>]*/>`, "g"), "");
|
41
|
+
files["[Content_Types].xml"] = Buffer.from(contentTypes.replace(new RegExp(`<Override[^>]+PartName=["']/${targetPath}["'][^>]*/>`, "g"), ""));
|
40
42
|
}
|
41
43
|
}
|
@@ -9,7 +9,7 @@
|
|
9
9
|
* @param {string[]} mergedRows - Array of XML strings representing each row in the merged sheet.
|
10
10
|
* @param {Object[]} [mergeCells] - Optional array of merge cell definitions.
|
11
11
|
* Each object should have a 'ref' property specifying the merge range (e.g., "A1:B2").
|
12
|
-
* @returns {
|
12
|
+
* @returns {Buffer} - The reconstructed XML string with merged content.
|
13
13
|
*/
|
14
14
|
export function buildMergedSheet(originalXml, mergedRows, mergeCells = []) {
|
15
15
|
// Remove any existing <mergeCells> section from the XML
|
@@ -24,5 +24,5 @@ export function buildMergedSheet(originalXml, mergedRows, mergeCells = []) {
|
|
24
24
|
// Insert <mergeCells> after </sheetData> and before the next XML tag
|
25
25
|
xmlData = xmlData.replace(/(<\/sheetData>)(\s*<)/, `$1\n${mergeCellsXml}\n$2`);
|
26
26
|
}
|
27
|
-
return xmlData;
|
27
|
+
return Buffer.from(xmlData);
|
28
28
|
}
|
@@ -1,42 +1,39 @@
|
|
1
|
-
import
|
1
|
+
import zlib from "node:zlib";
|
2
2
|
/**
|
3
3
|
* Parses a ZIP archive from a buffer and extracts the files within.
|
4
4
|
*
|
5
5
|
* @param {Buffer} buffer - The buffer containing the ZIP archive data.
|
6
|
-
* @returns {Object.<string,
|
6
|
+
* @returns {Object.<string, Buffer>} - An object where keys are file names and values are file contents as Buffers.
|
7
7
|
* @throws {Error} - Throws an error if an unsupported compression method is encountered or if decompression fails.
|
8
8
|
*/
|
9
9
|
export function readSync(buffer) {
|
10
10
|
const files = {};
|
11
11
|
let offset = 0;
|
12
|
-
while (offset +
|
12
|
+
while (offset + 30 <= buffer.length) {
|
13
13
|
const signature = buffer.readUInt32LE(offset);
|
14
14
|
if (signature !== 0x04034b50)
|
15
|
-
break;
|
15
|
+
break; // not a local file header
|
16
|
+
const generalPurposeBitFlag = buffer.readUInt16LE(offset + 6);
|
16
17
|
const compressionMethod = buffer.readUInt16LE(offset + 8);
|
17
18
|
const fileNameLength = buffer.readUInt16LE(offset + 26);
|
18
|
-
const
|
19
|
+
const extraFieldLength = buffer.readUInt16LE(offset + 28);
|
19
20
|
const fileNameStart = offset + 30;
|
20
21
|
const fileNameEnd = fileNameStart + fileNameLength;
|
21
22
|
const fileName = buffer.subarray(fileNameStart, fileNameEnd).toString();
|
22
|
-
const dataStart = fileNameEnd +
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
nextOffset++;
|
23
|
+
const dataStart = fileNameEnd + extraFieldLength;
|
24
|
+
const compressedSize = buffer.readUInt32LE(offset + 18);
|
25
|
+
const useDataDescriptor = (generalPurposeBitFlag & 0x08) !== 0;
|
26
|
+
if (useDataDescriptor) {
|
27
|
+
throw new Error(`File ${fileName} uses data descriptor. Not supported in this minimal parser.`);
|
28
28
|
}
|
29
|
-
|
30
|
-
|
31
|
-
}
|
32
|
-
const compressedData = buffer.subarray(dataStart, nextOffset);
|
33
|
-
let content = "";
|
29
|
+
const compressedData = buffer.subarray(dataStart, dataStart + compressedSize);
|
30
|
+
let content;
|
34
31
|
try {
|
35
32
|
if (compressionMethod === 0) {
|
36
|
-
content = compressedData
|
33
|
+
content = compressedData;
|
37
34
|
}
|
38
35
|
else if (compressionMethod === 8) {
|
39
|
-
content = inflateRawSync(
|
36
|
+
content = zlib.inflateRawSync(compressedData);
|
40
37
|
}
|
41
38
|
else {
|
42
39
|
throw new Error(`Unsupported compression method ${compressionMethod}`);
|
@@ -47,7 +44,7 @@ export function readSync(buffer) {
|
|
47
44
|
throw new Error(`Error unpacking file ${fileName}: ${message}`);
|
48
45
|
}
|
49
46
|
files[fileName] = content;
|
50
|
-
offset =
|
47
|
+
offset = dataStart + compressedSize;
|
51
48
|
}
|
52
49
|
return files;
|
53
50
|
}
|
@@ -5,40 +5,37 @@ const inflateRaw = util.promisify(zlib.inflateRaw);
|
|
5
5
|
* Parses a ZIP archive from a buffer and extracts the files within.
|
6
6
|
*
|
7
7
|
* @param {Buffer} buffer - The buffer containing the ZIP archive data.
|
8
|
-
* @returns {Object.<string,
|
8
|
+
* @returns {Object.<string, Buffer>} - An object where keys are file names and values are file contents as Buffers.
|
9
9
|
* @throws {Error} - Throws an error if an unsupported compression method is encountered or if decompression fails.
|
10
10
|
*/
|
11
11
|
export async function read(buffer) {
|
12
12
|
const files = {};
|
13
13
|
let offset = 0;
|
14
|
-
while (offset +
|
14
|
+
while (offset + 30 <= buffer.length) {
|
15
15
|
const signature = buffer.readUInt32LE(offset);
|
16
16
|
if (signature !== 0x04034b50)
|
17
|
-
break;
|
17
|
+
break; // not a local file header
|
18
|
+
const generalPurposeBitFlag = buffer.readUInt16LE(offset + 6);
|
18
19
|
const compressionMethod = buffer.readUInt16LE(offset + 8);
|
19
20
|
const fileNameLength = buffer.readUInt16LE(offset + 26);
|
20
|
-
const
|
21
|
+
const extraFieldLength = buffer.readUInt16LE(offset + 28);
|
21
22
|
const fileNameStart = offset + 30;
|
22
23
|
const fileNameEnd = fileNameStart + fileNameLength;
|
23
24
|
const fileName = buffer.subarray(fileNameStart, fileNameEnd).toString();
|
24
|
-
const dataStart = fileNameEnd +
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
nextOffset++;
|
25
|
+
const dataStart = fileNameEnd + extraFieldLength;
|
26
|
+
const compressedSize = buffer.readUInt32LE(offset + 18);
|
27
|
+
const useDataDescriptor = (generalPurposeBitFlag & 0x08) !== 0;
|
28
|
+
if (useDataDescriptor) {
|
29
|
+
throw new Error(`File ${fileName} uses data descriptor. Not supported in this minimal parser.`);
|
30
30
|
}
|
31
|
-
|
32
|
-
|
33
|
-
}
|
34
|
-
const compressedData = buffer.subarray(dataStart, nextOffset);
|
35
|
-
let content = "";
|
31
|
+
const compressedData = buffer.subarray(dataStart, dataStart + compressedSize);
|
32
|
+
let content;
|
36
33
|
try {
|
37
34
|
if (compressionMethod === 0) {
|
38
|
-
content = compressedData
|
35
|
+
content = compressedData;
|
39
36
|
}
|
40
37
|
else if (compressionMethod === 8) {
|
41
|
-
content =
|
38
|
+
content = await inflateRaw(compressedData);
|
42
39
|
}
|
43
40
|
else {
|
44
41
|
throw new Error(`Unsupported compression method ${compressionMethod}`);
|
@@ -49,7 +46,7 @@ export async function read(buffer) {
|
|
49
46
|
throw new Error(`Error unpacking file ${fileName}: ${message}`);
|
50
47
|
}
|
51
48
|
files[fileName] = content;
|
52
|
-
offset =
|
49
|
+
offset = dataStart + compressedSize;
|
53
50
|
}
|
54
51
|
return files;
|
55
52
|
}
|
@@ -16,10 +16,10 @@
|
|
16
16
|
*/
|
17
17
|
export declare function mergeSheetsToBaseFileProcess(data: {
|
18
18
|
additions: {
|
19
|
-
files: Record<string,
|
19
|
+
files: Record<string, Buffer>;
|
20
20
|
sheetIndexes: number[];
|
21
21
|
}[];
|
22
|
-
baseFiles: Record<string,
|
22
|
+
baseFiles: Record<string, Buffer>;
|
23
23
|
baseSheetIndex: number;
|
24
24
|
gap: number;
|
25
25
|
sheetNamesToRemove: string[];
|
@@ -4,4 +4,4 @@
|
|
4
4
|
* @param {string} sheetName - The name of the sheet to remove.
|
5
5
|
* @returns {void}
|
6
6
|
*/
|
7
|
-
export declare function removeSheetByName(files: Record<string,
|
7
|
+
export declare function removeSheetByName(files: Record<string, Buffer>, sheetName: string): void;
|
@@ -9,8 +9,8 @@
|
|
9
9
|
* @param {string[]} mergedRows - Array of XML strings representing each row in the merged sheet.
|
10
10
|
* @param {Object[]} [mergeCells] - Optional array of merge cell definitions.
|
11
11
|
* Each object should have a 'ref' property specifying the merge range (e.g., "A1:B2").
|
12
|
-
* @returns {
|
12
|
+
* @returns {Buffer} - The reconstructed XML string with merged content.
|
13
13
|
*/
|
14
14
|
export declare function buildMergedSheet(originalXml: string, mergedRows: string[], mergeCells?: {
|
15
15
|
ref: string;
|
16
|
-
}[]):
|
16
|
+
}[]): Buffer;
|
@@ -1,5 +1,3 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
/// <reference types="node" />
|
3
1
|
/**
|
4
2
|
* Parses a worksheet (either as Buffer or string) to extract row data,
|
5
3
|
* last row number, and merge cell information from Excel XML format.
|
@@ -26,4 +24,5 @@ export declare function extractRowsFromSheet(sheet: Buffer | string): {
|
|
26
24
|
mergeCells: {
|
27
25
|
ref: string;
|
28
26
|
}[];
|
27
|
+
xml: string;
|
29
28
|
};
|
@@ -1,5 +1,3 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
/// <reference types="node" />
|
3
1
|
/**
|
4
2
|
* Extracts and decompresses XML content from Excel system files (e.g., workbook.xml, [Content_Types].xml).
|
5
3
|
* Handles both compressed (raw DEFLATE) and uncompressed (plain XML) formats with comprehensive error handling.
|
@@ -1,5 +1,3 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
/// <reference types="node" />
|
3
1
|
import { Buffer } from "node:buffer";
|
4
2
|
/**
|
5
3
|
* ZIP file signature constants in Buffer format.
|
@@ -13,7 +11,7 @@ import { Buffer } from "node:buffer";
|
|
13
11
|
* Format: 'PK\01\02'
|
14
12
|
* Found in the central directory that appears at the end of the ZIP file.
|
15
13
|
*/
|
16
|
-
export declare const CENTRAL_DIR_HEADER_SIG: Buffer
|
14
|
+
export declare const CENTRAL_DIR_HEADER_SIG: Buffer<ArrayBuffer>;
|
17
15
|
/**
|
18
16
|
* End of Central Directory Record signature (0x504b0506).
|
19
17
|
* Marks the end of the central directory and contains global information
|
@@ -21,11 +19,11 @@ export declare const CENTRAL_DIR_HEADER_SIG: Buffer;
|
|
21
19
|
* Format: 'PK\05\06'
|
22
20
|
* This is the last record in a valid ZIP file.
|
23
21
|
*/
|
24
|
-
export declare const END_OF_CENTRAL_DIR_SIG: Buffer
|
22
|
+
export declare const END_OF_CENTRAL_DIR_SIG: Buffer<ArrayBuffer>;
|
25
23
|
/**
|
26
24
|
* Local File Header signature (0x504b0304).
|
27
25
|
* Marks the beginning of a file entry within the ZIP archive.
|
28
26
|
* Format: 'PK\03\04' (ASCII letters PK followed by version numbers)
|
29
27
|
* Appears before each file's compressed data.
|
30
28
|
*/
|
31
|
-
export declare const LOCAL_FILE_HEADER_SIG: Buffer
|
29
|
+
export declare const LOCAL_FILE_HEADER_SIG: Buffer<ArrayBuffer>;
|
@@ -1,10 +1,8 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
/// <reference types="node" />
|
3
1
|
/**
|
4
2
|
* Parses a ZIP archive from a buffer and extracts the files within.
|
5
3
|
*
|
6
4
|
* @param {Buffer} buffer - The buffer containing the ZIP archive data.
|
7
|
-
* @returns {Object.<string,
|
5
|
+
* @returns {Object.<string, Buffer>} - An object where keys are file names and values are file contents as Buffers.
|
8
6
|
* @throws {Error} - Throws an error if an unsupported compression method is encountered or if decompression fails.
|
9
7
|
*/
|
10
|
-
export declare function readSync(buffer: Buffer): Record<string,
|
8
|
+
export declare function readSync(buffer: Buffer): Record<string, Buffer>;
|
@@ -1,10 +1,8 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
/// <reference types="node" />
|
3
1
|
/**
|
4
2
|
* Parses a ZIP archive from a buffer and extracts the files within.
|
5
3
|
*
|
6
4
|
* @param {Buffer} buffer - The buffer containing the ZIP archive data.
|
7
|
-
* @returns {Object.<string,
|
5
|
+
* @returns {Object.<string, Buffer>} - An object where keys are file names and values are file contents as Buffers.
|
8
6
|
* @throws {Error} - Throws an error if an unsupported compression method is encountered or if decompression fails.
|
9
7
|
*/
|
10
|
-
export declare function read(buffer: Buffer): Promise<Record<string,
|
8
|
+
export declare function read(buffer: Buffer): Promise<Record<string, Buffer>>;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@js-ak/excel-toolbox",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.6",
|
4
4
|
"description": "excel-toolbox",
|
5
5
|
"publishConfig": {
|
6
6
|
"access": "public",
|
@@ -12,9 +12,10 @@
|
|
12
12
|
"types": "build/types/index.d.ts",
|
13
13
|
"exports": {
|
14
14
|
".": {
|
15
|
+
"types": "./build/types/index.d.ts",
|
15
16
|
"require": "./build/cjs/index.js",
|
16
17
|
"import": "./build/esm/index.js",
|
17
|
-
"
|
18
|
+
"default": "./build/esm/index.js"
|
18
19
|
},
|
19
20
|
"./cjs": {
|
20
21
|
"require": "./build/cjs/index.js"
|
@@ -26,8 +27,10 @@
|
|
26
27
|
"files": [
|
27
28
|
"build/esm/lib",
|
28
29
|
"build/esm/index.js",
|
30
|
+
"build/esm/package.json",
|
29
31
|
"build/cjs/lib",
|
30
32
|
"build/cjs/index.js",
|
33
|
+
"build/cjs/package.json",
|
31
34
|
"build/types/lib",
|
32
35
|
"build/types/index.d.ts",
|
33
36
|
"LICENSE",
|
@@ -35,10 +38,12 @@
|
|
35
38
|
"package.json"
|
36
39
|
],
|
37
40
|
"scripts": {
|
38
|
-
"build": "npm run build:
|
41
|
+
"build": "npm run build:cjs && npm run build:esm && npm run postbuild:esm && npm run postbuild:cjs",
|
39
42
|
"build:esm": "tsc -p tsconfig.esm.json",
|
40
43
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
41
44
|
"lint": "eslint . --ext .ts",
|
45
|
+
"postbuild:esm": "node scripts/write-esm-package.js",
|
46
|
+
"postbuild:cjs": "node scripts/write-cjs-package.js",
|
42
47
|
"test": "npm run build && node ./build/esm/test/index.js"
|
43
48
|
},
|
44
49
|
"repository": {
|
@@ -69,7 +74,7 @@
|
|
69
74
|
"eslint-plugin-sort-exports": "0.9.1",
|
70
75
|
"globals": "16.0.0",
|
71
76
|
"semantic-release": "24.0.0",
|
72
|
-
"typescript": "5.
|
77
|
+
"typescript": "5.8.3",
|
73
78
|
"typescript-eslint": "8.29.0"
|
74
79
|
},
|
75
80
|
"dependencies": {
|