@gui-chat-plugin/spreadsheet 4.1.0 → 4.2.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.
- package/README.md +38 -4
- package/dist/core/calculationErrors.d.ts +17 -0
- package/dist/core/contentVersion.d.ts +5 -0
- package/dist/core/definition.d.ts +1 -1
- package/dist/core/dispatch.d.ts +3 -3
- package/dist/core/dispatchReplies.d.ts +19 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/rangeValues.d.ts +2 -1
- package/dist/core/types.d.ts +14 -1
- package/dist/core-CTRlKL9k.js +52 -0
- package/dist/core-Cf9Pxo_q.cjs +1 -0
- package/dist/core.cjs +1 -1
- package/dist/core.js +3 -3
- package/dist/engine/blankOperands.d.ts +14 -0
- package/dist/engine/calculator.d.ts +0 -7
- package/dist/engine/cellEmpty.d.ts +3 -0
- package/dist/engine/cellFormatting.d.ts +3 -2
- package/dist/engine/concatOperand.d.ts +3 -0
- package/dist/engine/concatPrecedence.d.ts +32 -0
- package/dist/engine/customFunctionSpecs.d.ts +30 -0
- package/dist/engine/customFunctions.d.ts +32 -0
- package/dist/engine/date-calendar.d.ts +32 -0
- package/dist/engine/date-utils.d.ts +4 -1
- package/dist/engine/dateDisplay.d.ts +20 -0
- package/dist/engine/escapes.d.ts +10 -0
- package/dist/engine/evaluator.d.ts +9 -2
- package/dist/engine/formatter.d.ts +4 -0
- package/dist/engine/functions/aliases.d.ts +6 -0
- package/dist/engine/functions/analysis-math.d.ts +3 -0
- package/dist/engine/functions/calendar.d.ts +9 -0
- package/dist/engine/functions/date.d.ts +1 -1
- package/dist/engine/functions/distribution-math.d.ts +44 -0
- package/dist/engine/functions/distributions.d.ts +7 -0
- package/dist/engine/functions/index.d.ts +5 -0
- package/dist/engine/functions/regression-math.d.ts +25 -0
- package/dist/engine/functions/regression.d.ts +5 -0
- package/dist/engine/functions/shape-math.d.ts +21 -0
- package/dist/engine/functions/shape.d.ts +5 -0
- package/dist/engine/functions/special-functions.d.ts +17 -0
- package/dist/engine/functions/statistical-analysis.d.ts +8 -1
- package/dist/engine/functions/statistical.d.ts +21 -1
- package/dist/engine/jsonCellLocator.d.ts +0 -16
- package/dist/engine/logicalLiterals.d.ts +11 -0
- package/dist/engine/math-ops.d.ts +4 -2
- package/dist/engine/numericCoercion.d.ts +6 -0
- package/dist/engine/registry.d.ts +32 -4
- package/dist/engine/sheetReference.d.ts +14 -0
- package/dist/engine/textCollation.d.ts +8 -0
- package/dist/engine/textComparison.d.ts +22 -0
- package/dist/engine/translateFormula.d.ts +16 -5
- package/dist/engine/wholeReferences.d.ts +19 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +3 -3
- package/dist/lang/messages.d.ts +5 -0
- package/dist/samples-C5JjpxYJ.js +4513 -0
- package/dist/samples-UnTPgkyq.cjs +2 -0
- package/dist/style.css +1 -1
- package/dist/vue/fileFollow.d.ts +7 -0
- package/dist/vue/sheetSession.d.ts +10 -4
- package/dist/vue/useCustomFunctions.d.ts +7 -0
- package/dist/vue.cjs +32 -32
- package/dist/vue.js +3099 -2921
- package/package.json +4 -2
- package/dist/core-CaJMHb3p.js +0 -44
- package/dist/core-PwJLsuHs.cjs +0 -1
- package/dist/samples-B6CgK8O-.cjs +0 -1
- package/dist/samples-miYeCJeQ.js +0 -2856
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The t and normal distributions and the t-test, as pure numerics. Tails are computed
|
|
3
|
+
* directly rather than as 1 − (the rest), so a small p-value keeps its relative precision.
|
|
4
|
+
* The spreadsheet rules (argument checks, #NUM!) live in distributions.ts.
|
|
5
|
+
*/
|
|
6
|
+
export declare const normalDensity: (z: number) => number;
|
|
7
|
+
/** P(Z > z) for the standard normal. erfc(x) is Q(1/2, x²), so the upper tail is half of it. */
|
|
8
|
+
export declare function normalUpperTail(z: number): number;
|
|
9
|
+
/** P(Z ≤ z) for the standard normal. */
|
|
10
|
+
export declare const normalCdf: (z: number) => number;
|
|
11
|
+
/** The z with P(Z ≤ z) = p, for 0 < p < 1. */
|
|
12
|
+
export declare function normalQuantile(p: number): number;
|
|
13
|
+
/** The z with P(Z > z) = q, for 0 < q < 1. */
|
|
14
|
+
export declare const normalUpperQuantile: (q: number) => number;
|
|
15
|
+
/** The t density with `df` degrees of freedom: 1 / (√ν B(ν/2, 1/2)) · (1 + t²/ν)^(−(ν+1)/2). */
|
|
16
|
+
export declare function studentDensity(t: number, df: number): number;
|
|
17
|
+
/** P(T > t). For t ≥ 0 it is ½ · I_x(ν/2, ½) with x = ν / (ν + t²) = r / (1 + r), r = ν / t².
|
|
18
|
+
* It goes through ln r, so t² never overflows and 1 − x keeps its digits for a small t. */
|
|
19
|
+
export declare function studentUpperTail(t: number, df: number): number;
|
|
20
|
+
/** P(T ≤ t). */
|
|
21
|
+
export declare const studentCdf: (t: number, df: number) => number;
|
|
22
|
+
/** The t with P(T > t) = q, for 0 < q < 1. */
|
|
23
|
+
export declare function studentUpperQuantile(q: number, df: number): number;
|
|
24
|
+
/** The t with P(T ≤ t) = p, for 0 < p < 1. */
|
|
25
|
+
export declare const studentQuantile: (p: number, df: number) => number;
|
|
26
|
+
export interface SampleSummary {
|
|
27
|
+
count: number;
|
|
28
|
+
mean: number;
|
|
29
|
+
/** The sample variance, divided by n − 1. */
|
|
30
|
+
variance: number;
|
|
31
|
+
}
|
|
32
|
+
export declare function summarize(values: number[]): SampleSummary;
|
|
33
|
+
export interface TStatistic {
|
|
34
|
+
t: number;
|
|
35
|
+
df: number;
|
|
36
|
+
}
|
|
37
|
+
/** Paired: the one-sample t of the differences. */
|
|
38
|
+
export declare function pairedT(differences: number[]): TStatistic;
|
|
39
|
+
/** Two samples with a pooled (equal) variance. */
|
|
40
|
+
export declare function pooledT(first: SampleSummary, second: SampleSummary): TStatistic;
|
|
41
|
+
/** Two samples with unequal variances (Welch). The Welch–Satterthwaite df is not rounded. */
|
|
42
|
+
export declare function welchT(first: SampleSummary, second: SampleSummary): TStatistic;
|
|
43
|
+
/** The p-value of a t statistic: one tail, or both. */
|
|
44
|
+
export declare const tTestProbability: ({ t, df }: TStatistic, tails: 1 | 2) => number;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The t and normal distributions, the t-test and confidence intervals. The numerics live in
|
|
3
|
+
* distribution-math.ts; this file reads the arguments, applies Excel's argument rules —
|
|
4
|
+
* degrees of freedom, tails, type and size truncated to integers, anything out of range
|
|
5
|
+
* #NUM! — and registers the names.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
@@ -6,10 +6,15 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import "./statistical";
|
|
8
8
|
import "./statistical-analysis";
|
|
9
|
+
import "./regression";
|
|
10
|
+
import "./distributions";
|
|
11
|
+
import "./shape";
|
|
9
12
|
import "./mathematical";
|
|
10
13
|
import "./logical";
|
|
11
14
|
import "./text";
|
|
12
15
|
import "./financial";
|
|
13
16
|
import "./lookup";
|
|
14
17
|
import "./date";
|
|
18
|
+
import "./calendar";
|
|
19
|
+
import "./aliases";
|
|
15
20
|
export { functionRegistry } from "../registry";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure rules for the regression and covariance functions (FORECAST.LINEAR, TREND, STEYX,
|
|
3
|
+
* COVARIANCE.S/.P), separated from the range-reading handlers so they can be tested directly.
|
|
4
|
+
*/
|
|
5
|
+
import { type SpreadsheetError } from "../spreadsheet-errors";
|
|
6
|
+
import type { CellValue } from "../types";
|
|
7
|
+
import { type NumericPairs } from "./analysis-math";
|
|
8
|
+
/** FORECAST.LINEAR: the least-squares line's value at `x`. Ranges with no pair of numbers are
|
|
9
|
+
* #N/A, as Excel answers for empty ranges; an x that never varies has no line: #DIV/0!. */
|
|
10
|
+
export declare function forecastLinear(pairs: NumericPairs, x: number): number | SpreadsheetError;
|
|
11
|
+
/** STEYX: the standard error of the y predicted by the least-squares line. */
|
|
12
|
+
export declare function standardErrorOfEstimate(pairs: NumericPairs): number | SpreadsheetError;
|
|
13
|
+
/** COVARIANCE.P: the mean product of the deviations, divided by n. */
|
|
14
|
+
export declare function populationCovariance(pairs: NumericPairs): number | SpreadsheetError;
|
|
15
|
+
/** COVARIANCE.S: divided by n - 1, so it needs two pairs. */
|
|
16
|
+
export declare function sampleCovariance(pairs: NumericPairs): number | SpreadsheetError;
|
|
17
|
+
/** The positions 1..n, TREND's known_x when it is omitted. */
|
|
18
|
+
export declare const defaultKnownXs: (count: number) => number[];
|
|
19
|
+
/**
|
|
20
|
+
* TREND at one new x. Unlike FORECAST it reads the ranges whole, as LINEST does: ranges of
|
|
21
|
+
* different sizes are #REF!, an error cell is that error, and a blank or text cell is #VALUE!
|
|
22
|
+
* rather than a skipped row. With a constant, an x that never varies is collinear with it and is
|
|
23
|
+
* dropped, as LINEST drops it, leaving the mean of y; through the origin only an all-zero x is.
|
|
24
|
+
*/
|
|
25
|
+
export declare function trendAt(knownYs: CellValue[], knownXs: CellValue[], newX: number, withConstant: boolean): number | SpreadsheetError;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shape of one sample — skewness, kurtosis, percent rank — and its geometric and harmonic
|
|
3
|
+
* means, as pure numerics with Excel's formulas and Excel's errors. Registered in shape.ts.
|
|
4
|
+
*/
|
|
5
|
+
import { type SpreadsheetError } from "../spreadsheet-errors";
|
|
6
|
+
type Result = number | SpreadsheetError;
|
|
7
|
+
/** SKEW: n / ((n − 1)(n − 2)) · Σ z³. Fewer than three values, or none that differ: #DIV/0!. */
|
|
8
|
+
export declare function skewness(values: number[]): Result;
|
|
9
|
+
/** KURT: n(n + 1) / ((n − 1)(n − 2)(n − 3)) · Σ z⁴ − 3(n − 1)² / ((n − 2)(n − 3)). Fewer than four
|
|
10
|
+
* values, or none that differ: #DIV/0!. */
|
|
11
|
+
export declare function kurtosis(values: number[]): Result;
|
|
12
|
+
/** STANDARDIZE: (x − mean) / sd, for sd > 0. */
|
|
13
|
+
export declare const standardize: (x: number, center: number, sd: number) => Result;
|
|
14
|
+
/** GEOMEAN: the n-th root of the product, through logs. Any value at or below 0, or none: #NUM!. */
|
|
15
|
+
export declare function geometricMean(values: number[]): Result;
|
|
16
|
+
/** HARMEAN: n / Σ (1 / x). Any value at or below 0, or none: #NUM!. */
|
|
17
|
+
export declare function harmonicMean(values: number[]): Result;
|
|
18
|
+
/** PERCENTRANK.INC with `significance` digits, truncated as Excel truncates. No data, or fewer
|
|
19
|
+
* than one significant digit: #NUM!. An x outside the data: #N/A. One value: 1 when it is x. */
|
|
20
|
+
export declare function percentRank(values: number[], x: number, significance: number): Result;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The special functions the t and normal distributions are built from: log gamma,
|
|
3
|
+
* log beta, and the regularized incomplete beta and gamma functions. Pure numerics,
|
|
4
|
+
* no spreadsheet types; accurate to a relative error near 1e-15 in the ranges the
|
|
5
|
+
* distribution functions use, which tests/engine/test_distributions.ts checks
|
|
6
|
+
* against values computed at 50 digits.
|
|
7
|
+
*/
|
|
8
|
+
/** ln Γ(x) for x > 0. */
|
|
9
|
+
export declare function logGamma(x: number): number;
|
|
10
|
+
/** ln B(a, b) for a, b > 0. With one argument large (the t distribution's df / 2 beside ½) it is
|
|
11
|
+
* split like R's lbeta: ln Γ(q) − ln Γ(p + q) cancels once both are large and alike. */
|
|
12
|
+
export declare function logBeta(a: number, b: number): number;
|
|
13
|
+
/** I_x(a, b) from ln x and ln(1 − x). Taking logs lets a caller pass an x, or a 1 − x, too small
|
|
14
|
+
* for a double (t above 1e154 in the t distribution) without the front factor collapsing to 0. */
|
|
15
|
+
export declare function regularizedBetaFromLogs(logX: number, logComplement: number, a: number, b: number): number;
|
|
16
|
+
/** Q(a, x) = Γ(a, x) / Γ(a), the regularized upper incomplete gamma function. */
|
|
17
|
+
export declare function regularizedGammaUpper(a: number, x: number): number;
|
|
@@ -3,4 +3,11 @@
|
|
|
3
3
|
* population spread, and the multi-condition aggregates. The rules live in
|
|
4
4
|
* analysis-math.ts; this file reads the ranges and registers the names.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
import { type FunctionContext, type FunctionHandler } from "../registry";
|
|
7
|
+
import { type NumericPairs } from "./analysis-math";
|
|
8
|
+
import { type SpreadsheetError } from "../spreadsheet-errors";
|
|
9
|
+
/** A scalar argument as a number, or the error it evaluated to (`#VALUE!` for text). */
|
|
10
|
+
export declare const scalarArg: (args: string[], context: FunctionContext, index: number) => number | SpreadsheetError;
|
|
11
|
+
/** `(known_y, known_x)` from argument `first` on, read raw so the two ranges stay paired by position. */
|
|
12
|
+
export declare const pairsFrom: (args: string[], context: FunctionContext, first?: number) => NumericPairs | SpreadsheetError;
|
|
13
|
+
export declare const pairedHandler: (rule: (pairs: NumericPairs) => number | SpreadsheetError) => FunctionHandler;
|
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Statistical Functions
|
|
3
3
|
*/
|
|
4
|
-
import { type FunctionContext } from "../registry";
|
|
4
|
+
import { type FunctionContext, type FunctionHandler, type RangeGetter } from "../registry";
|
|
5
|
+
import { type SpreadsheetError } from "../spreadsheet-errors";
|
|
6
|
+
import type { CellValue } from "../types";
|
|
7
|
+
/** One value an argument contributed, tagged by where it came from. A range cell
|
|
8
|
+
* was already filtered by the range getter; a scalar is whatever the argument
|
|
9
|
+
* evaluated to and may hold no number at all. */
|
|
10
|
+
interface ArgumentValue {
|
|
11
|
+
value: CellValue;
|
|
12
|
+
isScalar: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare const collectArgumentValues: (args: string[], context: FunctionContext, readRange: RangeGetter) => ArgumentValue[];
|
|
15
|
+
/** The numbers an aggregate reads from its arguments, or the first error among them in argument
|
|
16
|
+
* order — an error cell in a range, or an argument that evaluated to one — read in one pass, so
|
|
17
|
+
* no argument is read or evaluated twice. A range keeps only the cells that hold a number, as the
|
|
18
|
+
* numeric read does. */
|
|
19
|
+
export declare const collectNumbersOrError: (args: string[], context: FunctionContext) => number[] | SpreadsheetError;
|
|
20
|
+
/** The cells of a range read blank-aware that hold a number, as numbers — what the numeric read keeps. */
|
|
21
|
+
export declare const rangeNumbers: (values: CellValue[]) => number[];
|
|
22
|
+
/** The handler's rule over the numbers of its arguments, or the first error among them. */
|
|
23
|
+
export declare const overNumbers: (rule: (values: number[]) => CellValue) => FunctionHandler;
|
|
5
24
|
export declare const collectNumericValues: (args: string[], context: FunctionContext) => number[];
|
|
25
|
+
export {};
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Locate the start offset of a specific cell value inside a
|
|
3
|
-
* pretty-printed JSON spreadsheet document. Extracted from
|
|
4
|
-
* `handleTableClick` in `src/plugins/spreadsheet/View.vue` where the
|
|
5
|
-
* inline scanner pushed cognitive complexity to 163.
|
|
6
|
-
*
|
|
7
|
-
* The scanner walks the raw editor text character-by-character,
|
|
8
|
-
* tracking string boundaries, bracket depth, and object depth to
|
|
9
|
-
* find the n-th cell of the m-th row within a named sheet's `data`
|
|
10
|
-
* array. We deliberately do NOT parse the JSON — we need the
|
|
11
|
-
* character offset inside the user's text buffer (which may not be
|
|
12
|
-
* valid JSON mid-edit), so a positional scan is required.
|
|
13
|
-
*
|
|
14
|
-
* Pure — no refs, no DOM. Returns -1 if the cell can't be located.
|
|
15
|
-
* Tested in `test/plugins/spreadsheet/engine/test_jsonCellLocator.ts`.
|
|
16
|
-
*/
|
|
17
1
|
/**
|
|
18
2
|
* Given the pretty-printed JSON editor text, a sheet name, and
|
|
19
3
|
* (rowIndex, colIndex), return the character offset of that cell's
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The logical literals `TRUE` and `FALSE` written in a formula, in any case, as the boolean values
|
|
3
|
+
* a logical cell already renders as (`true` / `false`), so a written TRUE and a cell holding TRUE
|
|
4
|
+
* read alike. A function call (`TRUE()`), a sheet name (`TRUE!A1`) and text in quotes are left.
|
|
5
|
+
*/
|
|
6
|
+
export declare function logicalLiteralsAsBooleans(formula: string): string;
|
|
7
|
+
/** The boolean an expression is when it is nothing but one, or null. */
|
|
8
|
+
export declare function loneBoolean(expr: string): boolean | null;
|
|
9
|
+
/** An expression with its booleans as the numbers arithmetic reads them (TRUE is 1), when it holds
|
|
10
|
+
* no text that could contain the words. */
|
|
11
|
+
export declare function booleansAsNumbers(expr: string): string;
|
|
@@ -12,7 +12,7 @@ import { type SpreadsheetError } from "./spreadsheet-errors";
|
|
|
12
12
|
* `ROUND(-2.5, 0)` came back -2 instead of -3). */
|
|
13
13
|
export declare function roundTo(value: number, digits: number): number;
|
|
14
14
|
/** Excel ROUNDUP: away from zero. */
|
|
15
|
-
export declare function roundUpTo(value: number, digits: number): number;
|
|
15
|
+
export declare function roundUpTo(value: number, digits: number): number | SpreadsheetError;
|
|
16
16
|
/** Excel ROUNDDOWN: toward zero. */
|
|
17
17
|
export declare function roundDownTo(value: number, digits: number): number;
|
|
18
18
|
/** Excel FLOOR: nearest multiple of `significance` toward zero; opposite signs
|
|
@@ -27,7 +27,9 @@ export declare function ceilingToSignificance(value: number, significance: numbe
|
|
|
27
27
|
* zero is #DIV/0!, not a silent 0. */
|
|
28
28
|
export declare function modulo(value: number, divisor: number): number | SpreadsheetError;
|
|
29
29
|
/** Excel POWER: a negative base with a non-integer exponent has no real root, so
|
|
30
|
-
* it is #NUM! rather than JS's NaN.
|
|
30
|
+
* it is #NUM! rather than JS's NaN. 0 to a negative power divides by zero
|
|
31
|
+
* (#DIV/0!), 0^0 is #NUM!, and a result too large for a number is #NUM! where
|
|
32
|
+
* JS answers Infinity. */
|
|
31
33
|
export declare function power(base: number, exponent: number): number | SpreadsheetError;
|
|
32
34
|
/** Natural log guarded to its domain: `LN(x)` for `x <= 0` is #NUM!, not
|
|
33
35
|
* -∞ / NaN. Reused by LN and LOG. */
|
|
@@ -36,3 +36,9 @@ export declare function holdsNumber(value: CellValue): boolean;
|
|
|
36
36
|
* leading number, matching the engine's other numeric reads.
|
|
37
37
|
*/
|
|
38
38
|
export declare function toScalarNumber(value: CellValue): number | SpreadsheetError;
|
|
39
|
+
/**
|
|
40
|
+
* Whether a calculated cell value counts as a number in a range read by SUM, AVERAGE or COUNT:
|
|
41
|
+
* a number, or text that is entirely a number. A logical value and an empty string — what a
|
|
42
|
+
* formula like `=IF(…,"",…)` leaves — are not, as in Excel.
|
|
43
|
+
*/
|
|
44
|
+
export declare function isRangeNumber(value: CellValue): boolean;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* allowing modular organization and easy extension of formula capabilities.
|
|
6
6
|
*/
|
|
7
7
|
import type { CellValue } from "./types";
|
|
8
|
+
import { type SpreadsheetError } from "./spreadsheet-errors";
|
|
8
9
|
export type { CellValue };
|
|
9
10
|
export type CellGetter = (ref: string) => CellValue;
|
|
10
11
|
export type RangeGetter = (range: string) => CellValue[];
|
|
@@ -16,7 +17,14 @@ export interface FunctionContext {
|
|
|
16
17
|
getCellValue: CellGetter;
|
|
17
18
|
getRangeValues: RangeGetter;
|
|
18
19
|
getRangeValuesRaw?: RawRangeGetter | undefined;
|
|
20
|
+
getRangeValuesKeepingBlanks?: RawRangeGetter | undefined;
|
|
21
|
+
/** How many cells of a range hold something, a formula's "" included (COUNTA). */
|
|
22
|
+
countFilledCells?: ((range: string) => number) | undefined;
|
|
19
23
|
evaluateFormula: (formula: string) => CellValue;
|
|
24
|
+
/** Whether an argument is nothing but a reference to a blank cell, which evaluating reads as 0. */
|
|
25
|
+
isBlankReference?: ((arg: string) => boolean) | undefined;
|
|
26
|
+
/** Read an ambiguous `01/02/2020` as day-first, as the sheet's own dates are. */
|
|
27
|
+
preferDDMMYYYY?: boolean | undefined;
|
|
20
28
|
}
|
|
21
29
|
/** The too-few-arguments error, raised by the evaluator from the registry's
|
|
22
30
|
* `minArgs` before any handler runs — and by `requiredArg` for the argument a
|
|
@@ -41,6 +49,11 @@ export declare const requiredArg: (context: FunctionContext, args: string[], ind
|
|
|
41
49
|
* `FunctionContext` — a host that predates it keeps its old behaviour rather
|
|
42
50
|
* than throwing. */
|
|
43
51
|
export declare const rawRangeReader: (context: FunctionContext) => RangeGetter;
|
|
52
|
+
/** The positional reader with a blank cell read as "" rather than 0, for the functions that
|
|
53
|
+
* must tell a blank from a stored 0: a criteria (`"<2"` does not match a blank), a pairing
|
|
54
|
+
* (CORREL drops a row with a blank side), COUNTA. Lookups keep `rawRangeReader`, where a
|
|
55
|
+
* blank reads as 0 the way Excel's INDEX returns it. */
|
|
56
|
+
export declare const blankAwareRangeReader: (context: FunctionContext) => RangeGetter;
|
|
44
57
|
export type FunctionHandler = (args: string[], context: FunctionContext) => CellValue;
|
|
45
58
|
export interface FunctionDefinition {
|
|
46
59
|
name: string;
|
|
@@ -53,9 +66,15 @@ export interface FunctionDefinition {
|
|
|
53
66
|
}
|
|
54
67
|
declare class FunctionRegistry {
|
|
55
68
|
private functions;
|
|
69
|
+
private overlay;
|
|
56
70
|
register(def: FunctionDefinition): void;
|
|
57
71
|
get(name: string): FunctionDefinition | undefined;
|
|
58
72
|
hasFunction(name: string): boolean;
|
|
73
|
+
/** Whether `name` is one of the engine's own functions, which a workbook may not redefine. */
|
|
74
|
+
isBuiltIn(name: string): boolean;
|
|
75
|
+
/** Run `calculate` with `functions` (keyed by upper-case name) visible as well. Only for a
|
|
76
|
+
* synchronous calculation: nothing else can run between setting the overlay and taking it off. */
|
|
77
|
+
withOverlay<T>(functions: ReadonlyMap<string, FunctionDefinition>, calculate: () => T): T;
|
|
59
78
|
getAllFunctions(): FunctionDefinition[];
|
|
60
79
|
getFunctionsByCategory(): Map<string, FunctionDefinition[]>;
|
|
61
80
|
}
|
|
@@ -63,6 +82,11 @@ export declare const functionRegistry: FunctionRegistry;
|
|
|
63
82
|
/** Whether `name` written before "(" is a function call. A letters-only name is,
|
|
64
83
|
* registered or not (an unknown one reports #NAME?). A name with digits is only
|
|
65
84
|
* when registered: LOG10 is also shaped like a cell reference, so `A1(2)` is not. */
|
|
85
|
+
/** A function name as a formula spells it: letters and digits, with `.`-joined
|
|
86
|
+
* parts for the names current Excel uses (`PERCENTILE.INC`, `STDEV.S`). A part may
|
|
87
|
+
* start with a digit (`T.DIST.2T`). Used as a regex SOURCE by every place that
|
|
88
|
+
* looks for a call. */
|
|
89
|
+
export declare const FUNCTION_NAME_SOURCE = "[A-Z][A-Z0-9]*(?:\\.[A-Z0-9]+)*";
|
|
66
90
|
export declare const isCallableName: (name: string) => boolean;
|
|
67
91
|
/**
|
|
68
92
|
* Lenient numeric coercion for range aggregation: anything unreadable is 0.
|
|
@@ -70,12 +94,16 @@ export declare const isCallableName: (name: string) => boolean;
|
|
|
70
94
|
* in numericCoercion.parseNumericString, shared with the strict scalar read.
|
|
71
95
|
*/
|
|
72
96
|
export declare function toNumber(value: CellValue): number;
|
|
73
|
-
/**
|
|
74
|
-
* Helper function to convert a value to a string
|
|
75
|
-
*/
|
|
97
|
+
/** A value as text, as Excel writes it: a logical value is TRUE or FALSE. */
|
|
76
98
|
export declare function toString(value: CellValue): string;
|
|
77
99
|
/**
|
|
78
100
|
* Helper to parse criteria for conditional functions like COUNTIF, SUMIF
|
|
79
101
|
* Returns a comparison function that tests if a value matches the criteria
|
|
80
102
|
*/
|
|
81
|
-
export declare function parseCriteria(criteria: string): (value: CellValue) => boolean;
|
|
103
|
+
export declare function parseCriteria(criteria: string, preferDDMMYYYY?: boolean): (value: CellValue) => boolean;
|
|
104
|
+
/** The matcher for the criteria argument at `index`, or the error it evaluated to.
|
|
105
|
+
*
|
|
106
|
+
* A criteria is an expression like any other argument: `">=2"`, `C1`, `">="&C1`. Reading its
|
|
107
|
+
* source text instead matched `C1` against the letters "C1", so a criteria held in a cell or
|
|
108
|
+
* built with `&` matched nothing and the function answered a silent 0. */
|
|
109
|
+
export declare function criteriaArg(context: FunctionContext, args: string[], index: number): ((value: CellValue) => boolean) | SpreadsheetError;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading the sheet out of a sheet-qualified reference: `Data!A1`, `'My Sheet'!A1:B2`, and a
|
|
3
|
+
* quoted name holding an apostrophe written twice, as Excel writes it (`'It''s'!A1` names It's).
|
|
4
|
+
*/
|
|
5
|
+
/** A reference split from the sheet it names. */
|
|
6
|
+
export interface SheetQualifiedReference {
|
|
7
|
+
sheetName: string;
|
|
8
|
+
ref: string;
|
|
9
|
+
}
|
|
10
|
+
/** The sheet a reference names and the reference within it, or null when it names no sheet. */
|
|
11
|
+
export declare function splitSheetReference(fullRef: string): SheetQualifiedReference | null;
|
|
12
|
+
/** The index just past the closing quote of the sheet name that opens at `start` (a `'`), a
|
|
13
|
+
* doubled `''` inside it read as part of the name; -1 when the name never closes. */
|
|
14
|
+
export declare function endOfQuotedSheetName(text: string, start: number): number;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comparing text the way Excel sorts it, without depending on the runtime's ICU: the browser
|
|
3
|
+
* and the server both calculate a sheet, and a collation that varies with the ICU build could
|
|
4
|
+
* answer one comparison two ways. Case is ignored and accents count, as in Intl.Collator("en",
|
|
5
|
+
* { sensitivity: "accent" }), whose order on ASCII this reproduces.
|
|
6
|
+
*/
|
|
7
|
+
/** Negative, zero or positive as `left` sorts before, with or after `right`. */
|
|
8
|
+
export declare function compareText(left: string, right: string): number;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Excel comparison (`=` `<>` `<` `>` `<=` `>=`) over values of any type.
|
|
3
|
+
*
|
|
4
|
+
* Comparison binds looser than `&`, so `A1&B1="12"` compares the joined text.
|
|
5
|
+
* Excel orders numbers before text before booleans, compares text by language order
|
|
6
|
+
* without regard to case (accents count), and never finds a number equal to text
|
|
7
|
+
* (`"12"=12` is FALSE). A chain reads left to right: `1=1=TRUE` is `(1=1)=TRUE`.
|
|
8
|
+
*/
|
|
9
|
+
import type { CellValue } from "./types";
|
|
10
|
+
export type ExcelComparisonOperator = "=" | "<>" | "<" | ">" | "<=" | ">=";
|
|
11
|
+
export interface ComparisonChain {
|
|
12
|
+
operands: string[];
|
|
13
|
+
operators: ExcelComparisonOperator[];
|
|
14
|
+
}
|
|
15
|
+
/** The operands and operators of a top-level comparison chain; null when there is none, or when a
|
|
16
|
+
* run is not one of Excel's six operators (`==`, `!=`) or an operand is empty. */
|
|
17
|
+
export declare function splitTopLevelComparisons(expr: string): ComparisonChain | null;
|
|
18
|
+
/** Negative, zero or positive as `left` sorts before, with or after `right` in Excel's order. */
|
|
19
|
+
export declare function compareCellValues(left: CellValue, right: CellValue): number;
|
|
20
|
+
export declare function applyComparison(operator: ExcelComparisonOperator, left: CellValue, right: CellValue): boolean;
|
|
21
|
+
/** Fold a chain left to right; `values` holds one more entry than `operators`. */
|
|
22
|
+
export declare function foldComparisons(values: CellValue[], operators: ExcelComparisonOperator[]): CellValue;
|
|
@@ -7,17 +7,21 @@
|
|
|
7
7
|
* allowlists that gate that evaluation. No engine or evaluator state is
|
|
8
8
|
* captured — every function here is input → output only.
|
|
9
9
|
*/
|
|
10
|
-
/** Excel `^` exponentiation → JS
|
|
10
|
+
/** Excel `^` exponentiation → JS `**`, with Excel's precedence.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
* right
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* JS rejects a unary minus directly before `**` (`-2**2` is a syntax error) and
|
|
13
|
+
* reads `**` right to left. Excel negates first (`-2^2` = 4) and reads `^` left
|
|
14
|
+
* to right (`2^3^2` = 64), so each chain is rebuilt as `((-2)**3)**2`. Text
|
|
15
|
+
* outside a chain, and any `^` inside a string literal, is left as it is. */
|
|
16
16
|
export declare function caretToPow(expr: string): string;
|
|
17
17
|
/** Excel `&` string concatenation → JS `+`, leaving any `&` inside a quoted
|
|
18
18
|
* string literal untouched. A quote toggles the "inside a literal" state only
|
|
19
19
|
* when it is not backslash-escaped. */
|
|
20
20
|
export declare function replaceConcatOperator(expr: string): string;
|
|
21
|
+
/** A space between two `+` or two `-` in a row, outside string literals. JS reads `--` and `++`
|
|
22
|
+
* as decrement and increment, so `=1--2` and `=--2` failed to parse; Excel reads each sign on
|
|
23
|
+
* its own (`1- -2` is 3). Applied to the expression handed to `new Function` only. */
|
|
24
|
+
export declare function separateRepeatedSigns(expr: string): string;
|
|
21
25
|
/** Excel `=` equality → JS `==`, without disturbing `<=`, `>=` or `!=`. A single
|
|
22
26
|
* `=` is rewritten only when flanked by a non-`<>!` char on the left and a
|
|
23
27
|
* non-`=` on the right.
|
|
@@ -35,3 +39,10 @@ export declare function isSafeArithmetic(expr: string): boolean;
|
|
|
35
39
|
/** Whether an expression contains only the characters a comparison evaluation
|
|
36
40
|
* may see: the arithmetic set plus ` < > ! = `. Gates `new Function`. */
|
|
37
41
|
export declare function isSafeComparison(expr: string): boolean;
|
|
42
|
+
interface OperatorToken {
|
|
43
|
+
kind: "literal" | "number" | "word" | "open" | "close" | "caret" | "space" | "symbol";
|
|
44
|
+
text: string;
|
|
45
|
+
}
|
|
46
|
+
/** Split an expression into the tokens operator precedence needs; joining the texts gives the input back. */
|
|
47
|
+
export declare function tokenizeOperators(expr: string): OperatorToken[];
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whole-column (`A:A`, `B:D`) and whole-row (`1:1`, `2:5`) references, rewritten as the bounded
|
|
3
|
+
* range they cover in their sheet: `A:A` becomes `A1:A<last row>`, `1:1` becomes
|
|
4
|
+
* `A1:<last column>1`. Everything past a sheet's data is blank, so the answers are Excel's, and
|
|
5
|
+
* every reader downstream (ranges, lookups, argument checks) sees an ordinary `A1:B2` range.
|
|
6
|
+
*/
|
|
7
|
+
/** How far a sheet's data reaches: the number of rows, and the longest row's length. */
|
|
8
|
+
export interface SheetExtent {
|
|
9
|
+
rows: number;
|
|
10
|
+
columns: number;
|
|
11
|
+
}
|
|
12
|
+
/** The extent of the sheet a reference names (`null` for the formula's own sheet), or null when there is no such sheet. */
|
|
13
|
+
export type ExtentOf = (sheetName: string | null) => SheetExtent | null;
|
|
14
|
+
/**
|
|
15
|
+
* The formula with every whole-column and whole-row reference bounded to its sheet's data. Text
|
|
16
|
+
* inside a string literal (`"A:A"`) is left as written. A reference to a sheet that does not
|
|
17
|
+
* exist is left as written too, so it fails as any reference to that sheet does.
|
|
18
|
+
*/
|
|
19
|
+
export declare function boundWholeReferences(formula: string, extentOf: ExtentOf): string;
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./samples-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./samples-UnTPgkyq.cjs"),t=require("./core-Cf9Pxo_q.cjs");exports.MAX_RANGE_CELLS=t.t,exports.SYSTEM_PROMPT=e.w,exports.TOOL_DEFINITION=e.T,exports.TOOL_NAME=e.E,exports.calculatedRange=t.n,exports.executeSpreadsheet=e.n,exports.executeSpreadsheetDispatch=e.g,exports.isSpreadsheetArtifactPath=e.y,exports.isSpreadsheetDispatchArgs=e._,exports.pluginCore=e.r,exports.readCalculatedRange=t.r,exports.samples=e.t;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as l, r as u, t as d } from "./core-
|
|
3
|
-
export { d as MAX_RANGE_CELLS,
|
|
1
|
+
import { E as e, T as t, _ as n, g as r, n as i, r as a, t as o, w as s, y as c } from "./samples-C5JjpxYJ.js";
|
|
2
|
+
import { n as l, r as u, t as d } from "./core-CTRlKL9k.js";
|
|
3
|
+
export { d as MAX_RANGE_CELLS, s as SYSTEM_PROMPT, t as TOOL_DEFINITION, e as TOOL_NAME, l as calculatedRange, i as executeSpreadsheet, r as executeSpreadsheetDispatch, c as isSpreadsheetArtifactPath, n as isSpreadsheetDispatchArgs, a as pluginCore, u as readCalculatedRange, o as samples };
|
package/dist/lang/messages.d.ts
CHANGED
|
@@ -12,6 +12,11 @@ export interface Messages {
|
|
|
12
12
|
dataMustBeArray: string;
|
|
13
13
|
loadFailed(error: string): string;
|
|
14
14
|
saveFailed(error: string): string;
|
|
15
|
+
fileChangedElsewhere: string;
|
|
16
|
+
saveConflict: string;
|
|
17
|
+
useFileVersion: string;
|
|
18
|
+
overwriteWithMine: string;
|
|
19
|
+
cellEditorClosedByChange: string;
|
|
15
20
|
invalidJsonAlert(error: string): string;
|
|
16
21
|
unknownError: string;
|
|
17
22
|
update: string;
|