javascript-excel 2.2.0 → 2.4.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.
- package/README.md +4 -2
- package/dist/{csv-DzGOFyHs.cjs → csv-DZ241Y5F.cjs} +57 -5
- package/dist/{csv-CrWF7JS1.js → csv-Dn4MIESx.js} +52 -6
- package/dist/csv.cjs +1 -1
- package/dist/csv.d.cts +16 -0
- package/dist/csv.d.ts +16 -0
- package/dist/csv.js +1 -1
- package/dist/{dataset-DzoMeOG1.cjs → dataset-CbZnEWXu.cjs} +45 -1
- package/dist/{dataset-BLo9CwB-.js → dataset-CyEHVht4.js} +46 -2
- package/dist/import.cjs +1 -1
- package/dist/import.d.cts +2 -2
- package/dist/import.d.ts +2 -2
- package/dist/import.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/{pipeline-C63qD7Ym.d.cts → pipeline-4U7Xnuc1.d.cts} +43 -6
- package/dist/{pipeline-6PmlmH1-.d.ts → pipeline-BegSPu8X.d.ts} +43 -6
- package/dist/{pipeline-DLYtAkPU.cjs → pipeline-BwkRpV5Z.cjs} +293 -138
- package/dist/{pipeline-BNhGRJcx.js → pipeline-C8F9lecW.js} +293 -138
- package/dist/{read-D5Gz4ph8.cjs → read-DmUPztqh.cjs} +544 -141
- package/dist/{read-CFmZioBG.js → read-cvxu6O-H.js} +521 -142
- package/dist/read.cjs +1 -1
- package/dist/read.d.cts +44 -3
- package/dist/read.d.ts +44 -3
- package/dist/read.js +1 -1
- package/dist/worker.cjs +3 -3
- package/dist/worker.d.cts +1 -1
- package/dist/worker.d.ts +1 -1
- package/dist/worker.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -153,6 +153,8 @@ const { columns, data, issues, meta } = await importDataset(file, {
|
|
|
153
153
|
console.log(meta.header, columns.map((c) => `${c.key}: ${c.type}`), data.length, issues);
|
|
154
154
|
```
|
|
155
155
|
|
|
156
|
+
A field typed `'day'` (in `types` or the schema) holds a calendar day: a date-time such as `31.10.2026 08:15` becomes 00:00 of 2026-10-31 in `dateZone`, and `toCsv` writes it as `2026-10-31`. `'date'` keeps the time of day.
|
|
157
|
+
|
|
156
158
|
## In a Web Worker
|
|
157
159
|
|
|
158
160
|
<!-- example: examples/snippets/src/worker.ts -->
|
|
@@ -179,13 +181,13 @@ const bytes = await excel.write(workbook, { signal: controller.signal, onProgres
|
|
|
179
181
|
- **Reader:** `.xlsx`, `.xlsm`, `.xltx` and `.xltm`, including ISO 29500 Strict files.
|
|
180
182
|
- Reads values, shared, inline and rich strings, and formula text with cached values (shared formulas expanded).
|
|
181
183
|
- 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.
|
|
182
|
-
- **Untrusted files:** bounded by limits on size, zip entries, compression ratio, XML depth and token length, sheets, cells and shared
|
|
184
|
+
- **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.
|
|
183
185
|
- **Rejected formats:** `.xls`, `.xlsb`, `.ods` and encrypted files throw `UNSUPPORTED_FORMAT`.
|
|
184
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.
|
|
185
187
|
- **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 }`.
|
|
186
188
|
- **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.
|
|
187
189
|
- **Worker:** progress, warnings and `AbortSignal` work across the boundary, and results are transferred, not copied.
|
|
188
|
-
- **Import:** `importDataset` turns a user's `.xlsx` or `.csv` into `{ columns, data }`. It detects title and header rows, including multi-row headers. It infers column types all-or-nothing, parses numbers and dates in an explicit locale (`1.234,56`, `15/01/2024`) and maps columns to your fields by name or alias. Problems are reported per row with their cell. Preview reads (`preview`) and `maxRows` stop reading early, and it also runs in the worker.
|
|
190
|
+
- **Import:** `importDataset` turns a user's `.xlsx` or `.csv` into `{ columns, data }`. It detects title and header rows, including multi-row headers. It infers column types all-or-nothing, parses numbers and dates in an explicit locale (`1.234,56`, `15/01/2024`, and with `twoDigitYearPivot` two-digit years such as `31.10.26`) and maps columns to your fields by name or alias. Problems are reported per row with their cell. Preview reads (`preview`) and `maxRows` stop reading early, and it also runs in the worker.
|
|
189
191
|
- **Not in 2.0:** `.xls`/`.xlsb`/`.ods`, charts, images, comments, pivot tables, conditional formatting and formula evaluation. These are planned for later releases, not ruled out.
|
|
190
192
|
|
|
191
193
|
## Runtime support
|
|
@@ -66,6 +66,24 @@ function cellRef(row, col) {
|
|
|
66
66
|
}
|
|
67
67
|
return `${name}${row + 1}`;
|
|
68
68
|
}
|
|
69
|
+
// src/internal/csv/parse.ts
|
|
70
|
+
/**
|
|
71
|
+
* CSV parser (RFC 4180, lenient by default). docs/api.md §5.3.
|
|
72
|
+
*
|
|
73
|
+
* A hand-written scanner: one pass over the string, no regular expressions on
|
|
74
|
+
* the hot path, no recursion. The parser works one record at a time, so the
|
|
75
|
+
* async API can stop between records to check an AbortSignal and yield.
|
|
76
|
+
*/
|
|
77
|
+
/** Default `maxFieldBytes`: 1 MiB of UTF-8 per field. */
|
|
78
|
+
const DEFAULT_MAX_FIELD_BYTES = 1048576;
|
|
79
|
+
/** Default `maxCellTextLength`: 1 Mi UTF-16 code units per field, as `DEFAULT_READ_LIMITS` for xlsx (JSE-58). */
|
|
80
|
+
const DEFAULT_MAX_CELL_TEXT_LENGTH = 1048576;
|
|
81
|
+
/**
|
|
82
|
+
* Default `maxColumns`: fields in one record (JSE-68). 1 Mi, 64 times Excel's 16,384 columns and
|
|
83
|
+
* beyond any spreadsheet's width, so it refuses no CSV file that 2.3 read; a record that wide is
|
|
84
|
+
* at least 1 MiB of text, so the rows parseCsv returns stay linear in the input.
|
|
85
|
+
*/
|
|
86
|
+
const DEFAULT_MAX_COLUMNS = 1048576;
|
|
69
87
|
/** Default `maxWarnings`: warnings kept per parse before the cap (internal/warning-cap.ts) applies. */
|
|
70
88
|
const MAX_WARNINGS = 1e3;
|
|
71
89
|
const CANDIDATES = [
|
|
@@ -163,6 +181,7 @@ var CsvParser = class {
|
|
|
163
181
|
value = this.quotedField(row, col);
|
|
164
182
|
} else value = this.plainField(row, col);
|
|
165
183
|
this.checkSize(value, row, col);
|
|
184
|
+
this.checkWidth(col, row);
|
|
166
185
|
fields.push({
|
|
167
186
|
text: value,
|
|
168
187
|
quoted
|
|
@@ -171,6 +190,7 @@ var CsvParser = class {
|
|
|
171
190
|
if (text.charCodeAt(this.pos) === this.delimCode) {
|
|
172
191
|
this.pos++;
|
|
173
192
|
if (this.pos >= len) {
|
|
193
|
+
this.checkWidth(fields.length, row);
|
|
174
194
|
fields.push({
|
|
175
195
|
text: "",
|
|
176
196
|
quoted: false
|
|
@@ -271,11 +291,33 @@ var CsvParser = class {
|
|
|
271
291
|
}
|
|
272
292
|
checkSize(value, row, col) {
|
|
273
293
|
const max = this.cfg.maxFieldBytes;
|
|
274
|
-
if (value.length * 3
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
294
|
+
if (value.length * 3 > max) {
|
|
295
|
+
const bytes = utf8Length(value);
|
|
296
|
+
if (bytes > max) throw new require_errors.LimitError("LIMIT_EXCEEDED", `Field at row ${row + 1} is ${bytes} bytes; maxFieldBytes is ${max}.`, { details: {
|
|
297
|
+
limit: "maxFieldBytes",
|
|
298
|
+
value: bytes,
|
|
299
|
+
max,
|
|
300
|
+
ref: cellRef(row, col)
|
|
301
|
+
} });
|
|
302
|
+
}
|
|
303
|
+
const maxText = this.cfg.maxCellTextLength;
|
|
304
|
+
if (value.length > maxText) throw new require_errors.LimitError("LIMIT_EXCEEDED", `Field at row ${row + 1} is ${value.length} characters; maxCellTextLength is ${maxText}.`, { details: {
|
|
305
|
+
limit: "maxCellTextLength",
|
|
306
|
+
value: value.length,
|
|
307
|
+
max: maxText,
|
|
308
|
+
ref: cellRef(row, col)
|
|
309
|
+
} });
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Field `col` (zero-based) of a record, before it is kept: refused past maxColumns (JSE-68). The
|
|
313
|
+
* record read only to find that maxRows was reached is dropped, so it is not checked.
|
|
314
|
+
*/
|
|
315
|
+
checkWidth(col, row) {
|
|
316
|
+
const max = this.cfg.maxColumns;
|
|
317
|
+
if (col < max || row >= this.cfg.maxRows) return;
|
|
318
|
+
throw new require_errors.LimitError("LIMIT_EXCEEDED", `Row ${row + 1} has more than maxColumns (${max}) fields.`, { details: {
|
|
319
|
+
limit: "maxColumns",
|
|
320
|
+
value: col + 1,
|
|
279
321
|
max,
|
|
280
322
|
ref: cellRef(row, col)
|
|
281
323
|
} });
|
|
@@ -317,6 +359,8 @@ function validateConfig(cfg) {
|
|
|
317
359
|
if (cfg.delimiterCandidates !== void 0) checkCandidates(cfg.delimiterCandidates, cfg.quote);
|
|
318
360
|
if (!(cfg.maxRows >= 0)) throw new TypeError("maxRows must be a non-negative number");
|
|
319
361
|
if (!(cfg.maxFieldBytes > 0)) throw new TypeError("maxFieldBytes must be a positive number");
|
|
362
|
+
if (!(cfg.maxCellTextLength > 0)) throw new TypeError("maxCellTextLength must be a positive number");
|
|
363
|
+
if (!(cfg.maxColumns > 0)) throw new TypeError("maxColumns must be a positive number");
|
|
320
364
|
require_infer.checkMaxWarnings("maxWarnings", cfg.maxWarnings);
|
|
321
365
|
}
|
|
322
366
|
/** A delimiter or quote: exactly one UTF-16 code unit, not CR or LF. */
|
|
@@ -551,6 +595,8 @@ function parseConfig(options) {
|
|
|
551
595
|
strict: (o.mode ?? "lenient") === "strict",
|
|
552
596
|
maxRows: o.maxRows ?? Number.POSITIVE_INFINITY,
|
|
553
597
|
maxFieldBytes: o.maxFieldBytes ?? 1048576,
|
|
598
|
+
maxCellTextLength: o.maxCellTextLength === void 0 ? DEFAULT_MAX_CELL_TEXT_LENGTH : o.maxCellTextLength,
|
|
599
|
+
maxColumns: o.maxColumns === void 0 ? DEFAULT_MAX_COLUMNS : o.maxColumns,
|
|
554
600
|
dateZone: o.dateZone ?? "local",
|
|
555
601
|
maxWarnings: o.maxWarnings === void 0 ? MAX_WARNINGS : o.maxWarnings
|
|
556
602
|
};
|
|
@@ -665,6 +711,12 @@ Object.defineProperty(exports, "CSV_MIME", {
|
|
|
665
711
|
return CSV_MIME;
|
|
666
712
|
}
|
|
667
713
|
});
|
|
714
|
+
Object.defineProperty(exports, "DEFAULT_MAX_FIELD_BYTES", {
|
|
715
|
+
enumerable: true,
|
|
716
|
+
get: function() {
|
|
717
|
+
return DEFAULT_MAX_FIELD_BYTES;
|
|
718
|
+
}
|
|
719
|
+
});
|
|
668
720
|
Object.defineProperty(exports, "parseCsv", {
|
|
669
721
|
enumerable: true,
|
|
670
722
|
get: function() {
|
|
@@ -66,6 +66,24 @@ function cellRef(row, col) {
|
|
|
66
66
|
}
|
|
67
67
|
return `${name}${row + 1}`;
|
|
68
68
|
}
|
|
69
|
+
// src/internal/csv/parse.ts
|
|
70
|
+
/**
|
|
71
|
+
* CSV parser (RFC 4180, lenient by default). docs/api.md §5.3.
|
|
72
|
+
*
|
|
73
|
+
* A hand-written scanner: one pass over the string, no regular expressions on
|
|
74
|
+
* the hot path, no recursion. The parser works one record at a time, so the
|
|
75
|
+
* async API can stop between records to check an AbortSignal and yield.
|
|
76
|
+
*/
|
|
77
|
+
/** Default `maxFieldBytes`: 1 MiB of UTF-8 per field. */
|
|
78
|
+
const DEFAULT_MAX_FIELD_BYTES = 1048576;
|
|
79
|
+
/** Default `maxCellTextLength`: 1 Mi UTF-16 code units per field, as `DEFAULT_READ_LIMITS` for xlsx (JSE-58). */
|
|
80
|
+
const DEFAULT_MAX_CELL_TEXT_LENGTH = 1048576;
|
|
81
|
+
/**
|
|
82
|
+
* Default `maxColumns`: fields in one record (JSE-68). 1 Mi, 64 times Excel's 16,384 columns and
|
|
83
|
+
* beyond any spreadsheet's width, so it refuses no CSV file that 2.3 read; a record that wide is
|
|
84
|
+
* at least 1 MiB of text, so the rows parseCsv returns stay linear in the input.
|
|
85
|
+
*/
|
|
86
|
+
const DEFAULT_MAX_COLUMNS = 1048576;
|
|
69
87
|
/** Default `maxWarnings`: warnings kept per parse before the cap (internal/warning-cap.ts) applies. */
|
|
70
88
|
const MAX_WARNINGS = 1e3;
|
|
71
89
|
const CANDIDATES = [
|
|
@@ -163,6 +181,7 @@ var CsvParser = class {
|
|
|
163
181
|
value = this.quotedField(row, col);
|
|
164
182
|
} else value = this.plainField(row, col);
|
|
165
183
|
this.checkSize(value, row, col);
|
|
184
|
+
this.checkWidth(col, row);
|
|
166
185
|
fields.push({
|
|
167
186
|
text: value,
|
|
168
187
|
quoted
|
|
@@ -171,6 +190,7 @@ var CsvParser = class {
|
|
|
171
190
|
if (text.charCodeAt(this.pos) === this.delimCode) {
|
|
172
191
|
this.pos++;
|
|
173
192
|
if (this.pos >= len) {
|
|
193
|
+
this.checkWidth(fields.length, row);
|
|
174
194
|
fields.push({
|
|
175
195
|
text: "",
|
|
176
196
|
quoted: false
|
|
@@ -271,11 +291,33 @@ var CsvParser = class {
|
|
|
271
291
|
}
|
|
272
292
|
checkSize(value, row, col) {
|
|
273
293
|
const max = this.cfg.maxFieldBytes;
|
|
274
|
-
if (value.length * 3
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
294
|
+
if (value.length * 3 > max) {
|
|
295
|
+
const bytes = utf8Length(value);
|
|
296
|
+
if (bytes > max) throw new LimitError("LIMIT_EXCEEDED", `Field at row ${row + 1} is ${bytes} bytes; maxFieldBytes is ${max}.`, { details: {
|
|
297
|
+
limit: "maxFieldBytes",
|
|
298
|
+
value: bytes,
|
|
299
|
+
max,
|
|
300
|
+
ref: cellRef(row, col)
|
|
301
|
+
} });
|
|
302
|
+
}
|
|
303
|
+
const maxText = this.cfg.maxCellTextLength;
|
|
304
|
+
if (value.length > maxText) throw new LimitError("LIMIT_EXCEEDED", `Field at row ${row + 1} is ${value.length} characters; maxCellTextLength is ${maxText}.`, { details: {
|
|
305
|
+
limit: "maxCellTextLength",
|
|
306
|
+
value: value.length,
|
|
307
|
+
max: maxText,
|
|
308
|
+
ref: cellRef(row, col)
|
|
309
|
+
} });
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Field `col` (zero-based) of a record, before it is kept: refused past maxColumns (JSE-68). The
|
|
313
|
+
* record read only to find that maxRows was reached is dropped, so it is not checked.
|
|
314
|
+
*/
|
|
315
|
+
checkWidth(col, row) {
|
|
316
|
+
const max = this.cfg.maxColumns;
|
|
317
|
+
if (col < max || row >= this.cfg.maxRows) return;
|
|
318
|
+
throw new LimitError("LIMIT_EXCEEDED", `Row ${row + 1} has more than maxColumns (${max}) fields.`, { details: {
|
|
319
|
+
limit: "maxColumns",
|
|
320
|
+
value: col + 1,
|
|
279
321
|
max,
|
|
280
322
|
ref: cellRef(row, col)
|
|
281
323
|
} });
|
|
@@ -317,6 +359,8 @@ function validateConfig(cfg) {
|
|
|
317
359
|
if (cfg.delimiterCandidates !== void 0) checkCandidates(cfg.delimiterCandidates, cfg.quote);
|
|
318
360
|
if (!(cfg.maxRows >= 0)) throw new TypeError("maxRows must be a non-negative number");
|
|
319
361
|
if (!(cfg.maxFieldBytes > 0)) throw new TypeError("maxFieldBytes must be a positive number");
|
|
362
|
+
if (!(cfg.maxCellTextLength > 0)) throw new TypeError("maxCellTextLength must be a positive number");
|
|
363
|
+
if (!(cfg.maxColumns > 0)) throw new TypeError("maxColumns must be a positive number");
|
|
320
364
|
checkMaxWarnings("maxWarnings", cfg.maxWarnings);
|
|
321
365
|
}
|
|
322
366
|
/** A delimiter or quote: exactly one UTF-16 code unit, not CR or LF. */
|
|
@@ -551,6 +595,8 @@ function parseConfig(options) {
|
|
|
551
595
|
strict: (o.mode ?? "lenient") === "strict",
|
|
552
596
|
maxRows: o.maxRows ?? Number.POSITIVE_INFINITY,
|
|
553
597
|
maxFieldBytes: o.maxFieldBytes ?? 1048576,
|
|
598
|
+
maxCellTextLength: o.maxCellTextLength === void 0 ? DEFAULT_MAX_CELL_TEXT_LENGTH : o.maxCellTextLength,
|
|
599
|
+
maxColumns: o.maxColumns === void 0 ? DEFAULT_MAX_COLUMNS : o.maxColumns,
|
|
554
600
|
dateZone: o.dateZone ?? "local",
|
|
555
601
|
maxWarnings: o.maxWarnings === void 0 ? MAX_WARNINGS : o.maxWarnings
|
|
556
602
|
};
|
|
@@ -659,4 +705,4 @@ function yieldToEventLoop() {
|
|
|
659
705
|
else Promise.resolve().then(resolve);
|
|
660
706
|
});
|
|
661
707
|
}
|
|
662
|
-
export { toCsvBlob as a, toCsv as i, parseCsv as n, readCsv as r, CSV_MIME as t };
|
|
708
|
+
export { toCsvBlob as a, toCsv as i, parseCsv as n, DEFAULT_MAX_FIELD_BYTES as o, readCsv as r, CSV_MIME as t };
|
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-
|
|
3
|
+
const require_csv = require("./csv-DZ241Y5F.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
|
@@ -44,6 +44,22 @@ export interface CsvParseOptions {
|
|
|
44
44
|
maxRows?: number | undefined;
|
|
45
45
|
/** Largest field, in UTF-8 bytes; a bigger one throws `LimitError` (`LIMIT_EXCEEDED`). Default 1,048,576 (1 MiB). */
|
|
46
46
|
maxFieldBytes?: number | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Longest field, in characters (UTF-16 code units, as `string.length` counts them, after
|
|
49
|
+
* unquoting); a longer one throws `LimitError` (`LIMIT_EXCEEDED`, `details.limit`
|
|
50
|
+
* `'maxCellTextLength'`). The same limit as `ReadLimits.maxCellTextLength` for xlsx (added in
|
|
51
|
+
* 2.3). Both this and `maxFieldBytes` apply; with both defaults a field over 1 MiB is reported
|
|
52
|
+
* as `maxFieldBytes`, as before. A positive number; default 1,048,576 (1 Mi).
|
|
53
|
+
*/
|
|
54
|
+
maxCellTextLength?: number | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Fields in one record; a record with more throws `LimitError` (`LIMIT_EXCEEDED`, `details.limit`
|
|
57
|
+
* `'maxColumns'`, `details.value` the field's 1-based position, `details.ref` its cell) while it
|
|
58
|
+
* is read. The same name as `ReadLimits.maxColumns` for xlsx (added in 2.4). A positive number;
|
|
59
|
+
* default 1,048,576, wider than any spreadsheet (Excel: 16,384 columns), so no existing file is
|
|
60
|
+
* refused; set it to the widest file you accept (for example 256) for untrusted input.
|
|
61
|
+
*/
|
|
62
|
+
maxColumns?: number | undefined;
|
|
47
63
|
/**
|
|
48
64
|
* Warnings kept before the cap applies (as `ReadLimits.maxWarnings` for `read`). Past it,
|
|
49
65
|
* informational warnings are dropped and counted in one `WARNINGS_TRUNCATED` at the end;
|
package/dist/csv.d.ts
CHANGED
|
@@ -44,6 +44,22 @@ export interface CsvParseOptions {
|
|
|
44
44
|
maxRows?: number | undefined;
|
|
45
45
|
/** Largest field, in UTF-8 bytes; a bigger one throws `LimitError` (`LIMIT_EXCEEDED`). Default 1,048,576 (1 MiB). */
|
|
46
46
|
maxFieldBytes?: number | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Longest field, in characters (UTF-16 code units, as `string.length` counts them, after
|
|
49
|
+
* unquoting); a longer one throws `LimitError` (`LIMIT_EXCEEDED`, `details.limit`
|
|
50
|
+
* `'maxCellTextLength'`). The same limit as `ReadLimits.maxCellTextLength` for xlsx (added in
|
|
51
|
+
* 2.3). Both this and `maxFieldBytes` apply; with both defaults a field over 1 MiB is reported
|
|
52
|
+
* as `maxFieldBytes`, as before. A positive number; default 1,048,576 (1 Mi).
|
|
53
|
+
*/
|
|
54
|
+
maxCellTextLength?: number | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Fields in one record; a record with more throws `LimitError` (`LIMIT_EXCEEDED`, `details.limit`
|
|
57
|
+
* `'maxColumns'`, `details.value` the field's 1-based position, `details.ref` its cell) while it
|
|
58
|
+
* is read. The same name as `ReadLimits.maxColumns` for xlsx (added in 2.4). A positive number;
|
|
59
|
+
* default 1,048,576, wider than any spreadsheet (Excel: 16,384 columns), so no existing file is
|
|
60
|
+
* refused; set it to the widest file you accept (for example 256) for untrusted input.
|
|
61
|
+
*/
|
|
62
|
+
maxColumns?: number | undefined;
|
|
47
63
|
/**
|
|
48
64
|
* Warnings kept before the cap applies (as `ReadLimits.maxWarnings` for `read`). Past it,
|
|
49
65
|
* informational warnings are dropped and counted in one `WARNINGS_TRUNCATED` at the end;
|
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-
|
|
2
|
+
import { a as toCsvBlob, i as toCsv, n as parseCsv, r as readCsv, t as CSV_MIME } from "./csv-Dn4MIESx.js";
|
|
3
3
|
export { CSV_MIME, isDataLossWarning, parseCsv, readCsv, toCsv, toCsvBlob };
|
|
@@ -594,8 +594,51 @@ function toDataset(sheet, options = {}) {
|
|
|
594
594
|
data
|
|
595
595
|
};
|
|
596
596
|
}
|
|
597
|
+
/**
|
|
598
|
+
* Every data row gets a key for every column, null where the row has no cell
|
|
599
|
+
* (the contract of toDataset). A wide header over short rows therefore costs
|
|
600
|
+
* rows × columns, far beyond the cells the sheet holds: 16,384 titles over
|
|
601
|
+
* 10,000 three-cell rows are 164 million fields. This counts those empty
|
|
602
|
+
* fields, row by row in the order they would be built, and refuses at the
|
|
603
|
+
* first row that passes `max`, before any row is built (JSE-68). A cell with
|
|
604
|
+
* neither value nor formula (only a hyperlink, which the reader charges to
|
|
605
|
+
* maxItems, or a style) is an empty field too. Work is
|
|
606
|
+
* bounded by the cells visited plus `max`: a row costs at most its stored
|
|
607
|
+
* cells plus its empty fields.
|
|
608
|
+
*/
|
|
609
|
+
function checkPadding(s, rng, firstData, max) {
|
|
610
|
+
const width = rng.end.col - rng.start.col + 1;
|
|
611
|
+
const height = rng.end.row - firstData + 1;
|
|
612
|
+
if (height <= 0 || width * height <= max) return;
|
|
613
|
+
let padding = 0;
|
|
614
|
+
let rows = 0;
|
|
615
|
+
for (let r = firstData; r <= rng.end.row; r++) {
|
|
616
|
+
const row = s.rows[r];
|
|
617
|
+
if (!row) continue;
|
|
618
|
+
const end = Math.min(rng.end.col, row.length - 1);
|
|
619
|
+
let any = false;
|
|
620
|
+
let present = 0;
|
|
621
|
+
for (let c = rng.start.col; c <= end; c++) {
|
|
622
|
+
const v = row[c];
|
|
623
|
+
if (v === void 0 || v === null) continue;
|
|
624
|
+
if (isCellObject(v) && (v.value === void 0 || v.value === null) && !v.formula) continue;
|
|
625
|
+
present++;
|
|
626
|
+
any = true;
|
|
627
|
+
}
|
|
628
|
+
if (!any) continue;
|
|
629
|
+
rows++;
|
|
630
|
+
padding += width - present;
|
|
631
|
+
if (padding > max) throw new require_errors.LimitError("LIMIT_EXCEEDED", `The dataset needs more than maxCells (${max}) empty fields: ${rows} data rows × ${width} columns hold few cells. Read a narrower range or set maxColumns.`, { details: {
|
|
632
|
+
limit: "maxCells",
|
|
633
|
+
value: padding,
|
|
634
|
+
max,
|
|
635
|
+
rows,
|
|
636
|
+
columns: width
|
|
637
|
+
} });
|
|
638
|
+
}
|
|
639
|
+
}
|
|
597
640
|
/** @internal */
|
|
598
|
-
function toDatasetDetailed(sheet, options = {}) {
|
|
641
|
+
function toDatasetDetailed(sheet, options = {}, budget) {
|
|
599
642
|
const s = sheet;
|
|
600
643
|
const rng = options.range ? require_address.decodeRange(options.range) : s.dimension ? require_address.decodeRange(s.dimension) : usedRange(s);
|
|
601
644
|
if (!rng) return {
|
|
@@ -631,6 +674,7 @@ function toDatasetDetailed(sheet, options = {}) {
|
|
|
631
674
|
const rowNumbers = [];
|
|
632
675
|
let lastRaw;
|
|
633
676
|
const firstData = headerRow === false ? rng.start.row : Math.max(rng.start.row, headerRow + headerRows);
|
|
677
|
+
if (budget) checkPadding(s, rng, firstData, budget.maxCells);
|
|
634
678
|
for (let r = firstData; r <= rng.end.row; r++) {
|
|
635
679
|
const row = s.rows[r];
|
|
636
680
|
if (!row) continue;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
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";
|
|
2
2
|
import { t as cellText } from "./cells-CrMF8h_t.js";
|
|
3
3
|
import { t as dateToSerial } from "./dates-BXcSWf9_.js";
|
|
4
|
-
import { o as ValidationError } from "./errors-CvGlfw0E.js";
|
|
4
|
+
import { a as LimitError, o as ValidationError } from "./errors-CvGlfw0E.js";
|
|
5
5
|
import { n as parseIsoDate, t as isoDate } from "./iso-date-CXnn-9mT.js";
|
|
6
6
|
import { l as textWidth, m as mergeStyles, n as validateSheetName, r as AUTO_WIDTH } from "./sheet-names-BLrwcn33.js";
|
|
7
7
|
// src/dataset.ts
|
|
@@ -594,8 +594,51 @@ function toDataset(sheet, options = {}) {
|
|
|
594
594
|
data
|
|
595
595
|
};
|
|
596
596
|
}
|
|
597
|
+
/**
|
|
598
|
+
* Every data row gets a key for every column, null where the row has no cell
|
|
599
|
+
* (the contract of toDataset). A wide header over short rows therefore costs
|
|
600
|
+
* rows × columns, far beyond the cells the sheet holds: 16,384 titles over
|
|
601
|
+
* 10,000 three-cell rows are 164 million fields. This counts those empty
|
|
602
|
+
* fields, row by row in the order they would be built, and refuses at the
|
|
603
|
+
* first row that passes `max`, before any row is built (JSE-68). A cell with
|
|
604
|
+
* neither value nor formula (only a hyperlink, which the reader charges to
|
|
605
|
+
* maxItems, or a style) is an empty field too. Work is
|
|
606
|
+
* bounded by the cells visited plus `max`: a row costs at most its stored
|
|
607
|
+
* cells plus its empty fields.
|
|
608
|
+
*/
|
|
609
|
+
function checkPadding(s, rng, firstData, max) {
|
|
610
|
+
const width = rng.end.col - rng.start.col + 1;
|
|
611
|
+
const height = rng.end.row - firstData + 1;
|
|
612
|
+
if (height <= 0 || width * height <= max) return;
|
|
613
|
+
let padding = 0;
|
|
614
|
+
let rows = 0;
|
|
615
|
+
for (let r = firstData; r <= rng.end.row; r++) {
|
|
616
|
+
const row = s.rows[r];
|
|
617
|
+
if (!row) continue;
|
|
618
|
+
const end = Math.min(rng.end.col, row.length - 1);
|
|
619
|
+
let any = false;
|
|
620
|
+
let present = 0;
|
|
621
|
+
for (let c = rng.start.col; c <= end; c++) {
|
|
622
|
+
const v = row[c];
|
|
623
|
+
if (v === void 0 || v === null) continue;
|
|
624
|
+
if (isCellObject(v) && (v.value === void 0 || v.value === null) && !v.formula) continue;
|
|
625
|
+
present++;
|
|
626
|
+
any = true;
|
|
627
|
+
}
|
|
628
|
+
if (!any) continue;
|
|
629
|
+
rows++;
|
|
630
|
+
padding += width - present;
|
|
631
|
+
if (padding > max) throw new LimitError("LIMIT_EXCEEDED", `The dataset needs more than maxCells (${max}) empty fields: ${rows} data rows × ${width} columns hold few cells. Read a narrower range or set maxColumns.`, { details: {
|
|
632
|
+
limit: "maxCells",
|
|
633
|
+
value: padding,
|
|
634
|
+
max,
|
|
635
|
+
rows,
|
|
636
|
+
columns: width
|
|
637
|
+
} });
|
|
638
|
+
}
|
|
639
|
+
}
|
|
597
640
|
/** @internal */
|
|
598
|
-
function toDatasetDetailed(sheet, options = {}) {
|
|
641
|
+
function toDatasetDetailed(sheet, options = {}, budget) {
|
|
599
642
|
const s = sheet;
|
|
600
643
|
const rng = options.range ? decodeRange(options.range) : s.dimension ? decodeRange(s.dimension) : usedRange(s);
|
|
601
644
|
if (!rng) return {
|
|
@@ -631,6 +674,7 @@ function toDatasetDetailed(sheet, options = {}) {
|
|
|
631
674
|
const rowNumbers = [];
|
|
632
675
|
let lastRaw;
|
|
633
676
|
const firstData = headerRow === false ? rng.start.row : Math.max(rng.start.row, headerRow + headerRows);
|
|
677
|
+
if (budget) checkPadding(s, rng, firstData, budget.maxCells);
|
|
634
678
|
for (let r = firstData; r <= rng.end.row; r++) {
|
|
635
679
|
const row = s.rows[r];
|
|
636
680
|
if (!row) continue;
|
package/dist/import.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_pipeline = require("./pipeline-
|
|
2
|
+
const require_pipeline = require("./pipeline-BwkRpV5Z.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
|
|
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
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";
|
|
8
8
|
import { t as AbortSignalLike } from "./signal-Dz0ZYe6d.cjs";
|
|
9
9
|
import { ReadLimits, SheetInfo } from "./read.cjs";
|
|
10
|
-
export { type AbortSignalLike, type BinaryInput, type BlobLike, type BlobType, type CoerceResult, type ColumnMapping, type ColumnType, type DatasetLike, type DateOrder, type DetectHeaderOptions, 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 };
|
|
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 };
|
package/dist/import.d.ts
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
|
|
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-BegSPu8X.js";
|
|
7
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.js";
|
|
8
8
|
import { t as AbortSignalLike } from "./signal-Dz0ZYe6d.js";
|
|
9
9
|
import { ReadLimits, SheetInfo } from "./read.js";
|
|
10
|
-
export { type AbortSignalLike, type BinaryInput, type BlobLike, type BlobType, type CoerceResult, type ColumnMapping, type ColumnType, type DatasetLike, type DateOrder, type DetectHeaderOptions, 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 };
|
|
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 };
|
package/dist/import.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as mapColumns, c as parseNumber, i as applyMapping, n as coerceColumns, o as detectHeader, r as inferColumnTypes, s as parseDate, t as importDataset } from "./pipeline-
|
|
1
|
+
import { a as mapColumns, c as parseNumber, i as applyMapping, n as coerceColumns, o as detectHeader, r as inferColumnTypes, s as parseDate, t as importDataset } from "./pipeline-C8F9lecW.js";
|
|
2
2
|
import { t as isDataLossWarning } from "./warnings-BPz1Ia3s.js";
|
|
3
3
|
export { applyMapping, coerceColumns, detectHeader, importDataset, inferColumnTypes, isDataLossWarning, mapColumns, parseDate, parseNumber };
|
package/dist/index.cjs
CHANGED
|
@@ -6,12 +6,12 @@ const require_dates = require("./dates-CA1dCizp.cjs");
|
|
|
6
6
|
const require_sheet_names = require("./sheet-names-DDY64-dt.cjs");
|
|
7
7
|
const require_colors = require("./colors-oBpjx97l.cjs");
|
|
8
8
|
const require_cells = require("./cells-CPXU722t.cjs");
|
|
9
|
-
const require_dataset = require("./dataset-
|
|
9
|
+
const require_dataset = require("./dataset-CbZnEWXu.cjs");
|
|
10
10
|
const require_numfmt = require("./numfmt-DwsnhZKe.cjs");
|
|
11
11
|
const require_address = require("./address-DZBHchLv.cjs");
|
|
12
12
|
// src/index.ts
|
|
13
13
|
/** Package version. Set from package.json by `npm run version-packages` (scripts/sync-version.mjs); a unit test checks it. */
|
|
14
|
-
const VERSION = "2.
|
|
14
|
+
const VERSION = "2.4.0";
|
|
15
15
|
exports.BUILTIN_NUM_FMTS = require_numfmt.BUILTIN_NUM_FMTS;
|
|
16
16
|
exports.CsvError = require_errors.CsvError;
|
|
17
17
|
exports.EnvironmentError = require_errors.EnvironmentError;
|
package/dist/index.d.cts
CHANGED
|
@@ -293,5 +293,5 @@ export declare function encodeRange(r: RangeAddress): string;
|
|
|
293
293
|
/** 'A1:C3' or 'A1' → range, normalised so start is top-left. */
|
|
294
294
|
export declare function decodeRange(ref: string): RangeAddress;
|
|
295
295
|
/** Package version. Set from package.json by `npm run version-packages` (scripts/sync-version.mjs); a unit test checks it. */
|
|
296
|
-
export declare const VERSION = "2.
|
|
296
|
+
export declare const VERSION = "2.4.0";
|
|
297
297
|
export { type AbortSignalLike, type Alignment, type AutoWidthOptions, type BinaryInput, type BlobLike, type BlobType, type Border, type BorderSide, type BorderStyle, type Cell, type CellAddress, type CellErrorValue, type CellInput, type CellTextOptions, type CellType, type CellValue, type Color, type ColorContext, type ColumnDef, type ColumnProps, type ColumnTotal, type ColumnWidth, type Dataset, type DatasetBlock, type DatasetOptions, type DatasetResult, type DateOptions, type DefinedName, type DocProperties, type DroppedWarnings, type ErrorCode, type ExcelErrorCode, type ExcelErrorOptions, type ExcelPartKind, type ExcelWarning, type ExcelWarningCode, type Fill, type Font, type GradientFill, type GroupColumn, type Hyperlink, type LeafColumn, type NumFmt, type PatternFill, type PatternType, type PrintSetup, type Progress, type RangeAddress, type RichText, type RichTextRun, type RowProps, type Sheet, type SheetNameProblem, type SheetView, type Style, type Theme, type ToDatasetOptions, type Workbook, type WriteOptions, XLSX_MIME, isDataLossWarning, toBlob, toUint8Array };
|
package/dist/index.d.ts
CHANGED
|
@@ -293,5 +293,5 @@ export declare function encodeRange(r: RangeAddress): string;
|
|
|
293
293
|
/** 'A1:C3' or 'A1' → range, normalised so start is top-left. */
|
|
294
294
|
export declare function decodeRange(ref: string): RangeAddress;
|
|
295
295
|
/** Package version. Set from package.json by `npm run version-packages` (scripts/sync-version.mjs); a unit test checks it. */
|
|
296
|
-
export declare const VERSION = "2.
|
|
296
|
+
export declare const VERSION = "2.4.0";
|
|
297
297
|
export { type AbortSignalLike, type Alignment, type AutoWidthOptions, type BinaryInput, type BlobLike, type BlobType, type Border, type BorderSide, type BorderStyle, type Cell, type CellAddress, type CellErrorValue, type CellInput, type CellTextOptions, type CellType, type CellValue, type Color, type ColorContext, type ColumnDef, type ColumnProps, type ColumnTotal, type ColumnWidth, type Dataset, type DatasetBlock, type DatasetOptions, type DatasetResult, type DateOptions, type DefinedName, type DocProperties, type DroppedWarnings, type ErrorCode, type ExcelErrorCode, type ExcelErrorOptions, type ExcelPartKind, type ExcelWarning, type ExcelWarningCode, type Fill, type Font, type GradientFill, type GroupColumn, type Hyperlink, type LeafColumn, type NumFmt, type PatternFill, type PatternType, type PrintSetup, type Progress, type RangeAddress, type RichText, type RichTextRun, type RowProps, type Sheet, type SheetNameProblem, type SheetView, type Style, type Theme, type ToDatasetOptions, type Workbook, type WriteOptions, XLSX_MIME, isDataLossWarning, toBlob, toUint8Array };
|
package/dist/index.js
CHANGED
|
@@ -5,10 +5,10 @@ import { n as serialToDate, t as dateToSerial } from "./dates-BXcSWf9_.js";
|
|
|
5
5
|
import { m as mergeStyles, n as validateSheetName, t as sanitizeSheetName } from "./sheet-names-BLrwcn33.js";
|
|
6
6
|
import { t as resolveColor } from "./colors-B8Nf_xTx.js";
|
|
7
7
|
import { t as cellText } from "./cells-CrMF8h_t.js";
|
|
8
|
-
import { n as fromDatasets, r as toDataset, t as fromDataset } from "./dataset-
|
|
8
|
+
import { n as fromDatasets, r as toDataset, t as fromDataset } from "./dataset-CyEHVht4.js";
|
|
9
9
|
import { n as isDateFormat, t as BUILTIN_NUM_FMTS } from "./numfmt-Ci_oW11p.js";
|
|
10
10
|
import { a as decodeRange, c as encodeRange, i as decodeCol, n as MAX_ROWS, o as encodeCell, r as decodeCell, s as encodeCol, t as MAX_COLS } from "./address-DUn7-5OS.js";
|
|
11
11
|
// src/index.ts
|
|
12
12
|
/** Package version. Set from package.json by `npm run version-packages` (scripts/sync-version.mjs); a unit test checks it. */
|
|
13
|
-
const VERSION = "2.
|
|
13
|
+
const VERSION = "2.4.0";
|
|
14
14
|
export { BUILTIN_NUM_FMTS, CsvError, EnvironmentError, ExcelError, FormatError, LimitError, MAX_COLS, MAX_ROWS, VERSION, ValidationError, XLSX_MIME, cellText, dateToSerial, decodeCell, decodeCol, decodeRange, encodeCell, encodeCol, encodeRange, fromDataset, fromDatasets, isDataLossWarning, isDateFormat, isExcelError, mergeStyles, resolveColor, sanitizeSheetName, serialToDate, toBlob, toDataset, toUint8Array, validateSheetName };
|
|
@@ -13,15 +13,27 @@ declare function parseNumber(text: string, options?: {
|
|
|
13
13
|
group?: NumberGroup;
|
|
14
14
|
}): number | undefined;
|
|
15
15
|
type DateOrder = "YMD" | "DMY" | "MDY";
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* ISO 8601 always; numeric dates (d/m/yyyy, …) only with `order`. Two-digit
|
|
18
|
+
* years only with `twoDigitYearPivot` and a DMY or MDY order.
|
|
19
|
+
*/
|
|
17
20
|
declare function parseDate(text: string, options?: {
|
|
18
|
-
order?: DateOrder;
|
|
19
|
-
zone?: "local" | "utc";
|
|
21
|
+
order?: DateOrder | undefined;
|
|
22
|
+
zone?: "local" | "utc" | undefined;
|
|
23
|
+
twoDigitYearPivot?: number | undefined;
|
|
20
24
|
}): Date | undefined;
|
|
21
25
|
interface ImportLocale {
|
|
22
26
|
decimal?: "." | "," | undefined;
|
|
23
27
|
group?: NumberGroup | undefined;
|
|
24
28
|
dateOrder?: "auto" | "YMD" | "DMY" | "MDY" | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Accept two-digit years in numeric dates such as 31.10.26 (DMY) or
|
|
31
|
+
* 10/31/26 (MDY): a year yy below the pivot is 20yy, from it on 19yy.
|
|
32
|
+
* An integer from 0 to 100; 30 is Excel's rule (00–29 → 2000s, 30–99 → 1900s).
|
|
33
|
+
* Needs an explicit DMY or MDY `dateOrder`; 'auto' leaves such columns text.
|
|
34
|
+
* Default undefined: two-digit years are not accepted.
|
|
35
|
+
*/
|
|
36
|
+
twoDigitYearPivot?: number | undefined;
|
|
25
37
|
}
|
|
26
38
|
interface DetectHeaderOptions {
|
|
27
39
|
range?: string | undefined;
|
|
@@ -35,7 +47,13 @@ interface HeaderDetection {
|
|
|
35
47
|
confidence: "high" | "low";
|
|
36
48
|
}
|
|
37
49
|
declare function detectHeader(sheet: Sheet<CellInput>, options?: DetectHeaderOptions): HeaderDetection;
|
|
38
|
-
|
|
50
|
+
/**
|
|
51
|
+
* A column's type. `'day'` is never inferred: forced (by `types` or a schema
|
|
52
|
+
* field), it converts like `'date'` and then drops the time of day, giving
|
|
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").
|
|
55
|
+
*/
|
|
56
|
+
type ColumnType = "string" | "number" | "boolean" | "date" | "datetime" | "day" | "mixed" | "empty";
|
|
39
57
|
interface DatasetLike {
|
|
40
58
|
columns: ReadonlyArray<{
|
|
41
59
|
key: string;
|
|
@@ -152,7 +170,19 @@ interface ImportDatasetOptions {
|
|
|
152
170
|
mapping?: ColumnMapping | undefined;
|
|
153
171
|
maxRows?: number | undefined;
|
|
154
172
|
preview?: number | undefined;
|
|
155
|
-
/**
|
|
173
|
+
/**
|
|
174
|
+
* Issues kept in `issues` (added in 2.3). Past it, an issue is counted in `meta.droppedIssues`
|
|
175
|
+
* instead, unless it is the first of its code, so every kind of issue that occurred is listed at
|
|
176
|
+
* least once (and so is an `error` severity, if any). An integer of at least 1, or `Infinity` for no
|
|
177
|
+
* cap; default 100,000.
|
|
178
|
+
*/
|
|
179
|
+
maxIssues?: number | undefined;
|
|
180
|
+
/**
|
|
181
|
+
* Reader limits for xlsx. For a CSV file, `maxWarnings` caps its warnings,
|
|
182
|
+
* `maxCellTextLength` limits its fields (raising CSV's 1 MiB `maxFieldBytes` to match)
|
|
183
|
+
* and `maxColumns` the fields of one record. For both formats, `maxCells` also bounds
|
|
184
|
+
* the empty fields the dataset pads short rows with (since 2.4; docs/api.md §5.6).
|
|
185
|
+
*/
|
|
156
186
|
limits?: Partial<ReadLimits> | undefined;
|
|
157
187
|
signal?: AbortSignalLike | undefined;
|
|
158
188
|
onProgress?: ((p: ImportProgress) => void) | undefined;
|
|
@@ -179,6 +209,13 @@ interface ImportMeta {
|
|
|
179
209
|
truncated: boolean;
|
|
180
210
|
mapping?: ColumnMapping | undefined;
|
|
181
211
|
unmappedColumns?: string[] | undefined;
|
|
212
|
+
/** Set only when `maxIssues` dropped issues: how many, by code (added in 2.3). */
|
|
213
|
+
droppedIssues?: DroppedIssues | undefined;
|
|
214
|
+
}
|
|
215
|
+
/** Issues `maxIssues` kept out of `ImportDatasetResult.issues`. */
|
|
216
|
+
interface DroppedIssues {
|
|
217
|
+
total: number;
|
|
218
|
+
byCode: Partial<Record<ImportIssueCode, number>>;
|
|
182
219
|
}
|
|
183
220
|
interface ImportDatasetResult {
|
|
184
221
|
columns: ImportedColumn[];
|
|
@@ -189,4 +226,4 @@ interface ImportDatasetResult {
|
|
|
189
226
|
meta: ImportMeta;
|
|
190
227
|
}
|
|
191
228
|
declare function importDataset(input: string | BinaryInput, options?: ImportDatasetOptions): Promise<ImportDatasetResult>;
|
|
192
|
-
export {
|
|
229
|
+
export { NumberGroup as A, coerceColumns as C, ImportLocale as D, HeaderDetection as E, parseNumber as M, detectHeader as O, TypeOptions as S, DetectHeaderOptions as T, ColumnType as _, ImportProgress as a, ImportIssueCode as b, FieldSpec as c, MappableDataset as d, MappedDataset as f, CoerceResult as g, mapColumns as h, ImportMeta as i, parseDate as j, DateOrder as k, ImportSchema as l, applyMapping as m, ImportDatasetOptions as n, importDataset as o, MappingResult as p, ImportDatasetResult as r, ColumnMapping as s, DroppedIssues as t, ImportedColumn as u, DatasetLike as v, inferColumnTypes as w, InferredColumn as x, ImportIssue as y };
|