@js-ak/excel-toolbox 1.3.1 → 1.4.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 (30) hide show
  1. package/build/cjs/lib/template/template-fs.js +678 -197
  2. package/build/cjs/lib/template/utils/apply-replacements.js +26 -0
  3. package/build/cjs/lib/template/utils/check-row.js +6 -11
  4. package/build/cjs/lib/template/utils/column-index-to-letter.js +14 -3
  5. package/build/cjs/lib/template/utils/extract-xml-declaration.js +22 -0
  6. package/build/cjs/lib/template/utils/get-by-path.js +18 -0
  7. package/build/cjs/lib/template/utils/index.js +5 -0
  8. package/build/cjs/lib/template/utils/update-dimension.js +40 -0
  9. package/build/cjs/lib/template/utils/validate-worksheet-xml.js +217 -0
  10. package/build/cjs/lib/zip/create-with-stream.js +67 -107
  11. package/build/esm/lib/template/template-fs.js +678 -197
  12. package/build/esm/lib/template/utils/apply-replacements.js +22 -0
  13. package/build/esm/lib/template/utils/check-row.js +6 -11
  14. package/build/esm/lib/template/utils/column-index-to-letter.js +14 -3
  15. package/build/esm/lib/template/utils/extract-xml-declaration.js +19 -0
  16. package/build/esm/lib/template/utils/get-by-path.js +15 -0
  17. package/build/esm/lib/template/utils/index.js +5 -0
  18. package/build/esm/lib/template/utils/update-dimension.js +37 -0
  19. package/build/esm/lib/template/utils/validate-worksheet-xml.js +214 -0
  20. package/build/esm/lib/zip/create-with-stream.js +68 -108
  21. package/build/types/lib/template/template-fs.d.ts +24 -0
  22. package/build/types/lib/template/utils/apply-replacements.d.ts +13 -0
  23. package/build/types/lib/template/utils/check-row.d.ts +5 -10
  24. package/build/types/lib/template/utils/column-index-to-letter.d.ts +11 -3
  25. package/build/types/lib/template/utils/extract-xml-declaration.d.ts +14 -0
  26. package/build/types/lib/template/utils/get-by-path.d.ts +8 -0
  27. package/build/types/lib/template/utils/index.d.ts +5 -0
  28. package/build/types/lib/template/utils/update-dimension.d.ts +1 -0
  29. package/build/types/lib/template/utils/validate-worksheet-xml.d.ts +9 -0
  30. package/package.json +6 -4
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Replaces placeholders in the given content string with values from the replacements map.
3
+ *
4
+ * The function searches for placeholders in the format `${key}` within the content
5
+ * string, where `key` corresponds to a path in the replacements object.
6
+ * If a value is found for the key, it replaces the placeholder with the value.
7
+ * If no value is found, the original placeholder remains unchanged.
8
+ *
9
+ * @param content - The string containing placeholders to be replaced.
10
+ * @param replacements - An object where keys represent placeholder paths and values are the replacements.
11
+ * @returns A new string with placeholders replaced by corresponding values from the replacements object.
12
+ */
13
+ export declare const applyReplacements: (content: string, replacements: Record<string, unknown>) => string;
@@ -1,14 +1,9 @@
1
1
  /**
2
- * Validates that each key in the given row object is a valid cell reference.
2
+ * Validates an object representing a single row of data to ensure that its keys
3
+ * are valid Excel column references. Throws an error if any of the keys are
4
+ * invalid.
3
5
  *
4
- * This function checks that all keys in the provided row object are composed
5
- * only of column letters (A-Z, case insensitive). If a key is found that does
6
- * not match this pattern, an error is thrown with a message indicating the
7
- * invalid cell reference.
8
- *
9
- * @param row - An object representing a row of data, where keys are cell
10
- * references and values are strings.
11
- *
12
- * @throws {Error} If any key in the row is not a valid column letter.
6
+ * @param row An object with string keys that represent the cell references and
7
+ * string values that represent the values of those cells.
13
8
  */
14
9
  export declare function checkRow(row: Record<string, string>): void;
@@ -1,7 +1,15 @@
1
1
  /**
2
- * Converts a 0-based column index to an Excel-style letter (A, B, ..., Z, AA, AB, ...).
2
+ * Converts a zero-based column index to its corresponding Excel column letter.
3
3
  *
4
- * @param index - The 0-based column index.
5
- * @returns The Excel-style letter for the given column index.
4
+ * @throws Will throw an error if the input is not a positive integer.
5
+ * @param {number} index - The zero-based index of the column to convert.
6
+ * @returns {string} The corresponding Excel column letter.
7
+ *
8
+ * @example
9
+ * columnIndexToLetter(0); // returns "A"
10
+ * columnIndexToLetter(25); // returns "Z"
11
+ * columnIndexToLetter(26); // returns "AA"
12
+ * columnIndexToLetter(51); // returns "AZ"
13
+ * columnIndexToLetter(52); // returns "BA"
6
14
  */
7
15
  export declare function columnIndexToLetter(index: number): string;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Extracts the XML declaration from a given XML string.
3
+ *
4
+ * The XML declaration is a string that looks like `<?xml ...?>` and is usually
5
+ * present at the beginning of an XML file. It contains information about the
6
+ * XML version, encoding, and standalone status.
7
+ *
8
+ * This function returns `null` if the input string does not have a valid XML
9
+ * declaration.
10
+ *
11
+ * @param xmlString - The XML string to extract the declaration from.
12
+ * @returns The extracted XML declaration string, or `null`.
13
+ */
14
+ export declare function extractXmlDeclaration(xmlString: string): string | null;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Gets a value from an object by a given path.
3
+ *
4
+ * @param obj - The object to search.
5
+ * @param path - The path to the value, separated by dots.
6
+ * @returns The value at the given path, or undefined if not found.
7
+ */
8
+ export declare function getByPath(obj: unknown, path: string): unknown;
@@ -1,11 +1,16 @@
1
+ export * from "./apply-replacements.js";
1
2
  export * from "./check-row.js";
2
3
  export * from "./check-rows.js";
3
4
  export * from "./check-start-row.js";
4
5
  export * from "./column-index-to-letter.js";
5
6
  export * from "./escape-xml.js";
7
+ export * from "./extract-xml-declaration.js";
8
+ export * from "./get-by-path.js";
6
9
  export * from "./get-max-row-number.js";
7
10
  export * from "./get-rows-above.js";
8
11
  export * from "./get-rows-below.js";
9
12
  export * from "./parse-rows.js";
10
13
  export * from "./to-excel-column-object.js";
14
+ export * from "./update-dimension.js";
15
+ export * from "./validate-worksheet-xml.js";
11
16
  export * from "./write-rows-to-stream.js";
@@ -0,0 +1 @@
1
+ export declare function updateDimension(xml: string): string;
@@ -0,0 +1,9 @@
1
+ interface ValidationResult {
2
+ isValid: boolean;
3
+ error?: {
4
+ message: string;
5
+ details?: string;
6
+ };
7
+ }
8
+ export declare function validateWorksheetXml(xml: string): ValidationResult;
9
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@js-ak/excel-toolbox",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "excel-toolbox",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -38,13 +38,14 @@
38
38
  "package.json"
39
39
  ],
40
40
  "scripts": {
41
- "build": "npm run build:cjs && npm run build:esm && npm run postbuild:esm && npm run postbuild:cjs",
41
+ "build": "npm run build:cjs && npm run build:esm && npm run postbuild:cjs && npm run postbuild:esm",
42
42
  "build:esm": "tsc -p tsconfig.esm.json",
43
43
  "build:cjs": "tsc -p tsconfig.cjs.json",
44
44
  "lint": "eslint . --ext .ts",
45
45
  "postbuild:esm": "node scripts/write-esm-package.js",
46
46
  "postbuild:cjs": "node scripts/write-cjs-package.js",
47
- "test": "npm run build && node ./build/esm/test/index.js"
47
+ "test": "vitest run",
48
+ "test:watch": "vitest"
48
49
  },
49
50
  "repository": {
50
51
  "type": "git",
@@ -75,7 +76,8 @@
75
76
  "globals": "16.0.0",
76
77
  "semantic-release": "24.0.0",
77
78
  "typescript": "5.8.3",
78
- "typescript-eslint": "8.29.0"
79
+ "typescript-eslint": "8.29.0",
80
+ "vitest": "3.1.1"
79
81
  },
80
82
  "dependencies": {
81
83
  "pako": "2.1.0"