sheetr 0.0.0-stage → 1.0.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 ADDED
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0
4
+
5
+ First release: create and read Excel .xlsx files with zero dependencies.
6
+
7
+ - `toXlsx(data, options?)` writes an .xlsx file from arrays of rows or arrays of objects (object keys become a bold header row), or from `{ "Sheet name": rows }` for several sheets.
8
+ - `toXlsxAsync(data, options?)` writes a compressed file with `CompressionStream("deflate-raw")`, and falls back to an uncompressed file where that isn't available.
9
+ - Cells can be text, numbers, booleans, dates (written with date or date-time formats), empty, or formulas (`{ formula, value? }`).
10
+ - Options: `sheetName`, `header`, `freezeHeader`, `columnWidths` (automatic or set by hand) and `utc`.
11
+ - Valid output: sheet names are cleaned and made unique, text is XML-escaped, characters XML 1.0 forbids are removed, and long text is cut to Excel's 32,767-character limit.
12
+ - `readXlsx(file, options?)` reads every sheet: shared and inline strings, numbers, booleans, errors, cached formula values and dates (detected from built-in and custom number formats, including the 1904 date system). Gaps in sparse sheets are filled with `null`.
13
+ - `toObjects(rows)` turns rows into objects using the first row as keys.
14
+ - Its own small ZIP writer and reader with CRC-32 checks, plus a built-in DEFLATE decoder for runtimes without `DecompressionStream("deflate-raw")`.
15
+ - Works in Node.js 18+ and browsers. ESM and CommonJS builds with TypeScript types.
16
+
17
+ ## 0.0.1
18
+
19
+ Name reservation. No working code.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CK Giri
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 CHANGED
@@ -1,3 +1,199 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ <h1>sheetr</h1>
4
+
5
+ <h3>Create and read Excel .xlsx files in Node.js and browsers.</h3>
6
+
7
+ <p>
8
+ <a href="https://www.npmjs.com/package/sheetr"><img src="https://img.shields.io/npm/v/sheetr?color=blue" alt="npm version"></a>
9
+ <a href="https://github.com/ckgiri/sheetr/actions/workflows/ci.yml"><img src="https://github.com/ckgiri/sheetr/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
10
+ <a href="https://www.npmjs.com/package/sheetr?activeTab=dependencies"><img src="https://img.shields.io/badge/dependencies-0-brightgreen" alt="zero dependencies"></a>
11
+ <a href="https://www.npmjs.com/package/sheetr"><img src="https://img.shields.io/npm/types/sheetr" alt="TypeScript types included"></a>
12
+ <a href="LICENSE"><img src="https://img.shields.io/npm/l/sheetr" alt="MIT license"></a>
13
+ <a href="#contributing"><img src="https://img.shields.io/badge/contributions-welcome-brightgreen" alt="contributions welcome"></a>
14
+ </p>
15
+
16
+ <p>
17
+ <a href="#installation">Installation</a> ·
18
+ <a href="#quick-start">Quick start</a> ·
19
+ <a href="#reading-files">Reading files</a> ·
20
+ <a href="#api">API</a> ·
21
+ <a href="#options">Options</a> ·
22
+ <a href="#contributing">Contributing</a>
23
+ </p>
24
+
25
+ </div>
26
+
27
+ **sheetr** is a lightweight, zero-dependency library that turns rows and objects into real Excel .xlsx files, and reads .xlsx files back into rows. It runs in Node.js and browsers using only standard web APIs. Dates stay dates, numbers stay numbers, and the files open in Excel without repair prompts.
28
+
29
+ ```js
30
+ const file = toXlsx([
31
+ { name: "Asha", age: 31, joined: new Date(2024, 0, 15) },
32
+ { name: "Ravi", age: 28, joined: new Date(2024, 2, 1) },
33
+ ]);
34
+ // → Uint8Array with a bold header row: name | age | joined
35
+ ```
36
+
37
+ ## ✨ Features
38
+
39
+ - 📝 **Write .xlsx**: from arrays of rows or arrays of objects, in one call
40
+ - 📖 **Read .xlsx**: get every sheet back as rows, or as objects with `toObjects`
41
+ - 📚 **Several sheets**: pass `{ "Sheet name": rows }` to write a whole workbook
42
+ - 📅 **Real dates**: `Date` values become Excel dates, and come back as `Date` objects
43
+ - 🧮 **Formulas**: write `{ formula: "SUM(A1:A3)" }`; reading returns the last calculated value
44
+ - 🎨 **Tidy output**: bold header, frozen first row and column widths that fit the content
45
+ - 🌍 **Any text**: Unicode, emoji and Hindi text are kept; characters XML can't hold are removed
46
+ - 🛡️ **Valid files**: sheet names, text and sizes are checked, so Excel never has to repair a file
47
+ - 🗜️ **Compression**: `toXlsxAsync` makes smaller files with the built-in CompressionStream
48
+ - 📦 **Zero dependencies**: its own small ZIP writer and reader, with TypeScript types included
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ npm install sheetr
54
+ ```
55
+
56
+ ## Quick start
57
+
58
+ **Node.js**: write the file to disk.
59
+
60
+ ```js
61
+ import { writeFileSync } from "node:fs";
62
+ import { toXlsx } from "sheetr";
63
+
64
+ const users = [
65
+ { name: "Asha", email: "asha@example.com", active: true },
66
+ { name: "Ravi", email: "ravi@example.com", active: false },
67
+ ];
68
+
69
+ writeFileSync("users.xlsx", toXlsx(users, { freezeHeader: true }));
70
+ ```
71
+
72
+ **Browser**: download the file.
73
+
74
+ ```js
75
+ import { toXlsx, XLSX_MIME_TYPE } from "sheetr";
76
+
77
+ const blob = new Blob([toXlsx(users)], { type: XLSX_MIME_TYPE });
78
+ const link = document.createElement("a");
79
+ link.href = URL.createObjectURL(blob);
80
+ link.download = "users.xlsx";
81
+ link.click();
82
+ URL.revokeObjectURL(link.href);
83
+ ```
84
+
85
+ **Several sheets, formulas and dates**
86
+
87
+ ```js
88
+ const file = toXlsx({
89
+ Orders: [
90
+ ["Item", "Price", "Ordered on"],
91
+ ["Pen", 20, new Date(2024, 4, 2)],
92
+ ["Book", 350, new Date(2024, 4, 3, 14, 30)],
93
+ ["Total", { formula: "SUM(B2:B3)" }],
94
+ ],
95
+ Customers: [{ id: 1, name: "Asha" }],
96
+ }, { header: true });
97
+ ```
98
+
99
+ Array rows are written as they are. Object rows get a header row made from their keys, in the order they first appear.
100
+
101
+ ## Reading files
102
+
103
+ `readXlsx` takes a `Uint8Array` (a Node.js `Buffer` works too) or an `ArrayBuffer`, and returns every sheet.
104
+
105
+ ```js
106
+ import { readFileSync } from "node:fs";
107
+ import { readXlsx, toObjects } from "sheetr";
108
+
109
+ const book = await readXlsx(readFileSync("users.xlsx"));
110
+
111
+ book.sheets[0].name; // "Sheet1"
112
+ book.sheets[0].rows; // [["name", "email", "active"], ["Asha", "asha@example.com", true], ...]
113
+ toObjects(book.sheets[0].rows); // [{ name: "Asha", email: "asha@example.com", active: true }, ...]
114
+ ```
115
+
116
+ In the browser, read a file from an `<input type="file">`:
117
+
118
+ ```js
119
+ const book = await readXlsx(await input.files[0].arrayBuffer());
120
+ ```
121
+
122
+ What you get back:
123
+
124
+ | In the cell | You get |
125
+ |---|---|
126
+ | Text | `string` |
127
+ | Number | `number` |
128
+ | TRUE / FALSE | `boolean` |
129
+ | Date or time (by its number format) | `Date` |
130
+ | Formula | its last calculated value |
131
+ | Error such as `#DIV/0!` | the error text as a `string` |
132
+ | Empty | `null` |
133
+
134
+ Every row has the same length. Gaps are filled with `null`.
135
+
136
+ ## API
137
+
138
+ | Function | Returns | What it does |
139
+ |---|---|---|
140
+ | `toXlsx(data, options?)` | `Uint8Array` | Creates an .xlsx file. Fast and synchronous; the file is not compressed |
141
+ | `toXlsxAsync(data, options?)` | `Promise<Uint8Array>` | Same, but compressed. Large sheets are often several times smaller |
142
+ | `readXlsx(file, options?)` | `Promise<Workbook>` | Reads an .xlsx file: `{ sheets: [{ name, rows }] }` |
143
+ | `toObjects(rows)` | `object[]` | Turns rows into objects, using the first row as keys |
144
+ | `XLSX_MIME_TYPE` | `string` | The .xlsx MIME type, for Blobs and HTTP responses |
145
+
146
+ `data` is an array of rows for one sheet, or `{ "Sheet name": rows }` for several. A row is an array of cells or an object. A cell can be a `string`, `number`, `boolean`, `Date`, `null`, `undefined` or `{ formula, value? }`.
147
+
148
+ `toObjects` names empty header cells `Column1`, `Column2` and so on, adds `_2` to repeated names, and skips rows with no values.
149
+
150
+ ## Options
151
+
152
+ For `toXlsx` and `toXlsxAsync`:
153
+
154
+ | Option | Default | What it does |
155
+ |---|---|---|
156
+ | `sheetName` | `"Sheet1"` | Sheet name when `data` is a single array of rows |
157
+ | `header` | `true` for object rows, `false` for array rows | Make the first row bold |
158
+ | `freezeHeader` | `false` | Keep the first row visible while scrolling |
159
+ | `columnWidths` | `"auto"` | `"auto"` fits each column to its content (up to 60 characters). An array such as `[20, null, 12]` sets widths in characters; `null` keeps a column automatic |
160
+ | `utc` | `false` | Write dates using UTC time instead of local time |
161
+
162
+ For `readXlsx`:
163
+
164
+ | Option | Default | What it does |
165
+ |---|---|---|
166
+ | `utc` | `false` | Return dates as UTC instead of local time. Use the same setting you wrote with |
167
+
168
+ ## Notes
169
+
170
+ - **Dates**: Excel dates have no time zone. By default sheetr writes and reads the local time shown by the `Date`. On servers that run in UTC, or when you want the same result everywhere, set `utc: true` on both sides. Dates before 1900 or after 9999 are written as ISO text.
171
+ - **Formulas**: Excel calculates them when the file opens. Readers that don't calculate (including `readXlsx`) see `value` if you gave one, and `null` otherwise.
172
+ - **Text**: cells hold at most 32,767 characters, so longer text is cut. Control characters that XML 1.0 forbids are removed. Tabs and line breaks are kept.
173
+ - **Sheet names**: they are cut to 31 characters, `[ ] : * ? / \` become `_`, and repeated names get a number, such as `Sales (2)`.
174
+ - **Limits**: up to 1,048,576 rows and 16,384 columns per sheet, as in Excel. Non-finite numbers (`NaN`, `Infinity`) are written as text. Empty rows and columns at the end of a sheet are not kept when reading.
175
+ - **Not supported**: charts, images, pivot tables, comments, merged cells, cell colors and borders, number formats other than dates, password-protected files, the old .xls format and files over 4 GB (ZIP64).
176
+ - **Runtimes**: Node.js 18 or newer and current browsers. It uses only standard web APIs, so other modern runtimes should work too. `readXlsx` uses `DecompressionStream` when it can and a built-in decoder otherwise. `toXlsxAsync` writes an uncompressed file if the runtime has no `CompressionStream("deflate-raw")`.
177
+
178
+ ## Contributing
179
+
180
+ **sheetr is open source and contributions are welcome.** Good places to start:
181
+
182
+ - **Files that read wrong**: an .xlsx file that `readXlsx` can't read or reads wrongly, reported in an [issue](https://github.com/ckgiri/sheetr/issues) with a small sample file.
183
+ - **Compatibility reports**: how the files look in spreadsheet apps you use.
184
+ - **New options**: open an issue first to talk about the idea.
185
+
186
+ ```bash
187
+ git clone https://github.com/ckgiri/sheetr.git
188
+ cd sheetr
189
+ npm install
190
+ npm test
191
+ ```
192
+
193
+ ## Changelog
194
+
195
+ See [CHANGELOG.md](CHANGELOG.md).
196
+
197
+ ## License
198
+
199
+ [MIT](LICENSE) © CK Giri