@borgar/fx 4.13.0 → 5.0.0
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/dist/index-BMr6cTgc.d.cts +1444 -0
- package/dist/index-BMr6cTgc.d.ts +1444 -0
- package/dist/index.cjs +3054 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2984 -0
- package/dist/index.js.map +1 -0
- package/dist/xlsx/index.cjs +3120 -0
- package/dist/xlsx/index.cjs.map +1 -0
- package/dist/xlsx/index.d.cts +55 -0
- package/dist/xlsx/index.d.ts +55 -0
- package/dist/xlsx/index.js +3049 -0
- package/dist/xlsx/index.js.map +1 -0
- package/docs/API.md +2959 -718
- package/docs/AST_format.md +2 -2
- package/eslint.config.mjs +40 -0
- package/lib/a1.spec.ts +32 -0
- package/lib/a1.ts +26 -0
- package/lib/addA1RangeBounds.ts +50 -0
- package/lib/addTokenMeta.spec.ts +166 -0
- package/lib/{addTokenMeta.js → addTokenMeta.ts} +53 -33
- package/lib/astTypes.ts +211 -0
- package/lib/cloneToken.ts +29 -0
- package/lib/{constants.js → constants.ts} +6 -3
- package/lib/fixRanges.spec.ts +220 -0
- package/lib/fixRanges.ts +260 -0
- package/lib/fromCol.spec.ts +15 -0
- package/lib/{fromCol.js → fromCol.ts} +1 -1
- package/lib/index.spec.ts +119 -0
- package/lib/index.ts +76 -0
- package/lib/isNodeType.ts +151 -0
- package/lib/isType.spec.ts +208 -0
- package/lib/{isType.js → isType.ts} +26 -25
- package/lib/lexers/{advRangeOp.js → advRangeOp.ts} +1 -1
- package/lib/lexers/{canEndRange.js → canEndRange.ts} +2 -2
- package/lib/lexers/{lexBoolean.js → lexBoolean.ts} +25 -6
- package/lib/lexers/{lexContext.js → lexContext.ts} +14 -6
- package/lib/lexers/{lexError.js → lexError.ts} +3 -3
- package/lib/lexers/{lexFunction.js → lexFunction.ts} +3 -2
- package/lib/lexers/lexNameFuncCntx.ts +112 -0
- package/lib/lexers/{lexNamed.js → lexNamed.ts} +4 -4
- package/lib/lexers/{lexNewLine.js → lexNewLine.ts} +3 -2
- package/lib/lexers/{lexNumber.js → lexNumber.ts} +4 -3
- package/lib/lexers/{lexOperator.js → lexOperator.ts} +5 -4
- package/lib/lexers/lexRange.ts +15 -0
- package/lib/lexers/{lexRangeA1.js → lexRangeA1.ts} +11 -7
- package/lib/lexers/{lexRangeR1C1.js → lexRangeR1C1.ts} +10 -6
- package/lib/lexers/{lexRangeTrim.js → lexRangeTrim.ts} +3 -2
- package/lib/lexers/{lexRefOp.js → lexRefOp.ts} +4 -3
- package/lib/lexers/{lexString.js → lexString.ts} +3 -3
- package/lib/lexers/{lexStructured.js → lexStructured.ts} +5 -5
- package/lib/lexers/{lexWhitespace.js → lexWhitespace.ts} +3 -2
- package/lib/lexers/sets.ts +51 -0
- package/lib/mergeRefTokens.spec.ts +141 -0
- package/lib/{mergeRefTokens.js → mergeRefTokens.ts} +14 -9
- package/lib/nodeTypes.ts +54 -0
- package/lib/parse.spec.ts +1410 -0
- package/lib/{parser.js → parse.ts} +81 -63
- package/lib/parseA1Range.spec.ts +233 -0
- package/lib/parseA1Range.ts +206 -0
- package/lib/parseA1Ref.spec.ts +337 -0
- package/lib/parseA1Ref.ts +115 -0
- package/lib/parseR1C1Range.ts +191 -0
- package/lib/parseR1C1Ref.spec.ts +323 -0
- package/lib/parseR1C1Ref.ts +127 -0
- package/lib/parseRef.spec.ts +90 -0
- package/lib/parseRef.ts +240 -0
- package/lib/{parseSRange.js → parseSRange.ts} +15 -10
- package/lib/parseStructRef.spec.ts +168 -0
- package/lib/parseStructRef.ts +76 -0
- package/lib/stringifyA1Range.spec.ts +72 -0
- package/lib/stringifyA1Range.ts +72 -0
- package/lib/stringifyA1Ref.spec.ts +64 -0
- package/lib/stringifyA1Ref.ts +59 -0
- package/lib/{stringifyPrefix.js → stringifyPrefix.ts} +17 -2
- package/lib/stringifyR1C1Range.spec.ts +92 -0
- package/lib/stringifyR1C1Range.ts +73 -0
- package/lib/stringifyR1C1Ref.spec.ts +63 -0
- package/lib/stringifyR1C1Ref.ts +67 -0
- package/lib/stringifyStructRef.spec.ts +124 -0
- package/lib/stringifyStructRef.ts +113 -0
- package/lib/stringifyTokens.ts +15 -0
- package/lib/toCol.spec.ts +11 -0
- package/lib/{toCol.js → toCol.ts} +4 -4
- package/lib/tokenTypes.ts +76 -0
- package/lib/tokenize-srefs.spec.ts +429 -0
- package/lib/tokenize.spec.ts +2103 -0
- package/lib/tokenize.ts +346 -0
- package/lib/translate.spec.ts +35 -0
- package/lib/translateToA1.spec.ts +247 -0
- package/lib/translateToA1.ts +231 -0
- package/lib/translateToR1C1.spec.ts +227 -0
- package/lib/translateToR1C1.ts +145 -0
- package/lib/types.ts +179 -0
- package/lib/xlsx/index.spec.ts +27 -0
- package/lib/xlsx/index.ts +32 -0
- package/package.json +45 -31
- package/tsconfig.json +28 -0
- package/typedoc-ignore-links.ts +17 -0
- package/typedoc.json +41 -0
- package/.eslintrc +0 -22
- package/benchmark/benchmark.js +0 -48
- package/benchmark/formulas.json +0 -15677
- package/dist/fx.d.ts +0 -823
- package/dist/fx.js +0 -2
- package/dist/package.json +0 -1
- package/lib/a1.js +0 -348
- package/lib/a1.spec.js +0 -458
- package/lib/addTokenMeta.spec.js +0 -153
- package/lib/astTypes.js +0 -96
- package/lib/extraTypes.js +0 -74
- package/lib/fixRanges.js +0 -104
- package/lib/fixRanges.spec.js +0 -171
- package/lib/fromCol.spec.js +0 -11
- package/lib/index.js +0 -134
- package/lib/index.spec.js +0 -67
- package/lib/isType.spec.js +0 -168
- package/lib/lexer-srefs.spec.js +0 -324
- package/lib/lexer.js +0 -264
- package/lib/lexer.spec.js +0 -1953
- package/lib/lexers/lexRange.js +0 -8
- package/lib/lexers/sets.js +0 -38
- package/lib/mergeRefTokens.spec.js +0 -121
- package/lib/package.json +0 -1
- package/lib/parseRef.js +0 -157
- package/lib/parseRef.spec.js +0 -71
- package/lib/parseStructRef.js +0 -48
- package/lib/parseStructRef.spec.js +0 -164
- package/lib/parser.spec.js +0 -1208
- package/lib/rc.js +0 -341
- package/lib/rc.spec.js +0 -403
- package/lib/stringifyStructRef.js +0 -80
- package/lib/stringifyStructRef.spec.js +0 -182
- package/lib/toCol.spec.js +0 -11
- package/lib/translate-toA1.spec.js +0 -214
- package/lib/translate-toRC.spec.js +0 -197
- package/lib/translate.js +0 -239
- package/lib/translate.spec.js +0 -21
- package/rollup.config.mjs +0 -22
- package/tsd.json +0 -12
|
@@ -0,0 +1,1444 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A formula language token.
|
|
3
|
+
*/
|
|
4
|
+
type Token = Record<string, unknown> & {
|
|
5
|
+
/** The type of the token */
|
|
6
|
+
type: string;
|
|
7
|
+
/** The value of the token */
|
|
8
|
+
value: string;
|
|
9
|
+
/** Signifies an unterminated string token */
|
|
10
|
+
unterminated?: boolean;
|
|
11
|
+
/** Source position offsets to the token */
|
|
12
|
+
loc?: number[];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A token with extra meta data.
|
|
16
|
+
*/
|
|
17
|
+
type TokenEnhanced = Token & {
|
|
18
|
+
/** A zero based position in a token list */
|
|
19
|
+
index: number;
|
|
20
|
+
/** The ID of a group which this token belongs (e.g. matching parens) */
|
|
21
|
+
groupId?: string;
|
|
22
|
+
/** This token's level of nesting inside parentheses */
|
|
23
|
+
depth?: number;
|
|
24
|
+
/** Token is of unknown type or a paren without a match */
|
|
25
|
+
error?: boolean;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A range in R1C1 style coordinates.
|
|
29
|
+
*/
|
|
30
|
+
type RangeR1C1 = {
|
|
31
|
+
/** Top row of the range */
|
|
32
|
+
r0?: number | null;
|
|
33
|
+
/** Bottom row of the range */
|
|
34
|
+
r1?: number | null;
|
|
35
|
+
/** Left column of the range */
|
|
36
|
+
c0?: number | null;
|
|
37
|
+
/** Right column of the range */
|
|
38
|
+
c1?: number | null;
|
|
39
|
+
/** Signifies that r0 is an absolute value */
|
|
40
|
+
$r0?: boolean | null;
|
|
41
|
+
/** Signifies that r1 is an absolute value */
|
|
42
|
+
$r1?: boolean | null;
|
|
43
|
+
/** Signifies that c0 is an absolute value */
|
|
44
|
+
$c0?: boolean | null;
|
|
45
|
+
/** Signifies that c1 is an absolute value */
|
|
46
|
+
$c1?: boolean | null;
|
|
47
|
+
/** Should empty rows and columns at the top/left or bottom/right be discarded when range is read? */
|
|
48
|
+
trim?: 'head' | 'tail' | 'both' | null;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* A range in A1 style coordinates.
|
|
52
|
+
*/
|
|
53
|
+
type RangeA1 = {
|
|
54
|
+
/** Top row of the range */
|
|
55
|
+
top: number | null;
|
|
56
|
+
/** Left column of the range */
|
|
57
|
+
left: number | null;
|
|
58
|
+
/** Bottom row of the range */
|
|
59
|
+
bottom?: number | null;
|
|
60
|
+
/** Right column of the range */
|
|
61
|
+
right?: number | null;
|
|
62
|
+
/** Signifies that top is a "locked" value */
|
|
63
|
+
$top?: boolean | null;
|
|
64
|
+
/** Signifies that bottom is a "locked" value */
|
|
65
|
+
$bottom?: boolean | null;
|
|
66
|
+
/** Signifies that left is a "locked" value */
|
|
67
|
+
$left?: boolean | null;
|
|
68
|
+
/** Signifies that right is a "locked" value */
|
|
69
|
+
$right?: boolean | null;
|
|
70
|
+
/** Should empty rows and columns at the top/left or bottom/right be discarded when range is read? */
|
|
71
|
+
trim?: 'head' | 'tail' | 'both' | null;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* A reference containing an A1 style range. See [Prefixes.md](Prefixes.md) for
|
|
75
|
+
* documentation on how scopes work in Fx.
|
|
76
|
+
*/
|
|
77
|
+
type ReferenceA1 = {
|
|
78
|
+
/** A collection of scopes for the reference */
|
|
79
|
+
context?: string[];
|
|
80
|
+
/** The reference's range */
|
|
81
|
+
range: RangeA1;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* A reference containing an A1 style range. See [Prefixes.md] for
|
|
85
|
+
* documentation on how scopes work in Fx.
|
|
86
|
+
*/
|
|
87
|
+
type ReferenceA1Xlsx = {
|
|
88
|
+
/** A context workbook scope */
|
|
89
|
+
workbookName?: string;
|
|
90
|
+
/** A context sheet scope */
|
|
91
|
+
sheetName?: string;
|
|
92
|
+
/** The reference's range */
|
|
93
|
+
range: RangeA1;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* A reference containing a name. See [Prefixes.md] for
|
|
97
|
+
* documentation on how scopes work in Fx.
|
|
98
|
+
*/
|
|
99
|
+
type ReferenceName = {
|
|
100
|
+
/** A collection of scopes for the reference */
|
|
101
|
+
context?: string[];
|
|
102
|
+
/** The reference's name */
|
|
103
|
+
name: string;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* A reference containing a name. See [Prefixes.md] for
|
|
107
|
+
* documentation on how scopes work in Fx.
|
|
108
|
+
*/
|
|
109
|
+
type ReferenceNameXlsx = {
|
|
110
|
+
/** A context workbook scope */
|
|
111
|
+
workbookName?: string;
|
|
112
|
+
/** A context sheet scope */
|
|
113
|
+
sheetName?: string;
|
|
114
|
+
/** The reference's name */
|
|
115
|
+
name: string;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* A reference containing a R1C1 style range. See [Prefixes.md] for
|
|
119
|
+
* documentation on how scopes work in Fx.
|
|
120
|
+
*/
|
|
121
|
+
type ReferenceR1C1 = {
|
|
122
|
+
/** A collection of scopes for the reference */
|
|
123
|
+
context?: string[];
|
|
124
|
+
/** The reference's range */
|
|
125
|
+
range: RangeR1C1;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* A reference containing a R1C1 style range. See [Prefixes.md] for
|
|
129
|
+
* documentation on how scopes work in Fx.
|
|
130
|
+
*/
|
|
131
|
+
type ReferenceR1C1Xlsx = {
|
|
132
|
+
/** A context workbook scope */
|
|
133
|
+
workbookName?: string;
|
|
134
|
+
/** A context sheet scope */
|
|
135
|
+
sheetName?: string;
|
|
136
|
+
/** The reference's range */
|
|
137
|
+
range: RangeR1C1;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* A reference containing a table slice definition. See [Prefixes.md] for
|
|
141
|
+
* documentation on how scopes work in Fx.
|
|
142
|
+
*/
|
|
143
|
+
type ReferenceStruct = {
|
|
144
|
+
/** A collection of scopes for the reference */
|
|
145
|
+
context?: string[];
|
|
146
|
+
/** The sections this reference targets */
|
|
147
|
+
sections?: string[];
|
|
148
|
+
/** The sections this reference targets */
|
|
149
|
+
columns?: string[];
|
|
150
|
+
/** The table this reference targets */
|
|
151
|
+
table?: string;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* A reference containing a table slice definition. See [Prefixes.md] for
|
|
155
|
+
* documentation on how scopes work in Fx.
|
|
156
|
+
*/
|
|
157
|
+
type ReferenceStructXlsx = {
|
|
158
|
+
/** A context workbook scope */
|
|
159
|
+
workbookName?: string;
|
|
160
|
+
/** A context sheet scope */
|
|
161
|
+
sheetName?: string;
|
|
162
|
+
/** The sections this reference targets */
|
|
163
|
+
sections?: string[];
|
|
164
|
+
/** The sections this reference targets */
|
|
165
|
+
columns?: string[];
|
|
166
|
+
/** The table this reference targets */
|
|
167
|
+
table?: string;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Options for {@link tokenize}.
|
|
172
|
+
*/
|
|
173
|
+
type OptsTokenize = {
|
|
174
|
+
/**
|
|
175
|
+
* Nodes will include source position offsets to the tokens: `{ loc: [ start, end ] }`
|
|
176
|
+
* @defaultValue true
|
|
177
|
+
*/
|
|
178
|
+
withLocation?: boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Should ranges be returned as whole references (`Sheet1!A1:B2`) or as separate tokens for each
|
|
181
|
+
* part: (`Sheet1`,`!`,`A1`,`:`,`B2`). This is the same as calling [`mergeRefTokens`](#mergeRefTokens)
|
|
182
|
+
* @defaultValue true
|
|
183
|
+
*/
|
|
184
|
+
mergeRefs?: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Merges unary minuses with their immediately following number tokens (`-`,`1`) => `-1`
|
|
187
|
+
* (alternatively these will be unary operations in the tree).
|
|
188
|
+
* @defaultValue true
|
|
189
|
+
*/
|
|
190
|
+
negativeNumbers?: boolean;
|
|
191
|
+
/**
|
|
192
|
+
* Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`. These are supported
|
|
193
|
+
* by Google Sheets but not Excel. See: [References.md](./References.md).
|
|
194
|
+
* @defaultValue false
|
|
195
|
+
*/
|
|
196
|
+
allowTernary?: boolean;
|
|
197
|
+
/**
|
|
198
|
+
* Ranges are expected to be in the R1C1 style format rather than the more popular A1 style.
|
|
199
|
+
* @defaultValue false
|
|
200
|
+
*/
|
|
201
|
+
r1c1?: boolean;
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Breaks a string formula into a list of tokens.
|
|
205
|
+
*
|
|
206
|
+
* The returned output will be an array of objects representing the tokens:
|
|
207
|
+
*
|
|
208
|
+
* ```js
|
|
209
|
+
* [
|
|
210
|
+
* { type: FX_PREFIX, value: '=' },
|
|
211
|
+
* { type: FUNCTION, value: 'SUM' },
|
|
212
|
+
* { type: OPERATOR, value: '(' },
|
|
213
|
+
* { type: REF_RANGE, value: 'A1:B2' },
|
|
214
|
+
* { type: OPERATOR, value: ')' }
|
|
215
|
+
* ]
|
|
216
|
+
* ```
|
|
217
|
+
*
|
|
218
|
+
* A collection of token types may be found as an object as the {@link tokenTypes}
|
|
219
|
+
* export on the package.
|
|
220
|
+
*
|
|
221
|
+
* _Warning:_ To support syntax highlighting as you type, `STRING` tokens are allowed to be
|
|
222
|
+
* "unterminated". For example, the incomplete formula `="Hello world` would be
|
|
223
|
+
* tokenized as:
|
|
224
|
+
*
|
|
225
|
+
* ```js
|
|
226
|
+
* [
|
|
227
|
+
* { type: FX_PREFIX, value: '=' },
|
|
228
|
+
* { type: STRING, value: '"Hello world', unterminated: true },
|
|
229
|
+
* ]
|
|
230
|
+
* ```
|
|
231
|
+
*
|
|
232
|
+
* Parsers will need to handle this.
|
|
233
|
+
*
|
|
234
|
+
* @see {@link OptsTokenize}
|
|
235
|
+
* @see {@link tokenTypes}
|
|
236
|
+
* @param formula An Excel formula string (an Excel expression).
|
|
237
|
+
* @param [options] Options
|
|
238
|
+
* @returns An array of Tokens
|
|
239
|
+
*/
|
|
240
|
+
declare function tokenize(formula: string, options?: OptsTokenize): Token[];
|
|
241
|
+
/**
|
|
242
|
+
* Breaks a string formula into a list of tokens.
|
|
243
|
+
*
|
|
244
|
+
* The returned output will be an array of objects representing the tokens:
|
|
245
|
+
*
|
|
246
|
+
* ```js
|
|
247
|
+
* [
|
|
248
|
+
* { type: FX_PREFIX, value: '=' },
|
|
249
|
+
* { type: FUNCTION, value: 'SUM' },
|
|
250
|
+
* { type: OPERATOR, value: '(' },
|
|
251
|
+
* { type: REF_RANGE, value: 'A1:B2' },
|
|
252
|
+
* { type: OPERATOR, value: ')' }
|
|
253
|
+
* ]
|
|
254
|
+
* ```
|
|
255
|
+
*
|
|
256
|
+
* A collection of token types may be found as an object as the {@link tokenTypes}
|
|
257
|
+
* export on the package.
|
|
258
|
+
*
|
|
259
|
+
* _Warning:_ To support syntax highlighting as you type, `STRING` tokens are allowed to be
|
|
260
|
+
* "unterminated". For example, the incomplete formula `="Hello world` would be
|
|
261
|
+
* tokenized as:
|
|
262
|
+
*
|
|
263
|
+
* ```js
|
|
264
|
+
* [
|
|
265
|
+
* { type: FX_PREFIX, value: '=' },
|
|
266
|
+
* { type: STRING, value: '"Hello world', unterminated: true },
|
|
267
|
+
* ]
|
|
268
|
+
* ```
|
|
269
|
+
*
|
|
270
|
+
* @see {@link OptsTokenize}
|
|
271
|
+
* @see {@link tokenTypes}
|
|
272
|
+
* @param formula An Excel formula string (an Excel expression).
|
|
273
|
+
* @param [options] Options
|
|
274
|
+
* @returns An array of Tokens
|
|
275
|
+
*/
|
|
276
|
+
declare function tokenizeXlsx(formula: string, options?: OptsTokenize): Token[];
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Represents the source location information of the node.
|
|
280
|
+
* If the node contains no information about the source location, the field is `null`;
|
|
281
|
+
* otherwise it is an array consisting of a two numbers: A start offset (the position of
|
|
282
|
+
* the first character of the parsed source region) and an end offset (the position of
|
|
283
|
+
* the first character after the parsed source region).
|
|
284
|
+
*/
|
|
285
|
+
type SourceLocation = number[];
|
|
286
|
+
/**
|
|
287
|
+
* All AST nodes are represented by `Node` objects.
|
|
288
|
+
* They may have any prototype inheritance but implement the same basic interface.
|
|
289
|
+
*
|
|
290
|
+
* The `type` field is a string representing the AST variant type.
|
|
291
|
+
* Each subtype of Node is documented below with the specific string of its `type` field.
|
|
292
|
+
* You can use this field to determine which interface a node implements.
|
|
293
|
+
*/
|
|
294
|
+
type Node = {
|
|
295
|
+
/** The type of this AST node. */
|
|
296
|
+
type: string;
|
|
297
|
+
/** The original source position of the node. */
|
|
298
|
+
loc?: SourceLocation;
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* An identifier. These appear on `CallExpression`, `LambdaExpression`, and `LetExpression`
|
|
302
|
+
* and will always be a static string representing the name of a function call or parameter.
|
|
303
|
+
*/
|
|
304
|
+
type Identifier = {
|
|
305
|
+
/** The type of this AST node. */
|
|
306
|
+
type: 'Identifier';
|
|
307
|
+
/** The original source position of the node. */
|
|
308
|
+
loc?: SourceLocation;
|
|
309
|
+
/** The identifying name. */
|
|
310
|
+
name: string;
|
|
311
|
+
} & Node;
|
|
312
|
+
/**
|
|
313
|
+
* An identifier for a range or a name.
|
|
314
|
+
*/
|
|
315
|
+
type ReferenceIdentifier = {
|
|
316
|
+
/** The type of this AST node. */
|
|
317
|
+
type: 'ReferenceIdentifier';
|
|
318
|
+
/** The original source position of the node. */
|
|
319
|
+
loc?: SourceLocation;
|
|
320
|
+
/** The untouched reference value. */
|
|
321
|
+
value: string;
|
|
322
|
+
/** The kind of reference the value holds. */
|
|
323
|
+
kind: 'name' | 'range' | 'beam' | 'table';
|
|
324
|
+
} & Node;
|
|
325
|
+
/**
|
|
326
|
+
* A literal token. Captures numbers, strings, and booleans.
|
|
327
|
+
* Literal errors have their own variant type.
|
|
328
|
+
*/
|
|
329
|
+
type Literal = {
|
|
330
|
+
/** The type of this AST node. */
|
|
331
|
+
type: 'Literal';
|
|
332
|
+
/** The original source position of the node. */
|
|
333
|
+
loc?: SourceLocation;
|
|
334
|
+
/** The untouched literal source. */
|
|
335
|
+
raw: string;
|
|
336
|
+
/** The value of the literal. */
|
|
337
|
+
value: string | number | boolean;
|
|
338
|
+
} & Node;
|
|
339
|
+
/**
|
|
340
|
+
* An Error expression.
|
|
341
|
+
*/
|
|
342
|
+
type ErrorLiteral = {
|
|
343
|
+
/** The type of this AST node. */
|
|
344
|
+
type: 'ErrorLiteral';
|
|
345
|
+
/** The original source position of the node. */
|
|
346
|
+
loc?: SourceLocation;
|
|
347
|
+
/** The untouched literal source. */
|
|
348
|
+
raw: string;
|
|
349
|
+
/** The value of the error. */
|
|
350
|
+
value: string;
|
|
351
|
+
} & Node;
|
|
352
|
+
/**
|
|
353
|
+
* A unary operator expression.
|
|
354
|
+
*/
|
|
355
|
+
type UnaryExpression = {
|
|
356
|
+
/** The type of this AST node. */
|
|
357
|
+
type: 'UnaryExpression';
|
|
358
|
+
/** The original source position of the node. */
|
|
359
|
+
loc?: SourceLocation;
|
|
360
|
+
/** The expression's operator. */
|
|
361
|
+
operator: UnaryOperator;
|
|
362
|
+
/** The arguments for the operator. */
|
|
363
|
+
arguments: AstExpression[];
|
|
364
|
+
} & Node;
|
|
365
|
+
/**
|
|
366
|
+
* A unary operator token.
|
|
367
|
+
*/
|
|
368
|
+
type UnaryOperator = ('+' | '-' | '%' | '#' | '@');
|
|
369
|
+
/**
|
|
370
|
+
* A binary operator expression.
|
|
371
|
+
*/
|
|
372
|
+
type BinaryExpression = {
|
|
373
|
+
/** The type of this AST node. */
|
|
374
|
+
type: 'BinaryExpression';
|
|
375
|
+
/** The original source position of the node. */
|
|
376
|
+
loc?: SourceLocation;
|
|
377
|
+
/** The expression's operator. */
|
|
378
|
+
operator: BinaryOperator;
|
|
379
|
+
/** The arguments for the operator. */
|
|
380
|
+
arguments: AstExpression[];
|
|
381
|
+
} & Node;
|
|
382
|
+
/**
|
|
383
|
+
* A binary operator token.
|
|
384
|
+
*
|
|
385
|
+
* Note that Excels union operator is whitespace so a parser must take care to normalize this to
|
|
386
|
+
* a single space.
|
|
387
|
+
*/
|
|
388
|
+
type BinaryOperator = ('=' | '<' | '>' | '<=' | '>=' | '<>' | '-' | '+' | '*' | '/' | '^' | ':' | ' ' | ',' | '&');
|
|
389
|
+
/**
|
|
390
|
+
* A function call expression.
|
|
391
|
+
*/
|
|
392
|
+
type CallExpression = {
|
|
393
|
+
/** The type of this AST node. */
|
|
394
|
+
type: 'CallExpression';
|
|
395
|
+
/** The original source position of the node. */
|
|
396
|
+
loc?: SourceLocation;
|
|
397
|
+
/** The function being called. */
|
|
398
|
+
callee: Identifier;
|
|
399
|
+
/** The arguments for the function. */
|
|
400
|
+
arguments: AstExpression[];
|
|
401
|
+
} & Node;
|
|
402
|
+
/**
|
|
403
|
+
* An array expression. Excel does not have empty or sparse arrays and restricts array elements to
|
|
404
|
+
* literals. Google Sheets allows `ReferenceIdentifier`s and `CallExpression`s as elements of
|
|
405
|
+
* arrays, the fx parser has options for this but they are off by default.
|
|
406
|
+
*/
|
|
407
|
+
type ArrayExpression = {
|
|
408
|
+
/** The type of this AST node. */
|
|
409
|
+
type: 'ArrayExpression';
|
|
410
|
+
/** The original source position of the node. */
|
|
411
|
+
loc?: SourceLocation;
|
|
412
|
+
/** The elements of the array. */
|
|
413
|
+
elements: (ReferenceIdentifier | Literal | ErrorLiteral | CallExpression)[][];
|
|
414
|
+
} & Node;
|
|
415
|
+
/**
|
|
416
|
+
* A LAMBDA expression.
|
|
417
|
+
*/
|
|
418
|
+
type LambdaExpression = {
|
|
419
|
+
/** The type of this AST node. */
|
|
420
|
+
type: 'LambdaExpression';
|
|
421
|
+
/** The original source position of the node. */
|
|
422
|
+
loc?: SourceLocation;
|
|
423
|
+
/** The LAMBDA's parameters. */
|
|
424
|
+
params: Identifier[];
|
|
425
|
+
/** The LAMBDA's expression. */
|
|
426
|
+
body: AstExpression | null;
|
|
427
|
+
} & Node;
|
|
428
|
+
/**
|
|
429
|
+
* A LET expression.
|
|
430
|
+
*/
|
|
431
|
+
type LetExpression = {
|
|
432
|
+
/** The type of this AST node. */
|
|
433
|
+
type: 'LetExpression';
|
|
434
|
+
/** The original source position of the node. */
|
|
435
|
+
loc?: SourceLocation;
|
|
436
|
+
/** The LET's variable declarations. */
|
|
437
|
+
declarations: LetDeclarator[];
|
|
438
|
+
/** The LET's scoped expression. */
|
|
439
|
+
body: AstExpression | null;
|
|
440
|
+
} & Node;
|
|
441
|
+
/**
|
|
442
|
+
* A LET parameter declaration.
|
|
443
|
+
*/
|
|
444
|
+
type LetDeclarator = {
|
|
445
|
+
/** The type of this AST node. */
|
|
446
|
+
type: 'LetDeclarator';
|
|
447
|
+
/** The original source position of the node. */
|
|
448
|
+
loc?: SourceLocation;
|
|
449
|
+
/** The name of the variable. */
|
|
450
|
+
id: Identifier;
|
|
451
|
+
/** The variable's initializing expression. */
|
|
452
|
+
init: AstExpression | null;
|
|
453
|
+
} & Node;
|
|
454
|
+
/**
|
|
455
|
+
* Represents an evaluate-able expression.
|
|
456
|
+
*/
|
|
457
|
+
type AstExpression = ReferenceIdentifier | Literal | ErrorLiteral | UnaryExpression | BinaryExpression | CallExpression | ArrayExpression | LambdaExpression | LetExpression;
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Options for {@link parse}.
|
|
461
|
+
*/
|
|
462
|
+
type OptsParse = {
|
|
463
|
+
/**
|
|
464
|
+
* Ranges are allowed as elements of arrays. This is a feature in Google Sheets while Excel
|
|
465
|
+
* does not allow it.
|
|
466
|
+
* @defaultValue false
|
|
467
|
+
*/
|
|
468
|
+
permitArrayRanges?: boolean;
|
|
469
|
+
/**
|
|
470
|
+
* Function calls are allowed as elements of arrays. This is a feature in Google Sheets
|
|
471
|
+
* while Excel does not allow it.
|
|
472
|
+
* @defaultValue false
|
|
473
|
+
*/
|
|
474
|
+
permitArrayCalls?: boolean;
|
|
475
|
+
/**
|
|
476
|
+
* Permits any function call where otherwise only functions that return references would
|
|
477
|
+
* be permitted.
|
|
478
|
+
* @defaultValue false
|
|
479
|
+
*/
|
|
480
|
+
looseRefCalls?: boolean;
|
|
481
|
+
};
|
|
482
|
+
/**
|
|
483
|
+
* Parses a string formula or list of tokens into an AST.
|
|
484
|
+
*
|
|
485
|
+
* The parser assumes `mergeRefs` and `negativeNumbers` were `true` when the tokens were generated.
|
|
486
|
+
* It does not yet recognize reference context tokens or know how to deal with unary minuses in
|
|
487
|
+
* arrays.
|
|
488
|
+
*
|
|
489
|
+
* The AST Abstract Syntax Tree's format is documented in
|
|
490
|
+
* [AST_format.md](./AST_format.md).
|
|
491
|
+
*
|
|
492
|
+
* @see {@link OptsParse}
|
|
493
|
+
* @see {@link nodeTypes}
|
|
494
|
+
* @see {@link tokenize}
|
|
495
|
+
* @param tokenlist An array of tokens.
|
|
496
|
+
* @param options Options for the parsers behavior.
|
|
497
|
+
* @returns An AST of nodes.
|
|
498
|
+
*/
|
|
499
|
+
declare function parse(tokenlist: Token[], options?: OptsParse): AstExpression;
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Options for {@link translateFormulaToR1C1}.
|
|
503
|
+
*/
|
|
504
|
+
type OptsTranslateToR1C1 = {
|
|
505
|
+
/**
|
|
506
|
+
* Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`.
|
|
507
|
+
* These are supported by Google Sheets but not Excel.
|
|
508
|
+
* See: [References.md](./References.md).
|
|
509
|
+
* @defaultValue true
|
|
510
|
+
*/
|
|
511
|
+
allowTernary?: boolean;
|
|
512
|
+
};
|
|
513
|
+
/**
|
|
514
|
+
* Translates ranges in a list of tokens from absolute A1 syntax to relative R1C1 syntax.
|
|
515
|
+
*
|
|
516
|
+
* ```js
|
|
517
|
+
* translateFormulaToR1C1("=SUM(E10,$E$2,Sheet!$E$3)", "D10");
|
|
518
|
+
* // => "=SUM(RC[1],R2C5,Sheet!R3C5)");
|
|
519
|
+
* ```
|
|
520
|
+
*
|
|
521
|
+
* @param tokens A token list that should be adjusted.
|
|
522
|
+
* @param anchorCell A simple string reference to an A1 cell ID (`AF123` or`$C$5`).
|
|
523
|
+
* @returns A token list.
|
|
524
|
+
*/
|
|
525
|
+
declare function translateTokensToR1C1(tokens: Token[], anchorCell: string): Token[];
|
|
526
|
+
/**
|
|
527
|
+
* Translates ranges in a formula from absolute A1 syntax to relative R1C1 syntax.
|
|
528
|
+
*
|
|
529
|
+
* ```js
|
|
530
|
+
* translateFormulaToR1C1("=SUM(E10,$E$2,Sheet!$E$3)", "D10");
|
|
531
|
+
* // => "=SUM(RC[1],R2C5,Sheet!R3C5)");
|
|
532
|
+
* ```
|
|
533
|
+
*
|
|
534
|
+
* @see {@link OptsTranslateToR1C1}
|
|
535
|
+
* @param formula An Excel formula that should be adjusted.
|
|
536
|
+
* @param anchorCell A simple string reference to an A1 cell ID (`AF123` or`$C$5`).
|
|
537
|
+
* @param [options={}] The options
|
|
538
|
+
* @returns A formula string.
|
|
539
|
+
*/
|
|
540
|
+
declare function translateFormulaToR1C1(formula: string, anchorCell: string, options?: OptsTranslateToR1C1): string;
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Options for {@link translateTokensToA1}
|
|
544
|
+
*/
|
|
545
|
+
type OptsTranslateTokensToA1 = {
|
|
546
|
+
/**
|
|
547
|
+
* Wrap out-of-bounds ranges around sheet edges rather than turning them to #REF! errors.
|
|
548
|
+
* @defaultValue true
|
|
549
|
+
*/
|
|
550
|
+
wrapEdges?: boolean;
|
|
551
|
+
};
|
|
552
|
+
/**
|
|
553
|
+
* Translates ranges in a list of tokens from relative R1C1 syntax to absolute A1 syntax.
|
|
554
|
+
*
|
|
555
|
+
* ```js
|
|
556
|
+
* translateToA1("=SUM(RC[1],R2C5,Sheet!R3C5)", "D10");
|
|
557
|
+
* // => "=SUM(E10,$E$2,Sheet!$E$3)");
|
|
558
|
+
* ```
|
|
559
|
+
*
|
|
560
|
+
* If an input range is -1,-1 relative rows/columns and the anchor is A1, the
|
|
561
|
+
* resulting range will (by default) wrap around to the bottom of the sheet
|
|
562
|
+
* resulting in the range XFD1048576. This may not be what you want so may set
|
|
563
|
+
* `{ wrapEdges }` to false which will instead turn the range into a `#REF!` error.
|
|
564
|
+
*
|
|
565
|
+
* ```js
|
|
566
|
+
* translateToA1("=R[-1]C[-1]", "A1");
|
|
567
|
+
* // => "=XFD1048576");
|
|
568
|
+
*
|
|
569
|
+
* translateToA1("=R[-1]C[-1]", "A1", { wrapEdges: false });
|
|
570
|
+
* // => "=#REF!");
|
|
571
|
+
* ```
|
|
572
|
+
*
|
|
573
|
+
* Note that if you are passing in a list of tokens that was not created using
|
|
574
|
+
* `mergeRefs` and you disable edge wrapping (or you simply set both options
|
|
575
|
+
* to false), you can end up with a formula such as `=#REF!:B2` or
|
|
576
|
+
* `=Sheet3!#REF!:F3`. These are valid formulas in the Excel formula language
|
|
577
|
+
* and Excel will accept them, but they are not supported in Google Sheets.
|
|
578
|
+
*
|
|
579
|
+
* @see {@link OptsTranslateTokensToA1}
|
|
580
|
+
* @param tokens A token list that should be adjusted.
|
|
581
|
+
* @param anchorCell A simple string reference to an A1 cell ID (`AF123` or`$C$5`).
|
|
582
|
+
* @param options Translation options.
|
|
583
|
+
* @returns A token list.
|
|
584
|
+
*/
|
|
585
|
+
declare function translateTokensToA1(tokens: Token[], anchorCell: string, options?: OptsTranslateTokensToA1): Token[];
|
|
586
|
+
/**
|
|
587
|
+
* Options for {@link translateFormulaToA1}.
|
|
588
|
+
*/
|
|
589
|
+
type OptsTranslateFormulaToA1 = {
|
|
590
|
+
/**
|
|
591
|
+
* Wrap out-of-bounds ranges around sheet edges rather than turning them to #REF! errors.
|
|
592
|
+
* @defaultValue true
|
|
593
|
+
*/
|
|
594
|
+
wrapEdges?: boolean;
|
|
595
|
+
/**
|
|
596
|
+
* Should ranges be treated as whole references (`Sheet1!A1:B2`) or as separate tokens
|
|
597
|
+
* for each part: (`Sheet1`,`!`,`A1`,`:`,`B2`).
|
|
598
|
+
* @defaultValue true
|
|
599
|
+
*/
|
|
600
|
+
mergeRefs?: boolean;
|
|
601
|
+
/**
|
|
602
|
+
* Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`.
|
|
603
|
+
* These are supported by Google Sheets but not Excel. See: References.md.
|
|
604
|
+
* @defaultValue true
|
|
605
|
+
*/
|
|
606
|
+
allowTernary?: boolean;
|
|
607
|
+
};
|
|
608
|
+
/**
|
|
609
|
+
* Translates ranges in a formula from relative R1C1 syntax to absolute A1 syntax.
|
|
610
|
+
*
|
|
611
|
+
* ```js
|
|
612
|
+
* translateToA1("=SUM(RC[1],R2C5,Sheet!R3C5)", "D10");
|
|
613
|
+
* // => "=SUM(E10,$E$2,Sheet!$E$3)");
|
|
614
|
+
* ```
|
|
615
|
+
*
|
|
616
|
+
* If an input range is -1,-1 relative rows/columns and the anchor is A1, the
|
|
617
|
+
* resulting range will (by default) wrap around to the bottom of the sheet
|
|
618
|
+
* resulting in the range XFD1048576. This may not be what you want so you can set
|
|
619
|
+
* `{ wrapEdges }` to false which will instead turn the range into a `#REF!` error.
|
|
620
|
+
*
|
|
621
|
+
* ```js
|
|
622
|
+
* translateToA1("=R[-1]C[-1]", "A1");
|
|
623
|
+
* // => "=XFD1048576");
|
|
624
|
+
*
|
|
625
|
+
* translateToA1("=R[-1]C[-1]", "A1", { wrapEdges: false });
|
|
626
|
+
* // => "=#REF!");
|
|
627
|
+
* ```
|
|
628
|
+
*
|
|
629
|
+
* @see {@link OptsTranslateFormulaToA1}
|
|
630
|
+
* @param formula An Excel formula string that should be adjusted.
|
|
631
|
+
* @param anchorCell A simple string reference to an A1 cell ID (`AF123` or`$C$5`).
|
|
632
|
+
* @param options Translation options.
|
|
633
|
+
* @returns A formula string.
|
|
634
|
+
*/
|
|
635
|
+
declare function translateFormulaToA1(formula: string, anchorCell: string, options?: OptsTranslateFormulaToA1): string;
|
|
636
|
+
|
|
637
|
+
/** The maximum number of columns a spreadsheet reference may hold (16383). */
|
|
638
|
+
declare const MAX_COLS: number;
|
|
639
|
+
/** The maximum number of rows a spreadsheet reference may hold (1048575). */
|
|
640
|
+
declare const MAX_ROWS: number;
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Merges context with reference tokens as possible in a list of tokens.
|
|
644
|
+
*
|
|
645
|
+
* When given a tokenlist, this function returns a new list with ranges returned
|
|
646
|
+
* as whole references (`Sheet1!A1:B2`) rather than separate tokens for each
|
|
647
|
+
* part: (`Sheet1`,`!`,`A1`,`:`,`B2`).
|
|
648
|
+
*
|
|
649
|
+
* @param tokenlist An array of tokens.
|
|
650
|
+
* @returns A new list of tokens with range parts merged.
|
|
651
|
+
*/
|
|
652
|
+
declare function mergeRefTokens(tokenlist: Token[]): Token[];
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* Options for {@link fixTokenRanges} and {@link fixFormulaRanges}.
|
|
656
|
+
*/
|
|
657
|
+
type OptsFixRanges = {
|
|
658
|
+
/**
|
|
659
|
+
* Fill in any undefined bounds of range objects. Top to 0, bottom to 1048575, left to 0, and right to 16383.
|
|
660
|
+
* @defaultValue false
|
|
661
|
+
*/
|
|
662
|
+
addBounds?: boolean;
|
|
663
|
+
/**
|
|
664
|
+
* Enforces using the `[#This Row]` instead of the `@` shorthand when serializing structured ranges.
|
|
665
|
+
* @defaultValue false
|
|
666
|
+
*/
|
|
667
|
+
thisRow?: boolean;
|
|
668
|
+
};
|
|
669
|
+
/**
|
|
670
|
+
* Normalizes A1 style ranges and structured references in a list of tokens.
|
|
671
|
+
*
|
|
672
|
+
* It ensures that that the top and left coordinates of an A1 range are on the
|
|
673
|
+
* left-hand side of a colon operator:
|
|
674
|
+
*
|
|
675
|
+
* ```
|
|
676
|
+
* B2:A1 → A1:B2
|
|
677
|
+
* 1:A1 → A1:1
|
|
678
|
+
* A:A1 → A1:A
|
|
679
|
+
* B:A → A:B
|
|
680
|
+
* 2:1 → 1:2
|
|
681
|
+
* A1:A1 → A1
|
|
682
|
+
* ```
|
|
683
|
+
*
|
|
684
|
+
* When `{ addBounds }` option is set to true, the missing bounds are also added.
|
|
685
|
+
* This can be done to ensure Excel compatible ranges. The fixes then additionally include:
|
|
686
|
+
*
|
|
687
|
+
* ```
|
|
688
|
+
* 1:A1 → A1:1 → 1:1
|
|
689
|
+
* A:A1 → A1:A → A:A
|
|
690
|
+
* A1:A → A:A
|
|
691
|
+
* A1:1 → A:1
|
|
692
|
+
* B2:B → B2:1048576
|
|
693
|
+
* B2:2 → B2:XFD2
|
|
694
|
+
* ```
|
|
695
|
+
*
|
|
696
|
+
* Structured ranges are normalized to have consistent order and capitalization
|
|
697
|
+
* of sections as well as removing redundant ones.
|
|
698
|
+
*
|
|
699
|
+
* Returns a new array of tokens with values and position data updated.
|
|
700
|
+
*
|
|
701
|
+
* @see {@link OptsFixRanges}
|
|
702
|
+
* @param tokens A list of tokens to be adjusted.
|
|
703
|
+
* @param [options] Options.
|
|
704
|
+
* @returns A token list with ranges adjusted.
|
|
705
|
+
*/
|
|
706
|
+
declare function fixTokenRanges(tokens: Token[], options?: OptsFixRanges): Token[];
|
|
707
|
+
/**
|
|
708
|
+
* Normalizes A1 style ranges and structured references in a list of tokens.
|
|
709
|
+
*
|
|
710
|
+
* It ensures that that the top and left coordinates of an A1 range are on the
|
|
711
|
+
* left-hand side of a colon operator:
|
|
712
|
+
*
|
|
713
|
+
* ```
|
|
714
|
+
* B2:A1 → A1:B2
|
|
715
|
+
* 1:A1 → A1:1
|
|
716
|
+
* A:A1 → A1:A
|
|
717
|
+
* B:A → A:B
|
|
718
|
+
* 2:1 → 1:2
|
|
719
|
+
* A1:A1 → A1
|
|
720
|
+
* ```
|
|
721
|
+
*
|
|
722
|
+
* When `{ addBounds }` option is set to true, the missing bounds are also added.
|
|
723
|
+
* This can be done to ensure Excel compatible ranges. The fixes then additionally include:
|
|
724
|
+
*
|
|
725
|
+
* ```
|
|
726
|
+
* 1:A1 → A1:1 → 1:1
|
|
727
|
+
* A:A1 → A1:A → A:A
|
|
728
|
+
* A1:A → A:A
|
|
729
|
+
* A1:1 → A:1
|
|
730
|
+
* B2:B → B2:1048576
|
|
731
|
+
* B2:2 → B2:XFD2
|
|
732
|
+
* ```
|
|
733
|
+
*
|
|
734
|
+
* Structured ranges are normalized to have consistent order and capitalization
|
|
735
|
+
* of sections as well as removing redundant ones.
|
|
736
|
+
*
|
|
737
|
+
* Returns a new array of tokens with values and position data updated.
|
|
738
|
+
*
|
|
739
|
+
* @see {@link OptsFixRanges}
|
|
740
|
+
* @param tokens A list of tokens to be adjusted.
|
|
741
|
+
* @param [options] Options.
|
|
742
|
+
* @returns A token list with ranges adjusted.
|
|
743
|
+
*/
|
|
744
|
+
declare function fixTokenRangesXlsx(tokens: Token[], options?: OptsFixRanges): Token[];
|
|
745
|
+
/**
|
|
746
|
+
* Normalizes A1 style ranges and structured references in a formula.
|
|
747
|
+
*
|
|
748
|
+
* Internally it uses {@link fixTokenRanges} so see it's documentation for details.
|
|
749
|
+
*
|
|
750
|
+
* Returns the same formula with the ranges updated. If an array of tokens was
|
|
751
|
+
* supplied, then a new array is returned.
|
|
752
|
+
*
|
|
753
|
+
* @see {@link OptsFixRanges} & {@link OptsTokenize}
|
|
754
|
+
* @param formula A string (an Excel formula) or a token list that should be adjusted.
|
|
755
|
+
* @param [options] Options
|
|
756
|
+
* @returns A formula string with ranges adjusted
|
|
757
|
+
*/
|
|
758
|
+
declare function fixFormulaRanges(formula: string, options?: OptsFixRanges & OptsTokenize): string;
|
|
759
|
+
/**
|
|
760
|
+
* Normalizes A1 style ranges and structured references in a formula.
|
|
761
|
+
*
|
|
762
|
+
* Internally it uses {@link fixTokenRanges} so see it's documentation for details.
|
|
763
|
+
*
|
|
764
|
+
* Returns the same formula with the ranges updated. If an array of tokens was
|
|
765
|
+
* supplied, then a new array is returned.
|
|
766
|
+
*
|
|
767
|
+
* @see {@link OptsFixRanges} & {@link OptsTokenize}
|
|
768
|
+
* @param formula A string (an Excel formula) or a token list that should be adjusted.
|
|
769
|
+
* @param [options] Options
|
|
770
|
+
* @returns A formula string with ranges adjusted
|
|
771
|
+
*/
|
|
772
|
+
declare function fixFormulaRangesXlsx(formula: string, options?: OptsFixRanges & OptsTokenize): string;
|
|
773
|
+
|
|
774
|
+
/**
|
|
775
|
+
* Determines whether the specified token is a range.
|
|
776
|
+
*
|
|
777
|
+
* Returns `true` if the input is a token that has a type of either REF_RANGE
|
|
778
|
+
* (`A1` or `A1:B2`), REF_TERNARY (`A1:A`, `A1:1`, `1:A1`, or `A:A1`), or
|
|
779
|
+
* REF_BEAM (`A:A` or `1:1`). In all other cases `false` is returned.
|
|
780
|
+
*
|
|
781
|
+
* @param token A token
|
|
782
|
+
* @returns True if the specified token is range, False otherwise.
|
|
783
|
+
*/
|
|
784
|
+
declare function isRange(token?: Pick<Token, 'type'> | null): boolean;
|
|
785
|
+
/**
|
|
786
|
+
* Determines whether the specified token is a reference.
|
|
787
|
+
*
|
|
788
|
+
* Returns `true` if the input is a token of type REF_RANGE (`A1` or `A1:B2`),
|
|
789
|
+
* REF_TERNARY (`A1:A`, `A1:1`, `1:A1`, or `A:A1`), REF_BEAM (`A:A` or `1:1`),
|
|
790
|
+
* or REF_NAMED (`myrange`). In all other cases `false` is returned.
|
|
791
|
+
*
|
|
792
|
+
* @param token The token
|
|
793
|
+
* @returns True if the specified token is reference, False otherwise.
|
|
794
|
+
*/
|
|
795
|
+
declare function isReference(token?: Pick<Token, 'type'> | null): boolean;
|
|
796
|
+
/**
|
|
797
|
+
* Determines whether the specified token is a literal.
|
|
798
|
+
*
|
|
799
|
+
* Returns `true` if the input is a token of type BOOLEAN (`TRUE` or `FALSE`),
|
|
800
|
+
* ERROR (`#VALUE!`), NUMBER (123.4), or STRING (`"lorem ipsum"`). In all other
|
|
801
|
+
* cases `false` is returned.
|
|
802
|
+
*
|
|
803
|
+
* @param token The token
|
|
804
|
+
* @returns True if the specified token is literal, False otherwise.
|
|
805
|
+
*/
|
|
806
|
+
declare function isLiteral(token?: Pick<Token, 'type'> | null): boolean;
|
|
807
|
+
/**
|
|
808
|
+
* Determines whether the specified token is an error.
|
|
809
|
+
*
|
|
810
|
+
* Returns `true` if the input is a token of type ERROR (`#VALUE!`). In all
|
|
811
|
+
* other cases `false` is returned.
|
|
812
|
+
*
|
|
813
|
+
* @param token The token
|
|
814
|
+
* @returns True if the specified token is error, False otherwise.
|
|
815
|
+
*/
|
|
816
|
+
declare function isError(token?: Pick<Token, 'type'> | null): boolean;
|
|
817
|
+
/**
|
|
818
|
+
* Determines whether the specified token is whitespace.
|
|
819
|
+
*
|
|
820
|
+
* Returns `true` if the input is a token of type WHITESPACE (` `) or
|
|
821
|
+
* NEWLINE (`\n`). In all other cases `false` is returned.
|
|
822
|
+
*
|
|
823
|
+
* @param token The token
|
|
824
|
+
* @returns True if the specified token is whitespace, False otherwise.
|
|
825
|
+
*/
|
|
826
|
+
declare function isWhitespace(token?: Pick<Token, 'type'> | null): boolean;
|
|
827
|
+
/**
|
|
828
|
+
* Determines whether the specified token is a function.
|
|
829
|
+
*
|
|
830
|
+
* Returns `true` if the input is a token of type FUNCTION.
|
|
831
|
+
* In all other cases `false` is returned.
|
|
832
|
+
*
|
|
833
|
+
* @param token The token
|
|
834
|
+
* @returns True if the specified token is function, False otherwise.
|
|
835
|
+
*/
|
|
836
|
+
declare function isFunction(token?: Pick<Token, 'type'> | null): boolean;
|
|
837
|
+
/**
|
|
838
|
+
* Returns `true` if the input is a token of type FX_PREFIX (leading `=` in
|
|
839
|
+
* formula). In all other cases `false` is returned.
|
|
840
|
+
*
|
|
841
|
+
* @param token The token
|
|
842
|
+
* @returns True if the specified token is effects prefix, False otherwise.
|
|
843
|
+
*/
|
|
844
|
+
declare function isFxPrefix(token?: Pick<Token, 'type'> | null): boolean;
|
|
845
|
+
/**
|
|
846
|
+
* Determines whether the specified token is an operator.
|
|
847
|
+
*
|
|
848
|
+
* Returns `true` if the input is a token of type OPERATOR (`+` or `:`). In all
|
|
849
|
+
* other cases `false` is returned.
|
|
850
|
+
*
|
|
851
|
+
* @param token The token
|
|
852
|
+
* @returns True if the specified token is operator, False otherwise.
|
|
853
|
+
*/
|
|
854
|
+
declare function isOperator(token?: Pick<Token, 'type'> | null): boolean;
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* Determines whether the specified node is an Identifier.
|
|
858
|
+
* @param node An AST node.
|
|
859
|
+
* @returns True if the specified token is an Identifier, False otherwise.
|
|
860
|
+
*/
|
|
861
|
+
declare function isIdentifierNode(node?: Node | null): node is Identifier;
|
|
862
|
+
/**
|
|
863
|
+
* Determines whether the specified node is a ReferenceIdentifier.
|
|
864
|
+
* @param node An AST node.
|
|
865
|
+
* @returns True if the specified token is a ReferenceIdentifier, False otherwise.
|
|
866
|
+
*/
|
|
867
|
+
declare function isReferenceNode(node?: Node | null): node is ReferenceIdentifier;
|
|
868
|
+
/**
|
|
869
|
+
* Determines whether the specified node is a Literal.
|
|
870
|
+
* @param node An AST node.
|
|
871
|
+
* @returns True if the specified token is a Literal, False otherwise.
|
|
872
|
+
*/
|
|
873
|
+
declare function isLiteralNode(node?: Node | null): node is Literal;
|
|
874
|
+
/**
|
|
875
|
+
* Determines whether the specified node is an ErrorLiteral.
|
|
876
|
+
* @param node An AST node.
|
|
877
|
+
* @returns True if the specified token is an ErrorLiteral, False otherwise.
|
|
878
|
+
*/
|
|
879
|
+
declare function isErrorNode(node?: Node | null): node is ErrorLiteral;
|
|
880
|
+
/**
|
|
881
|
+
* Determines whether the specified node is a UnaryExpression.
|
|
882
|
+
* @param node An AST node.
|
|
883
|
+
* @returns True if the specified token is a UnaryExpression, False otherwise.
|
|
884
|
+
*/
|
|
885
|
+
declare function isUnaryNode(node?: Node | null): node is UnaryExpression;
|
|
886
|
+
/**
|
|
887
|
+
* Determines whether the specified node is a BinaryExpression.
|
|
888
|
+
* @param node An AST node.
|
|
889
|
+
* @returns True if the specified token is a BinaryExpression, False otherwise.
|
|
890
|
+
*/
|
|
891
|
+
declare function isBinaryNode(node?: Node | null): node is BinaryExpression;
|
|
892
|
+
/**
|
|
893
|
+
* Determines whether the specified node is a CallExpression.
|
|
894
|
+
* @param node An AST node.
|
|
895
|
+
* @returns True if the specified token is a CallExpression, False otherwise.
|
|
896
|
+
*/
|
|
897
|
+
declare function isCallNode(node?: Node | null): node is CallExpression;
|
|
898
|
+
/**
|
|
899
|
+
* Determines whether the specified node is a ArrayExpression.
|
|
900
|
+
* @param node An AST node.
|
|
901
|
+
* @returns True if the specified token is a ArrayExpression, False otherwise.
|
|
902
|
+
*/
|
|
903
|
+
declare function isArrayNode(node?: Node | null): node is ArrayExpression;
|
|
904
|
+
/**
|
|
905
|
+
* Determines whether the specified node is a LambdaExpression.
|
|
906
|
+
* @param node An AST node.
|
|
907
|
+
* @returns True if the specified token is a LambdaExpression, False otherwise.
|
|
908
|
+
*/
|
|
909
|
+
declare function isLambdaNode(node?: Node | null): node is LambdaExpression;
|
|
910
|
+
/**
|
|
911
|
+
* Determines whether the specified node is a LetExpression.
|
|
912
|
+
* @param node An AST node.
|
|
913
|
+
* @returns True if the specified token is a LetExpression, False otherwise.
|
|
914
|
+
*/
|
|
915
|
+
declare function isLetNode(node?: Node | null): node is LetExpression;
|
|
916
|
+
/**
|
|
917
|
+
* Determines whether the specified node is a LetDeclarator.
|
|
918
|
+
* @param node An AST node.
|
|
919
|
+
* @returns True if the specified token is a LetDeclarator, False otherwise.
|
|
920
|
+
*/
|
|
921
|
+
declare function isLetDeclaratorNode(node?: Node | null): node is LetDeclarator;
|
|
922
|
+
/**
|
|
923
|
+
* Determines whether the specified node is a AstExpression.
|
|
924
|
+
* @param node An AST node.
|
|
925
|
+
* @returns True if the specified token is a AstExpression, False otherwise.
|
|
926
|
+
*/
|
|
927
|
+
declare function isExpressionNode(node?: Node | null): node is AstExpression;
|
|
928
|
+
|
|
929
|
+
/**
|
|
930
|
+
* Fill the any missing bounds in range objects. Top will be set to 0, bottom to
|
|
931
|
+
* 1048575, left to 0, and right to 16383, if they are `null` or `undefined`.
|
|
932
|
+
*
|
|
933
|
+
* ```js
|
|
934
|
+
* addA1RangeBounds({
|
|
935
|
+
* top: 0,
|
|
936
|
+
* left: 0,
|
|
937
|
+
* bottom: 1,
|
|
938
|
+
* $top: true,
|
|
939
|
+
* $left: false,
|
|
940
|
+
* $bottom: false,
|
|
941
|
+
* });
|
|
942
|
+
* // => {
|
|
943
|
+
* // top: 0,
|
|
944
|
+
* // left: 0,
|
|
945
|
+
* // bottom: 1,
|
|
946
|
+
* // right: 16383, // ← Added
|
|
947
|
+
* // $top: true,
|
|
948
|
+
* // $left: false,
|
|
949
|
+
* // $bottom: false,
|
|
950
|
+
* // $right: false // ← Added
|
|
951
|
+
* // }
|
|
952
|
+
* ```
|
|
953
|
+
*
|
|
954
|
+
* @param range The range part of a reference object.
|
|
955
|
+
* @returns The same range with missing bounds filled in.
|
|
956
|
+
*/
|
|
957
|
+
declare function addA1RangeBounds(range: RangeA1): RangeA1;
|
|
958
|
+
|
|
959
|
+
/**
|
|
960
|
+
* Convert a 0 based offset number to a column string
|
|
961
|
+
* representation (`0` = `"A"`, `2` = `"C"`).
|
|
962
|
+
*
|
|
963
|
+
* The method expects a number between 0 and 16383. Other input will
|
|
964
|
+
* return garbage.
|
|
965
|
+
*
|
|
966
|
+
* @param columnIndex Zero based column index number
|
|
967
|
+
* @returns The column string identifier
|
|
968
|
+
*/
|
|
969
|
+
declare function toCol(columnIndex: number): string;
|
|
970
|
+
|
|
971
|
+
/**
|
|
972
|
+
* Convert a column string representation to a 0 based
|
|
973
|
+
* offset number (`"C"` = `2`).
|
|
974
|
+
*
|
|
975
|
+
* The method expects a valid column identifier made up of _only_
|
|
976
|
+
* A-Z letters, which may be either upper or lower case. Other input will
|
|
977
|
+
* return garbage.
|
|
978
|
+
*
|
|
979
|
+
* @param {string} columnString The column string identifier
|
|
980
|
+
* @returns {number} Zero based column index number
|
|
981
|
+
*/
|
|
982
|
+
declare function fromCol(columnString: string): number;
|
|
983
|
+
|
|
984
|
+
/**
|
|
985
|
+
* Parse A1-style range string into a RangeA1 object.
|
|
986
|
+
*
|
|
987
|
+
* @param rangeString A1-style range string.
|
|
988
|
+
* @param [allowTernary] Permit ternary ranges like A2:A or B2:2.
|
|
989
|
+
* @return A reference object.
|
|
990
|
+
*/
|
|
991
|
+
declare function parseA1Range(rangeString: string, allowTernary?: boolean): RangeA1 | undefined;
|
|
992
|
+
|
|
993
|
+
/**
|
|
994
|
+
* Options for {@link parseA1Ref}.
|
|
995
|
+
*/
|
|
996
|
+
type OptsParseA1Ref = {
|
|
997
|
+
/**
|
|
998
|
+
* Enable parsing names as well as ranges.
|
|
999
|
+
* @defaultValue true
|
|
1000
|
+
*/
|
|
1001
|
+
allowNamed?: boolean;
|
|
1002
|
+
/**
|
|
1003
|
+
* Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`.
|
|
1004
|
+
* These are supported by Google Sheets but not Excel. See: [References.md](./References.md).
|
|
1005
|
+
* @defaultValue false
|
|
1006
|
+
*/
|
|
1007
|
+
allowTernary?: boolean;
|
|
1008
|
+
};
|
|
1009
|
+
/**
|
|
1010
|
+
* Parse a string reference into an object representing it.
|
|
1011
|
+
*
|
|
1012
|
+
* ```js
|
|
1013
|
+
* parseA1Ref('Sheet1!A$1:$B2');
|
|
1014
|
+
* // => {
|
|
1015
|
+
* // context: [ 'Sheet1' ],
|
|
1016
|
+
* // range: {
|
|
1017
|
+
* // top: 0,
|
|
1018
|
+
* // left: 0,
|
|
1019
|
+
* // bottom: 1,
|
|
1020
|
+
* // right: 1
|
|
1021
|
+
* // $top: true,
|
|
1022
|
+
* // $left: false,
|
|
1023
|
+
* // $bottom: false,
|
|
1024
|
+
* // $right: true
|
|
1025
|
+
* // }
|
|
1026
|
+
* // }
|
|
1027
|
+
* ```
|
|
1028
|
+
*
|
|
1029
|
+
* For A:A or A1:A style ranges, `null` will be used for any dimensions that the
|
|
1030
|
+
* syntax does not specify.
|
|
1031
|
+
*
|
|
1032
|
+
* @see {@link OptsParseA1Ref}
|
|
1033
|
+
* @param refString An A1-style reference string.
|
|
1034
|
+
* @param options Options.
|
|
1035
|
+
* @returns An object representing a valid reference or `undefined` if it is invalid.
|
|
1036
|
+
*/
|
|
1037
|
+
declare function parseA1Ref(refString: string, { allowNamed, allowTernary }?: OptsParseA1Ref): ReferenceA1 | ReferenceName | undefined;
|
|
1038
|
+
/**
|
|
1039
|
+
* Parse a string reference into an object representing it.
|
|
1040
|
+
*
|
|
1041
|
+
* ```js
|
|
1042
|
+
* parseA1Ref('Sheet1!A$1:$B2');
|
|
1043
|
+
* // => {
|
|
1044
|
+
* // workbookName: '',
|
|
1045
|
+
* // sheetName: 'Sheet1',
|
|
1046
|
+
* // range: {
|
|
1047
|
+
* // top: 0,
|
|
1048
|
+
* // left: 0,
|
|
1049
|
+
* // bottom: 1,
|
|
1050
|
+
* // right: 1
|
|
1051
|
+
* // $top: true,
|
|
1052
|
+
* // $left: false,
|
|
1053
|
+
* // $bottom: false,
|
|
1054
|
+
* // $right: true
|
|
1055
|
+
* // }
|
|
1056
|
+
* // }
|
|
1057
|
+
* ```
|
|
1058
|
+
*
|
|
1059
|
+
* For A:A or A1:A style ranges, `null` will be used for any dimensions that the
|
|
1060
|
+
* syntax does not specify.
|
|
1061
|
+
*
|
|
1062
|
+
* @see {@link OptsParseA1Ref}
|
|
1063
|
+
* @param refString An A1-style reference string.
|
|
1064
|
+
* @param options Options.
|
|
1065
|
+
* @returns An object representing a valid reference or `undefined` if it is invalid.
|
|
1066
|
+
*/
|
|
1067
|
+
declare function parseA1RefXlsx(refString: string, { allowNamed, allowTernary }?: OptsParseA1Ref): ReferenceA1Xlsx | ReferenceNameXlsx | undefined;
|
|
1068
|
+
|
|
1069
|
+
/**
|
|
1070
|
+
* Parse R1C1-style range string into a RangeR1C1 object.
|
|
1071
|
+
*
|
|
1072
|
+
* @param rangeString R1C1-style range string.
|
|
1073
|
+
* @return A reference object.
|
|
1074
|
+
*/
|
|
1075
|
+
declare function parseR1C1Range(rangeString: string): RangeR1C1 | null;
|
|
1076
|
+
|
|
1077
|
+
/**
|
|
1078
|
+
* Options for {@link parseR1C1Ref}.
|
|
1079
|
+
*/
|
|
1080
|
+
type OptsParseR1C1Ref = {
|
|
1081
|
+
/**
|
|
1082
|
+
* Enable parsing names as well as ranges.
|
|
1083
|
+
* @defaultValue true
|
|
1084
|
+
*/
|
|
1085
|
+
allowNamed?: boolean;
|
|
1086
|
+
/**
|
|
1087
|
+
* Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`.
|
|
1088
|
+
* These are supported by Google Sheets but not Excel.
|
|
1089
|
+
* See: [References.md](./References.md).
|
|
1090
|
+
* @defaultValue false
|
|
1091
|
+
*/
|
|
1092
|
+
allowTernary?: boolean;
|
|
1093
|
+
};
|
|
1094
|
+
/**
|
|
1095
|
+
* Parse a string reference into an object representing it.
|
|
1096
|
+
*
|
|
1097
|
+
* ```js
|
|
1098
|
+
* parseR1C1Ref('Sheet1!R[9]C9:R[9]C9');
|
|
1099
|
+
* // => {
|
|
1100
|
+
* // context: [ 'Sheet1' ],
|
|
1101
|
+
* // range: {
|
|
1102
|
+
* // r0: 9,
|
|
1103
|
+
* // c0: 8,
|
|
1104
|
+
* // r1: 9,
|
|
1105
|
+
* // c1: 8,
|
|
1106
|
+
* // $c0: true,
|
|
1107
|
+
* // $c1: true
|
|
1108
|
+
* // $r0: false,
|
|
1109
|
+
* // $r1: false
|
|
1110
|
+
* // }
|
|
1111
|
+
* // }
|
|
1112
|
+
* ```
|
|
1113
|
+
*
|
|
1114
|
+
* @see {@link OptsParseR1C1Ref}
|
|
1115
|
+
* @param refString An R1C1-style reference string.
|
|
1116
|
+
* @param [options] Options.
|
|
1117
|
+
* @returns An object representing a valid reference or `undefined` if it is invalid.
|
|
1118
|
+
*/
|
|
1119
|
+
declare function parseR1C1Ref(refString: string, options?: OptsParseR1C1Ref): ReferenceR1C1 | ReferenceName | undefined;
|
|
1120
|
+
/**
|
|
1121
|
+
* Parse a string reference into an object representing it.
|
|
1122
|
+
*
|
|
1123
|
+
* ```js
|
|
1124
|
+
* parseR1C1Ref('Sheet1!R[9]C9:R[9]C9');
|
|
1125
|
+
* // => {
|
|
1126
|
+
* // context: [ 'Sheet1' ],
|
|
1127
|
+
* // range: {
|
|
1128
|
+
* // r0: 9,
|
|
1129
|
+
* // c0: 8,
|
|
1130
|
+
* // r1: 9,
|
|
1131
|
+
* // c1: 8,
|
|
1132
|
+
* // $c0: true,
|
|
1133
|
+
* // $c1: true
|
|
1134
|
+
* // $r0: false,
|
|
1135
|
+
* // $r1: false
|
|
1136
|
+
* // }
|
|
1137
|
+
* // }
|
|
1138
|
+
* ```
|
|
1139
|
+
*
|
|
1140
|
+
* @see {@link OptsParseR1C1Ref}
|
|
1141
|
+
* @param refString An R1C1-style reference string.
|
|
1142
|
+
* @param [options] Options.
|
|
1143
|
+
* @returns An object representing a valid reference or `undefined` if it is invalid.
|
|
1144
|
+
*/
|
|
1145
|
+
declare function parseR1C1RefXlsx(refString: string, options?: OptsParseR1C1Ref): ReferenceR1C1Xlsx | ReferenceNameXlsx | undefined;
|
|
1146
|
+
|
|
1147
|
+
/**
|
|
1148
|
+
* Parse a structured reference string into an object representing it.
|
|
1149
|
+
*
|
|
1150
|
+
* ```js
|
|
1151
|
+
* parseStructRef('workbook.xlsx!tableName[[#Data],[Column1]:[Column2]]');
|
|
1152
|
+
* // => {
|
|
1153
|
+
* // context: [ 'workbook.xlsx' ],
|
|
1154
|
+
* // sections: [ 'data' ],
|
|
1155
|
+
* // columns: [ 'my column', '@foo' ],
|
|
1156
|
+
* // table: 'tableName',
|
|
1157
|
+
* // }
|
|
1158
|
+
* ```
|
|
1159
|
+
*
|
|
1160
|
+
* For A:A or A1:A style ranges, `null` will be used for any dimensions that the
|
|
1161
|
+
* syntax does not specify:
|
|
1162
|
+
*
|
|
1163
|
+
* See [References.md](./References.md).
|
|
1164
|
+
*
|
|
1165
|
+
* @param ref A structured reference string
|
|
1166
|
+
* @returns An object representing a valid reference or `undefined` if it is invalid.
|
|
1167
|
+
*/
|
|
1168
|
+
declare function parseStructRef(ref: string): ReferenceStruct | undefined;
|
|
1169
|
+
/**
|
|
1170
|
+
* Parse a structured reference string into an object representing it.
|
|
1171
|
+
*
|
|
1172
|
+
* ```js
|
|
1173
|
+
* parseStructRef('[workbook.xlsx]!tableName[[#Data],[Column1]:[Column2]]');
|
|
1174
|
+
* // => {
|
|
1175
|
+
* // workbookName: 'workbook.xlsx',
|
|
1176
|
+
* // sections: [ 'data' ],
|
|
1177
|
+
* // columns: [ 'my column', '@foo' ],
|
|
1178
|
+
* // table: 'tableName',
|
|
1179
|
+
* // }
|
|
1180
|
+
* ```
|
|
1181
|
+
*
|
|
1182
|
+
* For A:A or A1:A style ranges, `null` will be used for any dimensions that the
|
|
1183
|
+
* syntax does not specify:
|
|
1184
|
+
*
|
|
1185
|
+
* See [References.md](./References.md).
|
|
1186
|
+
*
|
|
1187
|
+
* @param ref A structured reference string
|
|
1188
|
+
* @returns An object representing a valid reference or null if it is invalid.
|
|
1189
|
+
*/
|
|
1190
|
+
declare function parseStructRefXlsx(ref: string): ReferenceStructXlsx | undefined;
|
|
1191
|
+
|
|
1192
|
+
/**
|
|
1193
|
+
* Get an A1-style string representation of a reference object.
|
|
1194
|
+
*
|
|
1195
|
+
* ```js
|
|
1196
|
+
* stringifyA1Ref({
|
|
1197
|
+
* context: [ 'Sheet1' ],
|
|
1198
|
+
* range: {
|
|
1199
|
+
* top: 0,
|
|
1200
|
+
* left: 0,
|
|
1201
|
+
* bottom: 1,
|
|
1202
|
+
* right: 1,
|
|
1203
|
+
* $top: true,
|
|
1204
|
+
* $left: false,
|
|
1205
|
+
* $bottom: false,
|
|
1206
|
+
* $right: true
|
|
1207
|
+
* }
|
|
1208
|
+
* });
|
|
1209
|
+
* // => 'Sheet1!A$1:$B2'
|
|
1210
|
+
* ```
|
|
1211
|
+
*
|
|
1212
|
+
* @param refObject A reference object.
|
|
1213
|
+
* @returns The reference in A1-style string format.
|
|
1214
|
+
*/
|
|
1215
|
+
declare function stringifyA1Ref(refObject: ReferenceA1 | ReferenceName): string;
|
|
1216
|
+
/**
|
|
1217
|
+
* Get an A1-style string representation of a reference object.
|
|
1218
|
+
*
|
|
1219
|
+
* ```js
|
|
1220
|
+
* stringifyA1Ref({
|
|
1221
|
+
* sheetName: 'Sheet1',
|
|
1222
|
+
* range: {
|
|
1223
|
+
* top: 0,
|
|
1224
|
+
* left: 0,
|
|
1225
|
+
* bottom: 1,
|
|
1226
|
+
* right: 1,
|
|
1227
|
+
* $top: true,
|
|
1228
|
+
* $left: false,
|
|
1229
|
+
* $bottom: false,
|
|
1230
|
+
* $right: true
|
|
1231
|
+
* }
|
|
1232
|
+
* });
|
|
1233
|
+
* // => 'Sheet1!A$1:$B2'
|
|
1234
|
+
* ```
|
|
1235
|
+
*
|
|
1236
|
+
* @param refObject A reference object.
|
|
1237
|
+
* @returns The reference in A1-style string format.
|
|
1238
|
+
*/
|
|
1239
|
+
declare function stringifyA1RefXlsx(refObject: ReferenceA1Xlsx | ReferenceNameXlsx): string;
|
|
1240
|
+
|
|
1241
|
+
/**
|
|
1242
|
+
* Get an R1C1-style string representation of a reference object.
|
|
1243
|
+
*
|
|
1244
|
+
* ```js
|
|
1245
|
+
* stringifyR1C1Ref({
|
|
1246
|
+
* context: [ 'Sheet1' ],
|
|
1247
|
+
* range: {
|
|
1248
|
+
* r0: 9,
|
|
1249
|
+
* c0: 8,
|
|
1250
|
+
* r1: 9,
|
|
1251
|
+
* c1: 8,
|
|
1252
|
+
* $c0: true,
|
|
1253
|
+
* $c1: true
|
|
1254
|
+
* $r0: false,
|
|
1255
|
+
* $r1: false
|
|
1256
|
+
* }
|
|
1257
|
+
* });
|
|
1258
|
+
* // => 'Sheet1!R[9]C9:R[9]C9'
|
|
1259
|
+
* ```
|
|
1260
|
+
*
|
|
1261
|
+
* @param refObject A reference object.
|
|
1262
|
+
* @returns The reference in R1C1-style string format.
|
|
1263
|
+
*/
|
|
1264
|
+
declare function stringifyR1C1Ref(refObject: ReferenceR1C1 | ReferenceName): string;
|
|
1265
|
+
/**
|
|
1266
|
+
* Get an R1C1-style string representation of a reference object.
|
|
1267
|
+
*
|
|
1268
|
+
* ```js
|
|
1269
|
+
* stringifyR1C1Ref({
|
|
1270
|
+
* sheetName: 'Sheet1',
|
|
1271
|
+
* range: {
|
|
1272
|
+
* r0: 9,
|
|
1273
|
+
* c0: 8,
|
|
1274
|
+
* r1: 9,
|
|
1275
|
+
* c1: 8,
|
|
1276
|
+
* $c0: true,
|
|
1277
|
+
* $c1: true
|
|
1278
|
+
* $r0: false,
|
|
1279
|
+
* $r1: false
|
|
1280
|
+
* }
|
|
1281
|
+
* });
|
|
1282
|
+
* // => 'Sheet1!R[9]C9:R[9]C9'
|
|
1283
|
+
* ```
|
|
1284
|
+
*
|
|
1285
|
+
* @param refObject A reference object.
|
|
1286
|
+
* @returns The reference in R1C1-style string format.
|
|
1287
|
+
*/
|
|
1288
|
+
declare function stringifyR1C1RefXlsx(refObject: ReferenceR1C1Xlsx | ReferenceNameXlsx): string;
|
|
1289
|
+
|
|
1290
|
+
/**
|
|
1291
|
+
* Options for {@link stringifyStructRef}
|
|
1292
|
+
*/
|
|
1293
|
+
type OptsStringifyStructRef = {
|
|
1294
|
+
/**
|
|
1295
|
+
* Enforces using the `[#This Row]` instead of the `@` shorthand when serializing structured ranges.
|
|
1296
|
+
* @defaultValue false
|
|
1297
|
+
*/
|
|
1298
|
+
thisRow?: boolean;
|
|
1299
|
+
};
|
|
1300
|
+
/**
|
|
1301
|
+
* Returns a string representation of a structured reference object.
|
|
1302
|
+
*
|
|
1303
|
+
* ```js
|
|
1304
|
+
* stringifyStructRef({
|
|
1305
|
+
* context: [ 'workbook.xlsx' ],
|
|
1306
|
+
* sections: [ 'data' ],
|
|
1307
|
+
* columns: [ 'my column', '@foo' ],
|
|
1308
|
+
* table: 'tableName',
|
|
1309
|
+
* });
|
|
1310
|
+
* // => 'workbook.xlsx!tableName[[#Data],[Column1]:[Column2]]'
|
|
1311
|
+
* ```
|
|
1312
|
+
*
|
|
1313
|
+
* @see {@link OptsStringifyStructRef}
|
|
1314
|
+
* @param refObject A structured reference object.
|
|
1315
|
+
* @param [options={}] Options.
|
|
1316
|
+
* @returns The given structured reference in string format.
|
|
1317
|
+
*/
|
|
1318
|
+
declare function stringifyStructRef(refObject: ReferenceStruct, options?: OptsStringifyStructRef): string;
|
|
1319
|
+
/**
|
|
1320
|
+
* Returns a string representation of a structured reference object.
|
|
1321
|
+
*
|
|
1322
|
+
* ```js
|
|
1323
|
+
* stringifyStructRef({
|
|
1324
|
+
* workbookName: 'workbook.xlsx',
|
|
1325
|
+
* sheetName: '',
|
|
1326
|
+
* sections: [ 'data' ],
|
|
1327
|
+
* columns: [ 'my column', '@foo' ],
|
|
1328
|
+
* table: 'tableName',
|
|
1329
|
+
* });
|
|
1330
|
+
* // => 'workbook.xlsx!tableName[[#Data],[Column1]:[Column2]]'
|
|
1331
|
+
* ```
|
|
1332
|
+
*
|
|
1333
|
+
* @param refObject A structured reference object.
|
|
1334
|
+
* @param [options] Options.
|
|
1335
|
+
* @returns The given structured reference in string format.
|
|
1336
|
+
*/
|
|
1337
|
+
declare function stringifyStructRefXlsx(refObject: ReferenceStructXlsx, options?: OptsStringifyStructRef): string;
|
|
1338
|
+
|
|
1339
|
+
/**
|
|
1340
|
+
* Collapses a list of tokens into a formula string.
|
|
1341
|
+
*
|
|
1342
|
+
* @param tokens A list of tokens.
|
|
1343
|
+
* @returns A formula string.
|
|
1344
|
+
*/
|
|
1345
|
+
declare function stringifyTokens(tokens: Token[]): string;
|
|
1346
|
+
|
|
1347
|
+
/**
|
|
1348
|
+
* A dictionary of the types used to identify token variants.
|
|
1349
|
+
* @prop OPERATOR - Unary or binary operator (`+`, `%`)
|
|
1350
|
+
* @prop BOOLEAN - Boolean literal (`TRUE`)
|
|
1351
|
+
* @prop ERROR - Error literal (`#VALUE!`)
|
|
1352
|
+
* @prop NUMBER - Number literal (`123.4`, `-1.5e+2`)
|
|
1353
|
+
* @prop FUNCTION - Function name (`SUM`)
|
|
1354
|
+
* @prop NEWLINE - Newline character (`\n`)
|
|
1355
|
+
* @prop WHITESPACE - Whitespace character sequence (` `)
|
|
1356
|
+
* @prop STRING - String literal (`"Lorem ipsum"`)
|
|
1357
|
+
* @prop CONTEXT - Reference context ([Workbook.xlsx]Sheet1)
|
|
1358
|
+
* @prop CONTEXT_QUOTE - Quoted reference context (`'[My workbook.xlsx]Sheet1'`)
|
|
1359
|
+
* @prop REF_RANGE - A range identifier (`A1`)
|
|
1360
|
+
* @prop REF_BEAM - A range "beam" identifier (`A:A` or `1:1`)
|
|
1361
|
+
* @prop REF_TERNARY - A ternary range identifier (`B2:B`)
|
|
1362
|
+
* @prop REF_NAMED - A name / named range identifier (`income`)
|
|
1363
|
+
* @prop REF_STRUCT - A structured reference identifier (`table[[Column1]:[Column2]]`)
|
|
1364
|
+
* @prop FX_PREFIX - A leading equals sign at the start of a formula (`=`)
|
|
1365
|
+
* @prop UNKNOWN - Any unidentifiable range of characters.
|
|
1366
|
+
*/
|
|
1367
|
+
declare const tokenTypes: Readonly<{
|
|
1368
|
+
/** Unary or binary operator (`+`, `%`) */
|
|
1369
|
+
OPERATOR: "operator";
|
|
1370
|
+
/** Boolean literal (`TRUE`) */
|
|
1371
|
+
BOOLEAN: "bool";
|
|
1372
|
+
/** Error literal (`#VALUE!`) */
|
|
1373
|
+
ERROR: "error";
|
|
1374
|
+
/** Number literal (`123.4`, `-1.5e+2`) */
|
|
1375
|
+
NUMBER: "number";
|
|
1376
|
+
/** Function name (`SUM`) */
|
|
1377
|
+
FUNCTION: "func";
|
|
1378
|
+
/** Newline character (`\n`) */
|
|
1379
|
+
NEWLINE: "newline";
|
|
1380
|
+
/** Whitespace character sequence (` `) */
|
|
1381
|
+
WHITESPACE: "whitespace";
|
|
1382
|
+
/** String literal (`"Lorem ipsum"`) */
|
|
1383
|
+
STRING: "string";
|
|
1384
|
+
/** Reference context ([Workbook.xlsx]Sheet1) */
|
|
1385
|
+
CONTEXT: "context";
|
|
1386
|
+
/** Quoted reference context (`'[My workbook.xlsx]Sheet1'`) */
|
|
1387
|
+
CONTEXT_QUOTE: "context_quote";
|
|
1388
|
+
/** A range identifier (`A1`) */
|
|
1389
|
+
REF_RANGE: "range";
|
|
1390
|
+
/** A range "beam" identifier (`A:A` or `1:1`) */
|
|
1391
|
+
REF_BEAM: "range_beam";
|
|
1392
|
+
/** A ternary range identifier (`B2:B`) */
|
|
1393
|
+
REF_TERNARY: "range_ternary";
|
|
1394
|
+
/** A name / named range identifier (`income`) */
|
|
1395
|
+
REF_NAMED: "range_named";
|
|
1396
|
+
/** A structured reference identifier (`table[[Column1]:[Column2]]`) */
|
|
1397
|
+
REF_STRUCT: "structured";
|
|
1398
|
+
/** A leading equals sign at the start of a formula (`=`) */
|
|
1399
|
+
FX_PREFIX: "fx_prefix";
|
|
1400
|
+
/** Any unidentifiable range of characters. */
|
|
1401
|
+
UNKNOWN: "unknown";
|
|
1402
|
+
}>;
|
|
1403
|
+
|
|
1404
|
+
/**
|
|
1405
|
+
* A dictionary of the types used to identify AST node variants.
|
|
1406
|
+
*
|
|
1407
|
+
* @prop UNARY - A unary operation (`10%`)
|
|
1408
|
+
* @prop BINARY - A binary operation (`10+10`)
|
|
1409
|
+
* @prop REFERENCE - A range identifier (`A1`)
|
|
1410
|
+
* @prop LITERAL - A literal (number, string, or boolean) (`123`, `"foo"`, `false`)
|
|
1411
|
+
* @prop ERROR - An error literal (`#VALUE!`)
|
|
1412
|
+
* @prop CALL - A function call expression (`SUM(1,2)`)
|
|
1413
|
+
* @prop ARRAY - An array expression (`{1,2;3,4}`)
|
|
1414
|
+
* @prop IDENTIFIER - A function name identifier (`SUM`)
|
|
1415
|
+
* @prop LAMBDA - A LAMBDA expression (`LAMBDA(x,y,x*y)``)
|
|
1416
|
+
* @prop LET - A LET expression (`LET(a,A1*10,b,SUM(F:F),a*b)`)
|
|
1417
|
+
* @prop LET_DECL - A LET declaration (LET(`a,A1*10`...)
|
|
1418
|
+
*/
|
|
1419
|
+
declare const nodeTypes: Readonly<{
|
|
1420
|
+
/** A unary operation (`10%`) */
|
|
1421
|
+
UNARY: "UnaryExpression";
|
|
1422
|
+
/** A binary operation (`10+10`) */
|
|
1423
|
+
BINARY: "BinaryExpression";
|
|
1424
|
+
/** A range identifier (`A1`) */
|
|
1425
|
+
REFERENCE: "ReferenceIdentifier";
|
|
1426
|
+
/** A literal (number, string, or boolean) (`123`, `"foo"`, `false`) */
|
|
1427
|
+
LITERAL: "Literal";
|
|
1428
|
+
/** An error literal (`#VALUE!`) */
|
|
1429
|
+
ERROR: "ErrorLiteral";
|
|
1430
|
+
/** A function call expression (`SUM(1,2)`) */
|
|
1431
|
+
CALL: "CallExpression";
|
|
1432
|
+
/** An array expression (`{1,2;3,4}`) */
|
|
1433
|
+
ARRAY: "ArrayExpression";
|
|
1434
|
+
/** A function name identifier (`SUM`) */
|
|
1435
|
+
IDENTIFIER: "Identifier";
|
|
1436
|
+
/** A LAMBDA expression (`LAMBDA(x,y,x*y)``) */
|
|
1437
|
+
LAMBDA: "LambdaExpression";
|
|
1438
|
+
/** A LET expression (`LET(a,A1*10,b,SUM(F:F),a*b)`) */
|
|
1439
|
+
LET: "LetExpression";
|
|
1440
|
+
/** A LET declaration (LET(`a,A1*10`...)*/
|
|
1441
|
+
LET_DECL: "LetDeclarator";
|
|
1442
|
+
}>;
|
|
1443
|
+
|
|
1444
|
+
export { stringifyTokens as $, isOperator as A, isRange as B, isReference as C, isWhitespace as D, isArrayNode as E, isBinaryNode as F, isCallNode as G, isErrorNode as H, isExpressionNode as I, isIdentifierNode as J, isLambdaNode as K, isLetDeclaratorNode as L, MAX_COLS as M, isLetNode as N, type OptsTokenize as O, isLiteralNode as P, isReferenceNode as Q, isUnaryNode as R, addA1RangeBounds as S, type Token as T, toCol as U, fromCol as V, parseA1Range as W, type OptsParseA1Ref as X, parseR1C1Range as Y, type OptsParseR1C1Ref as Z, type OptsStringifyStructRef as _, type TokenEnhanced as a, type RangeA1 as a0, type RangeR1C1 as a1, type ReferenceA1 as a2, type ReferenceA1Xlsx as a3, type ReferenceR1C1 as a4, type ReferenceR1C1Xlsx as a5, type ReferenceStruct as a6, type ReferenceStructXlsx as a7, type ReferenceName as a8, type ReferenceNameXlsx as a9, stringifyStructRef as aA, tokenTypes as aa, nodeTypes as ab, type SourceLocation as ac, type Node as ad, type Identifier as ae, type ReferenceIdentifier as af, type Literal as ag, type ErrorLiteral as ah, type UnaryExpression as ai, type UnaryOperator as aj, type BinaryExpression as ak, type BinaryOperator as al, type CallExpression as am, type ArrayExpression as an, type LambdaExpression as ao, type LetExpression as ap, type LetDeclarator as aq, type AstExpression as ar, tokenize as as, fixTokenRanges as at, fixFormulaRanges as au, parseA1Ref as av, parseR1C1Ref as aw, parseStructRef as ax, stringifyA1Ref as ay, stringifyR1C1Ref as az, fixFormulaRangesXlsx as b, parseR1C1RefXlsx as c, parseStructRefXlsx as d, stringifyR1C1RefXlsx as e, fixTokenRangesXlsx as f, stringifyStructRefXlsx as g, parse as h, type OptsParse as i, translateFormulaToR1C1 as j, translateTokensToR1C1 as k, type OptsTranslateToR1C1 as l, translateFormulaToA1 as m, type OptsTranslateFormulaToA1 as n, translateTokensToA1 as o, parseA1RefXlsx as p, type OptsTranslateTokensToA1 as q, MAX_ROWS as r, stringifyA1RefXlsx as s, tokenizeXlsx as t, mergeRefTokens as u, type OptsFixRanges as v, isError as w, isFunction as x, isFxPrefix as y, isLiteral as z };
|