@rowsncolumns/fast-formula-parser 6.2.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +319 -0
- package/dist/cjs/index.js +45768 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/index.js +45747 -0
- package/dist/esm/index.js.map +1 -0
- package/index.d.ts +234 -0
- package/package.json +63 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
declare module "@rowsncolumns/fast-formula-parser" {
|
|
2
|
+
export const MAX_ROW = 1048576;
|
|
3
|
+
export const MAX_COLUMN = 16384;
|
|
4
|
+
|
|
5
|
+
/** Set of all implemented function names for O(1) lookup */
|
|
6
|
+
export const implementedFunctionNames: Set<string>;
|
|
7
|
+
export type CellCoords = {
|
|
8
|
+
sheet?: string;
|
|
9
|
+
row: number;
|
|
10
|
+
col: number;
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
property?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type CellRange = {
|
|
16
|
+
sheet?: string;
|
|
17
|
+
from: Omit<CellCoords, "sheet">;
|
|
18
|
+
to: Omit<CellCoords, "sheet">;
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export class FormulaError {
|
|
23
|
+
readonly error: string;
|
|
24
|
+
readonly message?: string;
|
|
25
|
+
readonly details?: string;
|
|
26
|
+
constructor(error: string, message?: string, details?: string);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function lex(text: string): LexResult;
|
|
30
|
+
function tolerantLex(text: string): LexResult;
|
|
31
|
+
const tokenVocabulary: Record<string, import("chevrotain").TokenType>;
|
|
32
|
+
const allTokens: import("chevrotain").TokenType[];
|
|
33
|
+
export type LexResult = {
|
|
34
|
+
tokens: Token[];
|
|
35
|
+
errors: TokenError[];
|
|
36
|
+
groups: Record<string, string>;
|
|
37
|
+
};
|
|
38
|
+
export type Token = {
|
|
39
|
+
image: string;
|
|
40
|
+
startOffset: number;
|
|
41
|
+
startColumn: number;
|
|
42
|
+
endOffset: number;
|
|
43
|
+
endColumn: number;
|
|
44
|
+
endLine: number;
|
|
45
|
+
tokenType: {
|
|
46
|
+
name: string;
|
|
47
|
+
};
|
|
48
|
+
tokenTypeIdx: number;
|
|
49
|
+
};
|
|
50
|
+
export type TokenError = {
|
|
51
|
+
line: number;
|
|
52
|
+
column: number;
|
|
53
|
+
message: string;
|
|
54
|
+
};
|
|
55
|
+
export { lex, tolerantLex, tokenVocabulary, allTokens };
|
|
56
|
+
|
|
57
|
+
export interface FormulaParserConfig {
|
|
58
|
+
functionsNeedContext?: Record<string, Function>;
|
|
59
|
+
onVariable?: (
|
|
60
|
+
name: string,
|
|
61
|
+
sheetName: string,
|
|
62
|
+
position: CellCoords,
|
|
63
|
+
) => CellRange | CellCoords | undefined | FormulaResult;
|
|
64
|
+
onCell?: (
|
|
65
|
+
coords: CellCoords,
|
|
66
|
+
) =>
|
|
67
|
+
| string
|
|
68
|
+
| number
|
|
69
|
+
| boolean
|
|
70
|
+
| Date
|
|
71
|
+
| null
|
|
72
|
+
| undefined
|
|
73
|
+
| FormulaError
|
|
74
|
+
| import("@rowsncolumns/common-types").StructuredResult;
|
|
75
|
+
onRange?: (
|
|
76
|
+
range: CellRange,
|
|
77
|
+
) =>
|
|
78
|
+
| (
|
|
79
|
+
| string
|
|
80
|
+
| number
|
|
81
|
+
| boolean
|
|
82
|
+
| Date
|
|
83
|
+
| null
|
|
84
|
+
| undefined
|
|
85
|
+
| FormulaError
|
|
86
|
+
| import("@rowsncolumns/common-types").StructuredResult
|
|
87
|
+
)[][]
|
|
88
|
+
| undefined;
|
|
89
|
+
onStructuredReference?: (
|
|
90
|
+
tableName: string | undefined,
|
|
91
|
+
columnName: string[] | undefined,
|
|
92
|
+
thisRow: boolean,
|
|
93
|
+
specialItem: string | undefined,
|
|
94
|
+
sheetName: string,
|
|
95
|
+
coords: CellCoords,
|
|
96
|
+
) => CellCoords | CellRange | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Resolve Excel's `A1#` spilled-range operator. Called when a cell
|
|
99
|
+
* ref is flagged `isSpilledRange`. Return the current spill bounds
|
|
100
|
+
* (`{from, to, sheet}`) of the dynamic-array formula anchored at
|
|
101
|
+
* the given coords, a `FormulaError` (`#REF!` / `#NAME?`) when no
|
|
102
|
+
* spill exists, or `undefined` to fall back to `#REF!`.
|
|
103
|
+
*/
|
|
104
|
+
onSpilledRange?: (ref: {
|
|
105
|
+
col?: number;
|
|
106
|
+
row?: number;
|
|
107
|
+
sheet?: string;
|
|
108
|
+
}) => CellRange | FormulaError | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Report row visibility so SUBTOTAL can exclude hidden rows.
|
|
111
|
+
* Filtered-out rows are excluded for every function_number;
|
|
112
|
+
* manually-hidden rows only for 101-111.
|
|
113
|
+
*/
|
|
114
|
+
onRowHidden?: (ref: {
|
|
115
|
+
sheet?: string;
|
|
116
|
+
row: number;
|
|
117
|
+
}) => { hiddenByFilter?: boolean; hiddenByUser?: boolean } | undefined;
|
|
118
|
+
webServiceProvider?: (
|
|
119
|
+
url: string,
|
|
120
|
+
) =>
|
|
121
|
+
| string
|
|
122
|
+
| null
|
|
123
|
+
| undefined
|
|
124
|
+
| FormulaError
|
|
125
|
+
| Promise<string | null | undefined | FormulaError>;
|
|
126
|
+
fetch?: typeof fetch;
|
|
127
|
+
locale?: string;
|
|
128
|
+
}
|
|
129
|
+
export type FormulaResultArray = (string | number | boolean | Date)[][];
|
|
130
|
+
|
|
131
|
+
export type CompiledFormula = {
|
|
132
|
+
tokens: import("chevrotain").IToken[];
|
|
133
|
+
source?: string;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export type RecursiveFormula = {
|
|
137
|
+
_formulaResult: string;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export type FormulaResult =
|
|
141
|
+
| string
|
|
142
|
+
| number
|
|
143
|
+
| Date
|
|
144
|
+
| boolean
|
|
145
|
+
| undefined
|
|
146
|
+
| null
|
|
147
|
+
| FormulaResultArray
|
|
148
|
+
| import("@rowsncolumns/common-types").StructuredResult
|
|
149
|
+
| FormulaError
|
|
150
|
+
| RecursiveFormula
|
|
151
|
+
| import("@rowsncolumns/calculator").DataSource;
|
|
152
|
+
|
|
153
|
+
export default class FormulaParser<T extends unknown = any> {
|
|
154
|
+
constructor(config: FormulaParserConfig);
|
|
155
|
+
locale?: string;
|
|
156
|
+
parseAsync: (
|
|
157
|
+
text: string,
|
|
158
|
+
position: CellCoords,
|
|
159
|
+
returnArray?: boolean,
|
|
160
|
+
) => Promise<FormulaResult | undefined | null>;
|
|
161
|
+
parse: (
|
|
162
|
+
text: string,
|
|
163
|
+
position: CellCoords,
|
|
164
|
+
returnArray?: boolean,
|
|
165
|
+
) => FormulaResult;
|
|
166
|
+
parseCompiled: (
|
|
167
|
+
compiled: CompiledFormula,
|
|
168
|
+
position: CellCoords,
|
|
169
|
+
returnArray?: boolean,
|
|
170
|
+
) => FormulaResult;
|
|
171
|
+
parseCompiledAsync: (
|
|
172
|
+
compiled: CompiledFormula,
|
|
173
|
+
position: CellCoords,
|
|
174
|
+
returnArray?: boolean,
|
|
175
|
+
) => Promise<FormulaResult | undefined | null>;
|
|
176
|
+
compile(text: string): CompiledFormula;
|
|
177
|
+
static compileFormula(text: string): CompiledFormula;
|
|
178
|
+
position: CellCoords & { signal?: AbortSignal };
|
|
179
|
+
onRecalculation?(
|
|
180
|
+
position: CellCoords,
|
|
181
|
+
results: FormulaResult | null,
|
|
182
|
+
cleanup?: () => void,
|
|
183
|
+
): void;
|
|
184
|
+
registerCleanupFunction(position: CellCoords, cleanup?: () => void);
|
|
185
|
+
markAsQueued?(position: CellCoords): void;
|
|
186
|
+
markAsLoading?(position: CellCoords): void;
|
|
187
|
+
markAsError?(position: CellCoords, value: string): void;
|
|
188
|
+
getSheetId(sheetName: string): number;
|
|
189
|
+
getSheetIndex?(sheetName?: string): number | undefined;
|
|
190
|
+
getSheetCount?(): number;
|
|
191
|
+
makeKey(position: import("@rowsncolumns/dag").CellCoordinate): string;
|
|
192
|
+
addArrayReference(
|
|
193
|
+
source: import("@rowsncolumns/dag").CellCoordinate,
|
|
194
|
+
result: FormulaResultArray,
|
|
195
|
+
): void;
|
|
196
|
+
isPreview?: boolean;
|
|
197
|
+
getCellData(
|
|
198
|
+
position: CellCoords | CellRange,
|
|
199
|
+
): T | undefined | null | (T | undefined | null)[];
|
|
200
|
+
|
|
201
|
+
/** Get a Set of all implemented function names for O(1) lookup */
|
|
202
|
+
static getImplementedFunctionNames(
|
|
203
|
+
config?: FormulaParserConfig,
|
|
204
|
+
): Set<string>;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface DepParserConfig
|
|
208
|
+
extends Pick<FormulaParserConfig, "onVariable" | "onStructuredReference"> {}
|
|
209
|
+
export class DepParser {
|
|
210
|
+
constructor(config: DepParserConfig);
|
|
211
|
+
parse: (text: string, position: CellCoords) => CellCoords[] | CellRange[];
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function accept(
|
|
215
|
+
value: string | number,
|
|
216
|
+
type: Types,
|
|
217
|
+
defValue?: string | number | undefined,
|
|
218
|
+
flat?: boolean,
|
|
219
|
+
allowSingleValue?: boolean,
|
|
220
|
+
): string | number | boolean | {} | any[];
|
|
221
|
+
export const FormulaHelpers: {
|
|
222
|
+
accept: typeof accept;
|
|
223
|
+
};
|
|
224
|
+
export enum Types {
|
|
225
|
+
NUMBER = 0,
|
|
226
|
+
ARRAY = 1,
|
|
227
|
+
BOOLEAN = 2,
|
|
228
|
+
STRING = 3,
|
|
229
|
+
RANGE_REF = 4,
|
|
230
|
+
CELL_REF = 5,
|
|
231
|
+
COLLECTIONS = 6, // Unions of references
|
|
232
|
+
NUMBER_NO_BOOLEAN = 10,
|
|
233
|
+
}
|
|
234
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rowsncolumns/fast-formula-parser",
|
|
3
|
+
"version": "6.2.32",
|
|
4
|
+
"description": "fast excel formula parser",
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"module": "./dist/esm/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./index.d.ts",
|
|
10
|
+
"import": "./dist/esm/index.js",
|
|
11
|
+
"require": "./dist/cjs/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"typings": "index.d.ts",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "vitest --run",
|
|
17
|
+
"prepublishOnly": "yarn run build && yarn run test",
|
|
18
|
+
"build": "rollup --config rollup.config.mjs",
|
|
19
|
+
"build:watch": "rollup --watch --config rollup.config.mjs",
|
|
20
|
+
"diagram": "node grammar/diagram.js",
|
|
21
|
+
"docs": "yarn run diagram && jsdoc --configure .jsdoc.json --verbose",
|
|
22
|
+
"publish:docs": "yarn run docs && yarn run coverage && gh-pages -d docs"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/rowsncolumns/spreadsheet.git"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/rowsncolumns/spreadsheet/issues"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"excel",
|
|
33
|
+
"formula",
|
|
34
|
+
"spreadsheet",
|
|
35
|
+
"javascript",
|
|
36
|
+
"js",
|
|
37
|
+
"parser",
|
|
38
|
+
"excel-formula"
|
|
39
|
+
],
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"index.d.ts"
|
|
43
|
+
],
|
|
44
|
+
"author": "Lester(Dishu) Lyu",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@rowsncolumns/utils": ">=9.2.35",
|
|
48
|
+
"bahttext": "^2.3.0",
|
|
49
|
+
"bessel": "^1.0.2",
|
|
50
|
+
"chevrotain": "^10.5.0",
|
|
51
|
+
"jstat": "^1.9.6",
|
|
52
|
+
"jsonpath-plus": "^10.2.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@babel/preset-env": "^7.29.7",
|
|
56
|
+
"@babel/preset-react": "^7.29.7",
|
|
57
|
+
"@babel/preset-typescript": "^7.29.7",
|
|
58
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
59
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
60
|
+
"@rowsncolumns/common-types": ">=5.2.29",
|
|
61
|
+
"rollup": "^4.41.1"
|
|
62
|
+
}
|
|
63
|
+
}
|