javascript-excel 1.0.3 → 2.0.0-alpha.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.
Files changed (50) hide show
  1. package/README.md +50 -2
  2. package/dist/auto-width-2oBzjeNG.d.cts +11 -0
  3. package/dist/auto-width-CT-BihTW.d.ts +10 -0
  4. package/dist/csv.cjs +623 -0
  5. package/dist/csv.d.cts +89 -0
  6. package/dist/csv.d.ts +89 -0
  7. package/dist/csv.js +618 -0
  8. package/dist/dom.cjs +464 -0
  9. package/dist/dom.d.cts +78 -0
  10. package/dist/dom.d.ts +78 -0
  11. package/dist/dom.js +461 -0
  12. package/dist/errors-CvGlfw0E.js +28 -0
  13. package/dist/errors-DOPrrGS4.cjs +69 -0
  14. package/dist/index.cjs +1424 -0
  15. package/dist/index.d.cts +140 -0
  16. package/dist/index.d.ts +140 -0
  17. package/dist/index.js +1397 -0
  18. package/dist/infer-BR-J9BZa.js +88 -0
  19. package/dist/infer-D9EC9vJ-.cjs +105 -0
  20. package/dist/iso-date-B22IvwL1.js +21 -0
  21. package/dist/iso-date-BSUsPSWO.cjs +26 -0
  22. package/dist/numfmt-B-TlCgr7.cjs +476 -0
  23. package/dist/numfmt-DEm0sYBJ.js +399 -0
  24. package/dist/read.cjs +2899 -0
  25. package/dist/read.d.cts +88 -0
  26. package/dist/read.d.ts +88 -0
  27. package/dist/read.js +2895 -0
  28. package/dist/sheet-names-CDsVK15c.js +831 -0
  29. package/dist/sheet-names-Cm-IhbBk.cjs +1004 -0
  30. package/dist/signal-Dz0ZYe6d.d.cts +13 -0
  31. package/dist/signal-Dz0ZYe6d.d.ts +13 -0
  32. package/dist/warnings-C_12PT4t.d.cts +410 -0
  33. package/dist/warnings-DXJKe1lx.d.ts +410 -0
  34. package/dist/worker.cjs +11 -0
  35. package/dist/worker.d.cts +8 -0
  36. package/dist/worker.d.ts +8 -0
  37. package/dist/worker.js +10 -0
  38. package/dist/write-C5JgeIar.d.cts +29 -0
  39. package/dist/write-CYpLGuzl.d.ts +29 -0
  40. package/package.json +67 -51
  41. package/.babelrc +0 -10
  42. package/.circleci/config.yml +0 -39
  43. package/lib/index.d.ts +0 -1
  44. package/lib/index.js +0 -22
  45. package/lib/javascript-excel.js +0 -17703
  46. package/src/index.tsx +0 -11
  47. package/test/unit/sample.spec.js +0 -5
  48. package/tsconfig.json +0 -54
  49. package/webpack.config.js +0 -19
  50. /package/{LICENSE.md → LICENSE} +0 -0
@@ -0,0 +1,140 @@
1
+ /**
2
+ * javascript-excel 2.0 (in progress).
3
+ *
4
+ * This entry exports the workbook model types (docs/api.md §3), the error
5
+ * classes (§7), the xlsx writer (§5.1) and the address, date and style
6
+ * helpers (§4). Builders land in later pull requests.
7
+ */
8
+ import { A as RichTextRun, C as GradientFill, D as PatternType, E as PatternFill, F as Theme, I as Workbook, M as Sheet, N as SheetView, O as PrintSetup, P as Style, S as Font, T as NumFmt, _ as ColumnWidth, a as BlobType, b as ErrorCode, c as BorderSide, d as CellErrorValue, f as CellInput, g as ColumnProps, h as Color, i as BlobLike, j as RowProps, k as RichText, l as BorderStyle, m as CellValue, n as ExcelWarningCode, o as Alignment, p as CellType, r as BinaryInput, s as Border, t as ExcelWarning, u as Cell, v as DefinedName, w as Hyperlink, x as Fill, y as DocProperties } from "./warnings-C_12PT4t.cjs";
9
+ import { a as toUint8Array, i as toBlob, n as WriteOptions, r as XLSX_MIME, t as Progress } from "./write-C5JgeIar.cjs";
10
+ import { t as AbortSignalLike } from "./signal-Dz0ZYe6d.cjs";
11
+ import { t as AutoWidthOptions } from "./auto-width-2oBzjeNG.cjs";
12
+ /**
13
+ * Typed errors (docs/api.md §7).
14
+ *
15
+ * Check errors with `isExcelError(err)` or `err.code`, not `instanceof`: when an
16
+ * app ends up with both the ESM and the CJS build, each has its own classes.
17
+ */
18
+ /** Every error code the library throws. */
19
+ type ExcelErrorCode = "NO_SHEETS" | "INVALID_SHEET_NAME" | "DUPLICATE_SHEET_NAME" | "INVALID_ACTIVE_SHEET" | "INVALID_REF" | "OUT_OF_BOUNDS" | "INVALID_CELL" | "INVALID_NUMBER" | "INVALID_DATE" | "STRING_TOO_LONG" | "INVALID_STYLE" | "INVALID_NUMFMT" | "INVALID_HYPERLINK" | "OVERLAPPING_MERGE" | "INVALID_COLUMN" | "TOO_MANY_STYLES" | "ZIP64_REQUIRED" | "INVALID_PROPERTY" | "INVALID_SHEET_PROPERTY" | "INVALID_DEFINED_NAME" | "UNSUPPORTED_FORMAT" | "NOT_XLSX" | "ZIP_INVALID" | "ZIP_UNSUPPORTED_METHOD" | "ZIP_ENCRYPTED" | "ZIP_CRC_MISMATCH" | "XML_MALFORMED" | "XML_DTD_FORBIDDEN" | "LIMIT_EXCEEDED" | "CSV_MALFORMED" | "ENVIRONMENT_UNSUPPORTED";
20
+ /** Options accepted by every error constructor. */
21
+ interface ExcelErrorOptions {
22
+ cause?: unknown;
23
+ details?: Record<string, unknown>;
24
+ }
25
+ /** Base class of every error the library throws. */
26
+ export declare class ExcelError extends Error {
27
+ readonly code: ExcelErrorCode;
28
+ readonly details?: Record<string, unknown>;
29
+ constructor(code: ExcelErrorCode, message: string, options?: ExcelErrorOptions);
30
+ }
31
+ /** The model or options cannot be written. */
32
+ export declare class ValidationError extends ExcelError {}
33
+ /** The input is not a readable xlsx or zip file. */
34
+ export declare class FormatError extends ExcelError {}
35
+ /** A read limit was exceeded; `details.limit` names it. */
36
+ export declare class LimitError extends ExcelError {}
37
+ /** Malformed CSV in strict mode. */
38
+ export declare class CsvError extends ExcelError {}
39
+ /** A required platform API is missing. */
40
+ export declare class EnvironmentError extends ExcelError {}
41
+ /** True for any error thrown by this library, across ESM/CJS copies and realms. */
42
+ export declare function isExcelError(e: unknown): e is ExcelError;
43
+ /** Options for date conversion. */
44
+ interface DateOptions {
45
+ /** Use the 1904 date system. Default false. */
46
+ date1904?: boolean | undefined;
47
+ /** Default 'local'. */
48
+ dateZone?: "local" | "utc" | undefined;
49
+ }
50
+ /**
51
+ * Converts a Date to an Excel serial number.
52
+ * Throws `INVALID_DATE` for an invalid Date or one outside the date system's
53
+ * range (1900-01-01 or 1904-01-01 to 9999-12-31).
54
+ */
55
+ export declare function dateToSerial(d: Date, options?: DateOptions): number;
56
+ /**
57
+ * Converts an Excel serial number to a Date (inverse of `dateToSerial`).
58
+ * - 1900 system: serials 0 to <1 are Excel's day 0 ("1900-01-00", i.e.
59
+ * 1899-12-31), which is how time-only values such as 0.5 (12:00) are
60
+ * stored. Serial 60 (the fictitious 1900-02-29) has no real date and gives
61
+ * 1900-03-01; callers that must flag it (the reader) check for it themselves.
62
+ * - 1904 system: serial 0 = 1904-01-01.
63
+ * Throws `INVALID_DATE` for negative, non-finite or out-of-range serials.
64
+ */
65
+ export declare function serialToDate(serial: number, options?: DateOptions): Date;
66
+ /**
67
+ * Deep-merges styles, later ones winning field by field. `font`, `alignment`,
68
+ * `protection` and each `border` side merge by field; `fill` and `numFmt`
69
+ * replace as a whole. `undefined` layers and `undefined` fields are skipped.
70
+ * The inputs are not modified.
71
+ */
72
+ export declare function mergeStyles(...styles: Array<Style | undefined>): Style;
73
+ /** Options for `cellText`. */
74
+ interface CellTextOptions {
75
+ /** Fields used for dates. Default 'local'. */
76
+ dateZone?: "local" | "utc" | undefined;
77
+ }
78
+ /**
79
+ * Plain text of a cell: strings as they are, numbers as `String(n)`, booleans
80
+ * as TRUE/FALSE, dates as ISO 8601, errors as their code, rich text joined.
81
+ * A formula cell gives its cached value's text ('' when there is none).
82
+ * Number formats are not applied.
83
+ */
84
+ export declare function cellText(cell: CellInput, options?: CellTextOptions): string;
85
+ /**
86
+ * Sheet-name rules (docs/api.md §3.3, §4.6).
87
+ *
88
+ * Excel rejects names that are empty, longer than 31 characters, contain any
89
+ * of \ / ? * [ ] :, or start or end with an apostrophe. It reserves 'History'
90
+ * [to verify]. Names are unique case-insensitively (checked by the writer).
91
+ */
92
+ /** Why a sheet name is invalid. */
93
+ type SheetNameProblem = "empty" | "too-long" | "forbidden-char" | "apostrophe" | "reserved";
94
+ /** Returns null when `name` is a valid sheet name, or the reason it is not. */
95
+ export declare function validateSheetName(name: string): SheetNameProblem | null;
96
+ /**
97
+ * Makes any string a valid sheet name: forbidden characters become '_',
98
+ * leading and trailing apostrophes are removed, the result is cut to 31
99
+ * characters (without splitting a surrogate pair), and an empty or reserved
100
+ * result becomes 'Sheet'. Uniqueness is the caller's job.
101
+ */
102
+ export declare function sanitizeSheetName(name: string): string;
103
+ /** The built-in number formats ECMA-376 §18.8.30 defines (§11.2). Ids 14–17 and 22 render in the user's locale in Excel. */
104
+ export declare const BUILTIN_NUM_FMTS: Readonly<Record<number, string>>;
105
+ /**
106
+ * True when a number format shows a date or a time of day (§3.4.1): built-in
107
+ * ids 14–22, 45, 47, 27–36 and 50–58, or a custom code that contains a date or
108
+ * time token outside quoted text, escapes and brackets. Elapsed-time formats
109
+ * (`[h]:mm:ss`, built-in 46) are durations and return false.
110
+ */
111
+ export declare function isDateFormat(fmt: NumFmt | undefined): boolean;
112
+ /** A zero-based cell address. */
113
+ interface CellAddress {
114
+ row: number;
115
+ col: number;
116
+ }
117
+ /** A range of cells, inclusive. */
118
+ interface RangeAddress {
119
+ start: CellAddress;
120
+ end: CellAddress;
121
+ }
122
+ /** Rows per sheet in the xlsx format. */
123
+ export declare const MAX_ROWS = 1048576;
124
+ /** Columns per sheet in the xlsx format (A..XFD). */
125
+ export declare const MAX_COLS = 16384;
126
+ /** Column index to letters: 0 → 'A', 16383 → 'XFD'. */
127
+ export declare function encodeCol(col: number): string;
128
+ /** Column letters to index: 'A' → 0, 'XFD' → 16383. Case-insensitive. */
129
+ export declare function decodeCol(letters: string): number;
130
+ /** { row: 0, col: 1 } → 'B1'. */
131
+ export declare function encodeCell(a: CellAddress): string;
132
+ /** 'B1' or '$B$1' → { row: 0, col: 1 }. */
133
+ export declare function decodeCell(ref: string): CellAddress;
134
+ /** Range to 'A1:C3' (a single cell gives 'A1'). */
135
+ export declare function encodeRange(r: RangeAddress): string;
136
+ /** 'A1:C3' or 'A1' → range, normalised so start is top-left. */
137
+ export declare function decodeRange(ref: string): RangeAddress;
138
+ /** Package version. Kept in sync with package.json by a unit test. */
139
+ export declare const VERSION = "2.0.0-alpha.1";
140
+ export { type AbortSignalLike, type Alignment, type AutoWidthOptions, type BinaryInput, type BlobLike, type BlobType, type Border, type BorderSide, type BorderStyle, type Cell, type CellAddress, type CellErrorValue, type CellInput, type CellTextOptions, type CellType, type CellValue, type Color, type ColumnProps, type ColumnWidth, type DateOptions, type DefinedName, type DocProperties, type ErrorCode, type ExcelErrorCode, type ExcelErrorOptions, type ExcelWarning, type ExcelWarningCode, type Fill, type Font, type GradientFill, type Hyperlink, type NumFmt, type PatternFill, type PatternType, type PrintSetup, type Progress, type RangeAddress, type RichText, type RichTextRun, type RowProps, type Sheet, type SheetNameProblem, type SheetView, type Style, type Theme, type Workbook, type WriteOptions, XLSX_MIME, toBlob, toUint8Array };
@@ -0,0 +1,140 @@
1
+ /**
2
+ * javascript-excel 2.0 (in progress).
3
+ *
4
+ * This entry exports the workbook model types (docs/api.md §3), the error
5
+ * classes (§7), the xlsx writer (§5.1) and the address, date and style
6
+ * helpers (§4). Builders land in later pull requests.
7
+ */
8
+ import { A as SheetView, C as PatternFill, D as RichTextRun, E as RichText, F as BlobLike, I as BlobType, M as Theme, N as Workbook, O as RowProps, P as BinaryInput, S as NumFmt, T as PrintSetup, _ as ErrorCode, a as BorderSide, b as GradientFill, c as CellErrorValue, d as CellValue, f as Color, g as DocProperties, h as DefinedName, i as Border, j as Style, k as Sheet, l as CellInput, m as ColumnWidth, n as ExcelWarningCode, o as BorderStyle, p as ColumnProps, r as Alignment, s as Cell, t as ExcelWarning, u as CellType, v as Fill, w as PatternType, x as Hyperlink, y as Font } from "./warnings-DXJKe1lx.js";
9
+ import { a as toUint8Array, i as toBlob, n as WriteOptions, r as XLSX_MIME, t as Progress } from "./write-CYpLGuzl.js";
10
+ import { t as AbortSignalLike } from "./signal-Dz0ZYe6d.js";
11
+ import { t as AutoWidthOptions } from "./auto-width-CT-BihTW.js";
12
+ /**
13
+ * Typed errors (docs/api.md §7).
14
+ *
15
+ * Check errors with `isExcelError(err)` or `err.code`, not `instanceof`: when an
16
+ * app ends up with both the ESM and the CJS build, each has its own classes.
17
+ */
18
+ /** Every error code the library throws. */
19
+ type ExcelErrorCode = "NO_SHEETS" | "INVALID_SHEET_NAME" | "DUPLICATE_SHEET_NAME" | "INVALID_ACTIVE_SHEET" | "INVALID_REF" | "OUT_OF_BOUNDS" | "INVALID_CELL" | "INVALID_NUMBER" | "INVALID_DATE" | "STRING_TOO_LONG" | "INVALID_STYLE" | "INVALID_NUMFMT" | "INVALID_HYPERLINK" | "OVERLAPPING_MERGE" | "INVALID_COLUMN" | "TOO_MANY_STYLES" | "ZIP64_REQUIRED" | "INVALID_PROPERTY" | "INVALID_SHEET_PROPERTY" | "INVALID_DEFINED_NAME" | "UNSUPPORTED_FORMAT" | "NOT_XLSX" | "ZIP_INVALID" | "ZIP_UNSUPPORTED_METHOD" | "ZIP_ENCRYPTED" | "ZIP_CRC_MISMATCH" | "XML_MALFORMED" | "XML_DTD_FORBIDDEN" | "LIMIT_EXCEEDED" | "CSV_MALFORMED" | "ENVIRONMENT_UNSUPPORTED";
20
+ /** Options accepted by every error constructor. */
21
+ interface ExcelErrorOptions {
22
+ cause?: unknown;
23
+ details?: Record<string, unknown>;
24
+ }
25
+ /** Base class of every error the library throws. */
26
+ export declare class ExcelError extends Error {
27
+ readonly code: ExcelErrorCode;
28
+ readonly details?: Record<string, unknown>;
29
+ constructor(code: ExcelErrorCode, message: string, options?: ExcelErrorOptions);
30
+ }
31
+ /** The model or options cannot be written. */
32
+ export declare class ValidationError extends ExcelError {}
33
+ /** The input is not a readable xlsx or zip file. */
34
+ export declare class FormatError extends ExcelError {}
35
+ /** A read limit was exceeded; `details.limit` names it. */
36
+ export declare class LimitError extends ExcelError {}
37
+ /** Malformed CSV in strict mode. */
38
+ export declare class CsvError extends ExcelError {}
39
+ /** A required platform API is missing. */
40
+ export declare class EnvironmentError extends ExcelError {}
41
+ /** True for any error thrown by this library, across ESM/CJS copies and realms. */
42
+ export declare function isExcelError(e: unknown): e is ExcelError;
43
+ /** Options for date conversion. */
44
+ interface DateOptions {
45
+ /** Use the 1904 date system. Default false. */
46
+ date1904?: boolean | undefined;
47
+ /** Default 'local'. */
48
+ dateZone?: "local" | "utc" | undefined;
49
+ }
50
+ /**
51
+ * Converts a Date to an Excel serial number.
52
+ * Throws `INVALID_DATE` for an invalid Date or one outside the date system's
53
+ * range (1900-01-01 or 1904-01-01 to 9999-12-31).
54
+ */
55
+ export declare function dateToSerial(d: Date, options?: DateOptions): number;
56
+ /**
57
+ * Converts an Excel serial number to a Date (inverse of `dateToSerial`).
58
+ * - 1900 system: serials 0 to <1 are Excel's day 0 ("1900-01-00", i.e.
59
+ * 1899-12-31), which is how time-only values such as 0.5 (12:00) are
60
+ * stored. Serial 60 (the fictitious 1900-02-29) has no real date and gives
61
+ * 1900-03-01; callers that must flag it (the reader) check for it themselves.
62
+ * - 1904 system: serial 0 = 1904-01-01.
63
+ * Throws `INVALID_DATE` for negative, non-finite or out-of-range serials.
64
+ */
65
+ export declare function serialToDate(serial: number, options?: DateOptions): Date;
66
+ /**
67
+ * Deep-merges styles, later ones winning field by field. `font`, `alignment`,
68
+ * `protection` and each `border` side merge by field; `fill` and `numFmt`
69
+ * replace as a whole. `undefined` layers and `undefined` fields are skipped.
70
+ * The inputs are not modified.
71
+ */
72
+ export declare function mergeStyles(...styles: Array<Style | undefined>): Style;
73
+ /** Options for `cellText`. */
74
+ interface CellTextOptions {
75
+ /** Fields used for dates. Default 'local'. */
76
+ dateZone?: "local" | "utc" | undefined;
77
+ }
78
+ /**
79
+ * Plain text of a cell: strings as they are, numbers as `String(n)`, booleans
80
+ * as TRUE/FALSE, dates as ISO 8601, errors as their code, rich text joined.
81
+ * A formula cell gives its cached value's text ('' when there is none).
82
+ * Number formats are not applied.
83
+ */
84
+ export declare function cellText(cell: CellInput, options?: CellTextOptions): string;
85
+ /**
86
+ * Sheet-name rules (docs/api.md §3.3, §4.6).
87
+ *
88
+ * Excel rejects names that are empty, longer than 31 characters, contain any
89
+ * of \ / ? * [ ] :, or start or end with an apostrophe. It reserves 'History'
90
+ * [to verify]. Names are unique case-insensitively (checked by the writer).
91
+ */
92
+ /** Why a sheet name is invalid. */
93
+ type SheetNameProblem = "empty" | "too-long" | "forbidden-char" | "apostrophe" | "reserved";
94
+ /** Returns null when `name` is a valid sheet name, or the reason it is not. */
95
+ export declare function validateSheetName(name: string): SheetNameProblem | null;
96
+ /**
97
+ * Makes any string a valid sheet name: forbidden characters become '_',
98
+ * leading and trailing apostrophes are removed, the result is cut to 31
99
+ * characters (without splitting a surrogate pair), and an empty or reserved
100
+ * result becomes 'Sheet'. Uniqueness is the caller's job.
101
+ */
102
+ export declare function sanitizeSheetName(name: string): string;
103
+ /** The built-in number formats ECMA-376 §18.8.30 defines (§11.2). Ids 14–17 and 22 render in the user's locale in Excel. */
104
+ export declare const BUILTIN_NUM_FMTS: Readonly<Record<number, string>>;
105
+ /**
106
+ * True when a number format shows a date or a time of day (§3.4.1): built-in
107
+ * ids 14–22, 45, 47, 27–36 and 50–58, or a custom code that contains a date or
108
+ * time token outside quoted text, escapes and brackets. Elapsed-time formats
109
+ * (`[h]:mm:ss`, built-in 46) are durations and return false.
110
+ */
111
+ export declare function isDateFormat(fmt: NumFmt | undefined): boolean;
112
+ /** A zero-based cell address. */
113
+ interface CellAddress {
114
+ row: number;
115
+ col: number;
116
+ }
117
+ /** A range of cells, inclusive. */
118
+ interface RangeAddress {
119
+ start: CellAddress;
120
+ end: CellAddress;
121
+ }
122
+ /** Rows per sheet in the xlsx format. */
123
+ export declare const MAX_ROWS = 1048576;
124
+ /** Columns per sheet in the xlsx format (A..XFD). */
125
+ export declare const MAX_COLS = 16384;
126
+ /** Column index to letters: 0 → 'A', 16383 → 'XFD'. */
127
+ export declare function encodeCol(col: number): string;
128
+ /** Column letters to index: 'A' → 0, 'XFD' → 16383. Case-insensitive. */
129
+ export declare function decodeCol(letters: string): number;
130
+ /** { row: 0, col: 1 } → 'B1'. */
131
+ export declare function encodeCell(a: CellAddress): string;
132
+ /** 'B1' or '$B$1' → { row: 0, col: 1 }. */
133
+ export declare function decodeCell(ref: string): CellAddress;
134
+ /** Range to 'A1:C3' (a single cell gives 'A1'). */
135
+ export declare function encodeRange(r: RangeAddress): string;
136
+ /** 'A1:C3' or 'A1' → range, normalised so start is top-left. */
137
+ export declare function decodeRange(ref: string): RangeAddress;
138
+ /** Package version. Kept in sync with package.json by a unit test. */
139
+ export declare const VERSION = "2.0.0-alpha.1";
140
+ export { type AbortSignalLike, type Alignment, type AutoWidthOptions, type BinaryInput, type BlobLike, type BlobType, type Border, type BorderSide, type BorderStyle, type Cell, type CellAddress, type CellErrorValue, type CellInput, type CellTextOptions, type CellType, type CellValue, type Color, type ColumnProps, type ColumnWidth, type DateOptions, type DefinedName, type DocProperties, type ErrorCode, type ExcelErrorCode, type ExcelErrorOptions, type ExcelWarning, type ExcelWarningCode, type Fill, type Font, type GradientFill, type Hyperlink, type NumFmt, type PatternFill, type PatternType, type PrintSetup, type Progress, type RangeAddress, type RichText, type RichTextRun, type RowProps, type Sheet, type SheetNameProblem, type SheetView, type Style, type Theme, type Workbook, type WriteOptions, XLSX_MIME, toBlob, toUint8Array };