javascript-excel 2.3.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 +5 -3
  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-Bck8eW_D.js → csv-5jVhfM5l.js} +204 -33
  5. package/dist/{csv-f4P3fGs-.cjs → csv-BkVmMYQq.cjs} +204 -33
  6. package/dist/csv.cjs +1 -1
  7. package/dist/csv.d.cts +50 -3
  8. package/dist/csv.d.ts +50 -3
  9. package/dist/csv.js +1 -1
  10. package/dist/{dataset-DzoMeOG1.cjs → dataset-B4-SEdCn.cjs} +49 -5
  11. package/dist/{dataset-BLo9CwB-.js → dataset-Dh598YSG.js} +49 -5
  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-2dgQM9E9.js → pipeline-1AVJbbqT.js} +39 -12
  35. package/dist/{pipeline-LCTU0Eg_.cjs → pipeline-C9zhwGAV.cjs} +39 -12
  36. package/dist/{pipeline-D1eAhqJu.d.cts → pipeline-CJWE3NWg.d.cts} +12 -5
  37. package/dist/{pipeline-Bh7FUyzW.d.ts → pipeline-DVgO1aGC.d.ts} +12 -5
  38. package/dist/{read-BnXzPjGc.js → read-B6tY0ooT.js} +2479 -869
  39. package/dist/{read-BYI7EVMo.cjs → read-Dgw9kMzh.cjs} +2489 -861
  40. package/dist/read.cjs +2 -1
  41. package/dist/read.d.cts +73 -3
  42. package/dist/read.d.ts +73 -3
  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
@@ -1,9 +1,9 @@
1
- const require_csv = require("./csv-f4P3fGs-.cjs");
2
- const require_dataset = require("./dataset-DzoMeOG1.cjs");
3
- const require_errors = require("./errors-DOPrrGS4.cjs");
4
- const require_read = require("./read-BYI7EVMo.cjs");
5
- const require_infer = require("./infer-BniOucP6.cjs");
6
- const require_address = require("./address-DZBHchLv.cjs");
1
+ const require_csv = require("./csv-BkVmMYQq.cjs");
2
+ const require_dataset = require("./dataset-B4-SEdCn.cjs");
3
+ const require_errors = require("./errors-CKYdpCoB.cjs");
4
+ const require_read = require("./read-Dgw9kMzh.cjs");
5
+ const require_infer = require("./infer-B950M3-F.cjs");
6
+ const require_address = require("./address-DKd_3EGf.cjs");
7
7
  const require_iso_date = require("./iso-date-3TY1OlGd.cjs");
8
8
  // src/internal/import/parse.ts
9
9
  /**
@@ -612,6 +612,20 @@ function startOfDay(d, zone) {
612
612
  function isExcelDayZero(d, zone) {
613
613
  return zone === "utc" ? d.getUTCFullYear() === 1899 && d.getUTCMonth() === 11 && d.getUTCDate() === 31 : d.getFullYear() === 1899 && d.getMonth() === 11 && d.getDate() === 31;
614
614
  }
615
+ /**
616
+ * For 'day' (JSE-69): ISO text with an explicit offset or `Z` names its day in
617
+ * its date part, so that day, at 00:00 in `zone`; the offset does not move it.
618
+ * Undefined for anything else, including text the ISO parser refuses (an
619
+ * invalid date, time or offset), which then goes the usual way.
620
+ */
621
+ function isoDayAsWritten(text, zone) {
622
+ const s = text.trim();
623
+ if (s.length <= 16 || s.charCodeAt(4) !== 45 || require_infer.parseIsoDate(s, zone) === void 0) return void 0;
624
+ for (let i = 11; i < s.length; i++) {
625
+ const c = s.charCodeAt(i);
626
+ if (c === 90 || c === 43 || c === 45) return require_infer.parseIsoDate(s.slice(0, 10), zone);
627
+ }
628
+ }
615
629
  function textOf(v) {
616
630
  if (typeof v === "string") return v;
617
631
  if (v && typeof v === "object" && "richText" in v) return v.richText.map((r) => r.text).join("");
@@ -825,8 +839,11 @@ function convert(v, col, locale, zone) {
825
839
  let d;
826
840
  if (v instanceof Date) d = v;
827
841
  else if (t !== void 0) {
828
- const order = col.dateOrder ?? (locale.dateOrder && locale.dateOrder !== "auto" ? locale.dateOrder : void 0);
829
- d = order ? textToDate(t, order, zone, locale.twoDigitYearPivot) : parseDate(t, { zone });
842
+ if (col.type === "day") d = isoDayAsWritten(t, zone);
843
+ if (d === void 0) {
844
+ const order = col.dateOrder ?? (locale.dateOrder && locale.dateOrder !== "auto" ? locale.dateOrder : void 0);
845
+ d = order ? textToDate(t, order, zone, locale.twoDigitYearPivot) : parseDate(t, { zone });
846
+ }
830
847
  }
831
848
  if (d === void 0) return { ok: false };
832
849
  if (col.type !== "day") return {
@@ -1006,6 +1023,10 @@ async function importDataset(input, options = {}) {
1006
1023
  if (o.maxIssues !== Number.POSITIVE_INFINITY) checkCount("maxIssues", o.maxIssues, 1);
1007
1024
  const maxText = o.limits?.maxCellTextLength;
1008
1025
  if (maxText !== void 0 && (typeof maxText !== "number" || !(maxText > 0))) throw new TypeError("limits.maxCellTextLength must be a positive number");
1026
+ const maxInputBytes = o.limits?.maxInputBytes;
1027
+ if (maxInputBytes !== void 0 && (typeof maxInputBytes !== "number" || !(maxInputBytes > 0))) throw new TypeError("limits.maxInputBytes must be a positive number");
1028
+ const maxColumns = o.limits?.maxColumns;
1029
+ if (maxColumns !== void 0 && (typeof maxColumns !== "number" || !(maxColumns > 0))) throw new TypeError("limits.maxColumns must be a positive number");
1009
1030
  if (typeof o.header === "object" && o.header !== null) {
1010
1031
  checkCount("header.rows", o.header.rows, 1);
1011
1032
  checkCount("header.row", o.header.row, 0);
@@ -1032,6 +1053,7 @@ async function importDataset(input, options = {}) {
1032
1053
  let format;
1033
1054
  if (typeof input === "string") format = "csv";
1034
1055
  else {
1056
+ if (maxInputBytes !== void 0) require_infer.checkBlobSize(input, maxInputBytes);
1035
1057
  bytes = await require_infer.toBytes(input, "importDataset", "a string, ");
1036
1058
  if (o.format === "csv") format = "csv";
1037
1059
  else if (o.format === "xlsx") format = "xlsx";
@@ -1056,9 +1078,12 @@ async function importDataset(input, options = {}) {
1056
1078
  delimiter: o.delimiter ?? "auto",
1057
1079
  delimiterCandidates: o.delimiterCandidates,
1058
1080
  encoding: o.encoding,
1081
+ rejectBinary: o.rejectBinary,
1082
+ maxInputBytes,
1059
1083
  maxRows: cap,
1060
1084
  maxWarnings: o.limits?.maxWarnings,
1061
1085
  maxCellTextLength: maxText,
1086
+ maxColumns,
1062
1087
  maxFieldBytes: maxText !== void 0 && maxText > 1048576 ? 3 * maxText : void 0,
1063
1088
  signal: o.signal,
1064
1089
  inferTypes: false
@@ -1073,7 +1098,7 @@ async function importDataset(input, options = {}) {
1073
1098
  };
1074
1099
  meta.delimiter = r.delimiter;
1075
1100
  meta.bom = r.bom;
1076
- if (bytes) meta.encoding = bomEncoding(bytes) ?? (o.encoding ?? "utf-8").toLowerCase();
1101
+ if (bytes) meta.encoding = o.encoding === "auto" ? r.encoding : bomEncoding(bytes) ?? (o.encoding ?? "utf-8").toLowerCase();
1077
1102
  } else {
1078
1103
  const sheets = await require_read.readSheetNames(bytes, {
1079
1104
  limits: o.limits,
@@ -1085,7 +1110,7 @@ async function importDataset(input, options = {}) {
1085
1110
  sheet: want,
1086
1111
  sheets: sheets.map((s) => s.name)
1087
1112
  } });
1088
- const { workbook } = await require_read.read(bytes, {
1113
+ const { workbook } = await require_read.readImpl(bytes, {
1089
1114
  sheets: [info.index],
1090
1115
  styles: false,
1091
1116
  richText: "plain",
@@ -1100,7 +1125,7 @@ async function importDataset(input, options = {}) {
1100
1125
  if (w.code === "ROWS_TRUNCATED") truncatedRead = true;
1101
1126
  warn(w);
1102
1127
  }
1103
- });
1128
+ }, { sharedFormulaText: "master" });
1104
1129
  sheet = workbook.sheets[info.index];
1105
1130
  meta.sheet = {
1106
1131
  name: info.name,
@@ -1139,13 +1164,15 @@ async function importDataset(input, options = {}) {
1139
1164
  headerRows = Array.from({ length: header.rows }, (_, i) => start + i);
1140
1165
  join = header.join;
1141
1166
  }
1167
+ const maxCells = o.limits?.maxCells;
1168
+ if (maxCells !== void 0 && (typeof maxCells !== "number" || !(maxCells > 0))) throw new TypeError("limits.maxCells must be a positive number");
1142
1169
  const ds = require_dataset.toDatasetDetailed(sheet, {
1143
1170
  headerRow: headerRows.length ? headerRows[0] : false,
1144
1171
  headerRows: Math.max(1, headerRows.length),
1145
1172
  join,
1146
1173
  range: o.range,
1147
1174
  skipTotals: o.skipTotals ?? "auto"
1148
- });
1175
+ }, { maxCells: maxCells ?? require_read.DEFAULT_LIMITS.maxCells });
1149
1176
  const issueCap = new IssueCap(o.maxIssues ?? 1e5);
1150
1177
  const issues = issueCap.issues;
1151
1178
  const base = {
@@ -1,4 +1,4 @@
1
- import { o as BinaryInput, r as ExcelWarning } from "./warnings-DhonqJ7A.cjs";
1
+ import { o as BinaryInput, r as ExcelWarning } from "./warnings-DEsTp6rd.cjs";
2
2
  import { ReadLimits, SheetInfo } from "./read.cjs";
3
3
  import { t as AbortSignalLike } from "./signal-Dz0ZYe6d.cjs";
4
4
  import { D as Sheet, s as CellInput } from "./model-BUNp7B0Z.cjs";
@@ -50,7 +50,8 @@ declare function detectHeader(sheet: Sheet<CellInput>, options?: DetectHeaderOpt
50
50
  /**
51
51
  * A column's type. `'day'` is never inferred: forced (by `types` or a schema
52
52
  * field), it converts like `'date'` and then drops the time of day, giving
53
- * 00:00 of the calendar day in `dateZone` (docs/api.md §5.6, "Type rules").
53
+ * 00:00 of the calendar day in `dateZone`; for ISO text with an offset, the
54
+ * day written (docs/api.md §5.6, "Type rules").
54
55
  */
55
56
  type ColumnType = "string" | "number" | "boolean" | "date" | "datetime" | "day" | "mixed" | "empty";
56
57
  interface DatasetLike {
@@ -160,7 +161,10 @@ interface ImportDatasetOptions {
160
161
  delimiter?: string | undefined;
161
162
  /** CSV: the delimiters `'auto'` chooses from, in order of preference (see `CsvParseOptions`). */
162
163
  delimiterCandidates?: readonly string[] | undefined;
163
- encoding?: string | undefined;
164
+ /** CSV without a BOM: any `TextDecoder` label, or `'auto'` (UTF-8, then Windows-1252; see `CsvReadOptions`). Default `'utf-8'`. */
165
+ encoding?: string | "auto" | undefined;
166
+ /** CSV: refuse text with control characters text files do not contain (`CSV_BINARY_INPUT`; see `CsvReadOptions`). Default false. */
167
+ rejectBinary?: boolean | undefined;
164
168
  skipTotals?: "auto" | boolean | undefined;
165
169
  errorCells?: "null" | "keep" | undefined;
166
170
  dates?: "date" | "serial" | undefined;
@@ -177,8 +181,11 @@ interface ImportDatasetOptions {
177
181
  */
178
182
  maxIssues?: number | undefined;
179
183
  /**
180
- * Reader limits for xlsx. For a CSV file, `maxWarnings` caps its warnings and
181
- * `maxCellTextLength` limits its fields (raising CSV's 1 MiB `maxFieldBytes` to match).
184
+ * Reader limits for xlsx. For a CSV file, `maxInputBytes` (when given) limits its bytes,
185
+ * `maxWarnings` caps its warnings,
186
+ * `maxCellTextLength` limits its fields (raising CSV's 1 MiB `maxFieldBytes` to match)
187
+ * and `maxColumns` the fields of one record. For both formats, `maxCells` also bounds
188
+ * the empty fields the dataset pads short rows with (since 2.4; docs/api.md §5.6).
182
189
  */
183
190
  limits?: Partial<ReadLimits> | undefined;
184
191
  signal?: AbortSignalLike | undefined;
@@ -1,4 +1,4 @@
1
- import { o as BinaryInput, r as ExcelWarning } from "./warnings-DhonqJ7A.js";
1
+ import { o as BinaryInput, r as ExcelWarning } from "./warnings-DEsTp6rd.js";
2
2
  import { ReadLimits, SheetInfo } from "./read.js";
3
3
  import { t as AbortSignalLike } from "./signal-Dz0ZYe6d.js";
4
4
  import { D as Sheet, s as CellInput } from "./model-BUNp7B0Z.js";
@@ -50,7 +50,8 @@ declare function detectHeader(sheet: Sheet<CellInput>, options?: DetectHeaderOpt
50
50
  /**
51
51
  * A column's type. `'day'` is never inferred: forced (by `types` or a schema
52
52
  * field), it converts like `'date'` and then drops the time of day, giving
53
- * 00:00 of the calendar day in `dateZone` (docs/api.md §5.6, "Type rules").
53
+ * 00:00 of the calendar day in `dateZone`; for ISO text with an offset, the
54
+ * day written (docs/api.md §5.6, "Type rules").
54
55
  */
55
56
  type ColumnType = "string" | "number" | "boolean" | "date" | "datetime" | "day" | "mixed" | "empty";
56
57
  interface DatasetLike {
@@ -160,7 +161,10 @@ interface ImportDatasetOptions {
160
161
  delimiter?: string | undefined;
161
162
  /** CSV: the delimiters `'auto'` chooses from, in order of preference (see `CsvParseOptions`). */
162
163
  delimiterCandidates?: readonly string[] | undefined;
163
- encoding?: string | undefined;
164
+ /** CSV without a BOM: any `TextDecoder` label, or `'auto'` (UTF-8, then Windows-1252; see `CsvReadOptions`). Default `'utf-8'`. */
165
+ encoding?: string | "auto" | undefined;
166
+ /** CSV: refuse text with control characters text files do not contain (`CSV_BINARY_INPUT`; see `CsvReadOptions`). Default false. */
167
+ rejectBinary?: boolean | undefined;
164
168
  skipTotals?: "auto" | boolean | undefined;
165
169
  errorCells?: "null" | "keep" | undefined;
166
170
  dates?: "date" | "serial" | undefined;
@@ -177,8 +181,11 @@ interface ImportDatasetOptions {
177
181
  */
178
182
  maxIssues?: number | undefined;
179
183
  /**
180
- * Reader limits for xlsx. For a CSV file, `maxWarnings` caps its warnings and
181
- * `maxCellTextLength` limits its fields (raising CSV's 1 MiB `maxFieldBytes` to match).
184
+ * Reader limits for xlsx. For a CSV file, `maxInputBytes` (when given) limits its bytes,
185
+ * `maxWarnings` caps its warnings,
186
+ * `maxCellTextLength` limits its fields (raising CSV's 1 MiB `maxFieldBytes` to match)
187
+ * and `maxColumns` the fields of one record. For both formats, `maxCells` also bounds
188
+ * the empty fields the dataset pads short rows with (since 2.4; docs/api.md §5.6).
182
189
  */
183
190
  limits?: Partial<ReadLimits> | undefined;
184
191
  signal?: AbortSignalLike | undefined;