@cj-tech-master/excelts 1.1.0 → 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 (37) hide show
  1. package/dist/browser/excelts.iife.js +1049 -559
  2. package/dist/browser/excelts.iife.js.map +1 -1
  3. package/dist/browser/excelts.iife.min.js +17 -17
  4. package/dist/cjs/index.js +1 -1
  5. package/dist/cjs/utils/cell-format.js +815 -0
  6. package/dist/cjs/utils/parse-sax.js +2 -2
  7. package/dist/cjs/utils/{extra-utils.js → sheet-utils.js} +114 -89
  8. package/dist/cjs/utils/stream-buf.js +15 -4
  9. package/dist/cjs/utils/unzip/parse.js +82 -1
  10. package/dist/cjs/utils/utils.js +13 -17
  11. package/dist/cjs/utils/zip-stream.js +20 -32
  12. package/dist/cjs/xlsx/xlsx.js +1 -2
  13. package/dist/esm/index.browser.js +1 -1
  14. package/dist/esm/index.js +1 -1
  15. package/dist/esm/utils/cell-format.js +810 -0
  16. package/dist/esm/utils/parse-sax.js +1 -1
  17. package/dist/esm/utils/{extra-utils.js → sheet-utils.js} +97 -72
  18. package/dist/esm/utils/stream-buf.js +15 -4
  19. package/dist/esm/utils/unzip/parse.js +83 -2
  20. package/dist/esm/utils/utils.js +12 -16
  21. package/dist/esm/utils/zip-stream.js +20 -32
  22. package/dist/esm/xlsx/xlsx.js +1 -2
  23. package/dist/types/index.browser.d.ts +1 -1
  24. package/dist/types/index.d.ts +1 -1
  25. package/dist/types/utils/cell-format.d.ts +32 -0
  26. package/dist/types/utils/{extra-utils.d.ts → sheet-utils.d.ts} +51 -52
  27. package/dist/types/utils/utils.d.ts +5 -2
  28. package/package.json +5 -5
  29. package/dist/cjs/utils/browser-buffer-decode.js +0 -13
  30. package/dist/cjs/utils/browser-buffer-encode.js +0 -13
  31. package/dist/cjs/utils/browser.js +0 -6
  32. package/dist/esm/utils/browser-buffer-decode.js +0 -11
  33. package/dist/esm/utils/browser-buffer-encode.js +0 -11
  34. package/dist/esm/utils/browser.js +0 -3
  35. package/dist/types/utils/browser-buffer-decode.d.ts +0 -2
  36. package/dist/types/utils/browser-buffer-encode.d.ts +0 -2
  37. package/dist/types/utils/browser.d.ts +0 -1
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Excel Cell Format Parser
3
+ * A simplified implementation for formatting cell values according to Excel numFmt patterns
4
+ * Supports: General, percentages, decimals, thousands separators, dates, currencies,
5
+ * scientific notation, fractions, elapsed time, and more
6
+ */
7
+ /**
8
+ * Get format string from numFmtId
9
+ * Handles default mappings for certain format IDs
10
+ */
11
+ export declare function getFormat(numFmtId: number): string;
12
+ /**
13
+ * Check if format is "General"
14
+ */
15
+ declare function isGeneral(fmt: string): boolean;
16
+ /**
17
+ * Check if format is a date format
18
+ */
19
+ declare function isDateFormat(fmt: string): boolean;
20
+ /**
21
+ * Main format function - formats a value according to Excel numFmt
22
+ * @param fmt The Excel number format string (e.g., "0.00%", "#,##0", "yyyy-mm-dd")
23
+ * @param val The value to format
24
+ */
25
+ export declare function format(fmt: string, val: number | string | boolean): string;
26
+ export declare const cellFormat: {
27
+ format: typeof format;
28
+ getFormat: typeof getFormat;
29
+ isDateFormat: typeof isDateFormat;
30
+ isGeneral: typeof isGeneral;
31
+ };
32
+ export {};
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * Utility functions for ExcelTS
3
3
  * Provides convenient helper functions for common spreadsheet operations
4
- * compatible with xlsx library's utils API but built on excelts native types
5
4
  */
6
5
  import { Workbook } from "../doc/workbook.js";
7
6
  import type { Worksheet } from "../doc/worksheet.js";
@@ -30,44 +29,44 @@ export interface Range {
30
29
  export type JSONRow = Record<string, CellValue>;
31
30
  /**
32
31
  * Decode column string to 0-indexed number
33
- * @example decode_col("A") => 0, decode_col("Z") => 25, decode_col("AA") => 26
32
+ * @example decodeCol("A") => 0, decodeCol("Z") => 25, decodeCol("AA") => 26
34
33
  */
35
- export declare function decode_col(colstr: string): number;
34
+ export declare function decodeCol(colstr: string): number;
36
35
  /**
37
36
  * Encode 0-indexed column number to string
38
- * @example encode_col(0) => "A", encode_col(25) => "Z", encode_col(26) => "AA"
37
+ * @example encodeCol(0) => "A", encodeCol(25) => "Z", encodeCol(26) => "AA"
39
38
  */
40
- export declare function encode_col(col: number): string;
39
+ export declare function encodeCol(col: number): string;
41
40
  /**
42
41
  * Decode row string to 0-indexed number
43
- * @example decode_row("1") => 0, decode_row("10") => 9
42
+ * @example decodeRow("1") => 0, decodeRow("10") => 9
44
43
  */
45
- export declare function decode_row(rowstr: string): number;
44
+ export declare function decodeRow(rowstr: string): number;
46
45
  /**
47
46
  * Encode 0-indexed row number to string
48
- * @example encode_row(0) => "1", encode_row(9) => "10"
47
+ * @example encodeRow(0) => "1", encodeRow(9) => "10"
49
48
  */
50
- export declare function encode_row(row: number): string;
49
+ export declare function encodeRow(row: number): string;
51
50
  /**
52
51
  * Decode cell address string to CellAddress object
53
- * @example decode_cell("A1") => {c: 0, r: 0}, decode_cell("B2") => {c: 1, r: 1}
52
+ * @example decodeCell("A1") => {c: 0, r: 0}, decodeCell("B2") => {c: 1, r: 1}
54
53
  */
55
- export declare function decode_cell(cstr: string): CellAddress;
54
+ export declare function decodeCell(cstr: string): CellAddress;
56
55
  /**
57
56
  * Encode CellAddress object to cell address string
58
- * @example encode_cell({c: 0, r: 0}) => "A1", encode_cell({c: 1, r: 1}) => "B2"
57
+ * @example encodeCell({c: 0, r: 0}) => "A1", encodeCell({c: 1, r: 1}) => "B2"
59
58
  */
60
- export declare function encode_cell(cell: CellAddress): string;
59
+ export declare function encodeCell(cell: CellAddress): string;
61
60
  /**
62
61
  * Decode range string to Range object
63
- * @example decode_range("A1:B2") => {s: {c: 0, r: 0}, e: {c: 1, r: 1}}
62
+ * @example decodeRange("A1:B2") => {s: {c: 0, r: 0}, e: {c: 1, r: 1}}
64
63
  */
65
- export declare function decode_range(range: string): Range;
64
+ export declare function decodeRange(range: string): Range;
66
65
  /**
67
66
  * Encode Range object to range string
68
67
  */
69
- export declare function encode_range(range: Range): string;
70
- export declare function encode_range(start: CellAddress, end: CellAddress): string;
68
+ export declare function encodeRange(range: Range): string;
69
+ export declare function encodeRange(start: CellAddress, end: CellAddress): string;
71
70
  /** Origin can be cell address string, cell object, row number, or -1 to append */
72
71
  export type Origin = string | CellAddress | number;
73
72
  export interface JSON2SheetOpts {
@@ -89,13 +88,13 @@ export interface SheetAddJSONOpts extends JSON2SheetOpts {
89
88
  /**
90
89
  * Create a worksheet from an array of objects (xlsx compatible)
91
90
  * @example
92
- * const ws = json_to_sheet([{name: "Alice", age: 30}, {name: "Bob", age: 25}])
91
+ * const ws = jsonToSheet([{name: "Alice", age: 30}, {name: "Bob", age: 25}])
93
92
  */
94
- export declare function json_to_sheet(data: JSONRow[], opts?: JSON2SheetOpts): Worksheet;
93
+ export declare function jsonToSheet(data: JSONRow[], opts?: JSON2SheetOpts): Worksheet;
95
94
  /**
96
95
  * Add data from an array of objects to an existing worksheet (xlsx compatible)
97
96
  */
98
- export declare function sheet_add_json(worksheet: Worksheet, data: JSONRow[], opts?: SheetAddJSONOpts): Worksheet;
97
+ export declare function sheetAddJson(worksheet: Worksheet, data: JSONRow[], opts?: SheetAddJSONOpts): Worksheet;
99
98
  export interface Sheet2JSONOpts {
100
99
  /**
101
100
  * Control output format:
@@ -112,7 +111,7 @@ export interface Sheet2JSONOpts {
112
111
  * - undefined: Use worksheet range
113
112
  */
114
113
  range?: number | string;
115
- /** Use raw values (true) or formatted strings (false). Default: true */
114
+ /** Use raw values (true, default) or formatted text strings with trim (false) */
116
115
  raw?: boolean;
117
116
  /** Default value for empty cells */
118
117
  defval?: CellValue;
@@ -123,18 +122,18 @@ export interface Sheet2JSONOpts {
123
122
  * Convert worksheet to JSON array (xlsx compatible)
124
123
  * @example
125
124
  * // Default: array of objects with first row as headers
126
- * const data = sheet_to_json(worksheet)
125
+ * const data = sheetToJson(worksheet)
127
126
  * // => [{name: "Alice", age: 30}, {name: "Bob", age: 25}]
128
127
  *
129
128
  * // Array of arrays
130
- * const aoa = sheet_to_json(worksheet, { header: 1 })
129
+ * const aoa = sheetToJson(worksheet, { header: 1 })
131
130
  * // => [["name", "age"], ["Alice", 30], ["Bob", 25]]
132
131
  *
133
132
  * // Column letters as keys
134
- * const cols = sheet_to_json(worksheet, { header: "A" })
133
+ * const cols = sheetToJson(worksheet, { header: "A" })
135
134
  * // => [{A: "name", B: "age"}, {A: "Alice", B: 30}]
136
135
  */
137
- export declare function sheet_to_json<T = JSONRow>(worksheet: Worksheet, opts?: Sheet2JSONOpts): T[];
136
+ export declare function sheetToJson<T = JSONRow>(worksheet: Worksheet, opts?: Sheet2JSONOpts): T[];
138
137
  export interface Sheet2CSVOpts {
139
138
  /** Field separator (default: ",") */
140
139
  FS?: string;
@@ -148,19 +147,19 @@ export interface Sheet2CSVOpts {
148
147
  /**
149
148
  * Convert worksheet to CSV string
150
149
  */
151
- export declare function sheet_to_csv(worksheet: Worksheet, opts?: Sheet2CSVOpts): string;
150
+ export declare function sheetToCsv(worksheet: Worksheet, opts?: Sheet2CSVOpts): string;
152
151
  /**
153
152
  * Create a new workbook
154
153
  */
155
- export declare function book_new(): Workbook;
154
+ export declare function bookNew(): Workbook;
156
155
  /**
157
156
  * Append worksheet to workbook (xlsx compatible)
158
157
  * @example
159
- * const wb = book_new();
160
- * const ws = json_to_sheet([{a: 1, b: 2}]);
161
- * book_append_sheet(wb, ws, "Sheet1");
158
+ * const wb = bookNew();
159
+ * const ws = jsonToSheet([{a: 1, b: 2}]);
160
+ * bookAppendSheet(wb, ws, "Sheet1");
162
161
  */
163
- export declare function book_append_sheet(workbook: Workbook, worksheet: Worksheet, name?: string): void;
162
+ export declare function bookAppendSheet(workbook: Workbook, worksheet: Worksheet, name?: string): void;
164
163
  export interface AOA2SheetOpts {
165
164
  /** Use specified cell as starting point */
166
165
  origin?: Origin;
@@ -172,33 +171,33 @@ export interface AOA2SheetOpts {
172
171
  /**
173
172
  * Create a worksheet from an array of arrays (xlsx compatible)
174
173
  * @example
175
- * const ws = aoa_to_sheet([["Name", "Age"], ["Alice", 30], ["Bob", 25]])
174
+ * const ws = aoaToSheet([["Name", "Age"], ["Alice", 30], ["Bob", 25]])
176
175
  */
177
- export declare function aoa_to_sheet(data: CellValue[][], opts?: AOA2SheetOpts): Worksheet;
176
+ export declare function aoaToSheet(data: CellValue[][], opts?: AOA2SheetOpts): Worksheet;
178
177
  /**
179
178
  * Add data from an array of arrays to an existing worksheet (xlsx compatible)
180
179
  */
181
- export declare function sheet_add_aoa(worksheet: Worksheet, data: CellValue[][], opts?: AOA2SheetOpts): Worksheet;
180
+ export declare function sheetAddAoa(worksheet: Worksheet, data: CellValue[][], opts?: AOA2SheetOpts): Worksheet;
182
181
  /**
183
182
  * Convert worksheet to array of arrays
184
183
  */
185
- export declare function sheet_to_aoa(worksheet: Worksheet): CellValue[][];
184
+ export declare function sheetToAoa(worksheet: Worksheet): CellValue[][];
186
185
  export declare const utils: {
187
- decode_col: typeof decode_col;
188
- encode_col: typeof encode_col;
189
- decode_row: typeof decode_row;
190
- encode_row: typeof encode_row;
191
- decode_cell: typeof decode_cell;
192
- encode_cell: typeof encode_cell;
193
- decode_range: typeof decode_range;
194
- encode_range: typeof encode_range;
195
- json_to_sheet: typeof json_to_sheet;
196
- sheet_add_json: typeof sheet_add_json;
197
- sheet_to_json: typeof sheet_to_json;
198
- sheet_to_csv: typeof sheet_to_csv;
199
- aoa_to_sheet: typeof aoa_to_sheet;
200
- sheet_add_aoa: typeof sheet_add_aoa;
201
- sheet_to_aoa: typeof sheet_to_aoa;
202
- book_new: typeof book_new;
203
- book_append_sheet: typeof book_append_sheet;
186
+ decodeCol: typeof decodeCol;
187
+ encodeCol: typeof encodeCol;
188
+ decodeRow: typeof decodeRow;
189
+ encodeRow: typeof encodeRow;
190
+ decodeCell: typeof decodeCell;
191
+ encodeCell: typeof encodeCell;
192
+ decodeRange: typeof decodeRange;
193
+ encodeRange: typeof encodeRange;
194
+ jsonToSheet: typeof jsonToSheet;
195
+ sheetAddJson: typeof sheetAddJson;
196
+ sheetToJson: typeof sheetToJson;
197
+ sheetToCsv: typeof sheetToCsv;
198
+ aoaToSheet: typeof aoaToSheet;
199
+ sheetAddAoa: typeof sheetAddAoa;
200
+ sheetToAoa: typeof sheetToAoa;
201
+ bookNew: typeof bookNew;
202
+ bookAppendSheet: typeof bookAppendSheet;
204
203
  };
@@ -1,6 +1,5 @@
1
1
  export declare function delay(ms: number): Promise<void>;
2
2
  export declare function nop(): void;
3
- export declare function promiseImmediate<T>(value: T): Promise<T>;
4
3
  export declare const inherits: <T extends new (...args: any[]) => any, S extends new (...args: any[]) => any>(cls: T, superCtor: S, statics?: any, prototype?: any) => void;
5
4
  interface PathInfo {
6
5
  path: string;
@@ -23,7 +22,6 @@ export declare function objectFromProps<T = any>(props: string[], value?: T | nu
23
22
  /** @deprecated Import functions directly instead of using the utils object */
24
23
  export declare const utils: {
25
24
  nop: typeof nop;
26
- promiseImmediate: typeof promiseImmediate;
27
25
  inherits: <T extends new (...args: any[]) => any, S extends new (...args: any[]) => any>(cls: T, superCtor: S, statics?: any, prototype?: any) => void;
28
26
  dateToExcel: typeof dateToExcel;
29
27
  excelToDate: typeof excelToDate;
@@ -42,4 +40,9 @@ export declare const utils: {
42
40
  toSortedArray: typeof toSortedArray;
43
41
  objectFromProps: typeof objectFromProps;
44
42
  };
43
+ /**
44
+ * Convert a Buffer or ArrayBuffer to a UTF-8 string
45
+ * Works in both Node.js and browser environments
46
+ */
47
+ export declare function bufferToString(chunk: Buffer | ArrayBuffer | string): string;
45
48
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cj-tech-master/excelts",
3
- "version": "1.1.0",
3
+ "version": "1.4.0",
4
4
  "description": "TypeScript Excel Workbook Manager - Read and Write xlsx and csv Files.",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -33,8 +33,8 @@
33
33
  "browserslist": [
34
34
  "chrome >= 85",
35
35
  "edge >= 85",
36
- "firefox >= 79",
37
- "safari >= 14",
36
+ "firefox >= 113",
37
+ "safari >= 16.4",
38
38
  "opera >= 71"
39
39
  ],
40
40
  "exports": {
@@ -101,7 +101,6 @@
101
101
  "dayjs": "^1.11.19",
102
102
  "fast-csv": "^5.0.5",
103
103
  "fflate": "^0.8.2",
104
- "node-stdlib-browser": "^1.3.1",
105
104
  "saxes": "^6.0.0",
106
105
  "uuid": "^13.0.0"
107
106
  },
@@ -111,7 +110,7 @@
111
110
  "@types/node": "^24.10.1",
112
111
  "@typescript-eslint/eslint-plugin": "^8.48.1",
113
112
  "@typescript-eslint/parser": "^8.48.1",
114
- "@typescript/native-preview": "^7.0.0-dev.20251203.1",
113
+ "@typescript/native-preview": "^7.0.0-dev.20251208.1",
115
114
  "@vitest/browser": "^4.0.15",
116
115
  "@vitest/browser-playwright": "^4.0.15",
117
116
  "@vitest/ui": "^4.0.15",
@@ -126,6 +125,7 @@
126
125
  "express": "^5.2.1",
127
126
  "fast-xml-parser": "^5.3.2",
128
127
  "husky": "^9.1.7",
128
+ "node-stdlib-browser": "^1.3.1",
129
129
  "nodemon": "^3.1.11",
130
130
  "oxlint": "^1.31.0",
131
131
  "playwright": "^1.57.0",
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bufferToString = bufferToString;
4
- const textDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder("utf-8");
5
- function bufferToString(chunk) {
6
- if (typeof chunk === "string") {
7
- return chunk;
8
- }
9
- if (textDecoder) {
10
- return textDecoder.decode(chunk);
11
- }
12
- return String.fromCharCode(...new Uint8Array(chunk));
13
- }
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stringToBuffer = stringToBuffer;
4
- const textEncoder = typeof TextEncoder === "undefined" ? null : new TextEncoder();
5
- function stringToBuffer(str) {
6
- if (typeof str !== "string") {
7
- return str;
8
- }
9
- if (textEncoder) {
10
- return Buffer.from(textEncoder.encode(str).buffer);
11
- }
12
- return Buffer.from(str);
13
- }
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isBrowser = void 0;
4
- exports.isBrowser = typeof window !== "undefined" &&
5
- typeof document !== "undefined" &&
6
- typeof navigator !== "undefined";
@@ -1,11 +0,0 @@
1
- const textDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder("utf-8");
2
- function bufferToString(chunk) {
3
- if (typeof chunk === "string") {
4
- return chunk;
5
- }
6
- if (textDecoder) {
7
- return textDecoder.decode(chunk);
8
- }
9
- return String.fromCharCode(...new Uint8Array(chunk));
10
- }
11
- export { bufferToString };
@@ -1,11 +0,0 @@
1
- const textEncoder = typeof TextEncoder === "undefined" ? null : new TextEncoder();
2
- function stringToBuffer(str) {
3
- if (typeof str !== "string") {
4
- return str;
5
- }
6
- if (textEncoder) {
7
- return Buffer.from(textEncoder.encode(str).buffer);
8
- }
9
- return Buffer.from(str);
10
- }
11
- export { stringToBuffer };
@@ -1,3 +0,0 @@
1
- export const isBrowser = typeof window !== "undefined" &&
2
- typeof document !== "undefined" &&
3
- typeof navigator !== "undefined";
@@ -1,2 +0,0 @@
1
- declare function bufferToString(chunk: Buffer<ArrayBuffer> | string): string;
2
- export { bufferToString };
@@ -1,2 +0,0 @@
1
- declare function stringToBuffer(str: string | Buffer<ArrayBuffer>): Buffer<ArrayBuffer>;
2
- export { stringToBuffer };
@@ -1 +0,0 @@
1
- export declare const isBrowser: boolean;