@openjsxl/core 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 +21 -0
- package/README.md +24 -0
- package/dist/index.d.ts +181 -0
- package/dist/index.js +1262 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 openjsxl contributors
|
|
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,24 @@
|
|
|
1
|
+
# @openjsxl/core
|
|
2
|
+
|
|
3
|
+
The zero-dependency OOXML engine behind [`openjsxl`](https://www.npmjs.com/package/openjsxl) —
|
|
4
|
+
the `zip → xml → ooxml → reader` layers that turn an `.xlsx` into typed cells, built only on
|
|
5
|
+
platform Web APIs (`DecompressionStream`, `TextDecoder`, …).
|
|
6
|
+
|
|
7
|
+
**Most users should install [`openjsxl`](https://www.npmjs.com/package/openjsxl) instead** — it
|
|
8
|
+
re-exports everything here and is the stable public surface. Install `@openjsxl/core` directly
|
|
9
|
+
only if you want the engine without the facade.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @openjsxl/core
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { openXlsx, streamSheetRows, XlsxError } from '@openjsxl/core'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The API (`openXlsx`, `streamSheetRows`, `Workbook`, `Worksheet`, `XlsxError`, and the A1/date
|
|
20
|
+
helpers) is documented in the [project README](https://github.com/joaquimserafim/openjsxl#readme).
|
|
21
|
+
|
|
22
|
+
## License
|
|
23
|
+
|
|
24
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
type XlsxErrorCode = 'not-a-zip' | 'not-xlsx' | 'missing-part' | 'corrupt-zip' | 'unsupported' | 'no-such-sheet' | 'part-too-large';
|
|
2
|
+
declare class XlsxError extends Error {
|
|
3
|
+
/** Machine-readable discriminant; branch on this rather than the message. */
|
|
4
|
+
readonly code: XlsxErrorCode;
|
|
5
|
+
constructor(code: XlsxErrorCode, message: string, options?: {
|
|
6
|
+
cause?: unknown;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface CellRef {
|
|
11
|
+
/** 1-based column index (A = 1). */
|
|
12
|
+
readonly col: number;
|
|
13
|
+
/** 1-based row index. */
|
|
14
|
+
readonly row: number;
|
|
15
|
+
}
|
|
16
|
+
declare function columnToIndex(letters: string): number;
|
|
17
|
+
declare function indexToColumn(index: number): string;
|
|
18
|
+
declare function parseRef(ref: string): CellRef;
|
|
19
|
+
declare function formatRef(ref: CellRef): string;
|
|
20
|
+
|
|
21
|
+
declare function serialToDate(serial: number, date1904?: boolean): Date;
|
|
22
|
+
|
|
23
|
+
type CellType = 'empty' | 'string' | 'number' | 'boolean' | 'date' | 'error';
|
|
24
|
+
interface CellBase {
|
|
25
|
+
/** A1 reference, e.g. "B2". */
|
|
26
|
+
readonly ref: string;
|
|
27
|
+
}
|
|
28
|
+
type Cell = (CellBase & {
|
|
29
|
+
readonly type: 'empty';
|
|
30
|
+
readonly value: null;
|
|
31
|
+
}) | (CellBase & {
|
|
32
|
+
readonly type: 'string';
|
|
33
|
+
readonly value: string;
|
|
34
|
+
}) | (CellBase & {
|
|
35
|
+
readonly type: 'number';
|
|
36
|
+
readonly value: number;
|
|
37
|
+
}) | (CellBase & {
|
|
38
|
+
readonly type: 'boolean';
|
|
39
|
+
readonly value: boolean;
|
|
40
|
+
}) | (CellBase & {
|
|
41
|
+
readonly type: 'date';
|
|
42
|
+
readonly value: Date;
|
|
43
|
+
}) | (CellBase & {
|
|
44
|
+
readonly type: 'error';
|
|
45
|
+
readonly value: string;
|
|
46
|
+
});
|
|
47
|
+
interface SheetInfo {
|
|
48
|
+
/** Sheet name as shown on Excel's tab. */
|
|
49
|
+
readonly name: string;
|
|
50
|
+
/** Workbook-relative part path, resolved via the relationship graph. */
|
|
51
|
+
readonly path: string;
|
|
52
|
+
/** false for hidden or very-hidden sheets. */
|
|
53
|
+
readonly visible: boolean;
|
|
54
|
+
}
|
|
55
|
+
interface Comment {
|
|
56
|
+
/** The cell the comment is anchored to, e.g. "B2". */
|
|
57
|
+
readonly ref: string;
|
|
58
|
+
/** Comment author, resolved from the authors table. Absent when it can't be resolved. */
|
|
59
|
+
readonly author?: string;
|
|
60
|
+
/** The comment's plain text — rich-text runs concatenated, formatting dropped. */
|
|
61
|
+
readonly text: string;
|
|
62
|
+
}
|
|
63
|
+
interface Hyperlink {
|
|
64
|
+
/** The cell or range the link covers, e.g. "A1" or "B1:C2". */
|
|
65
|
+
readonly ref: string;
|
|
66
|
+
/**
|
|
67
|
+
* External destination (a URL, `mailto:`, or `file:` target) resolved through the
|
|
68
|
+
* worksheet's relationships. Absent for a purely in-workbook link.
|
|
69
|
+
*/
|
|
70
|
+
readonly target?: string;
|
|
71
|
+
/** In-workbook destination, e.g. "'Sheet2'!B5". Absent for a purely external link. */
|
|
72
|
+
readonly location?: string;
|
|
73
|
+
/** Hover text the producer attached to the link, if any. */
|
|
74
|
+
readonly tooltip?: string;
|
|
75
|
+
/** Display-text override for the link, if any. */
|
|
76
|
+
readonly display?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
interface StyleTable {
|
|
80
|
+
/** True when the cell format at this `s` index applies a date/time number format. */
|
|
81
|
+
isDateStyle(styleIndex: number | undefined): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* The number-format code applied at this `s` index — a custom code (`<numFmts>`) or a
|
|
84
|
+
* built-in one (e.g. `"0.00%"`, `"mm-dd-yy"`). `undefined` when the id is a locale/reserved
|
|
85
|
+
* built-in with no portable code, or the index is out of range.
|
|
86
|
+
*/
|
|
87
|
+
formatCode(styleIndex: number | undefined): string | undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
interface DecodeContext {
|
|
91
|
+
/** The workbook's shared string table (F1.5), indexed by `s`-type cells. */
|
|
92
|
+
readonly sharedStrings: readonly string[];
|
|
93
|
+
/** Style table (F2.1); when present, date-styled numbers decode as `date` cells. */
|
|
94
|
+
readonly styles?: StyleTable;
|
|
95
|
+
/** Workbook 1904 date system flag, selecting the serial epoch. Defaults to false. */
|
|
96
|
+
readonly date1904?: boolean;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
interface Relationship {
|
|
100
|
+
readonly id: string;
|
|
101
|
+
readonly type: string;
|
|
102
|
+
/** Target exactly as written; resolve internal ones with resolveTarget. */
|
|
103
|
+
readonly target: string;
|
|
104
|
+
readonly targetMode: 'Internal' | 'External';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
interface Row {
|
|
108
|
+
/** 1-based row index — from `<row r>`, or positional when the attribute is absent. */
|
|
109
|
+
readonly index: number;
|
|
110
|
+
/** Cells present in the row, in document order. Gaps are simply absent (sparse). */
|
|
111
|
+
readonly cells: readonly Cell[];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
declare class Worksheet {
|
|
115
|
+
#private;
|
|
116
|
+
/** Sheet name as shown on Excel's tab. */
|
|
117
|
+
readonly name: string;
|
|
118
|
+
constructor(info: SheetInfo, xml: string, context: DecodeContext, rels?: Map<string, Relationship>, commentsXml?: string);
|
|
119
|
+
/** Workbook-relative part path, e.g. `xl/worksheets/sheet1.xml`. */
|
|
120
|
+
get path(): string;
|
|
121
|
+
/** false for hidden or very-hidden sheets. */
|
|
122
|
+
get visible(): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Merged-cell ranges in A1 notation (e.g. `['A1:B1', 'A2:A4']`), in document order. Only the
|
|
125
|
+
* top-left cell of a merge holds a value; the rest read as `empty`. Empty when none.
|
|
126
|
+
*/
|
|
127
|
+
get mergedCells(): readonly string[];
|
|
128
|
+
/**
|
|
129
|
+
* Hyperlinks declared on this sheet, in document order. Each carries the covered `ref` and,
|
|
130
|
+
* where present, a resolved external `target`, an in-workbook `location`, a `tooltip`, and a
|
|
131
|
+
* `display` override. Empty when none.
|
|
132
|
+
*/
|
|
133
|
+
get hyperlinks(): readonly Hyperlink[];
|
|
134
|
+
/**
|
|
135
|
+
* The number-format code applied to the cell at `ref` — a custom code like `"yyyy-mm-dd"`
|
|
136
|
+
* or `"0.00%"`, or a built-in one. `undefined` when the workbook has no style table or the
|
|
137
|
+
* id has no portable code. An unstyled or absent cell resolves to the default format (style
|
|
138
|
+
* 0, usually `"General"`), mirroring how date detection defaults.
|
|
139
|
+
*/
|
|
140
|
+
numberFormat(ref: string): string | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* The sheet's declared used range in A1 notation (e.g. `"A1:E10"`, or a single cell), from
|
|
143
|
+
* the worksheet's `<dimension>`. `undefined` when the producer omits it — it is an optional
|
|
144
|
+
* hint, not authoritative, so treat a present value as advisory.
|
|
145
|
+
*/
|
|
146
|
+
get dimension(): string | undefined;
|
|
147
|
+
/**
|
|
148
|
+
* The comments anchored to cells on this sheet, in document order — each with its `ref`,
|
|
149
|
+
* resolved `author`, and plain `text`. Empty when the sheet has no comments part.
|
|
150
|
+
*/
|
|
151
|
+
get comments(): readonly Comment[];
|
|
152
|
+
/** The cell at an A1 reference. Absent cells read as `empty` (Excel treats them blank). */
|
|
153
|
+
cell(ref: string): Cell;
|
|
154
|
+
/** Stream the populated rows in document order. Sparse: empty rows/cells are absent. */
|
|
155
|
+
rows(): AsyncGenerator<Row>;
|
|
156
|
+
}
|
|
157
|
+
declare class Workbook {
|
|
158
|
+
#private;
|
|
159
|
+
/** Sheets in tab order. */
|
|
160
|
+
readonly sheets: readonly SheetInfo[];
|
|
161
|
+
constructor(sheets: SheetInfo[], byName: Map<string, Worksheet>);
|
|
162
|
+
/** The worksheet with this tab name. Throws if there is none. */
|
|
163
|
+
sheet(name: string): Worksheet;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Reader options. `maxPartBytes` caps the declared decompressed size of any single part — a
|
|
167
|
+
* zip-bomb guard independent of the archive's own (untrusted) size fields. Omit for no ceiling.
|
|
168
|
+
*/
|
|
169
|
+
interface ReadOptions {
|
|
170
|
+
readonly maxPartBytes?: number;
|
|
171
|
+
}
|
|
172
|
+
declare function openXlsx(source: Uint8Array | ArrayBuffer, options?: ReadOptions): Promise<Workbook>;
|
|
173
|
+
/**
|
|
174
|
+
* Stream the rows of one sheet with roughly constant memory: the worksheet is never
|
|
175
|
+
* materialized as a whole string — it is decompressed and tokenized chunk by chunk, and each
|
|
176
|
+
* row is yielded then discarded (F2.2). Use this for large sheets; use `openXlsx` when you
|
|
177
|
+
* need random `cell()` access. `sheetName` defaults to the first sheet in tab order.
|
|
178
|
+
*/
|
|
179
|
+
declare function streamSheetRows(source: Uint8Array | ArrayBuffer, sheetName?: string, options?: ReadOptions): AsyncGenerator<Row>;
|
|
180
|
+
|
|
181
|
+
export { type Cell, type CellRef, type CellType, type Comment, type Hyperlink, type ReadOptions, type Row, type SheetInfo, Workbook, Worksheet, XlsxError, type XlsxErrorCode, columnToIndex, formatRef, indexToColumn, openXlsx, parseRef, serialToDate, streamSheetRows };
|