xls-reader 0.1.2 → 0.2.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/CHANGELOG.md +34 -0
- package/README.md +15 -10
- package/README.pt-BR.md +17 -11
- package/dist/index.cjs +675 -618
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -9
- package/dist/index.d.mts +31 -0
- package/dist/index.mjs +803 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +13 -8
- package/dist/index.d.ts +0 -19
- package/dist/index.js +0 -722
- package/dist/index.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# xls-reader
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#33](https://github.com/zanlucathiago/xls-reader/pull/33) [`ada1411`](https://github.com/zanlucathiago/xls-reader/commit/ada1411238690bf8b3afbc970faeaf943e211a2d) Thanks [@zanlucathiago](https://github.com/zanlucathiago)! - Add `sheetToObjects(sheet, options?)`, a helper that turns a parsed sheet's dense
|
|
8
|
+
rows into an array of objects keyed by a header row — the shape most callers want
|
|
9
|
+
when they read an `.xls` "into JSON". Blank-header columns are skipped, a short
|
|
10
|
+
data row is padded with `null`, and `headerRow` selects which row supplies the
|
|
11
|
+
keys (the first by default). Additive and zero-dependency; existing APIs are
|
|
12
|
+
unchanged.
|
|
13
|
+
|
|
14
|
+
## 0.1.3
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- [#30](https://github.com/zanlucathiago/xls-reader/pull/30) [`333f275`](https://github.com/zanlucathiago/xls-reader/commit/333f275aaad387bb550d7bc29074a6d342026f4f) Thanks [@zanlucathiago](https://github.com/zanlucathiago)! - Harden the parser against malformed and malicious `.xls` input. Fuzzing surfaced
|
|
19
|
+
inputs that could crash the process with a raw `RangeError` or exhaust memory
|
|
20
|
+
(OOM) instead of failing with `XlsError`; all now fail cleanly:
|
|
21
|
+
|
|
22
|
+
- Validate the CFB sector/mini-sector power-of-two shift (only 512/4096/64 are
|
|
23
|
+
legal) — an out-of-range shift produced a negative or huge sector size.
|
|
24
|
+
- Guard the DIFAT chain walk against self-loops that grew the FAT unbounded.
|
|
25
|
+
- Reject a negative/non-integer read offset in the byte reader.
|
|
26
|
+
- Enforce the BIFF8 sheet limits (65536 rows × 256 columns) so a corrupt cell
|
|
27
|
+
column can't size the dense grid into a hundreds-of-megabytes allocation.
|
|
28
|
+
|
|
29
|
+
Adds a seeded fuzz suite and deterministic regression vectors. No API change.
|
|
30
|
+
|
|
31
|
+
- [#28](https://github.com/zanlucathiago/xls-reader/pull/28) [`9e773c3`](https://github.com/zanlucathiago/xls-reader/commit/9e773c37571b605361b03056253249567e212c55) Thanks [@zanlucathiago](https://github.com/zanlucathiago)! - Build with tsdown (rolldown) instead of tsup, which is no longer maintained. No
|
|
32
|
+
API change and no runtime dependencies — the public `import`/`require` entry
|
|
33
|
+
points resolve exactly as before via the `exports` map. Internally the ESM
|
|
34
|
+
output is now `index.mjs` (was `index.js`); the CJS build is unchanged. This also
|
|
35
|
+
drops the `ignoreDeprecations` TypeScript workaround that tsup required.
|
|
36
|
+
|
|
3
37
|
## 0.1.2
|
|
4
38
|
|
|
5
39
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
</p>
|
|
16
16
|
|
|
17
17
|
<p align="center">
|
|
18
|
-
<strong>English</strong> · <a href="./README.pt-BR.md">Português (BR)</a>
|
|
18
|
+
<a href="https://zanlucathiago.github.io/xls-reader/demo.html"><strong>Live demo</strong></a> · <a href="https://zanlucathiago.github.io/xls-reader/">Website</a> · <strong>English</strong> · <a href="./README.pt-BR.md">Português (BR)</a>
|
|
19
19
|
</p>
|
|
20
20
|
|
|
21
21
|
Runs in Node and the browser — it only needs `Uint8Array` / `DataView`. It ships
|
|
@@ -91,20 +91,20 @@ input.addEventListener("change", async () => {
|
|
|
91
91
|
|
|
92
92
|
## Convert an .xls to JSON
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
`sheetToObjects` uses the first row as the keys and returns one object per data
|
|
95
|
+
row:
|
|
95
96
|
|
|
96
97
|
```ts
|
|
97
|
-
import { readFirstSheet } from "xls-reader";
|
|
98
|
+
import { readFirstSheet, sheetToObjects } from "xls-reader";
|
|
98
99
|
|
|
99
100
|
const sheet = readFirstSheet(bytes);
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
const json = body.map((row) =>
|
|
103
|
-
Object.fromEntries(header.map((key, i) => [String(key), row[i] ?? null])),
|
|
104
|
-
);
|
|
101
|
+
const json = sheet ? sheetToObjects(sheet) : [];
|
|
105
102
|
// [{ Emitente: "BANCO X S/A", Taxa: 1.1, Data: 2024-04-02T00:00:00.000Z }, ...]
|
|
106
103
|
```
|
|
107
104
|
|
|
105
|
+
Blank-header columns are skipped and short rows are padded with `null`. Pass
|
|
106
|
+
`{ headerRow }` when the header isn't the first row (e.g. a title row above it).
|
|
107
|
+
|
|
108
108
|
Handling non-`.xls` input:
|
|
109
109
|
|
|
110
110
|
```ts
|
|
@@ -132,6 +132,11 @@ Parses a whole workbook. Throws `XlsError` if the bytes aren't a BIFF `.xls`.
|
|
|
132
132
|
|
|
133
133
|
The first worksheet, for the single-sheet case.
|
|
134
134
|
|
|
135
|
+
### `sheetToObjects(sheet: Sheet, options?: { headerRow?: number }): RowObject[]`
|
|
136
|
+
|
|
137
|
+
Turns a sheet's rows into objects keyed by a header row (the first by default).
|
|
138
|
+
Blank-header columns are skipped and short rows are padded with `null`.
|
|
139
|
+
|
|
135
140
|
### `excelSerialToDate(serial: number, date1904: boolean): Date`
|
|
136
141
|
|
|
137
142
|
The raw serial-number → `Date` (UTC) conversion, if you need it directly.
|
|
@@ -219,8 +224,8 @@ container. `xls-reader` handles the older binary BIFF8 `.xls` only. Use
|
|
|
219
224
|
|
|
220
225
|
### How do I convert an `.xls` to JSON?
|
|
221
226
|
|
|
222
|
-
See [Convert an .xls to JSON](#convert-an-xls-to-json) above —
|
|
223
|
-
|
|
227
|
+
See [Convert an .xls to JSON](#convert-an-xls-to-json) above — call
|
|
228
|
+
`sheetToObjects(sheet)` to key each data row by the header row.
|
|
224
229
|
|
|
225
230
|
### Does it work in the browser?
|
|
226
231
|
|
package/README.pt-BR.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
</p>
|
|
16
16
|
|
|
17
17
|
<p align="center">
|
|
18
|
-
<a href="./README.md">English</a> · <strong>Português (BR)</strong>
|
|
18
|
+
<a href="https://zanlucathiago.github.io/xls-reader/demo.html"><strong>Demo ao vivo</strong></a> · <a href="https://zanlucathiago.github.io/xls-reader/">Website</a> · <a href="./README.md">English</a> · <strong>Português (BR)</strong>
|
|
19
19
|
</p>
|
|
20
20
|
|
|
21
21
|
Roda no Node e no navegador — só precisa de `Uint8Array` / `DataView`. São
|
|
@@ -93,21 +93,21 @@ input.addEventListener("change", async () => {
|
|
|
93
93
|
|
|
94
94
|
## Converter um .xls para JSON
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
O `sheetToObjects` usa a primeira linha como chaves e retorna um objeto por
|
|
97
|
+
linha de dados:
|
|
98
98
|
|
|
99
99
|
```ts
|
|
100
|
-
import { readFirstSheet } from "xls-reader";
|
|
100
|
+
import { readFirstSheet, sheetToObjects } from "xls-reader";
|
|
101
101
|
|
|
102
102
|
const sheet = readFirstSheet(bytes);
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
const json = body.map((row) =>
|
|
106
|
-
Object.fromEntries(header.map((key, i) => [String(key), row[i] ?? null])),
|
|
107
|
-
);
|
|
103
|
+
const json = sheet ? sheetToObjects(sheet) : [];
|
|
108
104
|
// [{ Emitente: "BANCO X S/A", Taxa: 1.1, Data: 2024-04-02T00:00:00.000Z }, ...]
|
|
109
105
|
```
|
|
110
106
|
|
|
107
|
+
Colunas com cabeçalho vazio são ignoradas e linhas curtas são preenchidas com
|
|
108
|
+
`null`. Passe `{ headerRow }` quando o cabeçalho não for a primeira linha (ex.:
|
|
109
|
+
há uma linha de título acima dele).
|
|
110
|
+
|
|
111
111
|
Tratando uma entrada que não é `.xls`:
|
|
112
112
|
|
|
113
113
|
```ts
|
|
@@ -136,6 +136,12 @@ Faz o parsing do workbook inteiro. Lança `XlsError` se os bytes não forem um
|
|
|
136
136
|
|
|
137
137
|
A primeira planilha, para o caso de uma única aba.
|
|
138
138
|
|
|
139
|
+
### `sheetToObjects(sheet: Sheet, options?: { headerRow?: number }): RowObject[]`
|
|
140
|
+
|
|
141
|
+
Transforma as linhas de uma planilha em objetos com chaves vindas de uma linha
|
|
142
|
+
de cabeçalho (a primeira, por padrão). Colunas com cabeçalho vazio são ignoradas
|
|
143
|
+
e linhas curtas são preenchidas com `null`.
|
|
144
|
+
|
|
139
145
|
### `excelSerialToDate(serial: number, date1904: boolean): Date`
|
|
140
146
|
|
|
141
147
|
A conversão bruta de número serial → `Date` (UTC), caso você precise dela
|
|
@@ -229,8 +235,8 @@ Use o [ExcelJS](https://github.com/exceljs/exceljs) para `.xlsx`.
|
|
|
229
235
|
|
|
230
236
|
### Como converto um `.xls` para JSON?
|
|
231
237
|
|
|
232
|
-
Veja [Converter um .xls para JSON](#converter-um-xls-para-json) acima —
|
|
233
|
-
|
|
238
|
+
Veja [Converter um .xls para JSON](#converter-um-xls-para-json) acima — chame
|
|
239
|
+
`sheetToObjects(sheet)` para usar a linha de cabeçalho como chaves de cada linha.
|
|
234
240
|
|
|
235
241
|
### Funciona no navegador?
|
|
236
242
|
|