@cj-tech-master/excelts 3.0.1-canary.20251229011802.ccfcbcc → 3.0.1-canary.20251230173853.c3c79fa

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @cj-tech-master/excelts v3.0.1-canary.20251229011802.ccfcbcc
2
+ * @cj-tech-master/excelts v3.0.1-canary.20251230173853.c3c79fa
3
3
  * TypeScript Excel Workbook Manager - Read and Write xlsx and csv Files.
4
4
  * (c) 2025 cjnoname
5
5
  * Released under the MIT License
@@ -1672,6 +1672,27 @@ var Row = class {
1672
1672
  });
1673
1673
  }
1674
1674
  /**
1675
+ * Get row values as a 0-based sparse array (column 1 => index 0).
1676
+ *
1677
+ * This is useful when you want to compare/stringify values without the
1678
+ * leading separator produced by the 1-based sparse array returned by `values`.
1679
+ */
1680
+ getValues() {
1681
+ const values = [];
1682
+ this._cells.forEach((cell) => {
1683
+ if (cell && cell.type !== Enums.ValueType.Null) values[cell.col - 1] = cell.value;
1684
+ });
1685
+ return values;
1686
+ }
1687
+ /**
1688
+ * Convenience stringification for row values.
1689
+ *
1690
+ * Equivalent to `row.getValues().join(separator)`.
1691
+ */
1692
+ valuesToString(separator = ",") {
1693
+ return this.getValues().join(separator);
1694
+ }
1695
+ /**
1675
1696
  * Returns true if the row includes at least one cell with a value
1676
1697
  */
1677
1698
  get hasValues() {
@@ -17091,9 +17112,32 @@ var DateFormatter = class DateFormatter {
17091
17112
  }
17092
17113
  };
17093
17114
 
17115
+ //#endregion
17116
+ //#region src/csv/csv-number.ts
17117
+ function formatNumberForCsv(value, decimalSeparator) {
17118
+ if (decimalSeparator !== ",") return String(value);
17119
+ return String(value).split(".").join(",");
17120
+ }
17121
+ function parseNumberFromCsv(value, decimalSeparator) {
17122
+ if (decimalSeparator !== ",") return Number(value);
17123
+ const trimmed = value.trim();
17124
+ if (/^-?\d+(,\d+)?([eE][+-]?\d+)?$/.test(trimmed)) return Number(trimmed.replace(",", "."));
17125
+ return Number(value);
17126
+ }
17127
+
17094
17128
  //#endregion
17095
17129
  //#region src/csv/csv-core.ts
17096
17130
  /**
17131
+ * CSV Parser and Formatter - RFC 4180 compliant
17132
+ *
17133
+ * A lightweight, cross-platform CSV implementation that works in both
17134
+ * Node.js and Browser environments with zero dependencies.
17135
+ *
17136
+ * High-performance RFC 4180 compliant CSV parser and formatter.
17137
+ *
17138
+ * @see https://tools.ietf.org/html/rfc4180
17139
+ */
17140
+ /**
17097
17141
  * Escape special regex characters
17098
17142
  */
17099
17143
  function escapeRegex(str) {
@@ -17326,7 +17370,7 @@ function parseCsv(input, options = {}) {
17326
17370
  * Format data as a CSV string
17327
17371
  */
17328
17372
  function formatCsv(data, options = {}) {
17329
- const { delimiter = ",", quote: quoteOption = "\"", escape: escapeOption, rowDelimiter = "\n", alwaysQuote = false, quoteColumns = false, quoteHeaders = false, headers, writeHeaders: writeHeadersOption, writeBOM = false, includeEndRowDelimiter = false, alwaysWriteHeaders = false, transform } = options;
17373
+ const { delimiter = ",", quote: quoteOption = "\"", escape: escapeOption, rowDelimiter = "\n", alwaysQuote = false, quoteColumns = false, quoteHeaders = false, headers, writeHeaders: writeHeadersOption, writeBOM = false, includeEndRowDelimiter = false, alwaysWriteHeaders = false, transform, decimalSeparator = "." } = options;
17330
17374
  const shouldWriteHeaders = writeHeadersOption ?? true;
17331
17375
  const quoteEnabled = quoteOption !== false && quoteOption !== null;
17332
17376
  const quote = quoteEnabled ? String(quoteOption) : "";
@@ -17341,7 +17385,7 @@ function formatCsv(data, options = {}) {
17341
17385
  };
17342
17386
  const formatField = (value, index, header, isHeader = false) => {
17343
17387
  if (value === null || value === void 0) return "";
17344
- const str = String(value);
17388
+ const str = typeof value === "number" ? formatNumberForCsv(value, decimalSeparator) : String(value);
17345
17389
  if (!quoteEnabled) return str;
17346
17390
  const forceQuote = alwaysQuote || shouldQuoteColumn(index, header, isHeader);
17347
17391
  const quoteRegex = /* @__PURE__ */ new RegExp(`[${escapeRegex(delimiter)}${escapeRegex(quote)}\r\n]`);
@@ -17409,11 +17453,12 @@ const SpecialValues = {
17409
17453
  /**
17410
17454
  * Create the default value mapper for CSV parsing
17411
17455
  */
17412
- function createDefaultValueMapper(dateFormats) {
17456
+ function createDefaultValueMapper(dateFormats, parserOptions) {
17413
17457
  const dateParser = DateParser.create(dateFormats);
17458
+ const decimalSeparator = parserOptions?.decimalSeparator ?? ".";
17414
17459
  return function mapValue(datum) {
17415
17460
  if (datum === "") return null;
17416
- const datumNumber = Number(datum);
17461
+ const datumNumber = typeof datum === "string" ? parseNumberFromCsv(datum, decimalSeparator) : Number(datum);
17417
17462
  if (!Number.isNaN(datumNumber) && datumNumber !== Infinity) return datumNumber;
17418
17463
  const date = dateParser.parse(datum);
17419
17464
  if (date) return date;
@@ -17448,9 +17493,9 @@ function parseCsvToWorksheet(content, workbook, options = {}) {
17448
17493
  "YYYY-MM-DD[T]HH:mm:ss",
17449
17494
  "YYYY-MM-DD"
17450
17495
  ];
17451
- const map = options.map || createDefaultValueMapper(dateFormats);
17496
+ const effectiveMap = options.map || createDefaultValueMapper(dateFormats, options.parserOptions);
17452
17497
  const rows = parseCsv(content, options.parserOptions);
17453
- for (const row of rows) worksheet.addRow(row.map(map));
17498
+ for (const row of rows) worksheet.addRow(row.map(effectiveMap));
17454
17499
  return worksheet;
17455
17500
  }
17456
17501
  /**