@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.
@@ -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
- if (hasTablePlaceholders) {
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
- if (hasTablePlaceholders) {
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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@js-ak/excel-toolbox",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "excel-toolbox",
5
5
  "publishConfig": {
6
6
  "access": "public",