xls-reader 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Thiago Zanluca
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # xls-reader
2
+
3
+ Zero-dependency reader for **legacy `.xls`** files (BIFF8 — Excel 97–2003). It
4
+ returns each worksheet as a grid of typed cells: strings, numbers, booleans, and
5
+ dates. Runs in Node and the browser (it only needs `Uint8Array` / `DataView`).
6
+
7
+ ```bash
8
+ npm install xls-reader
9
+ ```
10
+
11
+ ## Why this exists
12
+
13
+ Modern readers like [ExcelJS](https://github.com/exceljs/exceljs) only handle the
14
+ newer `.xlsx` (OOXML) format. The de-facto `.xls` reader,
15
+ [SheetJS](https://sheetjs.com), **no longer publishes to the npm registry** — its
16
+ last npm release (`0.18.5`) is frozen with known advisories, and fixed versions
17
+ ship only from its own CDN. Installing from a CDN means `npm audit` and
18
+ Dependabot can't see the package, so you lose automated vulnerability alerts.
19
+
20
+ `xls-reader` is a small, focused, **npm-published** alternative for the common
21
+ case: _read the cells out of a legacy `.xls`_. No dependencies, MIT-licensed,
22
+ covered by the same supply-chain tooling as the rest of your tree.
23
+
24
+ ## Usage
25
+
26
+ ```ts
27
+ import { readFile } from "node:fs/promises";
28
+ import { readXls } from "xls-reader";
29
+
30
+ const workbook = readXls(await readFile("posicao.xls"));
31
+
32
+ for (const sheet of workbook.sheets) {
33
+ console.log(sheet.name);
34
+ for (const row of sheet.rows) {
35
+ console.log(row); // e.g. ["BANCO DAYCOVAL S/A", "CDB", "CDI", 1.1, Date(2024-04-02), 1000, ...]
36
+ }
37
+ }
38
+ ```
39
+
40
+ Single-sheet shortcut:
41
+
42
+ ```ts
43
+ import { readFirstSheet } from "xls-reader";
44
+
45
+ const sheet = readFirstSheet(bytes);
46
+ ```
47
+
48
+ ## API
49
+
50
+ ### `readXls(data: ArrayBuffer | Uint8Array): Workbook`
51
+
52
+ Parses a whole workbook. Throws `XlsError` if the bytes aren't a BIFF `.xls`.
53
+
54
+ ### `readFirstSheet(data): Sheet | undefined`
55
+
56
+ The first worksheet, for the single-sheet case.
57
+
58
+ ### Types
59
+
60
+ ```ts
61
+ type Cell = string | number | boolean | Date | null;
62
+ interface Sheet {
63
+ name: string;
64
+ rows: Cell[][]; // dense, null-padded to the last used column
65
+ }
66
+ interface Workbook {
67
+ sheets: Sheet[];
68
+ }
69
+ ```
70
+
71
+ - **Numbers** come back as `number` (both `NUMBER` and compact `RK` encodings).
72
+ - **Dates** — a number whose cell format is a date/time (built-in or custom) is
73
+ returned as a `Date` (UTC). Use `excelSerialToDate` if you need the raw
74
+ conversion.
75
+ - **Blank / error** cells are `null`.
76
+
77
+ ## Supported
78
+
79
+ - OLE2 / Compound File container (regular **and** mini streams).
80
+ - BIFF8 records: `LABELSST`, `LABEL`, `RSTRING`, `NUMBER`, `RK`, `MULRK`,
81
+ `BLANK`, `MULBLANK`, `BOOLERR`, `FORMULA` (+ its `STRING` result).
82
+ - Shared-string table (`SST`) including strings split across `CONTINUE` records.
83
+ - Date detection via `XF` + `FORMAT`, and the 1900 / 1904 date systems.
84
+
85
+ ## Limitations
86
+
87
+ - Read-only, and reads **values** — not styling, merged-cell geometry, or charts.
88
+ - BIFF8 only (Excel 97+). It does not read the much older BIFF5/BIFF2, nor the
89
+ HTML/XML files some tools mislabel as `.xls` (check the magic bytes).
90
+ - Encrypted workbooks are not supported.
91
+ - Dates before 1900-03-01 in the 1900 system are off by one day (Excel's
92
+ historical leap-year bug); real-world data is unaffected.
93
+
94
+ ## License
95
+
96
+ [MIT](./LICENSE) © Thiago Zanluca