javascript-excel 1.0.3 → 2.0.0-alpha.2

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 +69 -2
  2. package/dist/auto-width-2oBzjeNG.d.cts +11 -0
  3. package/dist/auto-width-CT-BihTW.d.ts +10 -0
  4. package/dist/csv-DyVH9y7S.cjs +647 -0
  5. package/dist/csv-pXfaputs.js +618 -0
  6. package/dist/csv.cjs +7 -0
  7. package/dist/csv.d.cts +89 -0
  8. package/dist/csv.d.ts +89 -0
  9. package/dist/csv.js +1 -0
  10. package/dist/dom.cjs +440 -0
  11. package/dist/dom.d.cts +78 -0
  12. package/dist/dom.d.ts +78 -0
  13. package/dist/dom.js +437 -0
  14. package/dist/errors-CvGlfw0E.js +28 -0
  15. package/dist/errors-DOPrrGS4.cjs +69 -0
  16. package/dist/index.cjs +627 -0
  17. package/dist/index.d.cts +255 -0
  18. package/dist/index.d.ts +255 -0
  19. package/dist/index.js +597 -0
  20. package/dist/infer-BR-J9BZa.js +88 -0
  21. package/dist/infer-D9EC9vJ-.cjs +105 -0
  22. package/dist/iso-date-3TY1OlGd.cjs +57 -0
  23. package/dist/iso-date-CXnn-9mT.js +46 -0
  24. package/dist/numfmt-BBgB7iQA.js +429 -0
  25. package/dist/numfmt-Dv6AjopS.cjs +512 -0
  26. package/dist/read-C6L7Nyy3.d.cts +78 -0
  27. package/dist/read-DDN5ZsPe.js +2909 -0
  28. package/dist/read-Ddkks7qC.d.ts +78 -0
  29. package/dist/read-Ym1voUct.cjs +2932 -0
  30. package/dist/read.cjs +6 -0
  31. package/dist/read.d.cts +15 -0
  32. package/dist/read.d.ts +15 -0
  33. package/dist/read.js +1 -0
  34. package/dist/sheet-names-qpXsvMpM.cjs +1005 -0
  35. package/dist/sheet-names-uT2EH5Ui.js +832 -0
  36. package/dist/signal-Dz0ZYe6d.d.cts +13 -0
  37. package/dist/signal-Dz0ZYe6d.d.ts +13 -0
  38. package/dist/warnings-C_12PT4t.d.cts +410 -0
  39. package/dist/warnings-DXJKe1lx.d.ts +410 -0
  40. package/dist/worker.cjs +240 -0
  41. package/dist/worker.d.cts +65 -0
  42. package/dist/worker.d.ts +65 -0
  43. package/dist/worker.js +238 -0
  44. package/dist/write-BOh9jfu1.cjs +1487 -0
  45. package/dist/write-C5JgeIar.d.cts +29 -0
  46. package/dist/write-CYpLGuzl.d.ts +29 -0
  47. package/dist/write-DubvcG-x.js +1470 -0
  48. package/package.json +101 -51
  49. package/.babelrc +0 -10
  50. package/.circleci/config.yml +0 -39
  51. package/lib/index.d.ts +0 -1
  52. package/lib/index.js +0 -22
  53. package/lib/javascript-excel.js +0 -17703
  54. package/src/index.tsx +0 -11
  55. package/test/unit/sample.spec.js +0 -5
  56. package/tsconfig.json +0 -54
  57. package/webpack.config.js +0 -19
  58. /package/{LICENSE.md → LICENSE} +0 -0
@@ -0,0 +1,255 @@
1
+ /**
2
+ * javascript-excel 2.0 (in progress).
3
+ *
4
+ * This entry exports the workbook model types (docs/api.md §3), the error
5
+ * classes (§7), the xlsx writer (§5.1) and the address, date and style
6
+ * helpers (§4). Builders land in later pull requests.
7
+ */
8
+ import { A as RichTextRun, C as GradientFill, D as PatternType, E as PatternFill, F as Theme, I as Workbook, M as Sheet, N as SheetView, O as PrintSetup, P as Style, S as Font, T as NumFmt, _ as ColumnWidth, a as BlobType, b as ErrorCode, c as BorderSide, d as CellErrorValue, f as CellInput, g as ColumnProps, h as Color, i as BlobLike, j as RowProps, k as RichText, l as BorderStyle, m as CellValue, n as ExcelWarningCode, o as Alignment, p as CellType, r as BinaryInput, s as Border, t as ExcelWarning, u as Cell, v as DefinedName, w as Hyperlink, x as Fill, y as DocProperties } from "./warnings-C_12PT4t.cjs";
9
+ import { a as toUint8Array, i as toBlob, n as WriteOptions, r as XLSX_MIME, t as Progress } from "./write-C5JgeIar.cjs";
10
+ import { t as AbortSignalLike } from "./signal-Dz0ZYe6d.cjs";
11
+ import { t as AutoWidthOptions } from "./auto-width-2oBzjeNG.cjs";
12
+ /**
13
+ * Typed errors (docs/api.md §7).
14
+ *
15
+ * Check errors with `isExcelError(err)` or `err.code`, not `instanceof`: when an
16
+ * app ends up with both the ESM and the CJS build, each has its own classes.
17
+ */
18
+ /** Every error code the library throws. */
19
+ type ExcelErrorCode = "NO_SHEETS" | "INVALID_SHEET_NAME" | "DUPLICATE_SHEET_NAME" | "INVALID_ACTIVE_SHEET" | "INVALID_REF" | "OUT_OF_BOUNDS" | "INVALID_CELL" | "INVALID_NUMBER" | "INVALID_DATE" | "STRING_TOO_LONG" | "INVALID_STYLE" | "INVALID_NUMFMT" | "INVALID_HYPERLINK" | "OVERLAPPING_MERGE" | "INVALID_COLUMN" | "TOO_MANY_STYLES" | "ZIP64_REQUIRED" | "INVALID_PROPERTY" | "INVALID_SHEET_PROPERTY" | "INVALID_DEFINED_NAME" | "UNSUPPORTED_FORMAT" | "NOT_XLSX" | "ZIP_INVALID" | "ZIP_UNSUPPORTED_METHOD" | "ZIP_ENCRYPTED" | "ZIP_CRC_MISMATCH" | "XML_MALFORMED" | "XML_DTD_FORBIDDEN" | "LIMIT_EXCEEDED" | "CSV_MALFORMED" | "ENVIRONMENT_UNSUPPORTED";
20
+ /** Options accepted by every error constructor. */
21
+ interface ExcelErrorOptions {
22
+ cause?: unknown;
23
+ details?: Record<string, unknown>;
24
+ }
25
+ /** Base class of every error the library throws. */
26
+ export declare class ExcelError extends Error {
27
+ readonly code: ExcelErrorCode;
28
+ readonly details?: Record<string, unknown>;
29
+ constructor(code: ExcelErrorCode, message: string, options?: ExcelErrorOptions);
30
+ }
31
+ /** The model or options cannot be written. */
32
+ export declare class ValidationError extends ExcelError {}
33
+ /** The input is not a readable xlsx or zip file. */
34
+ export declare class FormatError extends ExcelError {}
35
+ /** A read limit was exceeded; `details.limit` names it. */
36
+ export declare class LimitError extends ExcelError {}
37
+ /** Malformed CSV in strict mode. */
38
+ export declare class CsvError extends ExcelError {}
39
+ /** A required platform API is missing. */
40
+ export declare class EnvironmentError extends ExcelError {}
41
+ /** True for any error thrown by this library, across ESM/CJS copies and realms. */
42
+ export declare function isExcelError(e: unknown): e is ExcelError;
43
+ /** Options for date conversion. */
44
+ interface DateOptions {
45
+ /** Use the 1904 date system. Default false. */
46
+ date1904?: boolean | undefined;
47
+ /** Default 'local'. */
48
+ dateZone?: "local" | "utc" | undefined;
49
+ }
50
+ /**
51
+ * Converts a Date to an Excel serial number.
52
+ * Throws `INVALID_DATE` for an invalid Date or one outside the date system's
53
+ * range: 1899-12-31 (Excel's day 0, where time-only values live, as serials
54
+ * 0 to <1; serialToDate returns those) or 1904-01-01, to 9999-12-31.
55
+ */
56
+ export declare function dateToSerial(d: Date, options?: DateOptions): number;
57
+ /**
58
+ * Converts an Excel serial number to a Date (inverse of `dateToSerial`).
59
+ * - 1900 system: serials 0 to <1 are Excel's day 0 ("1900-01-00", i.e.
60
+ * 1899-12-31), which is how time-only values such as 0.5 (12:00) are
61
+ * stored. Serial 60 (the fictitious 1900-02-29) has no real date and gives
62
+ * 1900-03-01; callers that must flag it (the reader) check for it themselves.
63
+ * - 1904 system: serial 0 = 1904-01-01.
64
+ * Throws `INVALID_DATE` for negative, non-finite or out-of-range serials.
65
+ */
66
+ export declare function serialToDate(serial: number, options?: DateOptions): Date;
67
+ /**
68
+ * Deep-merges styles, later ones winning field by field. `font`, `alignment`,
69
+ * `protection` and each `border` side merge by field; `fill` and `numFmt`
70
+ * replace as a whole. `undefined` layers and `undefined` fields are skipped.
71
+ * The inputs are not modified.
72
+ */
73
+ export declare function mergeStyles(...styles: Array<Style | undefined>): Style;
74
+ /** Options for `cellText`. */
75
+ interface CellTextOptions {
76
+ /** Fields used for dates. Default 'local'. */
77
+ dateZone?: "local" | "utc" | undefined;
78
+ }
79
+ /**
80
+ * Plain text of a cell: strings as they are, numbers as `String(n)`, booleans
81
+ * as TRUE/FALSE, dates as ISO 8601, errors as their code, rich text joined.
82
+ * A formula cell gives its cached value's text ('' when there is none).
83
+ * Number formats are not applied.
84
+ */
85
+ export declare function cellText(cell: CellInput, options?: CellTextOptions): string;
86
+ /** A dataset: column definitions and rows (objects or arrays). */
87
+ interface Dataset<T> {
88
+ /** Falsy entries are skipped (conditional columns). Omitted: inferred from the keys of the first object row. */
89
+ columns?: Array<ColumnDef<T> | null | false | undefined> | undefined;
90
+ /** Objects (picked by key, path or value) or arrays (picked by index). */
91
+ data: readonly T[];
92
+ }
93
+ /** A column definition: a leaf (one sheet column) or a header group. */
94
+ type ColumnDef<T> = LeafColumn<T> | GroupColumn<T>;
95
+ /** A header group: its title spans its leaf columns (a merged header cell). */
96
+ interface GroupColumn<T> {
97
+ title: string | RichText | Cell;
98
+ headerStyle?: Style | undefined;
99
+ children: Array<ColumnDef<T> | null | false | undefined>;
100
+ }
101
+ /** What a totals cell may be: a built-in, a fixed cell, or a function of the column's data. */
102
+ type ColumnTotal = "sum" | "average" | "count" | "min" | "max" | CellInput | ((ctx: {
103
+ range: string;
104
+ values: CellValue[];
105
+ }) => CellInput);
106
+ /** A leaf column: one sheet column. */
107
+ interface LeafColumn<T> {
108
+ /** Header cell. Default: the key or path, or '' for value/index accessors. */
109
+ title?: string | RichText | Cell | undefined;
110
+ /** Own property name, taken literally ('a.b' is a key containing a dot). */
111
+ key?: string | undefined;
112
+ /** Path into nested data: 'a.b', 'items[0].name', "a['x.y']". */
113
+ path?: string | undefined;
114
+ /** Computed value. */
115
+ value?: ((row: T, ctx: {
116
+ rowIndex: number;
117
+ }) => CellInput) | undefined;
118
+ /** Array rows: index into the row. */
119
+ index?: number | undefined;
120
+ /** Coerce data cells. Default 'auto': take values as they are. */
121
+ type?: "auto" | "string" | "number" | "boolean" | "date" | "datetime" | undefined;
122
+ numFmt?: NumFmt | undefined;
123
+ /** Style of this column's data cells. */
124
+ style?: Style | undefined;
125
+ /** Merged over options.headerStyle. */
126
+ headerStyle?: Style | undefined;
127
+ width?: ColumnWidth | undefined;
128
+ hidden?: boolean | undefined;
129
+ /** Totals row entry for this column. */
130
+ total?: ColumnTotal | undefined;
131
+ }
132
+ /** Options for `fromDataset` and `fromDatasets`. */
133
+ interface DatasetOptions<T> {
134
+ /** Sheet name, default 'Sheet1'. An invalid name throws INVALID_SHEET_NAME (§12 Q19). */
135
+ name?: string | undefined;
136
+ /** Top-left cell of the block, default 'A1'. */
137
+ origin?: string | undefined;
138
+ /** Write header rows, default true. */
139
+ header?: boolean | undefined;
140
+ /** Default { font: { bold: true } }. */
141
+ headerStyle?: Style | undefined;
142
+ /** Freeze all header rows. */
143
+ freezeHeader?: boolean | undefined;
144
+ /** Autofilter from the last header row through the last data row (totals excluded). */
145
+ autoFilter?: boolean | undefined;
146
+ /** Estimate column widths from the text. Columns with their own width keep it. */
147
+ autoWidth?: boolean | AutoWidthOptions | undefined;
148
+ rightToLeft?: boolean | undefined;
149
+ /** Totals row label (in the first leaf column, if it has no total) and style. */
150
+ totals?: {
151
+ label?: string | undefined;
152
+ style?: Style | undefined;
153
+ } | undefined;
154
+ rowStyle?: ((row: T, rowIndex: number) => Style | undefined) | undefined;
155
+ /** COERCION_FAILED and NON_FINITE_NUMBER. */
156
+ onWarning?: ((w: ExcelWarning) => void) | undefined;
157
+ }
158
+ /** A block for `fromDatasets`, optionally offset from the previous one. */
159
+ type DatasetBlock<T> = Dataset<T> & {
160
+ offset?: {
161
+ rows?: number | undefined;
162
+ cols?: number | undefined;
163
+ } | undefined;
164
+ };
165
+ /** Builds a sheet from `{ columns, data }`. */
166
+ export declare function fromDataset<T>(dataset: Dataset<T>, options?: DatasetOptions<T>): Sheet;
167
+ /**
168
+ * Stacks several datasets on one sheet (replaces the old xSteps/ySteps).
169
+ * Each block starts `gap` empty rows (default 1) below the previous one, or
170
+ * `offset.rows` rows when given, and `offset.cols` columns right of the
171
+ * origin. Freeze and filter apply to the first block with header rows.
172
+ */
173
+ export declare function fromDatasets(blocks: Array<DatasetBlock<any>>, options?: DatasetOptions<any> & {
174
+ gap?: number | undefined;
175
+ }): Sheet;
176
+ /** Options for `toDataset`. */
177
+ interface ToDatasetOptions {
178
+ /** Zero-based header row, default 0; false = no header, keys are column letters. */
179
+ headerRow?: number | false | undefined;
180
+ /** Range to read, e.g. 'A1:F100'. Default: sheet.dimension, else the used range. */
181
+ range?: string | undefined;
182
+ /** 'value' (default): each field is the cell's value; 'cell': the whole Cell. */
183
+ values?: "value" | "cell" | undefined;
184
+ }
185
+ /** The result of `toDataset`. Rows are null-prototype objects. */
186
+ interface DatasetResult {
187
+ columns: Array<{
188
+ title: string;
189
+ key: string;
190
+ }>;
191
+ data: Array<Record<string, unknown>>;
192
+ }
193
+ /**
194
+ * Reads a sheet back into `{ columns, data }` (import direction). Keys come
195
+ * from the header text, deduplicated with _2, _3...; an empty header gives the
196
+ * column letter. Empty rows are skipped. Rows are null-prototype objects, so
197
+ * a header named __proto__ in an untrusted file is just a key.
198
+ */
199
+ export declare function toDataset(sheet: Sheet<Cell> | Sheet, options?: ToDatasetOptions): DatasetResult;
200
+ /**
201
+ * Sheet-name rules (docs/api.md §3.3, §4.6).
202
+ *
203
+ * Excel rejects names that are empty, longer than 31 characters, contain any
204
+ * of \ / ? * [ ] :, or start or end with an apostrophe. It reserves 'History'
205
+ * [to verify]. Names are unique case-insensitively (checked by the writer).
206
+ */
207
+ /** Why a sheet name is invalid. */
208
+ type SheetNameProblem = "empty" | "too-long" | "forbidden-char" | "apostrophe" | "reserved";
209
+ /** Returns null when `name` is a valid sheet name, or the reason it is not. */
210
+ export declare function validateSheetName(name: string): SheetNameProblem | null;
211
+ /**
212
+ * Makes any string a valid sheet name: forbidden characters become '_',
213
+ * leading and trailing apostrophes are removed, the result is cut to 31
214
+ * characters (without splitting a surrogate pair), and an empty or reserved
215
+ * result becomes 'Sheet'. Uniqueness is the caller's job.
216
+ */
217
+ export declare function sanitizeSheetName(name: string): string;
218
+ /** The built-in number formats ECMA-376 §18.8.30 defines (§11.2). Ids 14–17 and 22 render in the user's locale in Excel. */
219
+ export declare const BUILTIN_NUM_FMTS: Readonly<Record<number, string>>;
220
+ /**
221
+ * True when a number format shows a date or a time of day (§3.4.1): built-in
222
+ * ids 14–22, 45, 47, 27–36 and 50–58, or a custom code that contains a date or
223
+ * time token outside quoted text, escapes and brackets. Elapsed-time formats
224
+ * (`[h]:mm:ss`, built-in 46) are durations and return false.
225
+ */
226
+ export declare function isDateFormat(fmt: NumFmt | undefined): boolean;
227
+ /** A zero-based cell address. */
228
+ interface CellAddress {
229
+ row: number;
230
+ col: number;
231
+ }
232
+ /** A range of cells, inclusive. */
233
+ interface RangeAddress {
234
+ start: CellAddress;
235
+ end: CellAddress;
236
+ }
237
+ /** Rows per sheet in the xlsx format. */
238
+ export declare const MAX_ROWS = 1048576;
239
+ /** Columns per sheet in the xlsx format (A..XFD). */
240
+ export declare const MAX_COLS = 16384;
241
+ /** Column index to letters: 0 → 'A', 16383 → 'XFD'. */
242
+ export declare function encodeCol(col: number): string;
243
+ /** Column letters to index: 'A' → 0, 'XFD' → 16383. Case-insensitive. */
244
+ export declare function decodeCol(letters: string): number;
245
+ /** { row: 0, col: 1 } → 'B1'. */
246
+ export declare function encodeCell(a: CellAddress): string;
247
+ /** 'B1' or '$B$1' → { row: 0, col: 1 }. */
248
+ export declare function decodeCell(ref: string): CellAddress;
249
+ /** Range to 'A1:C3' (a single cell gives 'A1'). */
250
+ export declare function encodeRange(r: RangeAddress): string;
251
+ /** 'A1:C3' or 'A1' → range, normalised so start is top-left. */
252
+ export declare function decodeRange(ref: string): RangeAddress;
253
+ /** Package version. Set from package.json by `npm run version-packages` (scripts/sync-version.mjs); a unit test checks it. */
254
+ export declare const VERSION = "2.0.0-alpha.2";
255
+ 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 ColumnDef, type ColumnProps, type ColumnTotal, type ColumnWidth, type Dataset, type DatasetBlock, type DatasetOptions, type DatasetResult, type DateOptions, type DefinedName, type DocProperties, type ErrorCode, type ExcelErrorCode, type ExcelErrorOptions, 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, toBlob, toUint8Array };
@@ -0,0 +1,255 @@
1
+ /**
2
+ * javascript-excel 2.0 (in progress).
3
+ *
4
+ * This entry exports the workbook model types (docs/api.md §3), the error
5
+ * classes (§7), the xlsx writer (§5.1) and the address, date and style
6
+ * helpers (§4). Builders land in later pull requests.
7
+ */
8
+ import { A as SheetView, C as PatternFill, D as RichTextRun, E as RichText, F as BlobLike, I as BlobType, M as Theme, N as Workbook, O as RowProps, P as BinaryInput, S as NumFmt, T as PrintSetup, _ as ErrorCode, a as BorderSide, b as GradientFill, c as CellErrorValue, d as CellValue, f as Color, g as DocProperties, h as DefinedName, i as Border, j as Style, k as Sheet, l as CellInput, m as ColumnWidth, n as ExcelWarningCode, o as BorderStyle, p as ColumnProps, r as Alignment, s as Cell, t as ExcelWarning, u as CellType, v as Fill, w as PatternType, x as Hyperlink, y as Font } from "./warnings-DXJKe1lx.js";
9
+ import { a as toUint8Array, i as toBlob, n as WriteOptions, r as XLSX_MIME, t as Progress } from "./write-CYpLGuzl.js";
10
+ import { t as AbortSignalLike } from "./signal-Dz0ZYe6d.js";
11
+ import { t as AutoWidthOptions } from "./auto-width-CT-BihTW.js";
12
+ /**
13
+ * Typed errors (docs/api.md §7).
14
+ *
15
+ * Check errors with `isExcelError(err)` or `err.code`, not `instanceof`: when an
16
+ * app ends up with both the ESM and the CJS build, each has its own classes.
17
+ */
18
+ /** Every error code the library throws. */
19
+ type ExcelErrorCode = "NO_SHEETS" | "INVALID_SHEET_NAME" | "DUPLICATE_SHEET_NAME" | "INVALID_ACTIVE_SHEET" | "INVALID_REF" | "OUT_OF_BOUNDS" | "INVALID_CELL" | "INVALID_NUMBER" | "INVALID_DATE" | "STRING_TOO_LONG" | "INVALID_STYLE" | "INVALID_NUMFMT" | "INVALID_HYPERLINK" | "OVERLAPPING_MERGE" | "INVALID_COLUMN" | "TOO_MANY_STYLES" | "ZIP64_REQUIRED" | "INVALID_PROPERTY" | "INVALID_SHEET_PROPERTY" | "INVALID_DEFINED_NAME" | "UNSUPPORTED_FORMAT" | "NOT_XLSX" | "ZIP_INVALID" | "ZIP_UNSUPPORTED_METHOD" | "ZIP_ENCRYPTED" | "ZIP_CRC_MISMATCH" | "XML_MALFORMED" | "XML_DTD_FORBIDDEN" | "LIMIT_EXCEEDED" | "CSV_MALFORMED" | "ENVIRONMENT_UNSUPPORTED";
20
+ /** Options accepted by every error constructor. */
21
+ interface ExcelErrorOptions {
22
+ cause?: unknown;
23
+ details?: Record<string, unknown>;
24
+ }
25
+ /** Base class of every error the library throws. */
26
+ export declare class ExcelError extends Error {
27
+ readonly code: ExcelErrorCode;
28
+ readonly details?: Record<string, unknown>;
29
+ constructor(code: ExcelErrorCode, message: string, options?: ExcelErrorOptions);
30
+ }
31
+ /** The model or options cannot be written. */
32
+ export declare class ValidationError extends ExcelError {}
33
+ /** The input is not a readable xlsx or zip file. */
34
+ export declare class FormatError extends ExcelError {}
35
+ /** A read limit was exceeded; `details.limit` names it. */
36
+ export declare class LimitError extends ExcelError {}
37
+ /** Malformed CSV in strict mode. */
38
+ export declare class CsvError extends ExcelError {}
39
+ /** A required platform API is missing. */
40
+ export declare class EnvironmentError extends ExcelError {}
41
+ /** True for any error thrown by this library, across ESM/CJS copies and realms. */
42
+ export declare function isExcelError(e: unknown): e is ExcelError;
43
+ /** Options for date conversion. */
44
+ interface DateOptions {
45
+ /** Use the 1904 date system. Default false. */
46
+ date1904?: boolean | undefined;
47
+ /** Default 'local'. */
48
+ dateZone?: "local" | "utc" | undefined;
49
+ }
50
+ /**
51
+ * Converts a Date to an Excel serial number.
52
+ * Throws `INVALID_DATE` for an invalid Date or one outside the date system's
53
+ * range: 1899-12-31 (Excel's day 0, where time-only values live, as serials
54
+ * 0 to <1; serialToDate returns those) or 1904-01-01, to 9999-12-31.
55
+ */
56
+ export declare function dateToSerial(d: Date, options?: DateOptions): number;
57
+ /**
58
+ * Converts an Excel serial number to a Date (inverse of `dateToSerial`).
59
+ * - 1900 system: serials 0 to <1 are Excel's day 0 ("1900-01-00", i.e.
60
+ * 1899-12-31), which is how time-only values such as 0.5 (12:00) are
61
+ * stored. Serial 60 (the fictitious 1900-02-29) has no real date and gives
62
+ * 1900-03-01; callers that must flag it (the reader) check for it themselves.
63
+ * - 1904 system: serial 0 = 1904-01-01.
64
+ * Throws `INVALID_DATE` for negative, non-finite or out-of-range serials.
65
+ */
66
+ export declare function serialToDate(serial: number, options?: DateOptions): Date;
67
+ /**
68
+ * Deep-merges styles, later ones winning field by field. `font`, `alignment`,
69
+ * `protection` and each `border` side merge by field; `fill` and `numFmt`
70
+ * replace as a whole. `undefined` layers and `undefined` fields are skipped.
71
+ * The inputs are not modified.
72
+ */
73
+ export declare function mergeStyles(...styles: Array<Style | undefined>): Style;
74
+ /** Options for `cellText`. */
75
+ interface CellTextOptions {
76
+ /** Fields used for dates. Default 'local'. */
77
+ dateZone?: "local" | "utc" | undefined;
78
+ }
79
+ /**
80
+ * Plain text of a cell: strings as they are, numbers as `String(n)`, booleans
81
+ * as TRUE/FALSE, dates as ISO 8601, errors as their code, rich text joined.
82
+ * A formula cell gives its cached value's text ('' when there is none).
83
+ * Number formats are not applied.
84
+ */
85
+ export declare function cellText(cell: CellInput, options?: CellTextOptions): string;
86
+ /** A dataset: column definitions and rows (objects or arrays). */
87
+ interface Dataset<T> {
88
+ /** Falsy entries are skipped (conditional columns). Omitted: inferred from the keys of the first object row. */
89
+ columns?: Array<ColumnDef<T> | null | false | undefined> | undefined;
90
+ /** Objects (picked by key, path or value) or arrays (picked by index). */
91
+ data: readonly T[];
92
+ }
93
+ /** A column definition: a leaf (one sheet column) or a header group. */
94
+ type ColumnDef<T> = LeafColumn<T> | GroupColumn<T>;
95
+ /** A header group: its title spans its leaf columns (a merged header cell). */
96
+ interface GroupColumn<T> {
97
+ title: string | RichText | Cell;
98
+ headerStyle?: Style | undefined;
99
+ children: Array<ColumnDef<T> | null | false | undefined>;
100
+ }
101
+ /** What a totals cell may be: a built-in, a fixed cell, or a function of the column's data. */
102
+ type ColumnTotal = "sum" | "average" | "count" | "min" | "max" | CellInput | ((ctx: {
103
+ range: string;
104
+ values: CellValue[];
105
+ }) => CellInput);
106
+ /** A leaf column: one sheet column. */
107
+ interface LeafColumn<T> {
108
+ /** Header cell. Default: the key or path, or '' for value/index accessors. */
109
+ title?: string | RichText | Cell | undefined;
110
+ /** Own property name, taken literally ('a.b' is a key containing a dot). */
111
+ key?: string | undefined;
112
+ /** Path into nested data: 'a.b', 'items[0].name', "a['x.y']". */
113
+ path?: string | undefined;
114
+ /** Computed value. */
115
+ value?: ((row: T, ctx: {
116
+ rowIndex: number;
117
+ }) => CellInput) | undefined;
118
+ /** Array rows: index into the row. */
119
+ index?: number | undefined;
120
+ /** Coerce data cells. Default 'auto': take values as they are. */
121
+ type?: "auto" | "string" | "number" | "boolean" | "date" | "datetime" | undefined;
122
+ numFmt?: NumFmt | undefined;
123
+ /** Style of this column's data cells. */
124
+ style?: Style | undefined;
125
+ /** Merged over options.headerStyle. */
126
+ headerStyle?: Style | undefined;
127
+ width?: ColumnWidth | undefined;
128
+ hidden?: boolean | undefined;
129
+ /** Totals row entry for this column. */
130
+ total?: ColumnTotal | undefined;
131
+ }
132
+ /** Options for `fromDataset` and `fromDatasets`. */
133
+ interface DatasetOptions<T> {
134
+ /** Sheet name, default 'Sheet1'. An invalid name throws INVALID_SHEET_NAME (§12 Q19). */
135
+ name?: string | undefined;
136
+ /** Top-left cell of the block, default 'A1'. */
137
+ origin?: string | undefined;
138
+ /** Write header rows, default true. */
139
+ header?: boolean | undefined;
140
+ /** Default { font: { bold: true } }. */
141
+ headerStyle?: Style | undefined;
142
+ /** Freeze all header rows. */
143
+ freezeHeader?: boolean | undefined;
144
+ /** Autofilter from the last header row through the last data row (totals excluded). */
145
+ autoFilter?: boolean | undefined;
146
+ /** Estimate column widths from the text. Columns with their own width keep it. */
147
+ autoWidth?: boolean | AutoWidthOptions | undefined;
148
+ rightToLeft?: boolean | undefined;
149
+ /** Totals row label (in the first leaf column, if it has no total) and style. */
150
+ totals?: {
151
+ label?: string | undefined;
152
+ style?: Style | undefined;
153
+ } | undefined;
154
+ rowStyle?: ((row: T, rowIndex: number) => Style | undefined) | undefined;
155
+ /** COERCION_FAILED and NON_FINITE_NUMBER. */
156
+ onWarning?: ((w: ExcelWarning) => void) | undefined;
157
+ }
158
+ /** A block for `fromDatasets`, optionally offset from the previous one. */
159
+ type DatasetBlock<T> = Dataset<T> & {
160
+ offset?: {
161
+ rows?: number | undefined;
162
+ cols?: number | undefined;
163
+ } | undefined;
164
+ };
165
+ /** Builds a sheet from `{ columns, data }`. */
166
+ export declare function fromDataset<T>(dataset: Dataset<T>, options?: DatasetOptions<T>): Sheet;
167
+ /**
168
+ * Stacks several datasets on one sheet (replaces the old xSteps/ySteps).
169
+ * Each block starts `gap` empty rows (default 1) below the previous one, or
170
+ * `offset.rows` rows when given, and `offset.cols` columns right of the
171
+ * origin. Freeze and filter apply to the first block with header rows.
172
+ */
173
+ export declare function fromDatasets(blocks: Array<DatasetBlock<any>>, options?: DatasetOptions<any> & {
174
+ gap?: number | undefined;
175
+ }): Sheet;
176
+ /** Options for `toDataset`. */
177
+ interface ToDatasetOptions {
178
+ /** Zero-based header row, default 0; false = no header, keys are column letters. */
179
+ headerRow?: number | false | undefined;
180
+ /** Range to read, e.g. 'A1:F100'. Default: sheet.dimension, else the used range. */
181
+ range?: string | undefined;
182
+ /** 'value' (default): each field is the cell's value; 'cell': the whole Cell. */
183
+ values?: "value" | "cell" | undefined;
184
+ }
185
+ /** The result of `toDataset`. Rows are null-prototype objects. */
186
+ interface DatasetResult {
187
+ columns: Array<{
188
+ title: string;
189
+ key: string;
190
+ }>;
191
+ data: Array<Record<string, unknown>>;
192
+ }
193
+ /**
194
+ * Reads a sheet back into `{ columns, data }` (import direction). Keys come
195
+ * from the header text, deduplicated with _2, _3...; an empty header gives the
196
+ * column letter. Empty rows are skipped. Rows are null-prototype objects, so
197
+ * a header named __proto__ in an untrusted file is just a key.
198
+ */
199
+ export declare function toDataset(sheet: Sheet<Cell> | Sheet, options?: ToDatasetOptions): DatasetResult;
200
+ /**
201
+ * Sheet-name rules (docs/api.md §3.3, §4.6).
202
+ *
203
+ * Excel rejects names that are empty, longer than 31 characters, contain any
204
+ * of \ / ? * [ ] :, or start or end with an apostrophe. It reserves 'History'
205
+ * [to verify]. Names are unique case-insensitively (checked by the writer).
206
+ */
207
+ /** Why a sheet name is invalid. */
208
+ type SheetNameProblem = "empty" | "too-long" | "forbidden-char" | "apostrophe" | "reserved";
209
+ /** Returns null when `name` is a valid sheet name, or the reason it is not. */
210
+ export declare function validateSheetName(name: string): SheetNameProblem | null;
211
+ /**
212
+ * Makes any string a valid sheet name: forbidden characters become '_',
213
+ * leading and trailing apostrophes are removed, the result is cut to 31
214
+ * characters (without splitting a surrogate pair), and an empty or reserved
215
+ * result becomes 'Sheet'. Uniqueness is the caller's job.
216
+ */
217
+ export declare function sanitizeSheetName(name: string): string;
218
+ /** The built-in number formats ECMA-376 §18.8.30 defines (§11.2). Ids 14–17 and 22 render in the user's locale in Excel. */
219
+ export declare const BUILTIN_NUM_FMTS: Readonly<Record<number, string>>;
220
+ /**
221
+ * True when a number format shows a date or a time of day (§3.4.1): built-in
222
+ * ids 14–22, 45, 47, 27–36 and 50–58, or a custom code that contains a date or
223
+ * time token outside quoted text, escapes and brackets. Elapsed-time formats
224
+ * (`[h]:mm:ss`, built-in 46) are durations and return false.
225
+ */
226
+ export declare function isDateFormat(fmt: NumFmt | undefined): boolean;
227
+ /** A zero-based cell address. */
228
+ interface CellAddress {
229
+ row: number;
230
+ col: number;
231
+ }
232
+ /** A range of cells, inclusive. */
233
+ interface RangeAddress {
234
+ start: CellAddress;
235
+ end: CellAddress;
236
+ }
237
+ /** Rows per sheet in the xlsx format. */
238
+ export declare const MAX_ROWS = 1048576;
239
+ /** Columns per sheet in the xlsx format (A..XFD). */
240
+ export declare const MAX_COLS = 16384;
241
+ /** Column index to letters: 0 → 'A', 16383 → 'XFD'. */
242
+ export declare function encodeCol(col: number): string;
243
+ /** Column letters to index: 'A' → 0, 'XFD' → 16383. Case-insensitive. */
244
+ export declare function decodeCol(letters: string): number;
245
+ /** { row: 0, col: 1 } → 'B1'. */
246
+ export declare function encodeCell(a: CellAddress): string;
247
+ /** 'B1' or '$B$1' → { row: 0, col: 1 }. */
248
+ export declare function decodeCell(ref: string): CellAddress;
249
+ /** Range to 'A1:C3' (a single cell gives 'A1'). */
250
+ export declare function encodeRange(r: RangeAddress): string;
251
+ /** 'A1:C3' or 'A1' → range, normalised so start is top-left. */
252
+ export declare function decodeRange(ref: string): RangeAddress;
253
+ /** Package version. Set from package.json by `npm run version-packages` (scripts/sync-version.mjs); a unit test checks it. */
254
+ export declare const VERSION = "2.0.0-alpha.2";
255
+ 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 ColumnDef, type ColumnProps, type ColumnTotal, type ColumnWidth, type Dataset, type DatasetBlock, type DatasetOptions, type DatasetResult, type DateOptions, type DefinedName, type DocProperties, type ErrorCode, type ExcelErrorCode, type ExcelErrorOptions, 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, toBlob, toUint8Array };