@js-ak/excel-toolbox 1.8.0 → 1.8.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.
- package/build/cjs/lib/template/template-memory.js +2 -1
- package/build/cjs/lib/template/utils/found-arrays-in-replacements.js +26 -0
- package/build/cjs/lib/template/utils/index.js +1 -0
- package/build/esm/lib/template/template-memory.js +2 -1
- package/build/esm/lib/template/utils/found-arrays-in-replacements.js +23 -0
- package/build/esm/lib/template/utils/index.js +1 -0
- package/build/types/lib/template/utils/found-arrays-in-replacements.d.ts +7 -0
- package/build/types/lib/template/utils/index.d.ts +1 -0
- package/package.json +1 -1
@@ -241,7 +241,8 @@ class TemplateMemory {
|
|
241
241
|
sheetContent = await this.#extractXmlFromSheet(sheetPath);
|
242
242
|
const TABLE_REGEX = /\$\{table:([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)\}/g;
|
243
243
|
const hasTablePlaceholders = TABLE_REGEX.test(sharedStringsContent) || TABLE_REGEX.test(sheetContent);
|
244
|
-
|
244
|
+
const hasArraysInReplacements = Utils.foundArraysInReplacements(replacements);
|
245
|
+
if (hasTablePlaceholders && hasArraysInReplacements) {
|
245
246
|
const result = this.#expandTableRows(sheetContent, sharedStringsContent, replacements);
|
246
247
|
sheetContent = result.sheet;
|
247
248
|
sharedStringsContent = result.shared;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
"use strict";
|
2
|
+
/**
|
3
|
+
* Recursively checks if an object contains any arrays in its values.
|
4
|
+
*
|
5
|
+
* @param {Record<string, unknown>} replacements - The object to check for arrays.
|
6
|
+
* @returns {boolean} True if any arrays are found, false otherwise.
|
7
|
+
*/
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
9
|
+
exports.foundArraysInReplacements = foundArraysInReplacements;
|
10
|
+
function foundArraysInReplacements(replacements) {
|
11
|
+
let isFound = false;
|
12
|
+
for (const key in replacements) {
|
13
|
+
const value = replacements[key];
|
14
|
+
if (Array.isArray(value)) {
|
15
|
+
isFound = true;
|
16
|
+
return isFound;
|
17
|
+
}
|
18
|
+
if (typeof value === "object" && value !== null) {
|
19
|
+
isFound = foundArraysInReplacements(value);
|
20
|
+
if (isFound) {
|
21
|
+
return isFound;
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
return isFound;
|
26
|
+
}
|
@@ -46,6 +46,7 @@ __exportStar(require("./column-index-to-letter.js"), exports);
|
|
46
46
|
__exportStar(require("./compare-columns.js"), exports);
|
47
47
|
__exportStar(require("./escape-xml.js"), exports);
|
48
48
|
__exportStar(require("./extract-xml-declaration.js"), exports);
|
49
|
+
__exportStar(require("./found-arrays-in-replacements.js"), exports);
|
49
50
|
__exportStar(require("./get-by-path.js"), exports);
|
50
51
|
__exportStar(require("./get-max-row-number.js"), exports);
|
51
52
|
__exportStar(require("./get-rows-above.js"), exports);
|
@@ -205,7 +205,8 @@ export class TemplateMemory {
|
|
205
205
|
sheetContent = await this.#extractXmlFromSheet(sheetPath);
|
206
206
|
const TABLE_REGEX = /\$\{table:([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)\}/g;
|
207
207
|
const hasTablePlaceholders = TABLE_REGEX.test(sharedStringsContent) || TABLE_REGEX.test(sheetContent);
|
208
|
-
|
208
|
+
const hasArraysInReplacements = Utils.foundArraysInReplacements(replacements);
|
209
|
+
if (hasTablePlaceholders && hasArraysInReplacements) {
|
209
210
|
const result = this.#expandTableRows(sheetContent, sharedStringsContent, replacements);
|
210
211
|
sheetContent = result.sheet;
|
211
212
|
sharedStringsContent = result.shared;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/**
|
2
|
+
* Recursively checks if an object contains any arrays in its values.
|
3
|
+
*
|
4
|
+
* @param {Record<string, unknown>} replacements - The object to check for arrays.
|
5
|
+
* @returns {boolean} True if any arrays are found, false otherwise.
|
6
|
+
*/
|
7
|
+
export function foundArraysInReplacements(replacements) {
|
8
|
+
let isFound = false;
|
9
|
+
for (const key in replacements) {
|
10
|
+
const value = replacements[key];
|
11
|
+
if (Array.isArray(value)) {
|
12
|
+
isFound = true;
|
13
|
+
return isFound;
|
14
|
+
}
|
15
|
+
if (typeof value === "object" && value !== null) {
|
16
|
+
isFound = foundArraysInReplacements(value);
|
17
|
+
if (isFound) {
|
18
|
+
return isFound;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
return isFound;
|
23
|
+
}
|
@@ -7,6 +7,7 @@ export * from "./column-index-to-letter.js";
|
|
7
7
|
export * from "./compare-columns.js";
|
8
8
|
export * from "./escape-xml.js";
|
9
9
|
export * from "./extract-xml-declaration.js";
|
10
|
+
export * from "./found-arrays-in-replacements.js";
|
10
11
|
export * from "./get-by-path.js";
|
11
12
|
export * from "./get-max-row-number.js";
|
12
13
|
export * from "./get-rows-above.js";
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/**
|
2
|
+
* Recursively checks if an object contains any arrays in its values.
|
3
|
+
*
|
4
|
+
* @param {Record<string, unknown>} replacements - The object to check for arrays.
|
5
|
+
* @returns {boolean} True if any arrays are found, false otherwise.
|
6
|
+
*/
|
7
|
+
export declare function foundArraysInReplacements(replacements: Record<string, unknown>): boolean;
|
@@ -7,6 +7,7 @@ export * from "./column-index-to-letter.js";
|
|
7
7
|
export * from "./compare-columns.js";
|
8
8
|
export * from "./escape-xml.js";
|
9
9
|
export * from "./extract-xml-declaration.js";
|
10
|
+
export * from "./found-arrays-in-replacements.js";
|
10
11
|
export * from "./get-by-path.js";
|
11
12
|
export * from "./get-max-row-number.js";
|
12
13
|
export * from "./get-rows-above.js";
|