javascript-excel 2.4.0 → 2.5.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-1AVJbbqT.js} +12 -7
  35. package/dist/{pipeline-BwkRpV5Z.cjs → pipeline-C9zhwGAV.cjs} +12 -7
  36. package/dist/{pipeline-4U7Xnuc1.d.cts → pipeline-CJWE3NWg.d.cts} +7 -3
  37. package/dist/{pipeline-BegSPu8X.d.ts → pipeline-DVgO1aGC.d.ts} +7 -3
  38. package/dist/{read-cvxu6O-H.js → read-B6tY0ooT.js} +2202 -799
  39. package/dist/{read-DmUPztqh.cjs → read-Dgw9kMzh.cjs} +2203 -794
  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-DEsTp6rd.d.cts} +13 -2
  49. package/dist/{warnings-DhonqJ7A.d.cts → warnings-DEsTp6rd.d.ts} +13 -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-DKXhuvKR.cjs → write-Bgl_QfA8.cjs} +5 -5
  55. package/dist/{write-BaMv1Z7W.d.ts → write-BylKqAmD.d.ts} +1 -1
  56. package/dist/{write-BVXB2_2C.js → write-DFz-h8gz.js} +5 -5
  57. package/dist/{write-Izl2NG0Y.d.cts → write-JvXRv63d.d.cts} +1 -1
  58. package/package.json +1 -1
package/README.md CHANGED
@@ -91,7 +91,9 @@ const cell = exact.workbook.sheets[0]?.rows[0]?.[0];
91
91
  console.log(cell?.type, cell?.value, cell?.rawText); // "number" 50.3 "50.30"
92
92
  ```
93
93
 
94
- Damage the reader can recover from comes back as `warnings`. `isDataLossWarning(w)` tells the ones where data was lost (a cell skipped, rows cut, a part missing, comments or charts not read; `partKind` names the part) from informational ones; the warning cap (`limits.maxWarnings`, default 1,000) drops only informational warnings, so filtering `warnings` with it is enough to refuse a damaged file.
94
+ Damage the reader can recover from comes back as `warnings`. `isDataLossWarning(w)` tells the ones where data was lost (a cell skipped, rows cut, a part missing, comments or charts not read; `partKind` names the part, including ActiveX controls, embedded files, customUI, web add-ins and parts no relationship reaches, wherever they sit in the package) from informational ones; the warning cap (`limits.maxWarnings`, default 1,000) drops only informational warnings, so filtering `warnings` with it is enough to refuse a damaged file.
95
+
96
+ To accept or refuse an upload without reading it into the model, `inspect(file, { limits, signal })` checks it part by part without building cells: it refuses every file `read` refuses under the same limits, with the same error, and returns the format, the worksheets with their cell counts, and the part kinds `read` reports (`partKinds`: VBA, external links, OLE objects, …). It also inflates the parts `read` never opens, searches the bytes of every one of them for `<!DOCTYPE` (ASCII-compatible, UTF-16 and UTF-32 forms, whatever the part's name; a declaration inside an XML comment or in an embedded file is refused too), and refuses XML parts whose byte order mark, first bytes or complete declaration show an encoding other than UTF-8 or UTF-16, or whose declaration is malformed or not at the very start. Set `limits.maxItems` (for example 100,000): it bounds the styles and defined names `inspect` still holds, and the shared-formula masters and reference records it keeps. See [docs/api.md §5.2.1](https://github.com/securedeveloper/javascript-excel/blob/main/docs/api.md#521-inspect-inspect-added-in-25).
95
97
 
96
98
  ## CSV
97
99
 
@@ -183,7 +185,7 @@ const bytes = await excel.write(workbook, { signal: controller.signal, onProgres
183
185
  - Styles come back as shared frozen objects. Merges, column widths and row heights, views and panes, print setup, hyperlinks, defined names and document properties are read too.
184
186
  - **Untrusted files:** bounded by limits on size, zip entries, compression ratio, XML depth and token length, sheets, cells, sheet width (`maxColumns`; set it low, for example 256, for untrusted files), shared strings and the length of one cell's text; a shared formula is expanded only from a master within Excel's 8,192-character formula limit. A `DOCTYPE` is rejected, nothing is ever fetched or executed, and file content never becomes an object key.
185
187
  - **Rejected formats:** `.xls`, `.xlsb`, `.ods` and encrypted files throw `UNSUPPORTED_FORMAT`.
186
- - **CSV:** RFC 4180 parsing with delimiter detection, BOM and CRLF/LF/CR handling, lenient or strict modes, and optional type inference. `readCsv` decodes bytes in any `TextDecoder` encoding. Serializing gives you quoting, a BOM for Excel, ISO dates and a formula-injection guard, which is on by default.
188
+ - **CSV:** RFC 4180 parsing with delimiter detection, BOM and CRLF/LF/CR handling, lenient or strict modes, and optional type inference. `readCsv` decodes bytes in any `TextDecoder` encoding, or with `encoding: 'auto'` as UTF-8 and then Windows-1252, and for uploads can refuse binary input (`rejectBinary`), cap the input size (`maxInputBytes`) and check a file without keeping its rows (`keepRows: false`). Serializing gives you quoting, a BOM for Excel, ISO dates and a formula-injection guard, which is on by default.
187
189
  - **Datasets:** `fromDataset` and `fromDatasets` support `key`, `path` and function accessors, grouped headers, number formats, widths and a totals row. `toDataset` reads a sheet back into `{ columns, data }`.
188
190
  - **DOM:** `fromTable` handles `colspan`/`rowspan` merges, `data-*` type hints and computed styles. `download()` needs no dependency, and the module is safe to import during SSR.
189
191
  - **Worker:** progress, warnings and `AbortSignal` work across the boundary, and results are transferred, not copied.
@@ -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/address.ts
3
3
  /**
4
4
  * A1 address helpers (docs/api.md §4.1). Indices are zero-based.
@@ -1,4 +1,4 @@
1
- const require_errors = require("./errors-DOPrrGS4.cjs");
1
+ const require_errors = require("./errors-CKYdpCoB.cjs");
2
2
  // src/address.ts
3
3
  /**
4
4
  * A1 address helpers (docs/api.md §4.1). Indices are zero-based.
@@ -1,31 +1,43 @@
1
- import { a as LimitError, n as EnvironmentError, o as ValidationError, t as CsvError } from "./errors-CvGlfw0E.js";
2
- import { a as toBytes, i as checkMaxWarnings, r as WarningCap, t as inferValue } from "./infer-DcUyZ1T-.js";
1
+ import { a as LimitError, i as FormatError, n as EnvironmentError, o as ValidationError, t as CsvError } from "./errors-BQE62PFo.js";
2
+ import { a as checkBlobSize, i as checkMaxWarnings, o as inputTooLarge, r as WarningCap, s as toBytes, t as inferValue } from "./infer-DuSahY5i.js";
3
3
  import { t as isoDate } from "./iso-date-CXnn-9mT.js";
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 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,10 +63,106 @@ 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
71
+ };
72
+ }
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 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
54
108
  };
109
+ } catch {}
110
+ for (let i = 0; i < bytes.length; i++) if (isUndefined1252(bytes[i])) throw new 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;
55
166
  }
56
167
  }
57
168
  // src/internal/csv/ref.ts
@@ -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 : 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 : 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
  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
+ checkBlobSize(input, maxInputBytes);
640
763
  const bytes = await toBytes(input, "readCsv", "a string, ");
764
+ if (bytes.length > maxInputBytes) throw 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 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) {