@cj-tech-master/excelts 1.6.3-canary.20251224193141.8bff9dd → 1.6.3-canary.20251226035947.ef0b4f2

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 (68) hide show
  1. package/README.md +5 -4
  2. package/README_zh.md +5 -4
  3. package/dist/browser/excelts.esm.js +2447 -3094
  4. package/dist/browser/excelts.esm.js.map +1 -1
  5. package/dist/browser/excelts.esm.min.js +23 -25
  6. package/dist/browser/excelts.iife.js +2448 -3095
  7. package/dist/browser/excelts.iife.js.map +1 -1
  8. package/dist/browser/excelts.iife.min.js +23 -25
  9. package/dist/cjs/csv/csv-core.js +2 -2
  10. package/dist/cjs/csv/csv-stream.js +1 -1
  11. package/dist/cjs/csv/csv.base.js +10 -27
  12. package/dist/cjs/csv/csv.js +4 -12
  13. package/dist/cjs/doc/column.js +21 -0
  14. package/dist/cjs/doc/worksheet.js +4 -0
  15. package/dist/cjs/stream/xlsx/workbook-writer.js +4 -4
  16. package/dist/cjs/stream/xlsx/worksheet-writer.js +8 -1
  17. package/dist/cjs/utils/datetime.js +648 -0
  18. package/dist/cjs/utils/parse-sax.js +1190 -12
  19. package/dist/cjs/utils/unzip/zip-parser.js +11 -0
  20. package/dist/cjs/utils/zip/compress.base.js +3 -0
  21. package/dist/cjs/utils/zip/compress.browser.js +74 -30
  22. package/dist/cjs/utils/zip/deflate-fallback.js +575 -0
  23. package/dist/cjs/utils/zip/streaming-zip.js +264 -0
  24. package/dist/cjs/xlsx/xform/sheet/col-breaks-xform.js +38 -0
  25. package/dist/cjs/xlsx/xform/sheet/page-breaks-xform.js +13 -1
  26. package/dist/cjs/xlsx/xform/sheet/row-breaks-xform.js +11 -13
  27. package/dist/cjs/xlsx/xform/sheet/worksheet-xform.js +7 -2
  28. package/dist/cjs/xlsx/xlsx.browser.js +10 -53
  29. package/dist/cjs/xlsx/xlsx.js +27 -59
  30. package/dist/esm/csv/csv-core.js +2 -2
  31. package/dist/esm/csv/csv-stream.js +1 -1
  32. package/dist/esm/csv/csv.base.js +10 -24
  33. package/dist/esm/csv/csv.js +4 -12
  34. package/dist/esm/doc/column.js +21 -0
  35. package/dist/esm/doc/worksheet.js +4 -0
  36. package/dist/esm/stream/xlsx/workbook-writer.js +1 -1
  37. package/dist/esm/stream/xlsx/worksheet-writer.js +8 -1
  38. package/dist/esm/utils/datetime.js +639 -0
  39. package/dist/esm/utils/parse-sax.js +1188 -12
  40. package/dist/esm/utils/unzip/zip-parser.js +11 -0
  41. package/dist/esm/utils/zip/compress.base.js +3 -0
  42. package/dist/esm/utils/zip/compress.browser.js +76 -31
  43. package/dist/esm/utils/zip/deflate-fallback.js +570 -0
  44. package/dist/esm/utils/zip/streaming-zip.js +259 -0
  45. package/dist/esm/xlsx/xform/sheet/col-breaks-xform.js +35 -0
  46. package/dist/esm/xlsx/xform/sheet/page-breaks-xform.js +13 -1
  47. package/dist/esm/xlsx/xform/sheet/row-breaks-xform.js +11 -13
  48. package/dist/esm/xlsx/xform/sheet/worksheet-xform.js +7 -2
  49. package/dist/esm/xlsx/xlsx.browser.js +10 -53
  50. package/dist/esm/xlsx/xlsx.js +27 -59
  51. package/dist/types/csv/csv-core.d.ts +6 -6
  52. package/dist/types/csv/csv.base.d.ts +4 -3
  53. package/dist/types/doc/column.d.ts +6 -0
  54. package/dist/types/doc/worksheet.d.ts +3 -1
  55. package/dist/types/stream/xlsx/workbook-writer.d.ts +1 -1
  56. package/dist/types/stream/xlsx/worksheet-writer.d.ts +3 -1
  57. package/dist/types/types.d.ts +6 -0
  58. package/dist/types/utils/datetime.d.ts +85 -0
  59. package/dist/types/utils/parse-sax.d.ts +108 -1
  60. package/dist/types/utils/unzip/zip-parser.d.ts +5 -0
  61. package/dist/types/utils/zip/compress.base.d.ts +3 -0
  62. package/dist/types/utils/zip/compress.browser.d.ts +27 -18
  63. package/dist/types/utils/zip/deflate-fallback.d.ts +39 -0
  64. package/dist/types/utils/zip/streaming-zip.d.ts +96 -0
  65. package/dist/types/xlsx/xform/sheet/col-breaks-xform.d.ts +16 -0
  66. package/dist/types/xlsx/xform/sheet/page-breaks-xform.d.ts +4 -0
  67. package/dist/types/xlsx/xform/sheet/row-breaks-xform.d.ts +4 -0
  68. package/package.json +7 -28
@@ -5,7 +5,7 @@
5
5
  * A lightweight, cross-platform CSV implementation that works in both
6
6
  * Node.js and Browser environments with zero dependencies.
7
7
  *
8
- * Compatible with fast-csv API for drop-in replacement.
8
+ * High-performance RFC 4180 compliant CSV parser and formatter.
9
9
  *
10
10
  * @see https://tools.ietf.org/html/rfc4180
11
11
  */
@@ -160,7 +160,7 @@ function parseCsv(input, options = {}) {
160
160
  return false;
161
161
  }
162
162
  else {
163
- // Default: trim extra columns (matches fast-csv default behavior)
163
+ // Default: trim extra columns
164
164
  row.length = headerRow.length;
165
165
  }
166
166
  }
@@ -566,7 +566,7 @@ class CsvFormatterStream extends stream_1.Transform {
566
566
  });
567
567
  const formattedRow = fields.join(this.delimiter);
568
568
  // Use row delimiter as prefix (except for first row)
569
- // This matches fast-csv behavior where rowDelimiter separates rows
569
+ // rowDelimiter separates rows, no trailing delimiter by default
570
570
  if (this.rowCount === 0) {
571
571
  this.rowCount++;
572
572
  return formattedRow;
@@ -3,24 +3,16 @@
3
3
  * CSV Base class - Shared functionality for Node.js and Browser
4
4
  *
5
5
  * Uses native CSV parser (RFC 4180 compliant) with zero external dependencies.
6
- * Date parsing uses dayjs for format flexibility.
6
+ * Date parsing uses native high-performance datetime utilities.
7
7
  */
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
8
  Object.defineProperty(exports, "__esModule", { value: true });
12
9
  exports.parseCsvStream = exports.formatCsv = exports.parseCsv = void 0;
13
10
  exports.createDefaultValueMapper = createDefaultValueMapper;
14
11
  exports.createDefaultWriteMapper = createDefaultWriteMapper;
15
12
  exports.parseCsvToWorksheet = parseCsvToWorksheet;
16
13
  exports.formatWorksheetToCsv = formatWorksheetToCsv;
17
- const dayjs_1 = __importDefault(require("dayjs"));
18
- const customParseFormat_js_1 = __importDefault(require("dayjs/plugin/customParseFormat.js"));
19
- const utc_js_1 = __importDefault(require("dayjs/plugin/utc.js"));
14
+ const datetime_1 = require("../utils/datetime");
20
15
  const csv_core_1 = require("./csv-core");
21
- // Initialize dayjs plugins
22
- dayjs_1.default.extend(customParseFormat_js_1.default);
23
- dayjs_1.default.extend(utc_js_1.default);
24
16
  // Special Excel values mapping
25
17
  const SpecialValues = {
26
18
  true: true,
@@ -37,6 +29,7 @@ const SpecialValues = {
37
29
  * Create the default value mapper for CSV parsing
38
30
  */
39
31
  function createDefaultValueMapper(dateFormats) {
32
+ const dateParser = datetime_1.DateParser.create(dateFormats);
40
33
  return function mapValue(datum) {
41
34
  if (datum === "") {
42
35
  return null;
@@ -47,18 +40,9 @@ function createDefaultValueMapper(dateFormats) {
47
40
  return datumNumber;
48
41
  }
49
42
  // Try to parse as date
50
- const dt = dateFormats.reduce((matchingDate, currentDateFormat) => {
51
- if (matchingDate) {
52
- return matchingDate;
53
- }
54
- const dayjsObj = (0, dayjs_1.default)(datum, currentDateFormat, true);
55
- if (dayjsObj.isValid()) {
56
- return dayjsObj;
57
- }
58
- return null;
59
- }, null);
60
- if (dt) {
61
- return new Date(dt.valueOf());
43
+ const date = dateParser.parse(datum);
44
+ if (date) {
45
+ return date;
62
46
  }
63
47
  // Check for special values
64
48
  const special = SpecialValues[datum];
@@ -72,6 +56,9 @@ function createDefaultValueMapper(dateFormats) {
72
56
  * Create the default value mapper for CSV writing
73
57
  */
74
58
  function createDefaultWriteMapper(dateFormat, dateUTC) {
59
+ const formatter = dateFormat
60
+ ? datetime_1.DateFormatter.create(dateFormat, { utc: dateUTC })
61
+ : datetime_1.DateFormatter.iso(dateUTC);
75
62
  return function mapValue(value) {
76
63
  if (value) {
77
64
  // Handle hyperlinks
@@ -84,10 +71,7 @@ function createDefaultWriteMapper(dateFormat, dateUTC) {
84
71
  }
85
72
  // Handle dates
86
73
  if (value instanceof Date) {
87
- if (dateFormat) {
88
- return dateUTC ? dayjs_1.default.utc(value).format(dateFormat) : (0, dayjs_1.default)(value).format(dateFormat);
89
- }
90
- return dateUTC ? dayjs_1.default.utc(value).format() : (0, dayjs_1.default)(value).format();
74
+ return formatter.format(value);
91
75
  }
92
76
  // Handle errors
93
77
  if (value.error) {
@@ -109,7 +93,6 @@ function parseCsvToWorksheet(content, workbook, options = {}) {
109
93
  const dateFormats = options.dateFormats || [
110
94
  "YYYY-MM-DD[T]HH:mm:ssZ",
111
95
  "YYYY-MM-DD[T]HH:mm:ss",
112
- "MM-DD-YYYY",
113
96
  "YYYY-MM-DD"
114
97
  ];
115
98
  const map = options.map || createDefaultValueMapper(dateFormats);
@@ -87,12 +87,8 @@ class CSV {
87
87
  */
88
88
  async read(stream, options) {
89
89
  const worksheet = this.workbook.addWorksheet(options?.sheetName);
90
- const dateFormats = options?.dateFormats || [
91
- "YYYY-MM-DD[T]HH:mm:ssZ",
92
- "YYYY-MM-DD[T]HH:mm:ss",
93
- "MM-DD-YYYY",
94
- "YYYY-MM-DD"
95
- ];
90
+ const dateFormats = options?.dateFormats ??
91
+ ["YYYY-MM-DD[T]HH:mm:ssZ", "YYYY-MM-DD[T]HH:mm:ss", "MM-DD-YYYY", "YYYY-MM-DD"];
96
92
  const map = options?.map || (0, csv_base_1.createDefaultValueMapper)(dateFormats);
97
93
  const parser = new csv_stream_1.CsvParserStream(options?.parserOptions);
98
94
  return new Promise((resolve, reject) => {
@@ -237,12 +233,8 @@ class CSV {
237
233
  */
238
234
  createWriteStream(options) {
239
235
  const worksheet = this.workbook.addWorksheet(options?.sheetName);
240
- const dateFormats = options?.dateFormats || [
241
- "YYYY-MM-DD[T]HH:mm:ssZ",
242
- "YYYY-MM-DD[T]HH:mm:ss",
243
- "MM-DD-YYYY",
244
- "YYYY-MM-DD"
245
- ];
236
+ const dateFormats = options?.dateFormats ??
237
+ ["YYYY-MM-DD[T]HH:mm:ssZ", "YYYY-MM-DD[T]HH:mm:ss", "MM-DD-YYYY", "YYYY-MM-DD"];
246
238
  const map = options?.map || (0, csv_base_1.createDefaultValueMapper)(dateFormats);
247
239
  const parser = new csv_stream_1.CsvParserStream(options?.parserOptions);
248
240
  parser.on("data", (row) => {
@@ -218,6 +218,27 @@ class Column {
218
218
  });
219
219
  }
220
220
  // =========================================================================
221
+ // Page Breaks
222
+ /**
223
+ * Add a page break after this column.
224
+ * @param top - Optional top row limit for the page break (1-indexed)
225
+ * @param bottom - Optional bottom row limit for the page break (1-indexed)
226
+ */
227
+ addPageBreak(top, bottom) {
228
+ const ws = this._worksheet;
229
+ const topRow = Math.max(0, (top || 0) - 1) || 0;
230
+ const bottomRow = Math.max(0, (bottom || 0) - 1) || 1048575;
231
+ const pb = {
232
+ id: this._number,
233
+ max: bottomRow,
234
+ man: 1
235
+ };
236
+ if (topRow) {
237
+ pb.min = topRow;
238
+ }
239
+ ws.colBreaks.push(pb);
240
+ }
241
+ // =========================================================================
221
242
  // styles
222
243
  get numFmt() {
223
244
  return this.style.numFmt;
@@ -39,6 +39,7 @@ class Worksheet {
39
39
  this._merges = {};
40
40
  // record of all row and column pageBreaks
41
41
  this.rowBreaks = [];
42
+ this.colBreaks = [];
42
43
  // for tabColor, default row height, outline levels, etc
43
44
  this.properties = Object.assign({}, {
44
45
  defaultRowHeight: 15,
@@ -853,6 +854,7 @@ class Worksheet {
853
854
  pageSetup: this.pageSetup,
854
855
  headerFooter: this.headerFooter,
855
856
  rowBreaks: this.rowBreaks,
857
+ colBreaks: this.colBreaks,
856
858
  views: this.views,
857
859
  autoFilter: this.autoFilter,
858
860
  media: this._media.map(medium => medium.model),
@@ -911,6 +913,8 @@ class Worksheet {
911
913
  this.properties = value.properties;
912
914
  this.pageSetup = value.pageSetup;
913
915
  this.headerFooter = value.headerFooter;
916
+ this.rowBreaks = value.rowBreaks || [];
917
+ this.colBreaks = value.colBreaks || [];
914
918
  this.views = value.views;
915
919
  this.autoFilter = value.autoFilter;
916
920
  this._media = value.media.map(medium => new image_1.Image(this, medium));
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.WorkbookWriter = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
- const fflate_1 = require("fflate");
8
+ const streaming_zip_1 = require("../../utils/zip/streaming-zip");
9
9
  const stream_buf_1 = require("../../utils/stream-buf");
10
10
  const rel_type_1 = require("../../xlsx/rel-type");
11
11
  const styles_xform_1 = require("../../xlsx/xform/style/styles-xform");
@@ -44,7 +44,7 @@ class WorkbookWriter {
44
44
  this.media = [];
45
45
  this.commentRefs = [];
46
46
  // Create fflate Zip instance
47
- this.zip = new fflate_1.Zip((err, data, final) => {
47
+ this.zip = new streaming_zip_1.Zip((err, data, final) => {
48
48
  if (err) {
49
49
  this.stream.emit("error", err);
50
50
  }
@@ -73,7 +73,7 @@ class WorkbookWriter {
73
73
  _openStream(path) {
74
74
  const stream = new stream_buf_1.StreamBuf({ bufSize: 65536, batch: true });
75
75
  // Create a ZipDeflate for this file with compression
76
- const zipFile = new fflate_1.ZipDeflate(path, { level: this.compressionLevel });
76
+ const zipFile = new streaming_zip_1.ZipDeflate(path, { level: this.compressionLevel });
77
77
  this.zip.add(zipFile);
78
78
  // Don't pause the stream - we need data events to flow
79
79
  // The original implementation used archiver which consumed the stream internally
@@ -93,7 +93,7 @@ class WorkbookWriter {
93
93
  }
94
94
  _addFile(data, name, base64) {
95
95
  // Helper method to add a file to the zip using fflate with compression
96
- const zipFile = new fflate_1.ZipDeflate(name, { level: this.compressionLevel });
96
+ const zipFile = new streaming_zip_1.ZipDeflate(name, { level: this.compressionLevel });
97
97
  this.zip.add(zipFile);
98
98
  let buffer;
99
99
  if (base64) {
@@ -30,6 +30,7 @@ const picture_xform_1 = require("../../xlsx/xform/sheet/picture-xform");
30
30
  const conditional_formattings_xform_1 = require("../../xlsx/xform/sheet/cf/conditional-formattings-xform");
31
31
  const header_footer_xform_1 = require("../../xlsx/xform/sheet/header-footer-xform");
32
32
  const row_breaks_xform_1 = require("../../xlsx/xform/sheet/row-breaks-xform");
33
+ const col_breaks_xform_1 = require("../../xlsx/xform/sheet/col-breaks-xform");
33
34
  // since prepare and render are functional, we can use singletons
34
35
  const xform = {
35
36
  dataValidations: new data_validations_xform_1.DataValidationsXform(),
@@ -54,7 +55,8 @@ const xform = {
54
55
  picture: new picture_xform_1.PictureXform(),
55
56
  conditionalFormattings: new conditional_formattings_xform_1.ConditionalFormattingsXform(),
56
57
  headerFooter: new header_footer_xform_1.HeaderFooterXform(),
57
- rowBreaks: new row_breaks_xform_1.RowBreaksXform()
58
+ rowBreaks: new row_breaks_xform_1.RowBreaksXform(),
59
+ colBreaks: new col_breaks_xform_1.ColBreaksXform()
58
60
  };
59
61
  class WorksheetWriter {
60
62
  constructor(options) {
@@ -92,6 +94,7 @@ class WorksheetWriter {
92
94
  this.conditionalFormatting = [];
93
95
  // keep a record of all row and column pageBreaks
94
96
  this.rowBreaks = [];
97
+ this.colBreaks = [];
95
98
  // for default row height, outline levels, etc
96
99
  this.properties = Object.assign({}, {
97
100
  defaultRowHeight: 15,
@@ -196,6 +199,7 @@ class WorksheetWriter {
196
199
  this._writeBackground();
197
200
  this._writeHeaderFooter();
198
201
  this._writeRowBreaks();
202
+ this._writeColBreaks();
199
203
  // Legacy Data tag for comments
200
204
  this._writeLegacyData();
201
205
  this._writeCloseWorksheet();
@@ -546,6 +550,9 @@ class WorksheetWriter {
546
550
  _writeRowBreaks() {
547
551
  this.stream.write(xform.rowBreaks.toXml(this.rowBreaks));
548
552
  }
553
+ _writeColBreaks() {
554
+ this.stream.write(xform.colBreaks.toXml(this.colBreaks));
555
+ }
549
556
  _writeDataValidations() {
550
557
  this.stream.write(xform.dataValidations.toXml(this.dataValidations.model));
551
558
  }