@rangefoundry/importers 0.0.0-stage → 0.1.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 (55) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +21 -2
  3. package/dist/cells.d.ts +31 -0
  4. package/dist/cells.js +22 -0
  5. package/dist/cfb.d.ts +2 -0
  6. package/dist/cfb.js +196 -0
  7. package/dist/csrload.d.ts +12 -0
  8. package/dist/csrload.js +153 -0
  9. package/dist/diagnostics.d.ts +42 -0
  10. package/dist/diagnostics.js +29 -0
  11. package/dist/generic.d.ts +44 -0
  12. package/dist/generic.js +272 -0
  13. package/dist/grtload.d.ts +32 -0
  14. package/dist/grtload.js +264 -0
  15. package/dist/index.d.ts +85 -0
  16. package/dist/index.js +126 -0
  17. package/dist/limits.d.ts +7 -0
  18. package/dist/limits.js +12 -0
  19. package/dist/pressure-history.d.ts +61 -0
  20. package/dist/pressure-history.js +158 -0
  21. package/dist/rangefoundry-json.d.ts +17 -0
  22. package/dist/rangefoundry-json.js +176 -0
  23. package/dist/record-fields.d.ts +35 -0
  24. package/dist/record-fields.js +190 -0
  25. package/dist/record-ids.d.ts +2 -0
  26. package/dist/record-ids.js +28 -0
  27. package/dist/records.d.ts +91 -0
  28. package/dist/records.js +433 -0
  29. package/dist/result.d.ts +65 -0
  30. package/dist/result.js +90 -0
  31. package/dist/shot-rows.d.ts +11 -0
  32. package/dist/shot-rows.js +39 -0
  33. package/dist/shotview.d.ts +16 -0
  34. package/dist/shotview.js +131 -0
  35. package/dist/statistics.d.ts +12 -0
  36. package/dist/statistics.js +48 -0
  37. package/dist/tables.d.ts +41 -0
  38. package/dist/tables.js +277 -0
  39. package/dist/template.d.ts +13 -0
  40. package/dist/template.js +37 -0
  41. package/dist/text.d.ts +28 -0
  42. package/dist/text.js +150 -0
  43. package/dist/units.d.ts +12 -0
  44. package/dist/units.js +62 -0
  45. package/dist/workbook.d.ts +12 -0
  46. package/dist/workbook.js +264 -0
  47. package/dist/worksheet-strings.d.ts +36 -0
  48. package/dist/worksheet-strings.js +50 -0
  49. package/dist/xls.d.ts +3 -0
  50. package/dist/xls.js +486 -0
  51. package/dist/xml.d.ts +26 -0
  52. package/dist/xml.js +261 -0
  53. package/dist/zip.d.ts +27 -0
  54. package/dist/zip.js +183 -0
  55. package/package.json +62 -3
package/dist/xls.js ADDED
@@ -0,0 +1,486 @@
1
+ // Legacy Excel workbooks: BIFF8 records ([MS-XLS] Excel Binary File Format (.xls) Structure, v20250819, https://learn.microsoft.com/en-us/openspecs/office_file_formats/ms-xls/cd03cb5f-ca02-4934-a391-bb674cb8aa06; section numbers refer to it) in the Workbook stream of a compound file, read into the same rows of cell text as XLSX workbooks
2
+ import { clean, placeCell } from './cells.js';
3
+ import { compoundStreams } from './cfb.js';
4
+ import { locatedError, ReaderError, refuseFile } from './diagnostics.js';
5
+ import { maxCellCharacters, maxCells, maxPartSize } from './limits.js';
6
+ // record types (2.3)
7
+ const BOF = 0x0809;
8
+ const EOF = 0x000a;
9
+ const CONTINUE = 0x003c;
10
+ const FILEPASS = 0x002f;
11
+ const BOUNDSHEET8 = 0x0085;
12
+ const SST = 0x00fc;
13
+ const STRING = 0x0207;
14
+ const LABELSST = 0x00fd;
15
+ const LABEL = 0x0204;
16
+ const NUMBER = 0x0203;
17
+ const RK = 0x027e;
18
+ const MULRK = 0x00bd;
19
+ const FORMULA = 0x0006;
20
+ const BOOLERR = 0x0205;
21
+ const BLANK = 0x0201;
22
+ const MULBLANK = 0x00be;
23
+ const cellRecords = new Set([LABELSST, LABEL, NUMBER, RK, MULRK, FORMULA, BOOLERR, BLANK, MULBLANK]);
24
+ /** Refusals that name their place in the Workbook stream, so a worksheet does not name it again. */
25
+ const placed = [
26
+ 'xlsRecordPastEnd',
27
+ 'xlsSubstreamsOverlap',
28
+ 'xlsRecordShort',
29
+ 'xlsCellsMismatch',
30
+ 'xlsWorksheetNoEof',
31
+ ];
32
+ // BErr (2.5.198.2): the text an XLSX error cell holds
33
+ const errors = new Map([
34
+ [0x00, '#NULL!'],
35
+ [0x07, '#DIV/0!'],
36
+ [0x0f, '#VALUE!'],
37
+ [0x17, '#REF!'],
38
+ [0x1d, '#NAME?'],
39
+ [0x24, '#NUM!'],
40
+ [0x2a, '#N/A'],
41
+ ]);
42
+ /** End of data inside a string read; turned into a message by the caller. */
43
+ class Short extends Error {
44
+ }
45
+ /** Over a record and its Continue records (2.1.4), read in place; a Continue header is read when the cursor reaches the end of a chunk. */
46
+ class Cursor {
47
+ s;
48
+ at;
49
+ end;
50
+ constructor(s, at, end) {
51
+ this.s = s;
52
+ this.at = at;
53
+ this.end = end;
54
+ }
55
+ /** Moves to the next Continue record; false when there is none. */
56
+ advance() {
57
+ const s = this.s;
58
+ const e = this.end;
59
+ if (e + 4 > s.length || (this.byte(e) | (this.byte(e + 1) << 8)) !== CONTINUE)
60
+ return false;
61
+ this.at = e + 4;
62
+ this.end = this.at + (this.byte(e + 2) | (this.byte(e + 3) << 8));
63
+ return true;
64
+ }
65
+ /** Byte `k` of the stream; the records and Continue chunks were checked to lie inside it. */
66
+ byte(k) {
67
+ const b = this.s[k];
68
+ if (b === undefined)
69
+ throw new Short();
70
+ return b;
71
+ }
72
+ ready() {
73
+ while (this.at >= this.end)
74
+ if (!this.advance())
75
+ throw new Short();
76
+ }
77
+ u8() {
78
+ this.ready();
79
+ return this.byte(this.at++);
80
+ }
81
+ u16() {
82
+ return this.u8() | (this.u8() << 8);
83
+ }
84
+ u32() {
85
+ return (this.u16() | (this.u16() << 16)) >>> 0;
86
+ }
87
+ skip(n) {
88
+ for (let left = n; left > 0;) {
89
+ this.ready();
90
+ const step = Math.min(left, this.end - this.at);
91
+ this.at += step;
92
+ left -= step;
93
+ }
94
+ }
95
+ /** A chunk that ends while characters remain is followed by one starting with a new flag byte (2.5.293); built 4096 code units at a time. */
96
+ characters(count, high) {
97
+ let text = '';
98
+ let left = count;
99
+ let wide = high;
100
+ while (left > 0) {
101
+ if (this.at >= this.end) {
102
+ if (!this.advance())
103
+ throw new Short();
104
+ wide = (this.u8() & 1) === 1;
105
+ }
106
+ const room = wide ? Math.floor((this.end - this.at) / 2) : this.end - this.at;
107
+ if (room === 0)
108
+ throw new Short();
109
+ const n = Math.min(left, room, 4096);
110
+ text += this.codeUnits(n, wide);
111
+ left -= n;
112
+ }
113
+ return text;
114
+ }
115
+ /** `n` characters from the cursor inside the current chunk, one or two bytes each. */
116
+ codeUnits(n, wide) {
117
+ const codes = Array.from({ length: n }, (_, i) => {
118
+ const k = this.at + (wide ? 2 * i : i);
119
+ return wide ? this.byte(k) | (this.byte(k + 1) << 8) : this.byte(k);
120
+ });
121
+ this.at += wide ? 2 * n : n;
122
+ return String.fromCharCode(...codes);
123
+ }
124
+ /** XLUnicodeString (2.5.294): `u16` count, flag byte, characters. */
125
+ unicodeString() {
126
+ const count = this.u16();
127
+ return this.characters(count, (this.u8() & 1) === 1);
128
+ }
129
+ /** XLUnicodeRichExtendedString (2.5.293); throws `Short` or a malformed-string message. */
130
+ richString() {
131
+ const count = this.u16();
132
+ const flags = this.u8();
133
+ const runs = flags & 8 ? this.u16() : 0;
134
+ const phonetic = flags & 4 ? this.u32() : 0;
135
+ if (phonetic > 0x7fffffff)
136
+ refuseFile('xlsPhoneticNegative');
137
+ const text = this.characters(count, (flags & 1) === 1);
138
+ this.skip(4 * runs + phonetic);
139
+ return text;
140
+ }
141
+ }
142
+ /** Column letters for a column number from 1 (bijective base 26). */
143
+ function letters(column) {
144
+ let s = '';
145
+ for (let c = column; c > 0; c = Math.floor((c - 1) / 26)) {
146
+ s = String.fromCharCode(65 + ((c - 1) % 26)) + s;
147
+ }
148
+ return s;
149
+ }
150
+ /** RkNumber (2.5.217): a 30-bit integer or the high 30 bits of a double, divided by 100 when flagged. */
151
+ function rk(u) {
152
+ let x;
153
+ if (u & 2)
154
+ x = u >> 2;
155
+ else {
156
+ const view = new DataView(new ArrayBuffer(8));
157
+ view.setUint32(4, (u & 0xfffffffc) >>> 0, true);
158
+ x = view.getFloat64(0, true);
159
+ }
160
+ return u & 1 ? x / 100 : x;
161
+ }
162
+ /** A string read, with running out of data reported as a malformed string. */
163
+ function readText(read) {
164
+ try {
165
+ return read();
166
+ }
167
+ catch (e) {
168
+ if (e instanceof Short)
169
+ throw new ReaderError({ code: 'xlsStringMalformed', params: {} }, { cause: e });
170
+ throw e;
171
+ }
172
+ }
173
+ function recordReader(s) {
174
+ const view = new DataView(s.buffer, s.byteOffset, s.byteLength);
175
+ // bytes read over all substreams; more than the stream means substreams overlap
176
+ let scanned = 0;
177
+ const record = (at) => {
178
+ if (at + 4 > s.length)
179
+ refuseFile('xlsRecordPastEnd', { at });
180
+ const type = view.getUint16(at, true);
181
+ const end = at + 4 + view.getUint16(at + 2, true);
182
+ if (end > s.length)
183
+ refuseFile('xlsRecordPastEnd', { at });
184
+ // Continue records are checked and stepped over here; only string readers enter them
185
+ let next = end;
186
+ while (next + 4 <= s.length && view.getUint16(next, true) === CONTINUE) {
187
+ const e = next + 4 + view.getUint16(next + 2, true);
188
+ if (e > s.length)
189
+ refuseFile('xlsRecordPastEnd', { at: next });
190
+ next = e;
191
+ }
192
+ scanned += next - at;
193
+ if (scanned > s.length)
194
+ refuseFile('xlsSubstreamsOverlap');
195
+ return { type, at, end, next };
196
+ };
197
+ const isBof = (r, dt) => r.type === BOF &&
198
+ r.end - r.at >= 8 &&
199
+ view.getUint16(r.at + 4, true) === 0x0600 &&
200
+ view.getUint16(r.at + 6, true) === dt;
201
+ return { s, view, record, isBof };
202
+ }
203
+ /** `read()`, with a record that ends inside its data reported as too short. */
204
+ function whenShort(r, read) {
205
+ try {
206
+ return read();
207
+ }
208
+ catch (e) {
209
+ if (!(e instanceof Short))
210
+ throw e;
211
+ throw new ReaderError({ code: 'xlsRecordShort', params: { at: r.at } }, { cause: e });
212
+ }
213
+ }
214
+ /** BoundSheet8 (2.4.28): the position, type and name of a sheet. */
215
+ function boundSheet(c) {
216
+ const position = c.u32();
217
+ c.u8();
218
+ const type = c.u8();
219
+ const count = c.u8();
220
+ return { position, type, name: c.characters(count, (c.u8() & 1) === 1) };
221
+ }
222
+ /** From byte 0 (2.1.7.20.3): the BoundSheet8 entries, the shared strings, and the position after its EOF record. */
223
+ function readWorkbookSubstream(reader) {
224
+ const { s, record, isBof } = reader;
225
+ const head = s.length < 4 ? undefined : record(0);
226
+ if (!head || !isBof(head, 0x0005))
227
+ refuseFile('xlsNotBiff8');
228
+ const bound = [];
229
+ let strings = [];
230
+ let p = head.next;
231
+ for (;;) {
232
+ if (p >= s.length)
233
+ refuseFile('xlsNoWorkbookEof');
234
+ const r = record(p);
235
+ p = r.next;
236
+ if (r.type === EOF)
237
+ break;
238
+ if (r.type === FILEPASS)
239
+ refuseFile('xlsEncrypted');
240
+ if (r.type === BOUNDSHEET8) {
241
+ bound.push(whenShort(r, () => boundSheet(new Cursor(s, r.at + 4, r.end))));
242
+ }
243
+ else if (r.type === SST) {
244
+ strings = whenShort(r, () => sharedStrings(new Cursor(s, r.at + 4, r.end)));
245
+ }
246
+ }
247
+ return { bound, strings, end: p };
248
+ }
249
+ function put(st, row, col, text) {
250
+ let cells = st.rows.get(row);
251
+ if (!cells) {
252
+ cells = [];
253
+ st.rows.set(row, cells);
254
+ }
255
+ placeCell(cells, { column: col + 1, text, at: () => ({ cell: `${letters(col + 1)}${row + 1}` }) }, st.remaining);
256
+ }
257
+ /** Refuses a formula cell still waiting for its String record. */
258
+ function checkNoPending(st) {
259
+ if (!st.pending)
260
+ return;
261
+ const ref = `${letters(st.pending.col + 1)}${st.pending.row + 1}`;
262
+ refuseFile('xlsFormulaNoString', { cell: ref });
263
+ }
264
+ /** How a record changes the nesting of substreams: a BOF opens one, an EOF closes one. */
265
+ function depthChange(type) {
266
+ if (type === BOF)
267
+ return 1;
268
+ return type === EOF ? -1 : 0;
269
+ }
270
+ const cellRef = (c, col = c.col) => `${letters(col + 1)}${c.row + 1}`;
271
+ function need(c, size) {
272
+ if (c.d.length < size)
273
+ refuseFile('xlsRecordShort', { at: c.r.at });
274
+ }
275
+ /** Byte `k` of the record's data; a record shorter than the fields it must hold is refused. */
276
+ function dataByte(c, k) {
277
+ const b = c.d[k];
278
+ if (b === undefined)
279
+ refuseFile('xlsRecordShort', { at: c.r.at });
280
+ return b;
281
+ }
282
+ function numberText(c, x, col = c.col) {
283
+ if (!Number.isFinite(x))
284
+ refuseFile('xlsNumberNotFinite', { cell: cellRef(c, col) });
285
+ return String(x);
286
+ }
287
+ function errorText(c, code) {
288
+ const t = errors.get(code);
289
+ if (t === undefined)
290
+ refuseFile('xlsUnknownErrorCode', { cell: cellRef(c), code });
291
+ return t;
292
+ }
293
+ /** MulRk and MulBlank: a run of cells in one row, each with a number or empty. */
294
+ function putCellRun(reader, c, st) {
295
+ const { view } = reader;
296
+ const item = c.r.type === MULRK ? 6 : 2;
297
+ const last = view.getUint16(c.o + c.d.length - 2, true);
298
+ const size = c.d.length - 6;
299
+ if (last < c.col || size % item !== 0 || last - c.col + 1 !== size / item)
300
+ refuseFile('xlsCellsMismatch', { at: c.r.at });
301
+ for (let k = 0; k <= last - c.col; k++) {
302
+ const t = item === 6 ? numberText(c, rk(view.getUint32(c.o + 4 + 6 * k + 2, true)), c.col + k) : '';
303
+ put(st, c.row, c.col + k, t);
304
+ }
305
+ }
306
+ /** Formula (2.4.127): a cached number, or a boolean, error, empty or string result. */
307
+ function putFormula(reader, c, st) {
308
+ const { view } = reader;
309
+ need(c, 14);
310
+ if (view.getUint16(c.o + 12, true) !== 0xffff) {
311
+ put(st, c.row, c.col, numberText(c, view.getFloat64(c.o + 6, true)));
312
+ return;
313
+ }
314
+ const type = dataByte(c, 6);
315
+ if (type === 0)
316
+ st.pending = { row: c.row, col: c.col };
317
+ else if (type === 1)
318
+ put(st, c.row, c.col, dataByte(c, 8) ? '1' : '');
319
+ else if (type === 2)
320
+ put(st, c.row, c.col, errorText(c, dataByte(c, 8)));
321
+ else if (type === 3)
322
+ put(st, c.row, c.col, '');
323
+ else
324
+ refuseFile('xlsUnknownValueType', { cell: cellRef(c), type });
325
+ }
326
+ /** LabelSst (2.4.149): the shared string the cell refers to. */
327
+ function sharedCell(view, c, strings) {
328
+ need(c, 10);
329
+ const k = view.getUint32(c.o + 6, true);
330
+ const text = strings[k];
331
+ if (text === undefined) {
332
+ refuseFile('sharedStringOutOfRange', {
333
+ cell: cellRef(c),
334
+ index: k,
335
+ count: strings.length,
336
+ });
337
+ }
338
+ return text;
339
+ }
340
+ /** BoolErr (2.4.24): an error code as its text, TRUE as `1`, FALSE as empty text. */
341
+ function boolErrText(c) {
342
+ need(c, 8);
343
+ if (dataByte(c, 7))
344
+ return errorText(c, dataByte(c, 6));
345
+ return dataByte(c, 6) ? '1' : '';
346
+ }
347
+ /** Places the cell or cells of one cell record. */
348
+ function putCell(reader, r, strings, st) {
349
+ const { s, view } = reader;
350
+ const d = s.subarray(r.at + 4, r.end);
351
+ const o = r.at + 4;
352
+ const c = { r, d, o, row: 0, col: 0 };
353
+ need(c, 6);
354
+ c.row = view.getUint16(o, true);
355
+ c.col = view.getUint16(o + 2, true);
356
+ const { row, col } = c;
357
+ if (r.type === LABELSST) {
358
+ put(st, row, col, sharedCell(view, c, strings));
359
+ }
360
+ else if (r.type === LABEL) {
361
+ put(st, row, col, clean(readText(() => new Cursor(s, r.at + 10, r.end).unicodeString())));
362
+ }
363
+ else if (r.type === NUMBER) {
364
+ need(c, 14);
365
+ put(st, row, col, numberText(c, view.getFloat64(o + 6, true)));
366
+ }
367
+ else if (r.type === RK) {
368
+ need(c, 10);
369
+ put(st, row, col, numberText(c, rk(view.getUint32(o + 6, true))));
370
+ }
371
+ else if (r.type === MULRK || r.type === MULBLANK) {
372
+ putCellRun(reader, c, st);
373
+ }
374
+ else if (r.type === FORMULA) {
375
+ putFormula(reader, c, st);
376
+ }
377
+ else if (r.type === BOOLERR) {
378
+ put(st, row, col, boolErrText(c));
379
+ }
380
+ else if (r.type === BLANK) {
381
+ put(st, row, col, '');
382
+ }
383
+ }
384
+ /** The rows of worksheet `n` from `from`, after its BOF, and the position after its EOF record; cells are placed and counted against `remaining`. */
385
+ function readWorksheetCells(reader, { from, n }, strings, remaining) {
386
+ const { s, record } = reader;
387
+ const st = { rows: new Map(), remaining };
388
+ let depth = 1;
389
+ let end = 0;
390
+ for (let at = from;;) {
391
+ if (at >= s.length)
392
+ refuseFile('xlsWorksheetNoEof', { sheet: n });
393
+ const r = record(at);
394
+ at = r.next;
395
+ depth += depthChange(r.type);
396
+ if (depth === 0) {
397
+ end = at;
398
+ checkNoPending(st);
399
+ break;
400
+ }
401
+ if (r.type === BOF)
402
+ checkNoPending(st);
403
+ // cells of nested substreams (embedded charts) are not cells of the worksheet
404
+ if (depth !== 1)
405
+ continue;
406
+ if (st.pending && r.type === STRING) {
407
+ const text = clean(readText(() => new Cursor(s, r.at + 4, r.end).unicodeString()));
408
+ put(st, st.pending.row, st.pending.col, text);
409
+ st.pending = undefined;
410
+ continue;
411
+ }
412
+ if (!cellRecords.has(r.type))
413
+ continue;
414
+ checkNoPending(st);
415
+ putCell(reader, r, strings, st);
416
+ }
417
+ return { rows: [...st.rows].toSorted((a, b) => a[0] - b[0]).map(([, cells]) => cells), end };
418
+ }
419
+ /** Type 0 of the BoundSheet8 entries, in workbook order; one that does not start with a worksheet BOF, starts where another does, or lies inside another substream (`workbookEnd` ends the workbook substream) is refused. */
420
+ function assembleWorksheets(reader, bound, strings, workbookEnd) {
421
+ const { s, record, isBof } = reader;
422
+ const remaining = { cells: maxCells, characters: maxCellCharacters };
423
+ const starts = new Set();
424
+ // byte ranges of the substreams read; a worksheet inside another substream (for example at a BOF nested in a chart) is refused once all are read
425
+ const ranges = [[0, workbookEnd]];
426
+ const worksheets = [];
427
+ // only worksheets (and dialog sheets); macro, chart and VBA module sheets hold no cells
428
+ for (const sheet of bound.filter((b) => b.type === 0)) {
429
+ const n = worksheets.length + 1;
430
+ const first = sheet.position + 4 <= s.length ? record(sheet.position) : undefined;
431
+ if (!first || !isBof(first, 0x0010))
432
+ refuseFile('xlsWorksheetNoBof', { sheet: n });
433
+ if (starts.has(sheet.position))
434
+ refuseFile('xlsWorksheetSameStart', { sheet: n });
435
+ starts.add(sheet.position);
436
+ try {
437
+ const { rows, end } = readWorksheetCells(reader, { from: first.next, n }, strings, remaining);
438
+ worksheets.push({ name: sheet.name, rows });
439
+ ranges.push([sheet.position, end]);
440
+ }
441
+ catch (e) {
442
+ const own = e instanceof ReaderError && placed.includes(e.diagnostic.code);
443
+ throw own ? e : locatedError(e, { worksheet: n });
444
+ }
445
+ }
446
+ ranges.sort((a, b) => a[0] - b[0]);
447
+ if (ranges.some(([start], k) => {
448
+ const before = ranges[k - 1];
449
+ return before !== undefined && start < before[1];
450
+ })) {
451
+ refuseFile('xlsSubstreamsOverlap');
452
+ }
453
+ return worksheets;
454
+ }
455
+ /** The worksheets of a BIFF8 workbook in a compound file, in workbook order, as XLSX worksheets. */
456
+ export function readXls(bytes) {
457
+ const streams = compoundStreams(bytes, ['WORKBOOK', 'BOOK', 'ENCRYPTEDPACKAGE']);
458
+ const read = streams.get('WORKBOOK') ?? streams.get('BOOK');
459
+ if (!read) {
460
+ if (streams.has('ENCRYPTEDPACKAGE'))
461
+ refuseFile('xlsEncrypted');
462
+ refuseFile('xlsNoWorkbookStream');
463
+ }
464
+ const reader = recordReader(read(maxPartSize));
465
+ const { bound, strings, end } = readWorkbookSubstream(reader);
466
+ return { worksheets: assembleWorksheets(reader, bound, strings, end) };
467
+ }
468
+ /** SST (2.4.265): `cstUnique` strings, each trimmed and U+FEFF removed once. */
469
+ function sharedStrings(c) {
470
+ c.u32();
471
+ const unique = c.u32();
472
+ const strings = [];
473
+ while (strings.length < unique) {
474
+ try {
475
+ strings.push(clean(c.richString()));
476
+ }
477
+ catch (e) {
478
+ if (e instanceof Short) {
479
+ throw new ReaderError({ code: 'xlsSharedStringsEnd', params: { read: strings.length, unique } }, { cause: e });
480
+ }
481
+ throw locatedError(e, { sharedString: strings.length });
482
+ }
483
+ }
484
+ return strings;
485
+ }
486
+ //# sourceMappingURL=xls.js.map
package/dist/xml.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ export interface XmlElement {
2
+ /** Name without its namespace prefix. */
3
+ name: string;
4
+ /** Attributes by name without prefix; `xmlns` declarations left out. */
5
+ attributes: Record<string, string>;
6
+ children: (XmlElement | string)[];
7
+ }
8
+ /** Elements and characters (text and attribute markup) `scanXml` may still read. */
9
+ export interface XmlBudget {
10
+ elements: number;
11
+ characters: number;
12
+ }
13
+ /** Callbacks of `scanXml`; names and `path` entries are local names (without prefix). */
14
+ interface XmlEvents {
15
+ /** A start tag that passed its checks; `path` holds the enclosing elements, root first. */
16
+ open(name: string, attributes: Record<string, string>, path: readonly string[]): void;
17
+ /** Text or CDATA inside an element, references replaced; `path` ends with that element. */
18
+ text(text: string, path: readonly string[]): void;
19
+ /** An end tag, or the end of an empty-element tag; `path` holds the enclosing elements. */
20
+ close(name: string, path: readonly string[]): void;
21
+ }
22
+ /** Throws on markup this reader does not accept; `remaining` is counted down before each element or text is reported, so several parts can share one budget; errors thrown by `events` are not caught. */
23
+ export declare function scanXml(text: string, events: XmlEvents, remaining?: XmlBudget): void;
24
+ /** The root element of `text` as a tree, read with `scanXml` (same checks and budget). */
25
+ export declare function parseXml(text: string, remaining?: XmlBudget): XmlElement;
26
+ export {};