@lexaxai/spreadsheet-engine 0.0.0-stage → 0.1.0-dryrun.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.
@@ -0,0 +1,367 @@
1
+ // What reading and writing a file takes: an xlsx file whole or as a
2
+ // stream, and a CSV file with its parser's and formatter's options.
3
+
4
+ import type { CalculateOptions } from './calc';
5
+ import type { AddWorksheetOptions } from './sheet';
6
+
7
+ /**
8
+ * The options of reading an xlsx file, as the read methods of `Workbook.xlsx` take them.
9
+ */
10
+ export interface XlsxReadOptions {
11
+ /**
12
+ * The password a workbook encrypted with one is opened with ([MS-OFFCRYPTO] 2.3.4).
13
+ */
14
+ password: string;
15
+ /**
16
+ * Whether the data given is the file in Base64, as text.
17
+ */
18
+ base64: boolean;
19
+ }
20
+
21
+ /**
22
+ * The compression of a saved file's ZIP archive, as `XlsxWriteOptions.zip` gives it.
23
+ */
24
+ export interface ZipOptions {
25
+ /**
26
+ * `DEFLATE` by default; `STORE` keeps each part as it is.
27
+ */
28
+ compression: 'STORE' | 'DEFLATE';
29
+ /**
30
+ * The DEFLATE compression of the archive, with its level. The level is 6 by default, and null takes that
31
+ * default.
32
+ */
33
+ compressionOptions: null | {
34
+ /**
35
+ * From 0, none, to 9, the most; 6 by default.
36
+ */
37
+ level: number;
38
+ };
39
+ }
40
+
41
+ /**
42
+ * The options of saving a workbook as an xlsx file, as the write methods of `Workbook.xlsx` take them.
43
+ */
44
+ export interface XlsxWriteOptions {
45
+ /**
46
+ * The file's kind by its extension, such as `xlsm` or `xltx`, which sets the workbook part's content type.
47
+ */
48
+ extension: string;
49
+ /**
50
+ * Whether the cells' formats are written; `true` by default.
51
+ */
52
+ useStyles: boolean;
53
+ /**
54
+ * The compression of the file's archive.
55
+ */
56
+ zip: Partial<ZipOptions>;
57
+ /**
58
+ * 'throw' refuses a save that would drop anything of the file the workbook was read from, before anything
59
+ * is written.
60
+ */
61
+ onLoss: 'throw';
62
+ /**
63
+ * The password the file is encrypted with ([MS-OFFCRYPTO] 2.3.4), opened only with it.
64
+ */
65
+ password: string;
66
+ /**
67
+ * The workbook calculated before it is written, `true` or a calculation's options; its report is then
68
+ * `Workbook.calculation`.
69
+ */
70
+ calculate: boolean | CalculateOptions;
71
+ }
72
+
73
+ /**
74
+ * The options of `new WorkbookWriter`, a workbook written as a stream.
75
+ */
76
+ export interface WorkbookWriterOptions {
77
+ /**
78
+ * The file the workbook is written to at its commit, besides the bytes the commit gives.
79
+ */
80
+ filename: string;
81
+ /**
82
+ * Whether text goes to the shared strings part: a smaller file, every string held until the commit.
83
+ * `false` by default.
84
+ */
85
+ useSharedStrings: boolean;
86
+ /**
87
+ * Whether the cells' formats are written: without, every cell has the default format but a date, which
88
+ * has the date format. `false` by default.
89
+ */
90
+ useStyles: boolean;
91
+ /**
92
+ * When the workbook was made: now, where not given.
93
+ */
94
+ created: Date;
95
+ /**
96
+ * When it was last changed: when it was made, where not given.
97
+ */
98
+ modified: Date;
99
+ /**
100
+ * Who made it.
101
+ */
102
+ creator: string;
103
+ /**
104
+ * Who changed it last.
105
+ */
106
+ lastModifiedBy: string;
107
+ /**
108
+ * When it was last printed.
109
+ */
110
+ lastPrinted: Date;
111
+ /**
112
+ * Whether its dates count from 1904.
113
+ */
114
+ date1904: boolean;
115
+ }
116
+
117
+ /**
118
+ * The options of `WorkbookWriter.addWorksheet`: a worksheet's, and whether its own text goes to the shared
119
+ * strings part.
120
+ */
121
+ export interface WorksheetWriterOptions extends AddWorksheetOptions {
122
+ /**
123
+ * Whether the worksheet's text goes to the shared strings part; the workbook's choice where not given.
124
+ */
125
+ useSharedStrings: boolean;
126
+ }
127
+
128
+ /**
129
+ * The options of `new WorkbookReader`, a workbook read as a stream: what is done with each kind of thing read.
130
+ */
131
+ export interface WorkbookReaderOptions {
132
+ /**
133
+ * `emit`, the default, gives each sheet's rows; `ignore` gives the sheets without them.
134
+ */
135
+ worksheets: 'emit' | 'ignore';
136
+ /**
137
+ * `cache`, the default, keeps the shared strings, so a cell holding one has its text; `ignore` passes them
138
+ * over.
139
+ */
140
+ sharedStrings: 'cache' | 'emit' | 'ignore';
141
+ /**
142
+ * `cache` keeps each sheet's links; `ignore`, the default, passes them over.
143
+ */
144
+ hyperlinks: 'cache' | 'emit' | 'ignore';
145
+ /**
146
+ * `cache` keeps the formats, so a number under a date format is a date; `ignore`, the default, passes them
147
+ * over.
148
+ */
149
+ styles: 'cache' | 'ignore';
150
+ /**
151
+ * The password a workbook encrypted with one is opened with ([MS-OFFCRYPTO] 2.3.4).
152
+ */
153
+ password: string;
154
+ }
155
+
156
+ /**
157
+ * The options of `Csv.readFile` and `Csv.read`: the date formats, the worksheet name, and the parser options.
158
+ */
159
+ export interface CsvReadOptions {
160
+ /**
161
+ * The formats a text value is read as a date with, tried in turn. Left out, the formats are
162
+ * `YYYY-MM-DD[T]HH:mm:ssZ`, `YYYY-MM-DD[T]HH:mm:ss`, `MM-DD-YYYY` and `YYYY-MM-DD`.
163
+ */
164
+ dateFormats: string[];
165
+ /**
166
+ * The name of the worksheet the rows are read into. Left out, the worksheet is named `sheet` followed by its
167
+ * id, such as `sheet1`.
168
+ */
169
+ sheetName: string;
170
+ /**
171
+ * The options given to the parser. A `delimiter` given here is used as it is, and no delimiter is then
172
+ * picked from the file.
173
+ */
174
+ parserOptions: Partial<CsvParserOptions>;
175
+ }
176
+
177
+ /**
178
+ * The options of `Csv.writeFile` and `Csv.writeBuffer`: the date format, the worksheet to write, the
179
+ * encoding, and the formatter options.
180
+ */
181
+ export interface CsvWriteOptions {
182
+ /**
183
+ * The format dates are written in, as date format codes. Left out, a date is written as an ISO 8601 date and
184
+ * time with its offset from UTC.
185
+ */
186
+ dateFormat: string;
187
+ /**
188
+ * Whether dates are written in UTC rather than in local time; a local time is UTC, as every date of the
189
+ * engine is. `false` by default.
190
+ */
191
+ dateUTC: boolean;
192
+ /**
193
+ * The name of the worksheet to write. It takes precedence over `sheetId`. Left out with `sheetId` too, the
194
+ * first worksheet is written.
195
+ */
196
+ sheetName: string;
197
+ /**
198
+ * The id of the worksheet to write, used when no `sheetName` is given.
199
+ */
200
+ sheetId: number;
201
+ /**
202
+ * The text encoding of the file `writeFile` writes: `utf8` (the default), `latin1` or `binary`, `ascii`, or
203
+ * `utf16le` or `ucs2`.
204
+ */
205
+ encoding: string;
206
+ /**
207
+ * Whether the empty rows between filled rows are written as empty lines. `true` by default; `false` writes
208
+ * the filled rows one after another.
209
+ */
210
+ includeEmptyRows: boolean;
211
+ /**
212
+ * The options given to the formatter.
213
+ */
214
+ formatterOptions: Partial<CsvFormatterOptions>;
215
+ /** Text starting =, +, -, @, a tab or a carriage return written after a '. */
216
+ escapeFormulas: boolean;
217
+ }
218
+
219
+ /**
220
+ * The options the CSV reader gives its parser, as `CsvReadOptions.parserOptions` takes them: how the text is
221
+ * split into rows and values, and which rows are kept.
222
+ */
223
+ export interface CsvParserOptions {
224
+ /**
225
+ * The character that separates the values in a row. Left out, the reader picks it from the first ten
226
+ * records: a comma, unless a semicolon or a tab fits the records better.
227
+ */
228
+ delimiter: string;
229
+ /**
230
+ * The character that quotes a value, a double quote by default, or `null` for no quoting.
231
+ */
232
+ quote: string | null;
233
+ /**
234
+ * The character that escapes a quote inside a quoted value. Left out, the quote character escapes itself, so
235
+ * a doubled quote stands for one.
236
+ */
237
+ escape: string;
238
+ /**
239
+ * Whether a row names the columns: `true` uses the first row, and an array gives the names. Left out, no
240
+ * row names the columns.
241
+ */
242
+ headers: boolean | HeaderArray;
243
+ /**
244
+ * Whether the first row is dropped and the names given in `headers` are used instead. The `headers` option
245
+ * must then be an array.
246
+ */
247
+ renameHeaders: boolean;
248
+ /**
249
+ * Whether rows whose values are all empty are skipped. `false` by default.
250
+ */
251
+ ignoreEmpty: boolean;
252
+ /**
253
+ * The character that starts a comment line, which is skipped. Left out, no line is a comment.
254
+ */
255
+ comment: string;
256
+ /**
257
+ * Whether a row with more or fewer values than there are headers is invalid, rather than mapped to the
258
+ * headers. `false` by default.
259
+ */
260
+ strictColumnHandling: boolean;
261
+ /**
262
+ * Whether the values in columns without a header are dropped, rather than making the row invalid. `false` by
263
+ * default.
264
+ */
265
+ discardUnmappedColumns: boolean;
266
+ /**
267
+ * Whether the spaces at both ends of every value are removed. `false` by default.
268
+ */
269
+ trim: boolean;
270
+ /**
271
+ * Whether the spaces at the start of every value are removed. `false` by default.
272
+ */
273
+ ltrim: boolean;
274
+ /**
275
+ * Whether the spaces at the end of every value are removed. `false` by default.
276
+ */
277
+ rtrim: boolean;
278
+ /**
279
+ * The text encoding of the file, `utf8` by default.
280
+ */
281
+ encoding: string;
282
+ /**
283
+ * The most rows the reader reads. `0`, the default, reads every row.
284
+ */
285
+ maxRows: number;
286
+ /**
287
+ * The number of lines at the top of the file that are skipped before any row is read. `0` by default.
288
+ */
289
+ skipLines: number;
290
+ /**
291
+ * The number of data rows, after any header row, that are skipped at the start. `0` by default.
292
+ */
293
+ skipRows: number;
294
+ }
295
+
296
+ /**
297
+ * The options the CSV writer gives its formatter, as `CsvWriteOptions.formatterOptions` takes them: how each
298
+ * row is written as text, which values are quoted, and whether a header row is written.
299
+ */
300
+ export interface CsvFormatterOptions {
301
+ /**
302
+ * The character that separates the values in a row, a comma by default.
303
+ */
304
+ delimiter: string;
305
+ /**
306
+ * The text that ends each row, a line feed by default.
307
+ */
308
+ rowDelimiter: string;
309
+ /**
310
+ * The character that quotes a value, a double quote by default, or `false` for no quoting at all.
311
+ */
312
+ quote: string | boolean;
313
+ /**
314
+ * The character that escapes a quote inside a quoted value. Left out, the quote character escapes itself.
315
+ */
316
+ escape: string;
317
+ /**
318
+ * Which columns' values are quoted: `true` for all, a list of booleans by column position, or a map by
319
+ * header name (`QuoteColumnMap`). `false`, the default, quotes none.
320
+ */
321
+ quoteColumns: QuoteColumns;
322
+ /**
323
+ * Which header names are quoted, in the same forms as `quoteColumns`. Left out, it follows `quoteColumns`.
324
+ */
325
+ quoteHeaders: QuoteColumns;
326
+ /**
327
+ * Whether a header row is written: `true` writes the keys of the first row, an array writes the names given,
328
+ * and `null` or `false`, the default, writes no header row.
329
+ */
330
+ headers: null | boolean | string[];
331
+ /**
332
+ * Whether the text ends with a row delimiter after its last row. `false` by default.
333
+ */
334
+ includeEndRowDelimiter: boolean;
335
+ /**
336
+ * Whether the file starts with a byte order mark, as Excel's CSV UTF-8 format does. `false` by default.
337
+ */
338
+ writeBOM: boolean;
339
+ /**
340
+ * Whether the header row is written when there are no rows. It needs `headers` to be given, or the write
341
+ * fails. `false` by default.
342
+ */
343
+ alwaysWriteHeaders: boolean;
344
+ }
345
+
346
+ /**
347
+ * A set of columns to quote, keyed by header name: each key is the name of a column, and its value says
348
+ * whether that column is quoted.
349
+ */
350
+ export interface QuoteColumnMap {
351
+ /**
352
+ * Whether the column with the header name given as the key is quoted.
353
+ */
354
+ [s: string]: boolean;
355
+ }
356
+
357
+ /**
358
+ * Which columns are quoted when a CSV file is written: `true` for all, `false` for none, a list of booleans
359
+ * by column position, or a map by header name (`QuoteColumnMap`).
360
+ */
361
+ export type QuoteColumns = boolean | boolean[] | QuoteColumnMap;
362
+
363
+ /**
364
+ * The names of a CSV file's columns, one for each column. A column whose name is `undefined` is left out of
365
+ * the row object.
366
+ */
367
+ export type HeaderArray = (string | undefined | null)[];