sheetr 0.0.1 → 1.0.1

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.
@@ -0,0 +1,65 @@
1
+ /** A cell formula. `value` is an optional cached result shown before Excel recalculates. */
2
+ interface Formula {
3
+ formula: string;
4
+ value?: string | number | boolean;
5
+ }
6
+ /** Values a cell can hold when writing. Anything else is written as text. */
7
+ type CellValue = string | number | boolean | Date | Formula | null | undefined;
8
+ /** One row: an array of cells, or an object whose keys become the header row. */
9
+ type Row = readonly unknown[] | object;
10
+ /** Rows for one sheet, or `{ "Sheet name": rows }` for several sheets. */
11
+ type WorkbookInput = readonly Row[] | Readonly<Record<string, readonly Row[]>>;
12
+ interface WriteOptions {
13
+ /** Name of the sheet when `data` is a single array of rows. Default "Sheet1". */
14
+ sheetName?: string;
15
+ /** Make the first row bold. Default: true for object rows, false for array rows. */
16
+ header?: boolean;
17
+ /** Keep the first row visible while scrolling. Default false. */
18
+ freezeHeader?: boolean;
19
+ /** "auto" sizes columns to their content (default). An array sets widths in characters; null entries stay automatic. */
20
+ columnWidths?: "auto" | readonly (number | null | undefined)[];
21
+ /** Write dates using their UTC time instead of local time. Default false. */
22
+ utc?: boolean;
23
+ }
24
+ interface ReadOptions {
25
+ /** Return dates as UTC instead of local time. Use the same setting you wrote with. Default false. */
26
+ utc?: boolean;
27
+ }
28
+ /** A value read from a cell. Formulas return their last calculated value. */
29
+ type ReadValue = string | number | boolean | Date | null;
30
+ interface Sheet {
31
+ name: string;
32
+ /** Rows of cells. Every row has the same length; empty cells are null. */
33
+ rows: ReadValue[][];
34
+ }
35
+ interface Workbook {
36
+ sheets: Sheet[];
37
+ }
38
+
39
+ /** MIME type of .xlsx files, for Blob downloads and HTTP responses. */
40
+ declare const XLSX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
41
+ /**
42
+ * Creates an .xlsx file. `data` is rows for one sheet (arrays or objects), or
43
+ * `{ "Sheet name": rows }` for several sheets. Entries are stored without
44
+ * compression; use `toXlsxAsync` for smaller files.
45
+ */
46
+ declare function toXlsx(data: WorkbookInput, options?: WriteOptions): Uint8Array;
47
+ /**
48
+ * Like `toXlsx`, but compresses the file with CompressionStream when the
49
+ * runtime supports "deflate-raw". Falls back to an uncompressed file otherwise.
50
+ */
51
+ declare function toXlsxAsync(data: WorkbookInput, options?: WriteOptions): Promise<Uint8Array>;
52
+
53
+ /**
54
+ * Reads an .xlsx file. Returns every sheet with its rows; empty cells are
55
+ * null, dates become Date objects and formulas return their cached value.
56
+ */
57
+ declare function readXlsx(data: Uint8Array | ArrayBuffer, options?: ReadOptions): Promise<Workbook>;
58
+ /**
59
+ * Turns rows into objects, using the first row as keys. Empty or repeated
60
+ * header names get unique fallbacks ("Column3", "Name_2"). Rows with no
61
+ * values are skipped.
62
+ */
63
+ declare function toObjects<T = Record<string, ReadValue>>(rows: readonly (readonly unknown[])[]): T[];
64
+
65
+ export { type CellValue, type Formula, type ReadOptions, type ReadValue, type Row, type Sheet, type Workbook, type WorkbookInput, type WriteOptions, XLSX_MIME_TYPE, readXlsx, toObjects, toXlsx, toXlsxAsync };
@@ -0,0 +1,65 @@
1
+ /** A cell formula. `value` is an optional cached result shown before Excel recalculates. */
2
+ interface Formula {
3
+ formula: string;
4
+ value?: string | number | boolean;
5
+ }
6
+ /** Values a cell can hold when writing. Anything else is written as text. */
7
+ type CellValue = string | number | boolean | Date | Formula | null | undefined;
8
+ /** One row: an array of cells, or an object whose keys become the header row. */
9
+ type Row = readonly unknown[] | object;
10
+ /** Rows for one sheet, or `{ "Sheet name": rows }` for several sheets. */
11
+ type WorkbookInput = readonly Row[] | Readonly<Record<string, readonly Row[]>>;
12
+ interface WriteOptions {
13
+ /** Name of the sheet when `data` is a single array of rows. Default "Sheet1". */
14
+ sheetName?: string;
15
+ /** Make the first row bold. Default: true for object rows, false for array rows. */
16
+ header?: boolean;
17
+ /** Keep the first row visible while scrolling. Default false. */
18
+ freezeHeader?: boolean;
19
+ /** "auto" sizes columns to their content (default). An array sets widths in characters; null entries stay automatic. */
20
+ columnWidths?: "auto" | readonly (number | null | undefined)[];
21
+ /** Write dates using their UTC time instead of local time. Default false. */
22
+ utc?: boolean;
23
+ }
24
+ interface ReadOptions {
25
+ /** Return dates as UTC instead of local time. Use the same setting you wrote with. Default false. */
26
+ utc?: boolean;
27
+ }
28
+ /** A value read from a cell. Formulas return their last calculated value. */
29
+ type ReadValue = string | number | boolean | Date | null;
30
+ interface Sheet {
31
+ name: string;
32
+ /** Rows of cells. Every row has the same length; empty cells are null. */
33
+ rows: ReadValue[][];
34
+ }
35
+ interface Workbook {
36
+ sheets: Sheet[];
37
+ }
38
+
39
+ /** MIME type of .xlsx files, for Blob downloads and HTTP responses. */
40
+ declare const XLSX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
41
+ /**
42
+ * Creates an .xlsx file. `data` is rows for one sheet (arrays or objects), or
43
+ * `{ "Sheet name": rows }` for several sheets. Entries are stored without
44
+ * compression; use `toXlsxAsync` for smaller files.
45
+ */
46
+ declare function toXlsx(data: WorkbookInput, options?: WriteOptions): Uint8Array;
47
+ /**
48
+ * Like `toXlsx`, but compresses the file with CompressionStream when the
49
+ * runtime supports "deflate-raw". Falls back to an uncompressed file otherwise.
50
+ */
51
+ declare function toXlsxAsync(data: WorkbookInput, options?: WriteOptions): Promise<Uint8Array>;
52
+
53
+ /**
54
+ * Reads an .xlsx file. Returns every sheet with its rows; empty cells are
55
+ * null, dates become Date objects and formulas return their cached value.
56
+ */
57
+ declare function readXlsx(data: Uint8Array | ArrayBuffer, options?: ReadOptions): Promise<Workbook>;
58
+ /**
59
+ * Turns rows into objects, using the first row as keys. Empty or repeated
60
+ * header names get unique fallbacks ("Column3", "Name_2"). Rows with no
61
+ * values are skipped.
62
+ */
63
+ declare function toObjects<T = Record<string, ReadValue>>(rows: readonly (readonly unknown[])[]): T[];
64
+
65
+ export { type CellValue, type Formula, type ReadOptions, type ReadValue, type Row, type Sheet, type Workbook, type WorkbookInput, type WriteOptions, XLSX_MIME_TYPE, readXlsx, toObjects, toXlsx, toXlsxAsync };