@sheetxl/primitives 0.7.26 → 0.7.28-beta.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,78 @@
1
+ /**
2
+ * Parameter markers that declare how the engine handles `FormulaError` values *before* a
3
+ * function body runs. At the type level they are identity aliases — the body sees plain `T` —
4
+ * but the declaration records the policy for the engine.
5
+ *
6
+ * **ONE default, every position: errors reject.** Scalar arguments, lifted members,
7
+ * flattened members, and range parameters alike propagate the first error — preserving its
8
+ * identity (`#N/A` stays `#N/A`) — and the body never runs. Opt out with {@link AcceptError}.
9
+ * The single exception needs no marker: a `FormulaError.Known`-typed parameter receives
10
+ * errors because the type declares it.
11
+ *
12
+ * > *Errors propagate unless your function opts in to seeing them.*
13
+ *
14
+ * | position | default | opt-out |
15
+ * | --- | --- | --- |
16
+ * | scalar argument | reject — propagate with identity, body never runs | `AcceptError<T>` — body receives raw |
17
+ * | lifted member | reject — error becomes an error **member** of the output | `AcceptError<T>` |
18
+ * | flattened member (`Scalar[]`, rest) | reject — first error wins, argument order, row-major | `AcceptError<T>` |
19
+ * | range parameter | reject — first error (row-major) outranks everything | `AcceptError<IRange>` — members arrive raw |
20
+ * | `FormulaError.Known` parameter | receive (the type declares it) | — |
21
+ *
22
+ * One parameter splits the two by ARGUMENT SHAPE rather than picking one:
23
+ * {@link AcceptRefError} rejects a direct/computed error and accepts a reference-shaped one.
24
+ *
25
+ * There is no marker for the default. A `RejectError<T>` alias existed and declared nothing the
26
+ * engine did not already do, so it was removed rather than left as a second way to say nothing.
27
+ *
28
+ * Which-error-wins is ARGUMENT ORDER: the whole of argument N is scanned before argument
29
+ * N+1, row-major within each. The engine's range scan rides `IRange.errors()` /
30
+ * `IRange.hasError()` — raw stored members only, same definition as
31
+ * `getStats().getTypedCounts([ScalarType.Error])`.
32
+ *
33
+ * The tolerant set — parameters that declare `AcceptError` — is finite and documented
34
+ * (RANGE-ERROR-PROP.md §6.3): operators (broadcast is per-member), reshapers / dynamic
35
+ * arrays (error members pass through to the output), lookups (errors in never-consumed
36
+ * cells are tolerated), shape-only reference params (ROWS, COLUMNS, INDEX, OFFSET…),
37
+ * conditional consumers (SUMIF-family; the database family and SUBTOTAL/AGGREGATE keep
38
+ * their in-body, data-dependent policy), counters (COUNT, COUNTA), and the error handlers
39
+ * themselves (IS*, IFERROR…).
40
+ */
41
+ /**
42
+ * Opts a parameter out of the reject default: the body receives `FormulaError` values raw.
43
+ * Use this for functions whose job is to inspect, replace, or render errors (the IS*
44
+ * family, IFERROR, ERROR.TYPE, VALUETOTEXT…), that remap errors rather than propagate
45
+ * them, or that legitimately tolerate error members they may never consume (lookups,
46
+ * reshapers, conditional consumers — the §6.3 tolerant set).
47
+ *
48
+ * On a TYPED parameter (`IRange<number>`), `AcceptError` means errors and failed coercions
49
+ * arrive as raw MEMBERS instead of propagating — COUNT ignores them, COUNTA counts them.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * export function ISERROR(value: AcceptError<Scalar>): Scalar { ... }
54
+ * export function IFERROR(value: AcceptError<Scalar>, valueIfError: AcceptError<Scalar>): Scalar { ... }
55
+ * // Both parameters: an unused error fallback must pass through untouched (IFERROR(5,NA()) → 5).
56
+ * export function ROWS(array: AcceptError<IRange>): number { ... }
57
+ * // Shape-only: ROWS(A1:A2) is 2 even if A1 is #REF!.
58
+ * ```
59
+ */
60
+ export type AcceptError<T> = T;
61
+ /**
62
+ * Splits the policy by the ARGUMENT'S SHAPE: a **direct or computed** error rejects (propagates
63
+ * with its identity, exactly the default), while a **reference-shaped** one is accepted and the
64
+ * body receives it raw. "Direct" is the same runtime-shape test the coercion uses — a scalar,
65
+ * typed or computed; a reference or a computed array is not (`isDirectArg` in `TypedFunction`).
66
+ *
67
+ * ```
68
+ * =DSUM(A1:B3,NA(),G1:G2) #N/A direct — rejects, identity preserved
69
+ * =DSUM(A1:B3,NA()+0,G1:G2) #N/A computed — still direct
70
+ * =DSUM(A1:B3,E1,G1:G2) #VALUE! E1=#N/A — reference: body remaps
71
+ * =DSUM(A1:B3,E2,G1:G2) #VALUE! E2=#DIV/0!
72
+ * ```
73
+ *
74
+ * A body under this marker MUST handle the error it may now receive; a `FormulaError` reaching
75
+ * an unguarded body is the item 18 hazard.
76
+ */
77
+ export type AcceptRefError<T> = T;
78
+ //# sourceMappingURL=ErrorPolicy.d.ts.map
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Declares that a parameter takes ONE argument and receives it UNPACKED into a list.
3
+ *
4
+ * The length comes from the argument's CONTENTS, which is what separates it from every repeating
5
+ * form — there the length comes from the argument COUNT:
6
+ *
7
+ * ```
8
+ * IRR(values: Flatten<number>, guess?: number) IRR(A1:A5) → values is [1,2,3,4,5] ONE argument
9
+ * SUM(number: IRange<number>[]) SUM(A1:A5) → number is [IRange] ONE argument
10
+ * ```
11
+ *
12
+ * ### What "unpacked" means depends on the element type
13
+ *
14
+ * | `T` | the list holds | example |
15
+ * | --- | --- | --- |
16
+ * | a scalar (`number`, `string`, `Scalar`) | the argument's MEMBERS, blanks skipped | `NETWORKDAYS`'s holidays |
17
+ * | a range (`IRange`, `IReferenceRange`) | the argument's AREAS | `INDEX((A1:B2,C3:D4),…)` |
18
+ *
19
+ * Both are the same mechanism at different granularity — the marshaller picks the unit from the
20
+ * element type — and a blank drops out of either. The scalar case is the common one; the range case
21
+ * exists because a reference UNION is a single argument holding several areas, and a parameter that
22
+ * does not declare `Flatten` refuses one outright (`#REF!` — `ROWS((A1:A3,C1:C5))` in Excel).
23
+ *
24
+ * At the type level it is `T[]`, so the body reads the list directly.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * export function IRR(values: Flatten<number>, guess?: number): number { ... }
29
+ * export function NETWORKDAYS(start: Date, end: Date, holidays?: Flatten<Scalar>): number { ... }
30
+ * export function INDEX(array: Flatten<AcceptError<IRange>>, rowNum?: number, ...): any { ... }
31
+ * ```
32
+ */
33
+ export type Flatten<T> = T[];
34
+ //# sourceMappingURL=Flatten.d.ts.map
@@ -0,0 +1,227 @@
1
+ import { Scalar } from './Scalar';
2
+ import { FormulaError } from './FormulaError';
3
+ import { IRange } from './IRange';
4
+ import { IReferenceRange } from './IReferenceRange';
5
+ import { IFunction } from './IFunction';
6
+ import { IFormulaContext } from './IFormulaContext';
7
+ import { IRuntime } from './IRuntime';
8
+ import { LocaleProfile } from './LocaleProfile';
9
+ /**
10
+ * Default implementation of the IFormulaContext interface.
11
+ *
12
+ * @see IFormulaContext
13
+ *
14
+ * @remarks
15
+ * This is a stubbed implementation of the IFormulaContext interface.
16
+ * Runtime engines should provide a complete implementation.
17
+ * @internal
18
+ * @hidden
19
+ */
20
+ export declare class StubbedFormulaContext implements IFormulaContext {
21
+ /** @inheritdoc IFormulaContext.createRange */
22
+ createRange<TS extends Scalar = Scalar>(rows?: number, columns?: number, values?: Scalar | Scalar[][] | ((value: TS, coords: IRange.CellCoords, range: IRange<TS>) => TS)): IRange;
23
+ /** @inheritdoc IFormulaContext.getReference */
24
+ getReference(coords?: Readonly<IRange.Coords>, r1c1?: boolean): IReferenceRange;
25
+ /** @inheritdoc IFormulaContext.getResizedReference */
26
+ getResizedReference(anchor: Readonly<IRange.Coords>, rowCount: number, colCount: number): IReferenceRange;
27
+ /** @inheritdoc IFormulaContext.getNumberFormat */
28
+ getNumberFormat(formatText: string, value: Scalar): string;
29
+ /** @inheritdoc IFormulaContext.fromSerialDate */
30
+ fromSerialDate(serialDate: number, dateOnly?: boolean): Date;
31
+ /** @inheritdoc IFormulaContext.toSerialDate */
32
+ toSerialDate(date: Date, dateOnly?: boolean): number;
33
+ /** @inheritdoc IFormulaContext.getDateParts */
34
+ getDateParts(serialDate: number, reuseParts?: IFormulaContext.DateParts | boolean): IFormulaContext.DateParts;
35
+ /** @inheritdoc IFormulaContext.getSerialDate */
36
+ getSerialDate(year: number, month: number, day: number, hour?: number, minute?: number, second?: number, millis?: number): number;
37
+ /** @inheritdoc IFormulaContext.getNow */
38
+ getNow(): number;
39
+ /** @inheritdoc IFormulaContext.getValueAt */
40
+ getValueAt(row: number, column: number, sheetName?: string, options?: IRange.ValueOptions): Scalar | null;
41
+ /** @inheritdoc IFormulaContext.getEntireCoords */
42
+ getEntireCoords(): IRange.Coords;
43
+ /** @inheritdoc IFormulaContext.isValidDate */
44
+ isValidDate(value: any, jsDateOnly?: boolean): boolean;
45
+ /** @inheritdoc IFormulaContext.getRow */
46
+ getRow(): number;
47
+ /** @inheritdoc IFormulaContext.getColumn */
48
+ getColumn(): number;
49
+ /** @inheritdoc IFormulaContext.getFormulaAt */
50
+ getFormulaAt(row: number, column: number, sheetName?: string): string | null;
51
+ /** @inheritdoc IFormulaContext.getSpillAt */
52
+ getSpillAt(row: number, column: number, sheetName?: string): IReferenceRange | null;
53
+ /** @inheritdoc IFormulaContext.getSheetIndex */
54
+ getSheetIndex(sheet?: string | IReferenceRange): number;
55
+ /** @inheritdoc IFormulaContext.getSheetCount */
56
+ getSheetCount(): number | null;
57
+ /** @inheritdoc IFormulaContext.markVolatile */
58
+ markVolatile(): void;
59
+ /** @inheritdoc IFormulaContext.formatResults */
60
+ formatResults(numFmt: string): void;
61
+ /** @inheritdoc IFormulaContext.filterHidden */
62
+ filterHidden(range: IRange, axes?: IRange.AxisSelection): IRange;
63
+ /** @inheritdoc IFormulaContext.filterTotals */
64
+ filterTotals(range: IRange): IRange;
65
+ /** @inheritdoc IFormulaContext.getFunction */
66
+ getFunction(name: string): IFunction | null;
67
+ /** @inheritdoc IFormulaContext.getAddress */
68
+ getAddress(coords?: Readonly<IRange.FixableCoords | IRange.FixableCellCoords>, r1c1?: boolean): string;
69
+ /** @inheritdoc IFormulaContext.parseAsSerialDate */
70
+ parseAsSerialDate(textOrNumber: string | number, requireDate?: boolean): number;
71
+ /** @inheritdoc IFormulaContext.parseAsDate */
72
+ parseAsDate(serialOrString: string | number | Date | any, requireDate?: boolean): Date;
73
+ /** @inheritdoc IFormulaContext.parseAsNumber */
74
+ parseAsNumber(textOrNumber: Scalar, options?: IFormulaContext.ParseNumberOptions): number;
75
+ parseAsNumber(textOrNumber: Scalar | undefined, options?: IFormulaContext.ParseNumberOptions): number | undefined;
76
+ /**
77
+ * Unimplemented. See {@link IFormulaContext.createCriteria}.
78
+ *
79
+ * @remarks
80
+ * Unimplemented rather than approximated. Criteria parsing is the one rule that needs all three
81
+ * localization planes at once, and this stub has none of them — a "basic" version would answer
82
+ * plausibly and wrongly, where throwing names the actual mistake (evaluating criteria outside an
83
+ * installed scope).
84
+ */
85
+ createCriteria(criteria: Scalar): IFormulaContext.CriteriaEvaluator;
86
+ /**
87
+ * Parses the canonical English boolean and error literals.
88
+ * See {@link IFormulaContext.parseAsLiteral}.
89
+ *
90
+ * @remarks
91
+ * CANONICAL English only, deliberately. The localized spellings live in a language pack, which
92
+ * `@sheetxl/sdk` resolves and this package cannot see — the engine reaches `parseBooleanLocal` /
93
+ * `parseErrorLocal` through the calculation context and never lands here. Canonical is always
94
+ * accepted there too, so this stub is that rule with the localized alternates missing.
95
+ */
96
+ parseAsLiteral(text: string): boolean | FormulaError.Known | undefined;
97
+ /**
98
+ * Renders a scalar as text. See {@link IFormulaContext.toText}.
99
+ *
100
+ * @remarks
101
+ * A BASIC rendering, deliberately NOT Excel's. Excel's rule -- coercion General (15
102
+ * significant digits, plain decimal while the rendering fits 20 characters, else
103
+ * scientific) written with the workbook LOCALE's decimal separator -- is
104
+ * `formatNumberGeneral` in `@sheetxl/sdk`, and every evaluation path reaches it through
105
+ * the calculation context rather than through this stub. Numbers here get the plain JS
106
+ * rendering, which diverges from Excel on both precision and separator.
107
+ *
108
+ * This exists so authoring, type defs and other non-runtime access get usable text
109
+ * instead of throwing. Anything that needs Excel parity is running in the engine, and
110
+ * the engine never lands here.
111
+ */
112
+ toText(value: Scalar | undefined): string;
113
+ /**
114
+ * Orders two scalars. See {@link IFormulaContext.compare}.
115
+ *
116
+ * @remarks
117
+ * A BASIC total order, deliberately NOT Excel's. Excel's rule -- locale collation, the word
118
+ * sort, a blank taking the other operand's type, 11-decimal numeric normalization -- is
119
+ * `ScalarCollation` in `@sheetxl/sdk`, and every evaluation path reaches it through the
120
+ * calculation context rather than through this stub. `options` is ignored: strength is a
121
+ * collation concept and nothing here collates.
122
+ *
123
+ * This exists so authoring, type defs and other non-runtime access get a usable ordering
124
+ * instead of throwing. Anything that needs Excel parity is running in the engine, and the
125
+ * engine never lands here.
126
+ */
127
+ compare(a: Scalar, b: Scalar, options?: Intl.CollatorOptions): number;
128
+ /** @inheritdoc IFormulaContext.getRuntime */
129
+ getRuntime(): IRuntime;
130
+ }
131
+ /**
132
+ * The single, shared {@link IFormulaContext} that formula implementations use (via
133
+ * `import { FormulaContext } from '@sheetxl/primitives'`).
134
+ *
135
+ * @remarks
136
+ * A thin delegate: every method forwards to the currently-installed scope. The runtime (the
137
+ * calculation engine) installs the active per-evaluation scope; outside a calculation it falls back
138
+ * to {@link StubbedFormulaContext}. `@sheetxl/primitives` owns the interface and a default; the
139
+ * runtime supplies the implementation.
140
+ */
141
+ export declare class ScopedFormulaContext implements IFormulaContext {
142
+ protected _scope: Partial<IFormulaContext>;
143
+ /** @hidden Installed by the runtime around each evaluation; `null` restores the stub. */
144
+ _setScope(scope: Partial<IFormulaContext> | null): void;
145
+ /** @hidden */
146
+ _getScope(): Partial<IFormulaContext>;
147
+ /** @inheritdoc IFormulaContext.getNumberFormat */
148
+ getNumberFormat(formatText: string, value: Scalar): string | null;
149
+ /** @inheritdoc IFormulaContext.getEntireCoords */
150
+ getEntireCoords(): IRange.Coords;
151
+ /** @inheritdoc IFormulaContext.parseAsSerialDate */
152
+ parseAsSerialDate(textOrNumber: Scalar, requireDate?: boolean): number;
153
+ /** @inheritdoc IFormulaContext.parseAsDate */
154
+ parseAsDate(serialOrString: string | number | Date | any, requireDate?: boolean): Date;
155
+ /** @inheritdoc IFormulaContext.parseAsNumber */
156
+ parseAsNumber(textOrNumber: Scalar, options?: IFormulaContext.ParseNumberOptions): number;
157
+ parseAsNumber(textOrNumber: Scalar | undefined, options?: IFormulaContext.ParseNumberOptions): number | undefined;
158
+ /** @inheritdoc IFormulaContext.createCriteria */
159
+ createCriteria(criteria: Scalar): IFormulaContext.CriteriaEvaluator;
160
+ /** @inheritdoc IFormulaContext.parseAsLiteral */
161
+ parseAsLiteral(text: string): boolean | FormulaError.Known | undefined;
162
+ /** @inheritdoc IFormulaContext.toText */
163
+ toText(value: Scalar | undefined): string;
164
+ /** @inheritdoc IFormulaContext.isValidDate */
165
+ isValidDate(value: any, jsDateOnly?: boolean): boolean;
166
+ /** @inheritdoc IFormulaContext.fromSerialDate */
167
+ fromSerialDate(serialDate: number, dateOnly?: boolean): Date;
168
+ /** @inheritdoc IFormulaContext.toSerialDate */
169
+ toSerialDate(date: Date, dateOnly?: boolean): number;
170
+ /** @inheritdoc IFormulaContext.getDateParts */
171
+ getDateParts(serialDate: number, reuseParts?: IFormulaContext.DateParts | boolean): IFormulaContext.DateParts;
172
+ /** @inheritdoc IFormulaContext.getSerialDate */
173
+ getSerialDate(year: number, month: number, day: number, hour?: number, minute?: number, second?: number, millis?: number): number;
174
+ /** @inheritdoc IFormulaContext.getNow */
175
+ getNow(): number;
176
+ /** @inheritdoc IFormulaContext.createRange */
177
+ createRange<TS extends Scalar = Scalar>(rows?: number, columns?: number, values?: Scalar | Scalar[][] | ((value: TS, coords: IRange.CellCoords, range: IRange<TS>) => TS)): IRange;
178
+ /** @inheritdoc IFormulaContext.getRow */
179
+ getRow(): number;
180
+ /** @inheritdoc IFormulaContext.getColumn */
181
+ getColumn(): number;
182
+ /** @inheritdoc IFormulaContext.getReference */
183
+ getReference(coords?: Readonly<IRange.Coords>, r1c1?: boolean): IReferenceRange;
184
+ /** @inheritdoc IFormulaContext.getResizedReference */
185
+ getResizedReference(anchor: Readonly<IRange.Coords>, rowCount: number, colCount: number): IReferenceRange;
186
+ /** @inheritdoc IFormulaContext.getValueAt */
187
+ getValueAt(row: number, column: number, scope: string): Scalar | null;
188
+ /** @inheritdoc IFormulaContext.getFormulaAt */
189
+ getFormulaAt(row: number, column: number, scope: string): string | null;
190
+ /** @inheritdoc IFormulaContext.getSpillAt */
191
+ getSpillAt(row: number, column: number, scope: string): IReferenceRange | null;
192
+ /** @inheritdoc IFormulaContext.getSheetIndex */
193
+ getSheetIndex(sheet?: string | IReferenceRange): number;
194
+ /** @inheritdoc IFormulaContext.getSheetCount */
195
+ getSheetCount(): number | null;
196
+ /** @inheritdoc IFormulaContext.markVolatile */
197
+ markVolatile(): void;
198
+ /** @inheritdoc IFormulaContext.formatResults */
199
+ formatResults(numFmt: string): void;
200
+ /** @inheritdoc IFormulaContext.filterHidden */
201
+ filterHidden(range: IRange, axes?: IRange.AxisSelection): IRange;
202
+ /** @inheritdoc IFormulaContext.filterTotals */
203
+ filterTotals(range: IRange): IRange;
204
+ /** @inheritdoc IFormulaContext.getFunction */
205
+ getFunction(fnName: string): IFunction | null;
206
+ /** @inheritdoc IFormulaContext.getAddress */
207
+ getAddress(coords?: Readonly<IRange.FixableCoords | IRange.FixableCellCoords>, r1c1?: boolean): string;
208
+ /** @inheritdoc IFormulaContext.compare */
209
+ compare(a: Scalar, b: Scalar, options?: Intl.CollatorOptions): number;
210
+ /** @inheritdoc IFormulaContext.getRuntime */
211
+ getRuntime(): IRuntime;
212
+ get [Symbol.toStringTag](): string;
213
+ toString(): string;
214
+ }
215
+ /**
216
+ * A plain en-US profile, for stubs and for environments without `Intl`.
217
+ *
218
+ * @remarks
219
+ * Deliberately static data -- no probing. Real profiles come from
220
+ * `makeLocaleProfile` in `@sheetxl/sdk`.
221
+ */
222
+ export declare const DEFAULT_LOCALE_PROFILE: LocaleProfile;
223
+ /**
224
+ * The shared {@link IFormulaContext} for formula implementations. See {@link ScopedFormulaContext}.
225
+ */
226
+ export declare const FormulaContext: IFormulaContext;
227
+ //# sourceMappingURL=FormulaContext.d.ts.map
@@ -0,0 +1,328 @@
1
+ import { IRange } from './IRange';
2
+ import { IReferenceRange } from './IReferenceRange';
3
+ /**
4
+ * An error returned from a formula calculation.
5
+ *
6
+ * Standard Error Codes
7
+ * 0. #PARSE! If the formula contains a syntax error. (Not part of the OOXML spec.)
8
+ * 1. #NULL! Intersection of two ranges that don't intersect.
9
+ * 2. #DIV/0! Division by zero.
10
+ * 3. #VALUE! Wrong type of argument or operand.
11
+ * 4. #REF! Invalid cell reference.
12
+ * 5. #NAME? Unrecognized name (function, named range, etc.).
13
+ * 6. #NUM! Invalid numeric value.
14
+ * 7. #N/A Value not available.
15
+ * # Office 365
16
+ * 8. #GETTING_DATA This is raised for long running calculations that are not yet complete.
17
+ *
18
+ * (Saves as #N/A to disk)
19
+ * 9. #SPILL! Formula's output range is blocked.
20
+ *
21
+ * SpillErrorScalarSubType | "Unknown" | "Collision" | "IndeterminateSize" | "WorksheetEdge" | "OutOfMemoryWhileCalc" | "Table" | "MergedCell"
22
+ * # Office 2023
23
+ * 10. #CONNECT! This occurs when a data type is used that is not currently supported in this version of Excel.
24
+ * 11. #BLOCKED! Indicates that an action or feature is blocked, possibly due to security settings, protected view, or other restrictions. Often related to online features, external links, or macros.
25
+ * 12. #UNKNOWN! May be returned in the case of a protected workbook.
26
+ * 13. #FIELD! Invalid field name for a data type.
27
+ * 14. #CALC! Calculation error (often with LET or LAMBDA or a splitted array).
28
+ * 15.
29
+ * 16. #BUSY! When waiting on an external data source to return data.
30
+ * 17.
31
+ * 18.
32
+ * 19. #PYTHON! The Python interpreter returned the following error: Unexpected failure.
33
+ * 20. #TIMEOUT! Indicates that the operation took too long to complete.
34
+ */
35
+ export declare namespace FormulaError {
36
+ /**
37
+ * Standardized error codes for error types.
38
+ */
39
+ const Code: {
40
+ readonly Parse: 0;
41
+ readonly Null: 1;
42
+ readonly Div0: 2;
43
+ readonly Value: 3;
44
+ readonly Ref: 4;
45
+ readonly Name: 5;
46
+ readonly Num: 6;
47
+ readonly NA: 7;
48
+ readonly GettingData: 8;
49
+ readonly Spill: 9;
50
+ readonly Connect: 10;
51
+ readonly Blocked: 11;
52
+ readonly Unknown: 12;
53
+ readonly Field: 13;
54
+ readonly Calc: 14;
55
+ readonly Busy: 16;
56
+ readonly Python: 19;
57
+ readonly Timeout: 20;
58
+ };
59
+ /**
60
+ * Standardized error labels for error types.
61
+ */
62
+ const Label: {
63
+ readonly Parse: "#PARSE!";
64
+ readonly Null: "#NULL!";
65
+ readonly Div0: "#DIV/0!";
66
+ readonly Value: "#VALUE!";
67
+ readonly Ref: "#REF!";
68
+ readonly Name: "#NAME?";
69
+ readonly Num: "#NUM!";
70
+ readonly NA: "#N/A";
71
+ readonly GettingData: "#GETTING_DATA";
72
+ readonly Spill: "#SPILL!";
73
+ readonly Connect: "#CONNECT!";
74
+ readonly Blocked: "#BLOCKED!";
75
+ readonly Unknown: "#UNKNOWN!";
76
+ readonly Field: "#FIELD!";
77
+ readonly Calc: "#CALC!";
78
+ readonly Busy: "#BUSY!";
79
+ readonly Python: "#PYTHON!";
80
+ readonly Timeout: "#TIMEOUT!";
81
+ };
82
+ class Known extends Error {
83
+ protected _label: string;
84
+ protected _code: number;
85
+ protected details: any;
86
+ constructor(code: number, label: string, message?: string, details?: ErrorOptions);
87
+ static code: number;
88
+ get isFormulaError(): true;
89
+ getLabel(): string;
90
+ getCode(): number;
91
+ /**
92
+ * Return true if two errors are same.
93
+ *
94
+ * @param other any object to compare.
95
+ * @returns if two errors are the same type.
96
+ */
97
+ equals(other: any): boolean;
98
+ get [Symbol.toStringTag](): string;
99
+ /**
100
+ * The canonical spreadsheet spelling — `#VALUE!`, `#N/A`.
101
+ *
102
+ * @remarks
103
+ * Localization is a display concern and belongs to the layer that has a language pack
104
+ * (`localizeErrorLabel`); this stays canonical.
105
+ */
106
+ toString(): string;
107
+ }
108
+ /**
109
+ * #Parse!
110
+ *
111
+ * @remarks
112
+ * Not part of the OOXML spec.
113
+ */
114
+ class Parse extends Known {
115
+ constructor(message?: string, details?: ErrorOptions & {
116
+ line?: number;
117
+ column?: number;
118
+ offset?: number;
119
+ length?: number;
120
+ });
121
+ static code: number;
122
+ getDetails(): {
123
+ line: number;
124
+ column: number;
125
+ offset: number;
126
+ length: number;
127
+ };
128
+ }
129
+ /**
130
+ * When a reference is provided that doesn't exist. Usually an invalid range specification.
131
+ * =SUM(G5 G23)
132
+ */
133
+ class Null extends Known {
134
+ constructor(message?: string, details?: ErrorOptions);
135
+ static code: number;
136
+ }
137
+ /**
138
+ * Divide by Zero.
139
+ * * ex: The formula or function used is divided by zero.
140
+ */
141
+ class Div0 extends Known {
142
+ constructor(message?: string, details?: ErrorOptions);
143
+ static code: number;
144
+ }
145
+ /**
146
+ * Wrong argument in the formula. For example a string was given but a number was
147
+ * * ex: The row index number is too small. Specify a number great than or equal to 1.
148
+ */
149
+ class Value extends Known {
150
+ constructor(message?: string, details?: ErrorOptions);
151
+ static code: number;
152
+ }
153
+ /**
154
+ * Reference was remove due to a move or delete of cells.
155
+ * * ex: Moving or deleting cells caused an invalid cell reference, or function is returning reference error.
156
+ */
157
+ class Ref extends Known {
158
+ constructor(message?: string, details?: ErrorOptions);
159
+ static code: number;
160
+ }
161
+ /**
162
+ * A formula has references that can not be resolved or may contain parsing errors.
163
+ * * ex: The formula contains unrecognized text.
164
+ */
165
+ class Name extends Known {
166
+ constructor(message?: string, details?: ErrorOptions);
167
+ static code: number;
168
+ }
169
+ /**
170
+ * Invalid number.
171
+ */
172
+ class Num extends Known {
173
+ constructor(message?: string, details?: ErrorOptions);
174
+ static code: number;
175
+ }
176
+ /**
177
+ * Not available.
178
+ *
179
+ * @remarks
180
+ * Indicates the data needed is not available.
181
+ */
182
+ class NA extends Known {
183
+ constructor(message?: string, details?: ErrorOptions);
184
+ static code: number;
185
+ }
186
+ /**
187
+ * Getting Data.
188
+ */
189
+ class GettingData extends Known {
190
+ constructor(message?: string, details?: ErrorOptions);
191
+ static code: number;
192
+ }
193
+ /**
194
+ * Spill.
195
+ */
196
+ class Spill extends Known {
197
+ constructor(message?: string, details?: ErrorOptions);
198
+ static code: number;
199
+ }
200
+ /**
201
+ * Connect.
202
+ */
203
+ class Connect extends Known {
204
+ constructor(message?: string, details?: ErrorOptions);
205
+ static code: number;
206
+ }
207
+ /**
208
+ * Blocked.
209
+ */
210
+ class Blocked extends Known {
211
+ constructor(message?: string, details?: ErrorOptions);
212
+ static code: number;
213
+ }
214
+ /**
215
+ * Unknown.
216
+ */
217
+ class Unknown extends Known {
218
+ constructor(message?: string, details?: ErrorOptions);
219
+ static code: number;
220
+ }
221
+ /**
222
+ * Field does not exist.
223
+ *
224
+ * @remarks
225
+ * Indicates a field or property being access is not available.
226
+ */
227
+ class Field extends Known {
228
+ constructor(message?: string, details?: ErrorOptions);
229
+ static code: number;
230
+ }
231
+ /**
232
+ * Calc.
233
+ */
234
+ class Calc extends Known {
235
+ constructor(message?: string, details?: ErrorOptions);
236
+ static code: number;
237
+ }
238
+ /**
239
+ * Busy.
240
+ */
241
+ class Busy extends Known {
242
+ constructor(message?: string, details?: ErrorOptions);
243
+ static code: number;
244
+ }
245
+ /**
246
+ * Python.
247
+ */
248
+ class Python extends Known {
249
+ constructor(message?: string, details?: ErrorOptions);
250
+ static code: number;
251
+ }
252
+ /**
253
+ * Unknown.
254
+ */
255
+ class Timeout extends Known {
256
+ constructor(message?: string, details?: ErrorOptions);
257
+ static code: number;
258
+ }
259
+ }
260
+ export declare namespace FormulaError {
261
+ /**
262
+ * Returns a built-in error instance based on the error code.
263
+ *
264
+ * @param code The error code corresponding to a built-in error type.
265
+ * @returns A built-in error instance.
266
+ */
267
+ const getBuiltInByCode: (code: number) => FormulaError.Known | undefined;
268
+ /**
269
+ * Built-in errors instances for easy reference and comparison.
270
+ */
271
+ const BuiltIn: {
272
+ readonly Parse: FormulaError.Known;
273
+ readonly Null: FormulaError.Known;
274
+ readonly Div0: FormulaError.Known;
275
+ readonly Value: FormulaError.Known;
276
+ readonly Ref: FormulaError.Known;
277
+ readonly Name: FormulaError.Known;
278
+ readonly Num: FormulaError.Known;
279
+ readonly NA: FormulaError.Known;
280
+ readonly GettingData: FormulaError.Known;
281
+ readonly Spill: FormulaError.Known;
282
+ readonly Connect: FormulaError.Known;
283
+ readonly Blocked: FormulaError.Known;
284
+ readonly Unknown: FormulaError.Known;
285
+ readonly Field: FormulaError.Known;
286
+ readonly Calc: FormulaError.Known;
287
+ readonly Busy: FormulaError.Known;
288
+ readonly Python: FormulaError.Known;
289
+ readonly Timeout: FormulaError.Known;
290
+ };
291
+ /**
292
+ * Creates a new error instance based on the provided label or code.
293
+ *
294
+ * @param label The error label or code corresponding to a built-in error type.
295
+ * @param message Optional custom error message.
296
+ * @param details Optional additional error details.
297
+ * @returns A new instance of the specified error type, or an Unknown error if the label/code is not recognized.
298
+ *
299
+ * @remarks
300
+ * * Useful when wanting to convey details beyond the standard error code.
301
+ * * This should be used sparingly as creating new objects can have a performance impact.
302
+ */
303
+ const newTypedError: (label: string | number, message?: string, details?: ErrorOptions) => FormulaError.Known;
304
+ /**
305
+ * Returns a built-in error instance based on the error label.
306
+ *
307
+ * @param label The error label corresponding to a built-in error type.
308
+ * @returns A built-in error instance.
309
+ */
310
+ const getBuiltInByLabel: (label: string) => FormulaError.Known | undefined;
311
+ /**
312
+ * Used to determine if a value is a FormulaError.Known.
313
+ *
314
+ * @param v The value to check.
315
+ * @param code If provided, also checks that the error code matches.
316
+ * @returns a boolean.
317
+ */
318
+ function isError(v: unknown, code?: number): v is FormulaError.Known;
319
+ interface Known extends IRange {
320
+ }
321
+ interface Known extends IReferenceRange {
322
+ }
323
+ }
324
+ /**
325
+ * Indicates that the value can either be a valid value of type T or a FormulaError.Known.
326
+ */
327
+ export type MaybeError<T> = T | FormulaError.Known;
328
+ //# sourceMappingURL=FormulaError.d.ts.map