javascript-excel 2.4.0 → 2.6.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 (58) hide show
  1. package/README.md +4 -2
  2. package/dist/{address-DUn7-5OS.js → address-BGH42dEg.js} +1 -1
  3. package/dist/{address-DZBHchLv.cjs → address-DKd_3EGf.cjs} +1 -1
  4. package/dist/{csv-Dn4MIESx.js → csv-5jVhfM5l.js} +180 -33
  5. package/dist/{csv-DZ241Y5F.cjs → csv-BkVmMYQq.cjs} +180 -33
  6. package/dist/csv.cjs +1 -1
  7. package/dist/csv.d.cts +42 -3
  8. package/dist/csv.d.ts +42 -3
  9. package/dist/csv.js +1 -1
  10. package/dist/{dataset-CbZnEWXu.cjs → dataset-B4-SEdCn.cjs} +4 -4
  11. package/dist/{dataset-CyEHVht4.js → dataset-Dh598YSG.js} +4 -4
  12. package/dist/{dates-BXcSWf9_.js → dates-CIL1z9EY.js} +1 -1
  13. package/dist/{dates-CA1dCizp.cjs → dates-DcdgnJto.cjs} +1 -1
  14. package/dist/dom.cjs +2 -2
  15. package/dist/dom.d.cts +1 -1
  16. package/dist/dom.d.ts +1 -1
  17. package/dist/dom.js +2 -2
  18. package/dist/{dos-time-BsH7f0ef.js → dos-time-BEAyK3U8.js} +1 -1
  19. package/dist/{dos-time-CxEs--rI.cjs → dos-time-BUWyklco.cjs} +1 -1
  20. package/dist/{errors-CvGlfw0E.js → errors-BQE62PFo.js} +1 -1
  21. package/dist/{errors-DOPrrGS4.cjs → errors-CKYdpCoB.cjs} +1 -1
  22. package/dist/format.cjs +1 -1
  23. package/dist/format.js +1 -1
  24. package/dist/import.cjs +1 -1
  25. package/dist/import.d.cts +2 -2
  26. package/dist/import.d.ts +2 -2
  27. package/dist/import.js +1 -1
  28. package/dist/index.cjs +7 -7
  29. package/dist/index.d.cts +5 -5
  30. package/dist/index.d.ts +5 -5
  31. package/dist/index.js +7 -7
  32. package/dist/{infer-BniOucP6.cjs → infer-B950M3-F.cjs} +27 -0
  33. package/dist/{infer-DcUyZ1T-.js → infer-DuSahY5i.js} +16 -1
  34. package/dist/{pipeline-C8F9lecW.js → pipeline-BRzRd5v3.js} +12 -7
  35. package/dist/{pipeline-BegSPu8X.d.ts → pipeline-BY-SiQWW.d.ts} +7 -3
  36. package/dist/{pipeline-BwkRpV5Z.cjs → pipeline-C13EIWHJ.cjs} +12 -7
  37. package/dist/{pipeline-4U7Xnuc1.d.cts → pipeline-C7R86kQg.d.cts} +7 -3
  38. package/dist/{read-cvxu6O-H.js → read-CrI550TK.js} +2269 -784
  39. package/dist/{read-DmUPztqh.cjs → read-X1KxggZ7.cjs} +2284 -793
  40. package/dist/read.cjs +2 -1
  41. package/dist/read.d.cts +49 -2
  42. package/dist/read.d.ts +49 -2
  43. package/dist/read.js +2 -2
  44. package/dist/render.cjs +2 -2
  45. package/dist/render.js +2 -2
  46. package/dist/{sheet-names-DDY64-dt.cjs → sheet-names-D8sYcjSd.cjs} +2 -2
  47. package/dist/{sheet-names-BLrwcn33.js → sheet-names-RoFkpk_R.js} +2 -2
  48. package/dist/{warnings-DhonqJ7A.d.ts → warnings-Bphby2c7.d.cts} +28 -2
  49. package/dist/{warnings-DhonqJ7A.d.cts → warnings-Bphby2c7.d.ts} +28 -2
  50. package/dist/worker.cjs +5 -5
  51. package/dist/worker.d.cts +4 -4
  52. package/dist/worker.d.ts +4 -4
  53. package/dist/worker.js +5 -5
  54. package/dist/{write-Izl2NG0Y.d.cts → write-BbV7BlbS.d.cts} +1 -1
  55. package/dist/{write-DKXhuvKR.cjs → write-Bgl_QfA8.cjs} +5 -5
  56. package/dist/{write-BVXB2_2C.js → write-DFz-h8gz.js} +5 -5
  57. package/dist/{write-BaMv1Z7W.d.ts → write-DryxCc2Q.d.ts} +1 -1
  58. package/package.json +1 -1
@@ -1,31 +1,43 @@
1
- const require_errors = require("./errors-DOPrrGS4.cjs");
2
- const require_infer = require("./infer-BniOucP6.cjs");
1
+ const require_errors = require("./errors-CKYdpCoB.cjs");
2
+ const require_infer = require("./infer-B950M3-F.cjs");
3
3
  const require_iso_date = require("./iso-date-3TY1OlGd.cjs");
4
4
  // src/internal/csv/decode.ts
5
5
  /**
6
6
  * Bytes -> text for readCsv (docs/api.md §5.3): a UTF-8, UTF-16LE or UTF-16BE
7
7
  * BOM wins; otherwise the `encoding` label applies (default utf-8). Invalid
8
8
  * bytes become U+FFFD and the caller adds a CSV_INVALID_ENCODING warning.
9
+ *
10
+ * `encoding: 'auto'` (JSE-73): a BOM still wins; otherwise strict UTF-8, then
11
+ * strict Windows-1252 (the five bytes it leaves undefined are not text). Bytes
12
+ * that are neither throw FormatError CSV_INVALID_ENCODING.
13
+ *
14
+ * The binary check (`findBinary`) looks at the decoded text.
9
15
  */
10
- function decodeBytes(bytes, label) {
16
+ function decoderCtor() {
11
17
  const Ctor = globalThis.TextDecoder;
12
18
  if (typeof Ctor !== "function") throw new require_errors.EnvironmentError("ENVIRONMENT_UNSUPPORTED", "TextDecoder is not available in this runtime.", { details: { api: "TextDecoder" } });
13
- let encoding = label;
14
- let body = bytes;
15
- let bom = false;
16
- if (bytes[0] === 239 && bytes[1] === 187 && bytes[2] === 191) {
17
- encoding = "utf-8";
18
- body = bytes.subarray(3);
19
- bom = true;
20
- } else if (bytes[0] === 255 && bytes[1] === 254) {
21
- encoding = "utf-16le";
22
- body = bytes.subarray(2);
23
- bom = true;
24
- } else if (bytes[0] === 254 && bytes[1] === 255) {
25
- encoding = "utf-16be";
26
- body = bytes.subarray(2);
27
- bom = true;
28
- }
19
+ return Ctor;
20
+ }
21
+ function sniffBom(bytes) {
22
+ if (bytes[0] === 239 && bytes[1] === 187 && bytes[2] === 191) return {
23
+ encoding: "utf-8",
24
+ length: 3
25
+ };
26
+ if (bytes[0] === 255 && bytes[1] === 254) return {
27
+ encoding: "utf-16le",
28
+ length: 2
29
+ };
30
+ if (bytes[0] === 254 && bytes[1] === 255) return {
31
+ encoding: "utf-16be",
32
+ length: 2
33
+ };
34
+ }
35
+ function decodeBytes(bytes, label) {
36
+ const Ctor = decoderCtor();
37
+ const sniffed = sniffBom(bytes);
38
+ const encoding = sniffed ? sniffed.encoding : label;
39
+ const bomBytes = sniffed ? sniffed.length : 0;
40
+ const body = sniffed ? bytes.subarray(bomBytes) : bytes;
29
41
  let strict;
30
42
  try {
31
43
  strict = new Ctor(encoding, {
@@ -35,12 +47,15 @@ function decodeBytes(bytes, label) {
35
47
  } catch {
36
48
  throw new TypeError(`encoding ${JSON.stringify(label)} is not supported by this runtime's TextDecoder`);
37
49
  }
50
+ const canonical = strict.encoding;
38
51
  try {
39
52
  return {
40
53
  text: strict.decode(body),
41
- bom,
54
+ bom: sniffed !== void 0,
42
55
  encoding,
43
- invalid: false
56
+ canonical,
57
+ invalid: false,
58
+ bomBytes
44
59
  };
45
60
  } catch {
46
61
  return {
@@ -48,12 +63,108 @@ function decodeBytes(bytes, label) {
48
63
  fatal: false,
49
64
  ignoreBOM: true
50
65
  }).decode(body),
51
- bom,
66
+ bom: sniffed !== void 0,
52
67
  encoding,
53
- invalid: true
68
+ canonical,
69
+ invalid: true,
70
+ bomBytes
54
71
  };
55
72
  }
56
73
  }
74
+ /** The bytes Windows-1252 leaves undefined (WHATWG's decoder maps them to C1 controls). */
75
+ function isUndefined1252(b) {
76
+ return b === 129 || b === 141 || b === 143 || b === 144 || b === 157;
77
+ }
78
+ /** `encoding: 'auto'`: BOM, else strict UTF-8, else strict Windows-1252, else CSV_INVALID_ENCODING. */
79
+ function decodeAuto(bytes) {
80
+ const Ctor = decoderCtor();
81
+ const sniffed = sniffBom(bytes);
82
+ if (sniffed) try {
83
+ return {
84
+ text: new Ctor(sniffed.encoding, {
85
+ fatal: true,
86
+ ignoreBOM: true
87
+ }).decode(bytes.subarray(sniffed.length)),
88
+ bom: true,
89
+ encoding: sniffed.encoding,
90
+ canonical: sniffed.encoding,
91
+ invalid: false,
92
+ bomBytes: sniffed.length
93
+ };
94
+ } catch {
95
+ throw new require_errors.FormatError("CSV_INVALID_ENCODING", `The input starts with a ${sniffed.encoding} byte order mark but is not valid ${sniffed.encoding}.`, { details: { encodings: [sniffed.encoding] } });
96
+ }
97
+ try {
98
+ return {
99
+ text: new Ctor("utf-8", {
100
+ fatal: true,
101
+ ignoreBOM: true
102
+ }).decode(bytes),
103
+ bom: false,
104
+ encoding: "utf-8",
105
+ canonical: "utf-8",
106
+ invalid: false,
107
+ bomBytes: 0
108
+ };
109
+ } catch {}
110
+ for (let i = 0; i < bytes.length; i++) if (isUndefined1252(bytes[i])) throw new require_errors.FormatError("CSV_INVALID_ENCODING", `The input is neither valid UTF-8 nor valid Windows-1252 (byte ${i} is undefined in Windows-1252).`, { details: {
111
+ encodings: ["utf-8", "windows-1252"],
112
+ byteOffset: i
113
+ } });
114
+ return {
115
+ text: new Ctor("windows-1252", { ignoreBOM: true }).decode(bytes),
116
+ bom: false,
117
+ encoding: "windows-1252",
118
+ canonical: "windows-1252",
119
+ invalid: false,
120
+ bomBytes: 0
121
+ };
122
+ }
123
+ /**
124
+ * True for a character rejectBinary refuses: C0 controls other than TAB, LF, VT, FF,
125
+ * CR and ESC, and DEL; with `c1`, also U+0080..U+009F (Windows-1252 text, where only
126
+ * the undefined bytes decode to them).
127
+ */
128
+ function isBinaryChar(c, c1) {
129
+ if (c < 32) return c < 9 || c > 13 && c !== 27;
130
+ if (c === 127) return true;
131
+ return c1 && c >= 128 && c <= 159;
132
+ }
133
+ /** Index of the first refused character in text[from, to), or -1. Linear; stops at the first hit. */
134
+ function findBinary(text, from, to, c1) {
135
+ const end = Math.min(to, text.length);
136
+ for (let i = from; i < end; i++) {
137
+ const c = text.charCodeAt(i);
138
+ if ((c < 32 || c >= 127) && isBinaryChar(c, c1)) return i;
139
+ }
140
+ return -1;
141
+ }
142
+ /**
143
+ * Byte offset in the input of character `index` of text decoded without
144
+ * replacements, for the encodings where that is exact; undefined otherwise.
145
+ */
146
+ function byteOffsetOf(d, index) {
147
+ if (d.invalid) return void 0;
148
+ switch (d.canonical) {
149
+ case "utf-8": {
150
+ let n = d.bomBytes;
151
+ for (let i = 0; i < index; i++) {
152
+ const c = d.text.charCodeAt(i);
153
+ if (c < 128) n += 1;
154
+ else if (c < 2048) n += 2;
155
+ else if (c >= 55296 && c <= 56319) {
156
+ n += 4;
157
+ i++;
158
+ } else n += 3;
159
+ }
160
+ return n;
161
+ }
162
+ case "utf-16le":
163
+ case "utf-16be": return d.bomBytes + 2 * index;
164
+ case "windows-1252": return d.bomBytes + index;
165
+ default: return;
166
+ }
167
+ }
57
168
  // src/internal/csv/ref.ts
58
169
  /** A1 reference for a zero-based row and column, e.g. (2, 1) -> 'B3'. */
59
170
  function cellRef(row, col) {
@@ -99,6 +210,8 @@ const CR = 13;
99
210
  /** The resumable state of one parse. */
100
211
  var CsvParser = class {
101
212
  rows = [];
213
+ /** Records read so far, kept or not. */
214
+ rowCount = 0;
102
215
  warnings;
103
216
  delimiter;
104
217
  bom;
@@ -139,17 +252,17 @@ var CsvParser = class {
139
252
  const startLine = this.line;
140
253
  const fields = this.record();
141
254
  if (fields.length === 0 && cfg.skipEmptyLines) continue;
142
- if (this.rows.length >= cfg.maxRows) {
255
+ if (this.rowCount >= cfg.maxRows) {
143
256
  this.warn("CSV_ROWS_TRUNCATED", `Stopped after maxRows (${cfg.maxRows}) rows; the rest of the input was not read.`, void 0, false);
144
257
  this.finish();
145
258
  return;
146
259
  }
147
- const rowIndex = this.rows.length;
260
+ const rowIndex = this.rowCount++;
148
261
  if (fields.length > 0) {
149
262
  if (this.expectedFields === -1) this.expectedFields = fields.length;
150
263
  else if (fields.length !== this.expectedFields) this.warn("CSV_FIELD_COUNT", `Row ${rowIndex + 1} (line ${startLine}) has ${fields.length} fields; the first row has ${this.expectedFields}.`, cellRef(rowIndex, 0));
151
264
  }
152
- this.rows.push(cfg.inferTypes ? fields.map((f) => f.quoted ? f.text : require_infer.inferValue(f.text, cfg.dateZone)) : fields.map((f) => f.text));
265
+ if (cfg.keepRows) this.rows.push(cfg.inferTypes ? fields.map((f) => f.quoted ? f.text : require_infer.inferValue(f.text, cfg.dateZone)) : fields.map((f) => f.text));
153
266
  }
154
267
  }
155
268
  finish() {
@@ -173,7 +286,7 @@ var CsvParser = class {
173
286
  }
174
287
  for (;;) {
175
288
  const col = fields.length;
176
- const row = this.rows.length;
289
+ const row = this.rowCount;
177
290
  let value;
178
291
  let quoted = false;
179
292
  if (text.charCodeAt(this.pos) === this.quoteCode) {
@@ -362,6 +475,7 @@ function validateConfig(cfg) {
362
475
  if (!(cfg.maxCellTextLength > 0)) throw new TypeError("maxCellTextLength must be a positive number");
363
476
  if (!(cfg.maxColumns > 0)) throw new TypeError("maxColumns must be a positive number");
364
477
  require_infer.checkMaxWarnings("maxWarnings", cfg.maxWarnings);
478
+ if (typeof cfg.keepRows !== "boolean") throw new TypeError("keepRows must be a boolean");
365
479
  }
366
480
  /** A delimiter or quote: exactly one UTF-16 code unit, not CR or LF. */
367
481
  function checkSeparator(name, value) {
@@ -598,7 +712,8 @@ function parseConfig(options) {
598
712
  maxCellTextLength: o.maxCellTextLength === void 0 ? DEFAULT_MAX_CELL_TEXT_LENGTH : o.maxCellTextLength,
599
713
  maxColumns: o.maxColumns === void 0 ? DEFAULT_MAX_COLUMNS : o.maxColumns,
600
714
  dateZone: o.dateZone ?? "local",
601
- maxWarnings: o.maxWarnings === void 0 ? MAX_WARNINGS : o.maxWarnings
715
+ maxWarnings: o.maxWarnings === void 0 ? MAX_WARNINGS : o.maxWarnings,
716
+ keepRows: o.keepRows ?? true
602
717
  };
603
718
  }
604
719
  function checkMode(options) {
@@ -607,13 +722,14 @@ function checkMode(options) {
607
722
  const zone = options?.dateZone;
608
723
  if (zone !== void 0 && zone !== "local" && zone !== "utc") throw new TypeError(`dateZone must be 'local' or 'utc'`);
609
724
  }
610
- function result(p, bom, extra) {
725
+ function result(p, bom, extra, encoding) {
611
726
  return {
612
727
  rows: p.rows,
613
728
  delimiter: p.delimiter,
614
729
  newline: p.newline ?? "\r\n",
615
730
  bom: bom || p.bom,
616
- warnings: extra.length ? [...extra, ...p.warnings] : p.warnings
731
+ warnings: extra.length ? [...extra, ...p.warnings] : p.warnings,
732
+ ...encoding === void 0 ? {} : { encoding }
617
733
  };
618
734
  }
619
735
  /** Parses CSV text synchronously. */
@@ -630,16 +746,25 @@ function parseCsv(text, options) {
630
746
  */
631
747
  async function readCsv(input, options) {
632
748
  checkMode(options);
749
+ const rejectBinary = options?.rejectBinary ?? false;
750
+ if (typeof rejectBinary !== "boolean") throw new TypeError("rejectBinary must be a boolean");
751
+ const maxInputBytes = options?.maxInputBytes === void 0 ? Number.POSITIVE_INFINITY : options.maxInputBytes;
752
+ if (typeof maxInputBytes !== "number" || !(maxInputBytes > 0)) throw new TypeError("maxInputBytes must be a positive number");
753
+ const config = parseConfig(options);
633
754
  const signal = options?.signal;
634
755
  throwIfAborted(signal);
635
756
  let text;
636
757
  let bom = false;
758
+ let decoded;
637
759
  const extra = [];
638
760
  if (typeof input === "string") text = input;
639
761
  else {
762
+ require_infer.checkBlobSize(input, maxInputBytes);
640
763
  const bytes = await require_infer.toBytes(input, "readCsv", "a string, ");
764
+ if (bytes.length > maxInputBytes) throw require_infer.inputTooLarge(bytes.length, maxInputBytes);
641
765
  throwIfAborted(signal);
642
- const decoded = decodeBytes(bytes, options?.encoding ?? "utf-8");
766
+ const label = options?.encoding ?? "utf-8";
767
+ decoded = label === "auto" ? decodeAuto(bytes) : decodeBytes(bytes, label);
643
768
  text = decoded.text;
644
769
  bom = decoded.bom;
645
770
  if (decoded.invalid) {
@@ -654,7 +779,18 @@ async function readCsv(input, options) {
654
779
  });
655
780
  }
656
781
  }
657
- const p = new CsvParser(text, parseConfig(options));
782
+ if (rejectBinary) {
783
+ const c1 = decoded?.canonical === "windows-1252";
784
+ for (let from = 0; from < text.length; from += CHUNK_CHARS) {
785
+ const at = findBinary(text, from, from + CHUNK_CHARS, c1);
786
+ if (at >= 0) throw binaryInput(text, at, decoded);
787
+ if (from + CHUNK_CHARS < text.length) {
788
+ await yieldToEventLoop();
789
+ throwIfAborted(signal);
790
+ }
791
+ }
792
+ }
793
+ const p = new CsvParser(text, config);
658
794
  while (!p.done) {
659
795
  p.run(p.position + CHUNK_CHARS);
660
796
  if (!p.done) {
@@ -662,7 +798,18 @@ async function readCsv(input, options) {
662
798
  throwIfAborted(signal);
663
799
  }
664
800
  }
665
- return result(p, bom, extra);
801
+ return result(p, bom, extra, decoded?.canonical);
802
+ }
803
+ function binaryInput(text, offset, decoded) {
804
+ const codePoint = text.charCodeAt(offset);
805
+ const byteOffset = decoded === void 0 ? void 0 : byteOffsetOf(decoded, offset);
806
+ const hex = codePoint.toString(16).toUpperCase().padStart(4, "0");
807
+ return new require_errors.FormatError("CSV_BINARY_INPUT", `The input is not text: control character U+${hex} at character ${offset}${byteOffset === void 0 ? "" : ` (byte ${byteOffset})`}.`, { details: {
808
+ offset,
809
+ ...byteOffset === void 0 ? {} : { byteOffset },
810
+ codePoint,
811
+ ...decoded === void 0 ? {} : { encoding: decoded.canonical }
812
+ } });
666
813
  }
667
814
  /** Serializes a sheet (A1 to its last used cell) or an array of rows to CSV text. */
668
815
  function toCsv(source, options) {
package/dist/csv.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_warnings = require("./warnings-CJPiDqei.cjs");
3
- const require_csv = require("./csv-DZ241Y5F.cjs");
3
+ const require_csv = require("./csv-BkVmMYQq.cjs");
4
4
  exports.CSV_MIME = require_csv.CSV_MIME;
5
5
  exports.isDataLossWarning = require_warnings.isDataLossWarning;
6
6
  exports.parseCsv = require_csv.parseCsv;
package/dist/csv.d.cts CHANGED
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * @module javascript-excel/csv
10
10
  */
11
- import { a as isDataLossWarning, c as BlobType, i as ExcelWarningCode, n as ExcelPartKind, o as BinaryInput, r as ExcelWarning, s as BlobLike, t as DroppedWarnings } from "./warnings-DhonqJ7A.cjs";
11
+ import { a as isDataLossWarning, c as BlobType, i as ExcelWarningCode, n as ExcelPartKind, o as BinaryInput, r as ExcelWarning, s as BlobLike, t as DroppedWarnings } from "./warnings-Bphby2c7.cjs";
12
12
  import { D as Sheet, T as RichTextRun, a as Cell, c as CellType, h as ErrorCode, j as Workbook, l as CellValue, o as CellErrorValue, s as CellInput, w as RichText } from "./model-BUNp7B0Z.cjs";
13
13
  import { t as AbortSignalLike } from "./signal-Dz0ZYe6d.cjs";
14
14
  /** Options for `parseCsv` and `readCsv`. */
@@ -67,11 +67,44 @@ export interface CsvParseOptions {
67
67
  * A positive number; default 1,000.
68
68
  */
69
69
  maxWarnings?: number | undefined;
70
+ /**
71
+ * Default true. false: every record is parsed and checked (limits, `mode`, warnings) but none
72
+ * is kept, and `rows` is `[]` (added in 2.5). For checking that a file is readable CSV without
73
+ * holding its rows: memory stays at the input and its decoded text, plus one record. `null` is
74
+ * the default.
75
+ */
76
+ keepRows?: boolean | undefined;
70
77
  }
71
78
  /** Options for `readCsv`. */
72
79
  export interface CsvReadOptions extends CsvParseOptions {
73
- /** Used when the bytes have no BOM. Any label `TextDecoder` accepts. Default `'utf-8'`. */
74
- encoding?: string | undefined;
80
+ /**
81
+ * Used when the bytes have no BOM. Any label `TextDecoder` accepts. Default `'utf-8'`.
82
+ * `'auto'` (added in 2.5): a UTF-8, UTF-16LE or UTF-16BE BOM still wins; otherwise strict
83
+ * UTF-8, then strict Windows-1252 (its five undefined bytes 0x81, 0x8D, 0x8F, 0x90, 0x9D are
84
+ * not text). Bytes that are neither, or not valid after their BOM, throw `FormatError`
85
+ * (`CSV_INVALID_ENCODING`) in both modes, instead of being replaced. UTF-16 without a BOM is
86
+ * not guessed. The result's `encoding` says which one was used. Windows-1252 input costs three
87
+ * linear passes over the bytes (failed UTF-8 decode, undefined-byte scan, decode).
88
+ */
89
+ encoding?: string | "auto" | undefined;
90
+ /**
91
+ * Default false. true: text containing a control character that text files do not contain
92
+ * throws `FormatError` (`CSV_BINARY_INPUT`) before any record is parsed, with
93
+ * `details: { offset, byteOffset?, codePoint, encoding? }`, never the content (added in 2.5).
94
+ * Refused: U+0000..U+0008, U+000E..U+001A, U+001C..U+001F and U+007F; allowed: TAB, LF,
95
+ * VT, FF, CR and ESC. U+0080..U+009F are refused only in text decoded as Windows-1252, where
96
+ * they come from its undefined bytes. Applies to strings too. `null` is the default. It only
97
+ * answers "does this decode to text?": HTML, script or polyglot content is text and passes.
98
+ */
99
+ rejectBinary?: boolean | undefined;
100
+ /**
101
+ * Largest binary input, in bytes (a BOM included); a bigger one throws `LimitError`
102
+ * (`LIMIT_EXCEEDED`, `details: { limit: 'maxInputBytes', value, max }`), as for `read`. A
103
+ * `Blob` is checked by its `size` before it is read. Does not apply to string input. Default
104
+ * unlimited; as for `read`, any value but `undefined` must be a positive number (`null` is a
105
+ * `TypeError`) (added in 2.5).
106
+ */
107
+ maxInputBytes?: number | undefined;
75
108
  /** Rejects with `signal.reason` when aborted. */
76
109
  signal?: AbortSignalLike | undefined;
77
110
  }
@@ -85,6 +118,12 @@ export interface CsvParseResult {
85
118
  newline: "\r\n" | "\n" | "\r";
86
119
  /** The input started with a BOM (removed from the data). */
87
120
  bom: boolean;
121
+ /**
122
+ * `readCsv` with bytes: the encoding the text was decoded with, by its WHATWG name
123
+ * (`'utf-8'`, `'utf-16le'`, `'utf-16be'`, `'windows-1252'`, …; `'latin1'` gives
124
+ * `'windows-1252'`). Absent for a string and for `parseCsv` (added in 2.5).
125
+ */
126
+ encoding?: string | undefined;
88
127
  /** `CSV_UNTERMINATED_QUOTE`, `CSV_STRAY_QUOTE`, `CSV_FIELD_COUNT`, `CSV_INVALID_ENCODING`, `CSV_ROWS_TRUNCATED`, then `WARNINGS_TRUNCATED` if the cap dropped any (see `maxWarnings`). */
89
128
  warnings: ExcelWarning[];
90
129
  }
package/dist/csv.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * @module javascript-excel/csv
10
10
  */
11
- import { a as isDataLossWarning, c as BlobType, i as ExcelWarningCode, n as ExcelPartKind, o as BinaryInput, r as ExcelWarning, s as BlobLike, t as DroppedWarnings } from "./warnings-DhonqJ7A.js";
11
+ import { a as isDataLossWarning, c as BlobType, i as ExcelWarningCode, n as ExcelPartKind, o as BinaryInput, r as ExcelWarning, s as BlobLike, t as DroppedWarnings } from "./warnings-Bphby2c7.js";
12
12
  import { D as Sheet, T as RichTextRun, a as Cell, c as CellType, h as ErrorCode, j as Workbook, l as CellValue, o as CellErrorValue, s as CellInput, w as RichText } from "./model-BUNp7B0Z.js";
13
13
  import { t as AbortSignalLike } from "./signal-Dz0ZYe6d.js";
14
14
  /** Options for `parseCsv` and `readCsv`. */
@@ -67,11 +67,44 @@ export interface CsvParseOptions {
67
67
  * A positive number; default 1,000.
68
68
  */
69
69
  maxWarnings?: number | undefined;
70
+ /**
71
+ * Default true. false: every record is parsed and checked (limits, `mode`, warnings) but none
72
+ * is kept, and `rows` is `[]` (added in 2.5). For checking that a file is readable CSV without
73
+ * holding its rows: memory stays at the input and its decoded text, plus one record. `null` is
74
+ * the default.
75
+ */
76
+ keepRows?: boolean | undefined;
70
77
  }
71
78
  /** Options for `readCsv`. */
72
79
  export interface CsvReadOptions extends CsvParseOptions {
73
- /** Used when the bytes have no BOM. Any label `TextDecoder` accepts. Default `'utf-8'`. */
74
- encoding?: string | undefined;
80
+ /**
81
+ * Used when the bytes have no BOM. Any label `TextDecoder` accepts. Default `'utf-8'`.
82
+ * `'auto'` (added in 2.5): a UTF-8, UTF-16LE or UTF-16BE BOM still wins; otherwise strict
83
+ * UTF-8, then strict Windows-1252 (its five undefined bytes 0x81, 0x8D, 0x8F, 0x90, 0x9D are
84
+ * not text). Bytes that are neither, or not valid after their BOM, throw `FormatError`
85
+ * (`CSV_INVALID_ENCODING`) in both modes, instead of being replaced. UTF-16 without a BOM is
86
+ * not guessed. The result's `encoding` says which one was used. Windows-1252 input costs three
87
+ * linear passes over the bytes (failed UTF-8 decode, undefined-byte scan, decode).
88
+ */
89
+ encoding?: string | "auto" | undefined;
90
+ /**
91
+ * Default false. true: text containing a control character that text files do not contain
92
+ * throws `FormatError` (`CSV_BINARY_INPUT`) before any record is parsed, with
93
+ * `details: { offset, byteOffset?, codePoint, encoding? }`, never the content (added in 2.5).
94
+ * Refused: U+0000..U+0008, U+000E..U+001A, U+001C..U+001F and U+007F; allowed: TAB, LF,
95
+ * VT, FF, CR and ESC. U+0080..U+009F are refused only in text decoded as Windows-1252, where
96
+ * they come from its undefined bytes. Applies to strings too. `null` is the default. It only
97
+ * answers "does this decode to text?": HTML, script or polyglot content is text and passes.
98
+ */
99
+ rejectBinary?: boolean | undefined;
100
+ /**
101
+ * Largest binary input, in bytes (a BOM included); a bigger one throws `LimitError`
102
+ * (`LIMIT_EXCEEDED`, `details: { limit: 'maxInputBytes', value, max }`), as for `read`. A
103
+ * `Blob` is checked by its `size` before it is read. Does not apply to string input. Default
104
+ * unlimited; as for `read`, any value but `undefined` must be a positive number (`null` is a
105
+ * `TypeError`) (added in 2.5).
106
+ */
107
+ maxInputBytes?: number | undefined;
75
108
  /** Rejects with `signal.reason` when aborted. */
76
109
  signal?: AbortSignalLike | undefined;
77
110
  }
@@ -85,6 +118,12 @@ export interface CsvParseResult {
85
118
  newline: "\r\n" | "\n" | "\r";
86
119
  /** The input started with a BOM (removed from the data). */
87
120
  bom: boolean;
121
+ /**
122
+ * `readCsv` with bytes: the encoding the text was decoded with, by its WHATWG name
123
+ * (`'utf-8'`, `'utf-16le'`, `'utf-16be'`, `'windows-1252'`, …; `'latin1'` gives
124
+ * `'windows-1252'`). Absent for a string and for `parseCsv` (added in 2.5).
125
+ */
126
+ encoding?: string | undefined;
88
127
  /** `CSV_UNTERMINATED_QUOTE`, `CSV_STRAY_QUOTE`, `CSV_FIELD_COUNT`, `CSV_INVALID_ENCODING`, `CSV_ROWS_TRUNCATED`, then `WARNINGS_TRUNCATED` if the cap dropped any (see `maxWarnings`). */
89
128
  warnings: ExcelWarning[];
90
129
  }
package/dist/csv.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import { t as isDataLossWarning } from "./warnings-BPz1Ia3s.js";
2
- import { a as toCsvBlob, i as toCsv, n as parseCsv, r as readCsv, t as CSV_MIME } from "./csv-Dn4MIESx.js";
2
+ import { a as toCsvBlob, i as toCsv, n as parseCsv, r as readCsv, t as CSV_MIME } from "./csv-5jVhfM5l.js";
3
3
  export { CSV_MIME, isDataLossWarning, parseCsv, readCsv, toCsv, toCsvBlob };
@@ -1,9 +1,9 @@
1
- const require_address = require("./address-DZBHchLv.cjs");
1
+ const require_address = require("./address-DKd_3EGf.cjs");
2
2
  const require_cells = require("./cells-CPXU722t.cjs");
3
- const require_dates = require("./dates-CA1dCizp.cjs");
4
- const require_errors = require("./errors-DOPrrGS4.cjs");
3
+ const require_dates = require("./dates-DcdgnJto.cjs");
4
+ const require_errors = require("./errors-CKYdpCoB.cjs");
5
5
  const require_iso_date = require("./iso-date-3TY1OlGd.cjs");
6
- const require_sheet_names = require("./sheet-names-DDY64-dt.cjs");
6
+ const require_sheet_names = require("./sheet-names-D8sYcjSd.cjs");
7
7
  // src/dataset.ts
8
8
  /**
9
9
  * Dataset builders (docs/api.md §4.3): `{ columns, data }` ↔ Sheet.
@@ -1,9 +1,9 @@
1
- import { a as decodeRange, c as encodeRange, o as encodeCell, r as decodeCell, s as encodeCol, t as MAX_COLS } from "./address-DUn7-5OS.js";
1
+ import { a as decodeRange, c as encodeRange, o as encodeCell, r as decodeCell, s as encodeCol, t as MAX_COLS } from "./address-BGH42dEg.js";
2
2
  import { t as cellText } from "./cells-CrMF8h_t.js";
3
- import { t as dateToSerial } from "./dates-BXcSWf9_.js";
4
- import { a as LimitError, o as ValidationError } from "./errors-CvGlfw0E.js";
3
+ import { t as dateToSerial } from "./dates-CIL1z9EY.js";
4
+ import { a as LimitError, o as ValidationError } from "./errors-BQE62PFo.js";
5
5
  import { n as parseIsoDate, t as isoDate } from "./iso-date-CXnn-9mT.js";
6
- import { l as textWidth, m as mergeStyles, n as validateSheetName, r as AUTO_WIDTH } from "./sheet-names-BLrwcn33.js";
6
+ import { l as textWidth, m as mergeStyles, n as validateSheetName, r as AUTO_WIDTH } from "./sheet-names-RoFkpk_R.js";
7
7
  // src/dataset.ts
8
8
  /**
9
9
  * Dataset builders (docs/api.md §4.3): `{ columns, data }` ↔ Sheet.
@@ -1,4 +1,4 @@
1
- import { o as ValidationError } from "./errors-CvGlfw0E.js";
1
+ import { o as ValidationError } from "./errors-BQE62PFo.js";
2
2
  // src/dates.ts
3
3
  /**
4
4
  * Date ↔ serial conversion (docs/api.md §3.4.1, §4.5).
@@ -1,4 +1,4 @@
1
- const require_errors = require("./errors-DOPrrGS4.cjs");
1
+ const require_errors = require("./errors-CKYdpCoB.cjs");
2
2
  // src/dates.ts
3
3
  /**
4
4
  * Date ↔ serial conversion (docs/api.md §3.4.1, §4.5).
package/dist/dom.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_cells = require("./cells-CPXU722t.cjs");
3
- const require_sheet_names = require("./sheet-names-DDY64-dt.cjs");
4
- const require_errors = require("./errors-DOPrrGS4.cjs");
3
+ const require_sheet_names = require("./sheet-names-D8sYcjSd.cjs");
4
+ const require_errors = require("./errors-CKYdpCoB.cjs");
5
5
  const require_iso_date = require("./iso-date-3TY1OlGd.cjs");
6
6
  const require_warnings = require("./warnings-CJPiDqei.cjs");
7
7
  // src/auto-width.ts
package/dist/dom.d.cts CHANGED
@@ -8,7 +8,7 @@
8
8
  * @module javascript-excel/dom
9
9
  */
10
10
  import { t as AutoWidthOptions } from "./auto-width-DZvQSucm.cjs";
11
- import { a as isDataLossWarning, c as BlobType, i as ExcelWarningCode, n as ExcelPartKind, r as ExcelWarning, t as DroppedWarnings } from "./warnings-DhonqJ7A.cjs";
11
+ import { a as isDataLossWarning, c as BlobType, i as ExcelWarningCode, n as ExcelPartKind, r as ExcelWarning, t as DroppedWarnings } from "./warnings-Bphby2c7.cjs";
12
12
  import { D as Sheet, k as Style, s as CellInput } from "./model-BUNp7B0Z.cjs";
13
13
  /** `HTMLTableElement` when the consumer has DOM types, else `object`. */
14
14
  export type TableElement = typeof globalThis extends {
package/dist/dom.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  * @module javascript-excel/dom
9
9
  */
10
10
  import { t as AutoWidthOptions } from "./auto-width-CT-BihTW.js";
11
- import { a as isDataLossWarning, c as BlobType, i as ExcelWarningCode, n as ExcelPartKind, r as ExcelWarning, t as DroppedWarnings } from "./warnings-DhonqJ7A.js";
11
+ import { a as isDataLossWarning, c as BlobType, i as ExcelWarningCode, n as ExcelPartKind, r as ExcelWarning, t as DroppedWarnings } from "./warnings-Bphby2c7.js";
12
12
  import { D as Sheet, k as Style, s as CellInput } from "./model-BUNp7B0Z.js";
13
13
  /** `HTMLTableElement` when the consumer has DOM types, else `object`. */
14
14
  export type TableElement = typeof globalThis extends {
package/dist/dom.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as cellText } from "./cells-CrMF8h_t.js";
2
- import { c as hyperlinkSchemes, i as DEFAULT_HYPERLINK_SCHEMES, l as textWidth, m as mergeStyles, n as validateSheetName, r as AUTO_WIDTH } from "./sheet-names-BLrwcn33.js";
3
- import { n as EnvironmentError, o as ValidationError } from "./errors-CvGlfw0E.js";
2
+ import { c as hyperlinkSchemes, i as DEFAULT_HYPERLINK_SCHEMES, l as textWidth, m as mergeStyles, n as validateSheetName, r as AUTO_WIDTH } from "./sheet-names-RoFkpk_R.js";
3
+ import { n as EnvironmentError, o as ValidationError } from "./errors-BQE62PFo.js";
4
4
  import { n as parseIsoDate } from "./iso-date-CXnn-9mT.js";
5
5
  import { t as isDataLossWarning } from "./warnings-BPz1Ia3s.js";
6
6
  // src/auto-width.ts
@@ -1,4 +1,4 @@
1
- import { a as LimitError, i as FormatError, n as EnvironmentError } from "./errors-CvGlfw0E.js";
1
+ import { a as LimitError, i as FormatError, n as EnvironmentError } from "./errors-BQE62PFo.js";
2
2
  // src/internal/zip/bytes.ts
3
3
  /** Rejects with `signal.reason`, the same as fetch. */
4
4
  function throwIfAborted(signal) {
@@ -1,4 +1,4 @@
1
- const require_errors = require("./errors-DOPrrGS4.cjs");
1
+ const require_errors = require("./errors-CKYdpCoB.cjs");
2
2
  // src/internal/zip/bytes.ts
3
3
  /** Rejects with `signal.reason`, the same as fetch. */
4
4
  function throwIfAborted(signal) {
@@ -13,7 +13,7 @@ var ExcelError = class extends Error {
13
13
  };
14
14
  /** The model or options cannot be written. */
15
15
  var ValidationError = class extends ExcelError {};
16
- /** The input is not a readable xlsx or zip file. */
16
+ /** The input is not a readable xlsx or zip file, or (readCsv) not text. */
17
17
  var FormatError = class extends ExcelError {};
18
18
  /** A read limit was exceeded; `details.limit` names it. */
19
19
  var LimitError = class extends ExcelError {};
@@ -13,7 +13,7 @@ var ExcelError = class extends Error {
13
13
  };
14
14
  /** The model or options cannot be written. */
15
15
  var ValidationError = class extends ExcelError {};
16
- /** The input is not a readable xlsx or zip file. */
16
+ /** The input is not a readable xlsx or zip file, or (readCsv) not text. */
17
17
  var FormatError = class extends ExcelError {};
18
18
  /** A read limit was exceeded; `details.limit` names it. */
19
19
  var LimitError = class extends ExcelError {};
package/dist/format.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_cells = require("./cells-CPXU722t.cjs");
3
- const require_dates = require("./dates-CA1dCizp.cjs");
3
+ const require_dates = require("./dates-DcdgnJto.cjs");
4
4
  const require_numfmt = require("./numfmt-DwsnhZKe.cjs");
5
5
  // src/internal/format/parse.ts
6
6
  const COLOR_NAMES = /* @__PURE__ */ new Set([
package/dist/format.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as cellText } from "./cells-CrMF8h_t.js";
2
- import { t as dateToSerial } from "./dates-BXcSWf9_.js";
2
+ import { t as dateToSerial } from "./dates-CIL1z9EY.js";
3
3
  import { t as BUILTIN_NUM_FMTS } from "./numfmt-Ci_oW11p.js";
4
4
  // src/internal/format/parse.ts
5
5
  const COLOR_NAMES = /* @__PURE__ */ new Set([
package/dist/import.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_pipeline = require("./pipeline-BwkRpV5Z.cjs");
2
+ const require_pipeline = require("./pipeline-C13EIWHJ.cjs");
3
3
  const require_warnings = require("./warnings-CJPiDqei.cjs");
4
4
  exports.applyMapping = require_pipeline.applyMapping;
5
5
  exports.coerceColumns = require_pipeline.coerceColumns;
package/dist/import.d.cts CHANGED
@@ -3,8 +3,8 @@
3
3
  * (docs/api.md §5.6). Header detection, type inference, locale-aware
4
4
  * parsing and column mapping, plus the `importDataset` pipeline.
5
5
  */
6
- import { A as NumberGroup, C as coerceColumns, D as ImportLocale, E as HeaderDetection, M as parseNumber, O as detectHeader, S as TypeOptions, T as DetectHeaderOptions, _ as ColumnType, a as ImportProgress, b as ImportIssueCode, c as FieldSpec, d as MappableDataset, f as MappedDataset, g as CoerceResult, h as mapColumns, i as ImportMeta, j as parseDate, k as DateOrder, l as ImportSchema, m as applyMapping, n as ImportDatasetOptions, o as importDataset, p as MappingResult, r as ImportDatasetResult, s as ColumnMapping, t as DroppedIssues, u as ImportedColumn, v as DatasetLike, w as inferColumnTypes, x as InferredColumn, y as ImportIssue } from "./pipeline-4U7Xnuc1.cjs";
7
- import { a as isDataLossWarning, c as BlobType, i as ExcelWarningCode, n as ExcelPartKind, o as BinaryInput, r as ExcelWarning, s as BlobLike, t as DroppedWarnings } from "./warnings-DhonqJ7A.cjs";
6
+ import { A as NumberGroup, C as coerceColumns, D as ImportLocale, E as HeaderDetection, M as parseNumber, O as detectHeader, S as TypeOptions, T as DetectHeaderOptions, _ as ColumnType, a as ImportProgress, b as ImportIssueCode, c as FieldSpec, d as MappableDataset, f as MappedDataset, g as CoerceResult, h as mapColumns, i as ImportMeta, j as parseDate, k as DateOrder, l as ImportSchema, m as applyMapping, n as ImportDatasetOptions, o as importDataset, p as MappingResult, r as ImportDatasetResult, s as ColumnMapping, t as DroppedIssues, u as ImportedColumn, v as DatasetLike, w as inferColumnTypes, x as InferredColumn, y as ImportIssue } from "./pipeline-C7R86kQg.cjs";
7
+ import { a as isDataLossWarning, c as BlobType, i as ExcelWarningCode, n as ExcelPartKind, o as BinaryInput, r as ExcelWarning, s as BlobLike, t as DroppedWarnings } from "./warnings-Bphby2c7.cjs";
8
8
  import { t as AbortSignalLike } from "./signal-Dz0ZYe6d.cjs";
9
9
  import { ReadLimits, SheetInfo } from "./read.cjs";
10
10
  export { type AbortSignalLike, type BinaryInput, type BlobLike, type BlobType, type CoerceResult, type ColumnMapping, type ColumnType, type DatasetLike, type DateOrder, type DetectHeaderOptions, type DroppedIssues, type DroppedWarnings, type ExcelPartKind, type ExcelWarning, type ExcelWarningCode, type FieldSpec, type HeaderDetection, type ImportDatasetOptions, type ImportDatasetResult, type ImportIssue, type ImportIssueCode, type ImportLocale, type ImportMeta, type ImportProgress, type ImportSchema, type ImportedColumn, type InferredColumn, type MappableDataset, type MappedDataset, type MappingResult, type NumberGroup, type ReadLimits, type SheetInfo, type TypeOptions, applyMapping, coerceColumns, detectHeader, importDataset, inferColumnTypes, isDataLossWarning, mapColumns, parseDate, parseNumber };