@borgar/fx 4.3.1 → 4.5.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/fx.d.ts ADDED
@@ -0,0 +1,653 @@
1
+ /**
2
+ * Fill the any missing bounds in range objects. Top will be set to 0, bottom to
3
+ * 1048575, left to 0, and right to 16383, if they are `null` or `undefined`.
4
+ * ```js
5
+ * addA1RangeBounds({
6
+ * context: [ 'Sheet1' ],
7
+ * range: {
8
+ * top: 0,
9
+ * left: 0,
10
+ * bottom: 1,
11
+ * $top: true,
12
+ * $left: false,
13
+ * $bottom: false,
14
+ * }
15
+ * });
16
+ * // => {
17
+ * // context: [ 'Sheet1' ],
18
+ * // range: {
19
+ * // top: 0,
20
+ * // left: 0,
21
+ * // bottom: 1,
22
+ * // right: 16383,
23
+ * // $top: true,
24
+ * // $left: false,
25
+ * // $bottom: false,
26
+ * // $right: false
27
+ * // }
28
+ * // }
29
+ * ```
30
+ *
31
+ * @param range The range part of a reference object.
32
+ * @returns same range with missing bounds filled in.
33
+ */
34
+ export declare function addA1RangeBounds(range: object): object;
35
+
36
+ /**
37
+ * Runs through a list of tokens and adds extra attributes such as matching
38
+ * parens and ranges.
39
+ * The `context` parameter defines default reference attributes:
40
+ * `{ workbookName: 'report.xlsx', sheetName: 'Sheet1' }`.
41
+ * If supplied, these are used to match `A1` to `Sheet1!A1`.
42
+ * All tokens will be tagged with a `.depth` number value to indicating the
43
+ * level of nesting in parentheses as well as an `.index` number indicating
44
+ * their zero based position in the list.
45
+ * The returned output will be the same array of tokens but the following
46
+ * properties will added to tokens (as applicable):
47
+ * #### Parentheses ( )
48
+ * Matching parens will be tagged with `.groupId` string identifier as well as
49
+ * a `.depth` number value (indicating the level of nesting).
50
+ * Closing parens without a counterpart will be tagged with `.error`
51
+ * (boolean true).
52
+ * #### Curly brackets { }
53
+ * Matching curly brackets will be tagged with `.groupId` string identifier.
54
+ * These may not be nested in Excel.
55
+ * Closing curly brackets without a counterpart will be tagged with `.error`
56
+ * (boolean `true`).
57
+ * #### Ranges (`REF_RANGE` or `REF_BEAM` type tokens)
58
+ * All ranges will be tagged with `.groupId` string identifier regardless of
59
+ * the number of times they occur.
60
+ * #### Tokens of type `UNKNOWN`
61
+ * All will be tagged with `.error` (boolean `true`).
62
+ *
63
+ * @param tokenlist An array of tokens (from `tokenize()`)
64
+ * @param [context={}] A contest used to match `A1` to `Sheet1!A1`.
65
+ * @param [context.sheetName=''] An implied sheet name ('Sheet1')
66
+ * @param [context.workbookName=''] An implied workbook name ('report.xlsx')
67
+ * @returns The input array with the enchanced tokens
68
+ */
69
+ export declare function addTokenMeta(tokenlist: Array<object>, context?: {
70
+ /** An implied sheet name ('Sheet1') */
71
+ sheetName?: string;
72
+ /** An implied workbook name ('report.xlsx') */
73
+ workbookName?: string;
74
+ }): Array<object>;
75
+
76
+ /**
77
+ * Normalizes A1 style ranges and structured references in a formula or list of
78
+ * tokens.
79
+ * It ensures that that the top and left coordinates of an A1 range are on the
80
+ * left-hand side of a colon operator:
81
+ * `B2:A1` → `A1:B2`
82
+ * `1:A1` → `A1:1`
83
+ * `A:A1` → `A1:A`
84
+ * `B:A` → `A:B`
85
+ * `2:1` → `1:2`
86
+ * `A1:A1` → `A1`
87
+ * When `{ addBounds: true }` is passed as an option, the missing bounds are
88
+ * also added. This can be done to ensure Excel compatible ranges. The fixes
89
+ * then additionally include:
90
+ * `1:A1` → `A1:1` → `1:1`
91
+ * `A:A1` → `A1:A` → `A:A`
92
+ * `A1:A` → `A:A`
93
+ * `A1:1` → `A:1`
94
+ * `B2:B` → `B2:1048576`
95
+ * `B2:2` → `B2:XFD2`
96
+ * Structured ranges are normalized cleaned up to have consistent order and
97
+ * capitalization of sections as well as removing redundant ones.
98
+ * Returns the same formula with the ranges updated. If an array of tokens was
99
+ * supplied, then a new array is returned.
100
+ *
101
+ * @param formula A string (an Excel formula) or a token list that should be adjusted.
102
+ * @param [options={}] Options
103
+ * @param [options.addBounds=false] Fill in any undefined bounds of range objects. Top to 0, bottom to 1048575, left to 0, and right to 16383.
104
+ * @param [options.xlsx=false] Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md)
105
+ * @returns A formula string or token list (depending on which was input)
106
+ */
107
+ export declare function fixRanges(formula: (string | Array<object>), options?: {
108
+ /** Fill in any undefined bounds of range objects. Top to 0, bottom to 1048575, left to 0, and right to 16383. */
109
+ addBounds?: boolean;
110
+ /** Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) */
111
+ xlsx?: boolean;
112
+ }): (string | Array<object>);
113
+
114
+ /**
115
+ * Parse a simple string reference to an A1 range into a range object.
116
+ * Will accept `A1`, `A2`, `A:A`, or `1:1`.
117
+ *
118
+ * @param rangeString A range string
119
+ * @returns An object representing a valid reference or null if it is invalid.
120
+ */
121
+ declare function fromA1(rangeString: string): (object | null);
122
+
123
+ /**
124
+ * Convert a column string representation to a 0 based
125
+ * offset number (`"C"` = `2`).
126
+ * The method expects a valid column identifier made up of _only_
127
+ * A-Z letters, which may be either upper or lower case. Other input will
128
+ * return garbage.
129
+ *
130
+ * @param columnString The column string identifier
131
+ * @returns Zero based column index number
132
+ */
133
+ export declare function fromCol(columnString: string): number;
134
+
135
+ /**
136
+ * Parse a simple string reference to an R1C1 range into a range object.
137
+ *
138
+ * @param rangeString A range string
139
+ * @returns An object representing a valid reference or null if it is invalid.
140
+ */
141
+ declare function fromR1C1(rangeString: string): (object | null);
142
+
143
+ /**
144
+ * Determines whether the specified token is an error.
145
+ * Returns `true` if the input is a token of type ERROR (`#VALUE!`). In all
146
+ * other cases `false` is returned.
147
+ *
148
+ * @param token The token
149
+ * @returns True if the specified token is error, False otherwise.
150
+ */
151
+ export declare function isError(token: object): boolean;
152
+
153
+ /**
154
+ * Determines whether the specified token is a function.
155
+ * Returns `true` if the input is a token of type FUNCTION.
156
+ * In all other cases `false` is returned.
157
+ *
158
+ * @param token The token
159
+ * @returns True if the specified token is function, False otherwise.
160
+ */
161
+ export declare function isFunction(token: object): boolean;
162
+
163
+ /**
164
+ * Returns `true` if the input is a token of type FX_PREFIX (leading `=` in
165
+ * formula). In all other cases `false` is returned.
166
+ *
167
+ * @param token The token
168
+ * @returns True if the specified token is effects prefix, False otherwise.
169
+ */
170
+ export declare function isFxPrefix(token: object): boolean;
171
+
172
+ /**
173
+ * Determines whether the specified token is a literal.
174
+ * Returns `true` if the input is a token of type BOOLEAN (`TRUE` or `FALSE`),
175
+ * ERROR (`#VALUE!`), NUMBER (123.4), or STRING (`"lorem ipsum"`). In all other
176
+ * cases `false` is returned.
177
+ *
178
+ * @param token The token
179
+ * @returns True if the specified token is literal, False otherwise.
180
+ */
181
+ export declare function isLiteral(token: object): boolean;
182
+
183
+ /**
184
+ * Determines whether the specified token is an operator.
185
+ * Returns `true` if the input is a token of type OPERATOR (`+` or `:`). In all
186
+ * other cases `false` is returned.
187
+ *
188
+ * @param token The token
189
+ * @returns True if the specified token is operator, False otherwise.
190
+ */
191
+ export declare function isOperator(token: object): boolean;
192
+
193
+ /**
194
+ * Determines whether the specified token is a range.
195
+ * Returns `true` if the input is a token that has a type of either REF_RANGE
196
+ * (`A1` or `A1:B2`), REF_TERNARY (`A1:A`, `A1:1`, `1:A1`, or `A:A1`), or
197
+ * REF_BEAM (`A:A` or `1:1`). In all other cases `false` is returned.
198
+ *
199
+ * @param token A token
200
+ * @returns True if the specified token is range, False otherwise.
201
+ */
202
+ export declare function isRange(token: object): boolean;
203
+
204
+ /**
205
+ * Determines whether the specified token is a reference.
206
+ * Returns `true` if the input is a token of type REF_RANGE (`A1` or `A1:B2`),
207
+ * REF_TERNARY (`A1:A`, `A1:1`, `1:A1`, or `A:A1`), REF_BEAM (`A:A` or `1:1`),
208
+ * or REF_NAMED (`myrange`). In all other cases `false` is returned.
209
+ *
210
+ * @param token The token
211
+ * @returns True if the specified token is reference, False otherwise.
212
+ */
213
+ export declare function isReference(token: object): boolean;
214
+
215
+ /**
216
+ * Determines whether the specified token is whitespace.
217
+ * Returns `true` if the input is a token of type WHITESPACE (` `) or
218
+ * NEWLINE (`\n`). In all other cases `false` is returned.
219
+ *
220
+ * @param token The token
221
+ * @returns True if the specified token is whitespace, False otherwise.
222
+ */
223
+ export declare function isWhitespace(token: object): boolean;
224
+
225
+ /**
226
+ * Merges context with reference tokens as possible in a list of tokens.
227
+ * When given a tokenlist, this function returns a new list with ranges returned
228
+ * as whole references (`Sheet1!A1:B2`) rather than separate tokens for each
229
+ * part: (`Sheet1`,`!`,`A1`,`:`,`B2`).
230
+ *
231
+ * @param tokenlist An array of tokens (from `tokenize()`)
232
+ * @returns A new list of tokens with range parts merged.
233
+ */
234
+ export declare function mergeRefTokens(tokenlist: Array<object>): Array<any>;
235
+
236
+ /**
237
+ * Parses a string formula or list of tokens into an AST.
238
+ * The parser requires `mergeRefs` to have been `true` in tokenlist options,
239
+ * because it does not recognize reference context tokens.
240
+ * The AST Abstract Syntax Tree's format is documented in
241
+ * [AST_format.md](./AST_format.md)
242
+ *
243
+ * @param formula An Excel formula string (an Excel expression) or an array of tokens.
244
+ * @param [options={}] Options
245
+ * @param [options.allowNamed=true] Enable parsing names as well as ranges.
246
+ * @param [options.allowTernary=false] Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`. These are supported by Google Sheets but not Excel. See: References.md.
247
+ * @param [options.negativeNumbers=true] Merges unary minuses with their immediately following number tokens (`-`,`1`) => `-1` (alternatively these will be unary operations in the tree).
248
+ * @param [options.permitArrayCalls=false] Function calls are allowed as elements of arrays. This is a feature in Google Sheets while Excel does not allow it.
249
+ * @param [options.permitArrayRanges=false] Ranges are allowed as elements of arrays. This is a feature in Google Sheets while Excel does not allow it.
250
+ * @param [options.r1c1=false] Ranges are expected to be in the R1C1 style format rather than the more popular A1 style.
251
+ * @param [options.withLocation=false] Nodes will include source position offsets to the tokens: `{ loc: [ start, end ] }`
252
+ * @param [options.xlsx=false] Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md)
253
+ * @returns An AST of nodes
254
+ */
255
+ export declare function parse(formula: (string | Array<object>), options?: {
256
+ /** Enable parsing names as well as ranges. */
257
+ allowNamed?: boolean;
258
+ /** Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`. These are supported by Google Sheets but not Excel. See: References.md. */
259
+ allowTernary?: boolean;
260
+ /** Merges unary minuses with their immediately following number tokens (`-`,`1`) => `-1` (alternatively these will be unary operations in the tree). */
261
+ negativeNumbers?: boolean;
262
+ /** Function calls are allowed as elements of arrays. This is a feature in Google Sheets while Excel does not allow it. */
263
+ permitArrayCalls?: boolean;
264
+ /** Ranges are allowed as elements of arrays. This is a feature in Google Sheets while Excel does not allow it. */
265
+ permitArrayRanges?: boolean;
266
+ /** Ranges are expected to be in the R1C1 style format rather than the more popular A1 style. */
267
+ r1c1?: boolean;
268
+ /** Nodes will include source position offsets to the tokens: `{ loc: [ start, end ] }` */
269
+ withLocation?: boolean;
270
+ /** Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) */
271
+ xlsx?: boolean;
272
+ }): object;
273
+
274
+ /**
275
+ * Parse a string reference into an object representing it.
276
+ * ```js
277
+ * parseA1Ref('Sheet1!A$1:$B2');
278
+ * // => {
279
+ * // context: [ 'Sheet1' ],
280
+ * // range: {
281
+ * // top: 0,
282
+ * // left: 0,
283
+ * // bottom: 1,
284
+ * // right: 1
285
+ * // $top: true,
286
+ * // $left: false,
287
+ * // $bottom: false,
288
+ * // $right: true
289
+ * // }
290
+ * // }
291
+ * ```
292
+ * For A:A or A1:A style ranges, `null` will be used for any dimensions that the
293
+ * syntax does not specify:
294
+ *
295
+ * @param refString An A1-style reference string
296
+ * @param [options={}] Options
297
+ * @param [options.allowNamed=true] Enable parsing names as well as ranges.
298
+ * @param [options.allowTernary=false] Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`. These are supported by Google Sheets but not Excel. See: References.md.
299
+ * @param [options.xlsx=false] Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md)
300
+ * @returns An object representing a valid reference or null if it is invalid.
301
+ */
302
+ export declare function parseA1Ref(refString: string, options?: {
303
+ /** Enable parsing names as well as ranges. */
304
+ allowNamed?: boolean;
305
+ /** Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`. These are supported by Google Sheets but not Excel. See: References.md. */
306
+ allowTernary?: boolean;
307
+ /** Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) */
308
+ xlsx?: boolean;
309
+ }): (object | null);
310
+
311
+ /**
312
+ * Parse a string reference into an object representing it.
313
+ * ```js
314
+ * parseR1C1Ref('Sheet1!R[9]C9:R[9]C9');
315
+ * // => {
316
+ * // context: [ 'Sheet1' ],
317
+ * // range: {
318
+ * // r0: 9,
319
+ * // c0: 8,
320
+ * // r1: 9,
321
+ * // c1: 8,
322
+ * // $c0: true,
323
+ * // $c1: true
324
+ * // $r0: false,
325
+ * // $r1: false
326
+ * // }
327
+ * // }
328
+ * ```
329
+ *
330
+ * @param refString An R1C1-style reference string
331
+ * @param [options={}] Options
332
+ * @param [options.allowNamed=true] Enable parsing names as well as ranges.
333
+ * @param [options.allowTernary=false] Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`. These are supported by Google Sheets but not Excel. See: References.md.
334
+ * @param [options.xlsx=false] Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md)
335
+ * @returns An object representing a valid reference or null if it is invalid.
336
+ */
337
+ export declare function parseR1C1Ref(refString: string, options?: {
338
+ /** Enable parsing names as well as ranges. */
339
+ allowNamed?: boolean;
340
+ /** Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`. These are supported by Google Sheets but not Excel. See: References.md. */
341
+ allowTernary?: boolean;
342
+ /** Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) */
343
+ xlsx?: boolean;
344
+ }): (object | null);
345
+
346
+ /**
347
+ * Parse a structured reference string into an object representing it.
348
+ * ```js
349
+ * parseStructRef('workbook.xlsx!tableName[[#Data],[Column1]:[Column2]]');
350
+ * // => {
351
+ * // context: [ 'workbook.xlsx' ],
352
+ * // sections: [ 'data' ],
353
+ * // columns: [ 'my column', '@foo' ],
354
+ * // table: 'tableName',
355
+ * // }
356
+ * ```
357
+ * For A:A or A1:A style ranges, `null` will be used for any dimensions that the
358
+ * syntax does not specify:
359
+ *
360
+ * @param ref A structured reference string
361
+ * @param [options={}] Options
362
+ * @param [options.xlsx=false] Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md)
363
+ * @returns An object representing a valid reference or null if it is invalid.
364
+ */
365
+ export declare function parseStructRef(ref: string, options?: {
366
+ /** Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) */
367
+ xlsx?: boolean;
368
+ }): (object | null);
369
+
370
+ /**
371
+ * Get an A1-style string representation of a reference object.
372
+ * ```js
373
+ * stringifyA1Ref({
374
+ * context: [ 'Sheet1' ],
375
+ * range: {
376
+ * top: 0,
377
+ * left: 0,
378
+ * bottom: 1,
379
+ * right: 1,
380
+ * $top: true,
381
+ * $left: false,
382
+ * $bottom: false,
383
+ * $right: true
384
+ * }
385
+ * });
386
+ * // => 'Sheet1!A$1:$B2'
387
+ * ```
388
+ *
389
+ * @param refObject A reference object
390
+ * @param [options={}] Options
391
+ * @param [options.xlsx=false] Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md)
392
+ * @returns The reference in A1-style string format
393
+ */
394
+ export declare function stringifyA1Ref(refObject: object, options?: {
395
+ /** Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) */
396
+ xlsx?: boolean;
397
+ }): object;
398
+
399
+ /**
400
+ * Get an R1C1-style string representation of a reference object.
401
+ * ```js
402
+ * stringifyR1C1Ref({
403
+ * context: [ 'Sheet1' ],
404
+ * range: {
405
+ * r0: 9,
406
+ * c0: 8,
407
+ * r1: 9,
408
+ * c1: 8,
409
+ * $c0: true,
410
+ * $c1: true
411
+ * $r0: false,
412
+ * $r1: false
413
+ * }
414
+ * });
415
+ * // => 'Sheet1!R[9]C9:R[9]C9'
416
+ * ```
417
+ *
418
+ * @param refObject A reference object
419
+ * @param [options={}] Options
420
+ * @param [options.xlsx=false] Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md)
421
+ * @returns The reference in R1C1-style string format
422
+ */
423
+ export declare function stringifyR1C1Ref(refObject: object, options?: {
424
+ /** Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) */
425
+ xlsx?: boolean;
426
+ }): object;
427
+
428
+ /**
429
+ * Get a string representation of a structured reference object.
430
+ * ```js
431
+ * stringifyStructRef({
432
+ * context: [ 'workbook.xlsx' ],
433
+ * sections: [ 'data' ],
434
+ * columns: [ 'my column', '@foo' ],
435
+ * table: 'tableName',
436
+ * });
437
+ * // => 'workbook.xlsx!tableName[[#Data],[Column1]:[Column2]]'
438
+ * ```
439
+ *
440
+ * @param refObject A structured reference object
441
+ * @param [options={}] Options
442
+ * @param [options.xlsx=false] Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md)
443
+ * @returns The structured reference in string format
444
+ */
445
+ export declare function stringifyStructRef(refObject: object, options?: {
446
+ /** Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) */
447
+ xlsx?: boolean;
448
+ }): object;
449
+
450
+ /**
451
+ * Stringify a range object into A1 syntax.
452
+ *
453
+ * @param range A range object
454
+ * @returns An A1-style string represenation of a range
455
+ */
456
+ declare function toA1(range: object): string;
457
+
458
+ /**
459
+ * Convert a 0 based offset number to a column string
460
+ * representation (`2` = `"C"`).
461
+ * The method expects a number between 0 and 16383. Other input will
462
+ * return garbage.
463
+ *
464
+ * @param columnIndex Zero based column index number
465
+ * @returns The column string identifier
466
+ */
467
+ export declare function toCol(columnIndex: number): string;
468
+
469
+ /**
470
+ * Stringify a range object into R1C1 syntax.
471
+ *
472
+ * @param range A range object
473
+ * @returns An R1C1-style string represenation of a range
474
+ */
475
+ declare function toR1C1(range: object): string;
476
+
477
+ /**
478
+ * Breaks a string formula into a list of tokens.
479
+ * The returned output will be an array of objects representing the tokens:
480
+ * ```js
481
+ * [
482
+ * { type: FX_PREFIX, value: '=' },
483
+ * { type: FUNCTION, value: 'SUM' },
484
+ * { type: OPERATOR, value: '(' },
485
+ * { type: REF_RANGE, value: 'A1:B2' },
486
+ * { type: OPERATOR, value: ')' }
487
+ * ]
488
+ * ```
489
+ * Token types may be found as an Object as the
490
+ * [`tokenTypes` export]{@link tokenTypes} on the package
491
+ * (`import {tokenTypes} from '@borgar/fx';`).
492
+ * To support syntax highlighting as you type, `STRING` tokens are allowed to be
493
+ * "unterminated". For example, the incomplete formula `="Hello world` would be
494
+ * tokenized as:
495
+ * ```js
496
+ * [
497
+ * { type: FX_PREFIX, value: '=' },
498
+ * { type: STRING, value: '"Hello world', unterminated: true },
499
+ * ]
500
+ * ```
501
+ *
502
+ * @param formula An Excel formula string (an Excel expression) or an array of tokens.
503
+ * @param [options={}] Options
504
+ * @param [options.allowTernary=false] Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`. These are supported by Google Sheets but not Excel. See: References.md.
505
+ * @param [options.mergeRefs=true] Should ranges be returned as whole references (`Sheet1!A1:B2`) or as separate tokens for each part: (`Sheet1`,`!`,`A1`,`:`,`B2`). This is the same as calling [`mergeRefTokens`](#mergeRefTokens)
506
+ * @param [options.negativeNumbers=true] Merges unary minuses with their immediately following number tokens (`-`,`1`) => `-1` (alternatively these will be unary operations in the tree).
507
+ * @param [options.r1c1=false] Ranges are expected to be in the R1C1 style format rather than the more popular A1 style.
508
+ * @param [options.withLocation=true] Nodes will include source position offsets to the tokens: `{ loc: [ start, end ] }`
509
+ * @param [options.xlsx=false] Enables a `[1]Sheet1!A1` or `[1]!name` syntax form for external workbooks found only in XLSX files.
510
+ * @returns An AST of nodes
511
+ */
512
+ export declare function tokenize(formula: string, options?: {
513
+ /** Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`. These are supported by Google Sheets but not Excel. See: References.md. */
514
+ allowTernary?: boolean;
515
+ /** Should ranges be returned as whole references (`Sheet1!A1:B2`) or as separate tokens for each part: (`Sheet1`,`!`,`A1`,`:`,`B2`). This is the same as calling [`mergeRefTokens`](#mergeRefTokens) */
516
+ mergeRefs?: boolean;
517
+ /** Merges unary minuses with their immediately following number tokens (`-`,`1`) => `-1` (alternatively these will be unary operations in the tree). */
518
+ negativeNumbers?: boolean;
519
+ /** Ranges are expected to be in the R1C1 style format rather than the more popular A1 style. */
520
+ r1c1?: boolean;
521
+ /** Nodes will include source position offsets to the tokens: `{ loc: [ start, end ] }` */
522
+ withLocation?: boolean;
523
+ /** Enables a `[1]Sheet1!A1` or `[1]!name` syntax form for external workbooks found only in XLSX files. */
524
+ xlsx?: boolean;
525
+ }): Array<object>;
526
+
527
+ /**
528
+ * Translates ranges in a formula or list of tokens from relative R1C1 syntax to
529
+ * absolute A1 syntax.
530
+ * Returns the same formula with the ranges translated. If an array of tokens
531
+ * was supplied, then the same array is returned.
532
+ * ```js
533
+ * translateToA1("=SUM(RC[1],R2C5,Sheet!R3C5)", "D10");
534
+ * // => "=SUM(E10,$E$2,Sheet!$E$3)");
535
+ * ```
536
+ * If an input range is -1,-1 relative rows/columns and the anchor is A1, the
537
+ * resulting range will (by default) wrap around to the bottom of the sheet
538
+ * resulting in the range XFD1048576. This may not be what you want so may set
539
+ * `wrapEdges` to false which will instead turn the range into a `#REF!` error.
540
+ * ```js
541
+ * translateToA1("=R[-1]C[-1]", "A1");
542
+ * // => "=XFD1048576");
543
+ * translateToA1("=R[-1]C[-1]", "A1", { wrapEdges: false });
544
+ * // => "=#REF!");
545
+ * ```
546
+ * Note that if you are passing in a list of tokens that was not created using
547
+ * `mergeRefs` and you disable edge wrapping (or you simply set both options
548
+ * to false), you can end up with a formula such as `=#REF!:B2` or
549
+ * `=Sheet3!#REF!:F3`. These are valid formulas in the Excel formula language
550
+ * and Excel will accept them, but they are not supported in Google Sheets.
551
+ *
552
+ * @param formula A string (an Excel formula) or a token list that should be adjusted.
553
+ * @param anchorCell A simple string reference to an A1 cell ID (`AF123` or`$C$5`).
554
+ * @param [options={}] The options
555
+ * @param [options.allowTernary=true] Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`. These are supported by Google Sheets but not Excel. See: References.md.
556
+ * @param [options.mergeRefs=true] Should ranges be treated as whole references (`Sheet1!A1:B2`) or as separate tokens for each part: (`Sheet1`,`!`,`A1`,`:`,`B2`).
557
+ * @param [options.wrapEdges=true] Wrap out-of-bounds ranges around sheet edges rather than turning them to #REF! errors
558
+ * @param [options.xlsx=false] Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md)
559
+ * @returns A formula string or token list (depending on which was input)
560
+ */
561
+ export declare function translateToA1(formula: (string | Array<object>), anchorCell: string, options?: {
562
+ /** Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`. These are supported by Google Sheets but not Excel. See: References.md. */
563
+ allowTernary?: boolean;
564
+ /** Should ranges be treated as whole references (`Sheet1!A1:B2`) or as separate tokens for each part: (`Sheet1`,`!`,`A1`,`:`,`B2`). */
565
+ mergeRefs?: boolean;
566
+ /** Wrap out-of-bounds ranges around sheet edges rather than turning them to #REF! errors */
567
+ wrapEdges?: boolean;
568
+ /** Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) */
569
+ xlsx?: boolean;
570
+ }): (string | Array<object>);
571
+
572
+ /**
573
+ * Translates ranges in a formula or list of tokens from absolute A1 syntax to
574
+ * relative R1C1 syntax.
575
+ * Returns the same formula with the ranges translated. If an array of tokens
576
+ * was supplied, then the same array is returned.
577
+ * ```js
578
+ * translateToR1C1("=SUM(E10,$E$2,Sheet!$E$3)", "D10");
579
+ * // => "=SUM(RC[1],R2C5,Sheet!R3C5)");
580
+ * ```
581
+ *
582
+ * @param formula A string (an Excel formula) or a token list that should be adjusted.
583
+ * @param anchorCell A simple string reference to an A1 cell ID (`AF123` or`$C$5`).
584
+ * @param [options={}] The options
585
+ * @param [options.allowTernary=true] Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`. These are supported by Google Sheets but not Excel. See: References.md.
586
+ * @param [options.xlsx=false] Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md)
587
+ * @returns A formula string or token list (depending on which was input)
588
+ */
589
+ export declare function translateToR1C1(formula: (string | Array<object>), anchorCell: string, options?: {
590
+ /** Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`. These are supported by Google Sheets but not Excel. See: References.md. */
591
+ allowTernary?: boolean;
592
+ /** Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) */
593
+ xlsx?: boolean;
594
+ }): (string | Array<object>);
595
+
596
+ /** A dictionary of the types used to identify AST node variants. */
597
+ export declare const nodeTypes: Readonly<{
598
+ /** An array expression (`{1,2;3,4}`) */
599
+ ARRAY: string;
600
+ /** A binary operation (`10+10`) */
601
+ BINARY: string;
602
+ /** A function call expression (`SUM(1,2)`) */
603
+ CALL: string;
604
+ /** An error literal (`#VALUE!`) */
605
+ ERROR: string;
606
+ /** A function name identifier (`SUM`) */
607
+ IDENTIFIER: string;
608
+ /** A literal (number, string, or boolean) (`123`, `"foo"`, `false`) */
609
+ LITERAL: string;
610
+ /** A range identifier (`A1`) */
611
+ REFERENCE: string;
612
+ /** A unary operation (`10%`) */
613
+ UNARY: string;
614
+ }>;
615
+
616
+ /** A dictionary of the types used to identify token variants. */
617
+ export declare const tokenTypes: Readonly<{
618
+ /** Boolean literal (`TRUE`) */
619
+ BOOLEAN: string;
620
+ /** Reference context ([Workbook.xlsx]Sheet1) */
621
+ CONTEXT: string;
622
+ /** Quoted reference context (`'[My workbook.xlsx]Sheet1'`) */
623
+ CONTEXT_QUOTE: string;
624
+ /** Error literal (`#VALUE!`) */
625
+ ERROR: string;
626
+ /** Function name (`SUM`) */
627
+ FUNCTION: string;
628
+ /** A leading equals sign at the start of a formula (`=`) */
629
+ FX_PREFIX: string;
630
+ /** Newline character (`\n`) */
631
+ NEWLINE: string;
632
+ /** Number literal (`123.4`, `-1.5e+2`) */
633
+ NUMBER: string;
634
+ /** Newline (`\n`) */
635
+ OPERATOR: string;
636
+ /** A range "beam" identifier (`A:A` or `1:1`) */
637
+ REF_BEAM: string;
638
+ /** A name / named range identifier (`income`) */
639
+ REF_NAMED: string;
640
+ /** A range identifier (`A1`) */
641
+ REF_RANGE: string;
642
+ /** A structured reference identifier (`table[[Column1]:[Column2]]`) */
643
+ REF_STRUCT: string;
644
+ /** A ternary range identifier (`B2:B`) */
645
+ REF_TERNARY: string;
646
+ /** String literal (`"Lorem ipsum"`) */
647
+ STRING: string;
648
+ /** Any unidentifiable range of characters. */
649
+ UNKNOWN: string;
650
+ /** Whitespace character sequence (` `) */
651
+ WHITESPACE: string;
652
+ }>;
653
+