@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.
Files changed (141) hide show
  1. package/dist/index-BMr6cTgc.d.cts +1444 -0
  2. package/dist/index-BMr6cTgc.d.ts +1444 -0
  3. package/dist/index.cjs +3054 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +1 -0
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.js +2984 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/xlsx/index.cjs +3120 -0
  10. package/dist/xlsx/index.cjs.map +1 -0
  11. package/dist/xlsx/index.d.cts +55 -0
  12. package/dist/xlsx/index.d.ts +55 -0
  13. package/dist/xlsx/index.js +3049 -0
  14. package/dist/xlsx/index.js.map +1 -0
  15. package/docs/API.md +2959 -718
  16. package/docs/AST_format.md +2 -2
  17. package/eslint.config.mjs +40 -0
  18. package/lib/a1.spec.ts +32 -0
  19. package/lib/a1.ts +26 -0
  20. package/lib/addA1RangeBounds.ts +50 -0
  21. package/lib/addTokenMeta.spec.ts +166 -0
  22. package/lib/{addTokenMeta.js → addTokenMeta.ts} +53 -33
  23. package/lib/astTypes.ts +211 -0
  24. package/lib/cloneToken.ts +29 -0
  25. package/lib/{constants.js → constants.ts} +6 -3
  26. package/lib/fixRanges.spec.ts +220 -0
  27. package/lib/fixRanges.ts +260 -0
  28. package/lib/fromCol.spec.ts +15 -0
  29. package/lib/{fromCol.js → fromCol.ts} +1 -1
  30. package/lib/index.spec.ts +119 -0
  31. package/lib/index.ts +76 -0
  32. package/lib/isNodeType.ts +151 -0
  33. package/lib/isType.spec.ts +208 -0
  34. package/lib/{isType.js → isType.ts} +26 -25
  35. package/lib/lexers/{advRangeOp.js → advRangeOp.ts} +1 -1
  36. package/lib/lexers/{canEndRange.js → canEndRange.ts} +2 -2
  37. package/lib/lexers/{lexBoolean.js → lexBoolean.ts} +25 -6
  38. package/lib/lexers/{lexContext.js → lexContext.ts} +14 -6
  39. package/lib/lexers/{lexError.js → lexError.ts} +3 -3
  40. package/lib/lexers/{lexFunction.js → lexFunction.ts} +3 -2
  41. package/lib/lexers/lexNameFuncCntx.ts +112 -0
  42. package/lib/lexers/{lexNamed.js → lexNamed.ts} +4 -4
  43. package/lib/lexers/{lexNewLine.js → lexNewLine.ts} +3 -2
  44. package/lib/lexers/{lexNumber.js → lexNumber.ts} +4 -3
  45. package/lib/lexers/{lexOperator.js → lexOperator.ts} +5 -4
  46. package/lib/lexers/lexRange.ts +15 -0
  47. package/lib/lexers/{lexRangeA1.js → lexRangeA1.ts} +11 -7
  48. package/lib/lexers/{lexRangeR1C1.js → lexRangeR1C1.ts} +10 -6
  49. package/lib/lexers/{lexRangeTrim.js → lexRangeTrim.ts} +3 -2
  50. package/lib/lexers/{lexRefOp.js → lexRefOp.ts} +4 -3
  51. package/lib/lexers/{lexString.js → lexString.ts} +3 -3
  52. package/lib/lexers/{lexStructured.js → lexStructured.ts} +5 -5
  53. package/lib/lexers/{lexWhitespace.js → lexWhitespace.ts} +3 -2
  54. package/lib/lexers/sets.ts +51 -0
  55. package/lib/mergeRefTokens.spec.ts +141 -0
  56. package/lib/{mergeRefTokens.js → mergeRefTokens.ts} +14 -9
  57. package/lib/nodeTypes.ts +54 -0
  58. package/lib/parse.spec.ts +1410 -0
  59. package/lib/{parser.js → parse.ts} +81 -63
  60. package/lib/parseA1Range.spec.ts +233 -0
  61. package/lib/parseA1Range.ts +206 -0
  62. package/lib/parseA1Ref.spec.ts +337 -0
  63. package/lib/parseA1Ref.ts +115 -0
  64. package/lib/parseR1C1Range.ts +191 -0
  65. package/lib/parseR1C1Ref.spec.ts +323 -0
  66. package/lib/parseR1C1Ref.ts +127 -0
  67. package/lib/parseRef.spec.ts +90 -0
  68. package/lib/parseRef.ts +240 -0
  69. package/lib/{parseSRange.js → parseSRange.ts} +15 -10
  70. package/lib/parseStructRef.spec.ts +168 -0
  71. package/lib/parseStructRef.ts +76 -0
  72. package/lib/stringifyA1Range.spec.ts +72 -0
  73. package/lib/stringifyA1Range.ts +72 -0
  74. package/lib/stringifyA1Ref.spec.ts +64 -0
  75. package/lib/stringifyA1Ref.ts +59 -0
  76. package/lib/{stringifyPrefix.js → stringifyPrefix.ts} +17 -2
  77. package/lib/stringifyR1C1Range.spec.ts +92 -0
  78. package/lib/stringifyR1C1Range.ts +73 -0
  79. package/lib/stringifyR1C1Ref.spec.ts +63 -0
  80. package/lib/stringifyR1C1Ref.ts +67 -0
  81. package/lib/stringifyStructRef.spec.ts +124 -0
  82. package/lib/stringifyStructRef.ts +113 -0
  83. package/lib/stringifyTokens.ts +15 -0
  84. package/lib/toCol.spec.ts +11 -0
  85. package/lib/{toCol.js → toCol.ts} +4 -4
  86. package/lib/tokenTypes.ts +76 -0
  87. package/lib/tokenize-srefs.spec.ts +429 -0
  88. package/lib/tokenize.spec.ts +2103 -0
  89. package/lib/tokenize.ts +346 -0
  90. package/lib/translate.spec.ts +35 -0
  91. package/lib/translateToA1.spec.ts +247 -0
  92. package/lib/translateToA1.ts +231 -0
  93. package/lib/translateToR1C1.spec.ts +227 -0
  94. package/lib/translateToR1C1.ts +145 -0
  95. package/lib/types.ts +179 -0
  96. package/lib/xlsx/index.spec.ts +27 -0
  97. package/lib/xlsx/index.ts +32 -0
  98. package/package.json +45 -31
  99. package/tsconfig.json +28 -0
  100. package/typedoc-ignore-links.ts +17 -0
  101. package/typedoc.json +41 -0
  102. package/.eslintrc +0 -22
  103. package/benchmark/benchmark.js +0 -48
  104. package/benchmark/formulas.json +0 -15677
  105. package/dist/fx.d.ts +0 -823
  106. package/dist/fx.js +0 -2
  107. package/dist/package.json +0 -1
  108. package/lib/a1.js +0 -348
  109. package/lib/a1.spec.js +0 -458
  110. package/lib/addTokenMeta.spec.js +0 -153
  111. package/lib/astTypes.js +0 -96
  112. package/lib/extraTypes.js +0 -74
  113. package/lib/fixRanges.js +0 -104
  114. package/lib/fixRanges.spec.js +0 -171
  115. package/lib/fromCol.spec.js +0 -11
  116. package/lib/index.js +0 -134
  117. package/lib/index.spec.js +0 -67
  118. package/lib/isType.spec.js +0 -168
  119. package/lib/lexer-srefs.spec.js +0 -324
  120. package/lib/lexer.js +0 -264
  121. package/lib/lexer.spec.js +0 -1953
  122. package/lib/lexers/lexRange.js +0 -8
  123. package/lib/lexers/sets.js +0 -38
  124. package/lib/mergeRefTokens.spec.js +0 -121
  125. package/lib/package.json +0 -1
  126. package/lib/parseRef.js +0 -157
  127. package/lib/parseRef.spec.js +0 -71
  128. package/lib/parseStructRef.js +0 -48
  129. package/lib/parseStructRef.spec.js +0 -164
  130. package/lib/parser.spec.js +0 -1208
  131. package/lib/rc.js +0 -341
  132. package/lib/rc.spec.js +0 -403
  133. package/lib/stringifyStructRef.js +0 -80
  134. package/lib/stringifyStructRef.spec.js +0 -182
  135. package/lib/toCol.spec.js +0 -11
  136. package/lib/translate-toA1.spec.js +0 -214
  137. package/lib/translate-toRC.spec.js +0 -197
  138. package/lib/translate.js +0 -239
  139. package/lib/translate.spec.js +0 -21
  140. package/rollup.config.mjs +0 -22
  141. package/tsd.json +0 -12
package/docs/API.md CHANGED
@@ -1,1059 +1,3300 @@
1
- # _Fx_ API
2
-
3
- **Functions**
4
-
5
- - [addA1RangeBounds( range )](#addA1RangeBounds)
6
- - [addTokenMeta( tokenlist, _\[context\]_ )](#addTokenMeta)
7
- - [fixRanges( formula, _\[options\]_ )](#fixRanges)
8
- - [fromCol( columnString )](#fromCol)
9
- - [isError( token )](#isError)
10
- - [isFunction( token )](#isFunction)
11
- - [isFxPrefix( token )](#isFxPrefix)
12
- - [isLiteral( token )](#isLiteral)
13
- - [isOperator( token )](#isOperator)
14
- - [isRange( token )](#isRange)
15
- - [isReference( token )](#isReference)
16
- - [isWhitespace( token )](#isWhitespace)
17
- - [mergeRefTokens( tokenlist )](#mergeRefTokens)
18
- - [parse( formula, _\[options\]_ )](#parse)
19
- - [parseA1Ref( refString, _\[options\]_ )](#parseA1Ref)
20
- - [parseR1C1Ref( refString, _\[options\]_ )](#parseR1C1Ref)
21
- - [parseStructRef( ref, _\[options\]_ )](#parseStructRef)
22
- - [stringifyA1Ref( refObject, _\[options\]_ )](#stringifyA1Ref)
23
- - [stringifyR1C1Ref( refObject, _\[options\]_ )](#stringifyR1C1Ref)
24
- - [stringifyStructRef( refObject, _\[options\]_ )](#stringifyStructRef)
25
- - [toCol( columnIndex )](#toCol)
26
- - [tokenize( formula, _\[options\]_ )](#tokenize)
27
- - [translateToA1( formula, anchorCell, _\[options\]_ )](#translateToA1)
28
- - [translateToR1C1( formula, anchorCell, _\[options\]_ )](#translateToR1C1)
29
-
30
- **Constants**
31
-
32
- - [nodeTypes](#nodeTypes)
33
- - [tokenTypes](#tokenTypes)
34
-
35
- **Types**
36
-
37
- - [AstExpression](#AstExpression)
38
- - [BinaryExpression](#BinaryExpression)
39
- - [CallExpression](#CallExpression)
40
- - [ErrorLiteral](#ErrorLiteral)
41
- - [Identifier](#Identifier)
42
- - [LambdaExpression](#LambdaExpression)
43
- - [LetDeclarator](#LetDeclarator)
44
- - [LetExpression](#LetExpression)
45
- - [Literal](#Literal)
46
- - [MatrixExpression](#MatrixExpression)
47
- - [RangeA1](#RangeA1)
48
- - [RangeR1C1](#RangeR1C1)
49
- - [ReferenceA1](#ReferenceA1)
50
- - [ReferenceIdentifier](#ReferenceIdentifier)
51
- - [ReferenceR1C1](#ReferenceR1C1)
52
- - [ReferenceStruct](#ReferenceStruct)
53
- - [SourceLocation](#SourceLocation)
54
- - [Token](#Token)
55
- - [TokenEnhanced](#TokenEnhanced)
56
- - [UnaryExpression](#UnaryExpression)
1
+
2
+ <a name="readmemd"></a>
3
+
4
+ # @borgar/fx
5
+
6
+ ## Modules
7
+
8
+ - [fx](#fxreadmemd)
9
+ - [fx/xlsx](#fxxlsxreadmemd)
10
+
11
+
12
+ <a name="fxreadmemd"></a>
13
+
14
+ # fx
15
+
16
+ A tokenizer, parser, and other utilities to work with Excel formula code.
17
+
18
+ The base entry-point methods expect and return the variant of references that uses contexts.
19
+ If you are using xlsx files or otherwise want to work with the xlsx-file variant of references
20
+ you should use the [fx/xlsx](#fxxlsxreadmemd) variant methods.
21
+
22
+ See [Prefixes.md](./Prefixes.md) for documentation on how scopes work in Fx.
23
+
24
+ ## Type Aliases
25
+
26
+ - [ArrayExpression](#fxtype-aliasesarrayexpressionmd)
27
+ - [AstExpression](#fxtype-aliasesastexpressionmd)
28
+ - [BinaryExpression](#fxtype-aliasesbinaryexpressionmd)
29
+ - [BinaryOperator](#fxtype-aliasesbinaryoperatormd)
30
+ - [CallExpression](#fxtype-aliasescallexpressionmd)
31
+ - [ErrorLiteral](#fxtype-aliaseserrorliteralmd)
32
+ - [Identifier](#fxtype-aliasesidentifiermd)
33
+ - [LambdaExpression](#fxtype-aliaseslambdaexpressionmd)
34
+ - [LetDeclarator](#fxtype-aliasesletdeclaratormd)
35
+ - [LetExpression](#fxtype-aliasesletexpressionmd)
36
+ - [Literal](#fxtype-aliasesliteralmd)
37
+ - [Node](#fxtype-aliasesnodemd)
38
+ - [OptsFixRanges](#fxtype-aliasesoptsfixrangesmd)
39
+ - [OptsParse](#fxtype-aliasesoptsparsemd)
40
+ - [OptsParseA1Ref](#fxtype-aliasesoptsparsea1refmd)
41
+ - [OptsParseR1C1Ref](#fxtype-aliasesoptsparser1c1refmd)
42
+ - [OptsStringifyStructRef](#fxtype-aliasesoptsstringifystructrefmd)
43
+ - [OptsTokenize](#fxtype-aliasesoptstokenizemd)
44
+ - [OptsTranslateFormulaToA1](#fxtype-aliasesoptstranslateformulatoa1md)
45
+ - [OptsTranslateTokensToA1](#fxtype-aliasesoptstranslatetokenstoa1md)
46
+ - [OptsTranslateToR1C1](#fxtype-aliasesoptstranslatetor1c1md)
47
+ - [RangeA1](#fxtype-aliasesrangea1md)
48
+ - [RangeR1C1](#fxtype-aliasesranger1c1md)
49
+ - [ReferenceA1](#fxtype-aliasesreferencea1md)
50
+ - [ReferenceA1Xlsx](#fxtype-aliasesreferencea1xlsxmd)
51
+ - [ReferenceIdentifier](#fxtype-aliasesreferenceidentifiermd)
52
+ - [ReferenceName](#fxtype-aliasesreferencenamemd)
53
+ - [ReferenceNameXlsx](#fxtype-aliasesreferencenamexlsxmd)
54
+ - [ReferenceR1C1](#fxtype-aliasesreferencer1c1md)
55
+ - [ReferenceR1C1Xlsx](#fxtype-aliasesreferencer1c1xlsxmd)
56
+ - [ReferenceStruct](#fxtype-aliasesreferencestructmd)
57
+ - [ReferenceStructXlsx](#fxtype-aliasesreferencestructxlsxmd)
58
+ - [SourceLocation](#fxtype-aliasessourcelocationmd)
59
+ - [Token](#fxtype-aliasestokenmd)
60
+ - [TokenEnhanced](#fxtype-aliasestokenenhancedmd)
61
+ - [UnaryExpression](#fxtype-aliasesunaryexpressionmd)
62
+ - [UnaryOperator](#fxtype-aliasesunaryoperatormd)
63
+
64
+ ## Variables
65
+
66
+ - [MAX\_COLS](#fxvariablesmax_colsmd)
67
+ - [MAX\_ROWS](#fxvariablesmax_rowsmd)
68
+ - [nodeTypes](#fxvariablesnodetypesmd)
69
+ - [tokenTypes](#fxvariablestokentypesmd)
57
70
 
58
71
  ## Functions
59
72
 
60
- ### <a id="addA1RangeBounds" href="#addA1RangeBounds">#</a> addA1RangeBounds( range ) ⇒ [`RangeA1`](#RangeA1)
73
+ - [addA1RangeBounds](#fxfunctionsadda1rangeboundsmd)
74
+ - [fixFormulaRanges](#fxfunctionsfixformularangesmd)
75
+ - [fixTokenRanges](#fxfunctionsfixtokenrangesmd)
76
+ - [fromCol](#fxfunctionsfromcolmd)
77
+ - [isArrayNode](#fxfunctionsisarraynodemd)
78
+ - [isBinaryNode](#fxfunctionsisbinarynodemd)
79
+ - [isCallNode](#fxfunctionsiscallnodemd)
80
+ - [isError](#fxfunctionsiserrormd)
81
+ - [isErrorNode](#fxfunctionsiserrornodemd)
82
+ - [isExpressionNode](#fxfunctionsisexpressionnodemd)
83
+ - [isFunction](#fxfunctionsisfunctionmd)
84
+ - [isFxPrefix](#fxfunctionsisfxprefixmd)
85
+ - [isIdentifierNode](#fxfunctionsisidentifiernodemd)
86
+ - [isLambdaNode](#fxfunctionsislambdanodemd)
87
+ - [isLetDeclaratorNode](#fxfunctionsisletdeclaratornodemd)
88
+ - [isLetNode](#fxfunctionsisletnodemd)
89
+ - [isLiteral](#fxfunctionsisliteralmd)
90
+ - [isLiteralNode](#fxfunctionsisliteralnodemd)
91
+ - [isOperator](#fxfunctionsisoperatormd)
92
+ - [isRange](#fxfunctionsisrangemd)
93
+ - [isReference](#fxfunctionsisreferencemd)
94
+ - [isReferenceNode](#fxfunctionsisreferencenodemd)
95
+ - [isUnaryNode](#fxfunctionsisunarynodemd)
96
+ - [isWhitespace](#fxfunctionsiswhitespacemd)
97
+ - [mergeRefTokens](#fxfunctionsmergereftokensmd)
98
+ - [parse](#fxfunctionsparsemd)
99
+ - [parseA1Range](#fxfunctionsparsea1rangemd)
100
+ - [parseA1Ref](#fxfunctionsparsea1refmd)
101
+ - [parseR1C1Range](#fxfunctionsparser1c1rangemd)
102
+ - [parseR1C1Ref](#fxfunctionsparser1c1refmd)
103
+ - [parseStructRef](#fxfunctionsparsestructrefmd)
104
+ - [stringifyA1Ref](#fxfunctionsstringifya1refmd)
105
+ - [stringifyR1C1Ref](#fxfunctionsstringifyr1c1refmd)
106
+ - [stringifyStructRef](#fxfunctionsstringifystructrefmd)
107
+ - [stringifyTokens](#fxfunctionsstringifytokensmd)
108
+ - [toCol](#fxfunctionstocolmd)
109
+ - [tokenize](#fxfunctionstokenizemd)
110
+ - [translateFormulaToA1](#fxfunctionstranslateformulatoa1md)
111
+ - [translateFormulaToR1C1](#fxfunctionstranslateformulator1c1md)
112
+ - [translateTokensToA1](#fxfunctionstranslatetokenstoa1md)
113
+ - [translateTokensToR1C1](#fxfunctionstranslatetokenstor1c1md)
114
+
115
+
116
+ <a name="fxfunctionsadda1rangeboundsmd"></a>
117
+
118
+ # addA1RangeBounds()
119
+
120
+ ```ts
121
+ function addA1RangeBounds(range: RangeA1): RangeA1;
122
+ ```
61
123
 
62
- Fill the any missing bounds in range objects. Top will be set to 0, bottom to 1048575, left to 0, and right to 16383, if they are `null` or `undefined`.
124
+ Fill the any missing bounds in range objects. Top will be set to 0, bottom to
125
+ 1048575, left to 0, and right to 16383, if they are `null` or `undefined`.
63
126
 
64
127
  ```js
65
128
  addA1RangeBounds({
66
- context: [ 'Sheet1' ],
67
- range: {
68
- top: 0,
69
- left: 0,
70
- bottom: 1,
71
- $top: true,
72
- $left: false,
73
- $bottom: false,
74
- }
129
+ top: 0,
130
+ left: 0,
131
+ bottom: 1,
132
+ $top: true,
133
+ $left: false,
134
+ $bottom: false,
75
135
  });
76
136
  // => {
77
- // context: [ 'Sheet1' ],
78
- // range: {
79
- // top: 0,
80
- // left: 0,
81
- // bottom: 1,
82
- // right: 16383,
83
- // $top: true,
84
- // $left: false,
85
- // $bottom: false,
86
- // $right: false
87
- // }
137
+ // top: 0,
138
+ // left: 0,
139
+ // bottom: 1,
140
+ // right: 16383, // ← Added
141
+ // $top: true,
142
+ // $left: false,
143
+ // $bottom: false,
144
+ // $right: false // ← Added
88
145
  // }
89
146
  ```
90
147
 
91
- ##### Parameters
148
+ ## Parameters
92
149
 
93
- | Name | Type | Description |
94
- | ----- | --------------------- | ------------------------------------- |
95
- | range | [`RangeA1`](#RangeA1) | The range part of a reference object. |
150
+ | Parameter | Type | Description |
151
+ | ------ | ------ | ------ |
152
+ | `range` | [`RangeA1`](#fxtype-aliasesrangea1md) | The range part of a reference object. |
96
153
 
97
- ##### Returns
154
+ ## Returns
98
155
 
99
- [`RangeA1`](#RangeA1) – same range with missing bounds filled in.
156
+ [`RangeA1`](#fxtype-aliasesrangea1md)
100
157
 
101
- ---
158
+ The same range with missing bounds filled in.
102
159
 
103
- ### <a id="addTokenMeta" href="#addTokenMeta">#</a> addTokenMeta( tokenlist, _[context = `{}`]_ ) ⇒ `Array<TokenEnhanced>`
104
160
 
105
- Runs through a list of tokens and adds extra attributes such as matching parens and ranges.
161
+ <a name="fxfunctionsfixformularangesmd"></a>
106
162
 
107
- The `context` parameter defines default reference attributes: `{ workbookName: 'report.xlsx', sheetName: 'Sheet1' }`. If supplied, these are used to match `A1` to `Sheet1!A1`.
163
+ # fixFormulaRanges()
108
164
 
109
- All tokens will be tagged with a `.depth` number value to indicating the level of nesting in parentheses as well as an `.index` number indicating their zero based position in the list.
165
+ ```ts
166
+ function fixFormulaRanges(formula: string, options?: OptsFixRanges & OptsTokenize): string;
167
+ ```
110
168
 
111
- The returned output will be the same array of tokens but the following properties will added to tokens (as applicable):
169
+ Normalizes A1 style ranges and structured references in a formula.
112
170
 
113
- #### Parentheses ( )
171
+ Internally it uses [fixTokenRanges](#fxfunctionsfixtokenrangesmd) so see it's documentation for details.
114
172
 
115
- Matching parens will be tagged with `.groupId` string identifier as well as a `.depth` number value (indicating the level of nesting).
173
+ Returns the same formula with the ranges updated. If an array of tokens was
174
+ supplied, then a new array is returned.
116
175
 
117
- Closing parens without a counterpart will be tagged with `.error` (boolean true).
176
+ ## Parameters
118
177
 
119
- #### Curly brackets { }
178
+ | Parameter | Type | Description |
179
+ | ------ | ------ | ------ |
180
+ | `formula` | `string` | A string (an Excel formula) or a token list that should be adjusted. |
181
+ | `options?` | [`OptsFixRanges`](#fxtype-aliasesoptsfixrangesmd) & [`OptsTokenize`](#fxtype-aliasesoptstokenizemd) | Options |
120
182
 
121
- Matching curly brackets will be tagged with `.groupId` string identifier. These may not be nested in Excel.
183
+ ## Returns
122
184
 
123
- Closing curly brackets without a counterpart will be tagged with `.error` (boolean `true`).
185
+ `string`
124
186
 
125
- #### Ranges (`REF_RANGE` or `REF_BEAM` type tokens)
187
+ A formula string with ranges adjusted
126
188
 
127
- All ranges will be tagged with `.groupId` string identifier regardless of the number of times they occur.
189
+ ## See
128
190
 
129
- #### Tokens of type `UNKNOWN`
191
+ [OptsFixRanges](#fxtype-aliasesoptsfixrangesmd) & [OptsTokenize](#fxtype-aliasesoptstokenizemd)
130
192
 
131
- All will be tagged with `.error` (boolean `true`).
132
193
 
133
- ##### Parameters
194
+ <a name="fxfunctionsfixtokenrangesmd"></a>
134
195
 
135
- | Name | Type | Default | Description |
136
- | ---------------------- | -------------- | ------- | -------------------------------------------- |
137
- | tokenlist | `Array<Token>` | | An array of tokens (from `tokenize()`) |
138
- | [context] | `object` | `{}` | A contest used to match `A1` to `Sheet1!A1`. |
139
- | [context].sheetName | `string` | `""` | An implied sheet name ('Sheet1') |
140
- | [context].workbookName | `string` | `""` | An implied workbook name ('report.xlsx') |
196
+ # fixTokenRanges()
141
197
 
142
- ##### Returns
198
+ ```ts
199
+ function fixTokenRanges(tokens: Token[], options?: OptsFixRanges): Token[];
200
+ ```
143
201
 
144
- `Array<TokenEnhanced>` The input array with the enchanced tokens
202
+ Normalizes A1 style ranges and structured references in a list of tokens.
145
203
 
146
- ---
204
+ It ensures that that the top and left coordinates of an A1 range are on the
205
+ left-hand side of a colon operator:
147
206
 
148
- ### <a id="fixRanges" href="#fixRanges">#</a> fixRanges( formula, _[options = `{}`]_ ) ⇒ `string` | `Array<Token>`
207
+ ```
208
+ B2:A1 → A1:B2
209
+ 1:A1 → A1:1
210
+ A:A1 → A1:A
211
+ B:A → A:B
212
+ 2:1 → 1:2
213
+ A1:A1 → A1
214
+ ```
149
215
 
150
- Normalizes A1 style ranges and structured references in a formula or list of tokens.
216
+ When `{ addBounds }` option is set to true, the missing bounds are also added.
217
+ This can be done to ensure Excel compatible ranges. The fixes then additionally include:
151
218
 
152
- It ensures that that the top and left coordinates of an A1 range are on the left-hand side of a colon operator:
219
+ ```
220
+ 1:A1 → A1:1 → 1:1
221
+ A:A1 → A1:A → A:A
222
+ A1:A → A:A
223
+ A1:1 → A:1
224
+ B2:B → B2:1048576
225
+ B2:2 → B2:XFD2
226
+ ```
153
227
 
154
- `B2:A1` `A1:B2`
155
- `1:A1` `A1:1`
156
- `A:A1` → `A1:A`
157
- `B:A` → `A:B`
158
- `2:1` → `1:2`
159
- `A1:A1` → `A1`
228
+ Structured ranges are normalized to have consistent order and capitalization
229
+ of sections as well as removing redundant ones.
160
230
 
161
- When `{ addBounds: true }` is passed as an option, the missing bounds are also added. This can be done to ensure Excel compatible ranges. The fixes then additionally include:
231
+ Returns a new array of tokens with values and position data updated.
162
232
 
163
- `1:A1` → `A1:1` → `1:1`
164
- `A:A1` → `A1:A` → `A:A`
165
- `A1:A` → `A:A`
166
- `A1:1` → `A:1`
167
- `B2:B` → `B2:1048576`
168
- `B2:2` → `B2:XFD2`
233
+ ## Parameters
169
234
 
170
- Structured ranges are normalized cleaned up to have consistent order and capitalization of sections as well as removing redundant ones.
235
+ | Parameter | Type | Description |
236
+ | ------ | ------ | ------ |
237
+ | `tokens` | [`Token`](#fxtype-aliasestokenmd)[] | A list of tokens to be adjusted. |
238
+ | `options?` | [`OptsFixRanges`](#fxtype-aliasesoptsfixrangesmd) | Options. |
171
239
 
172
- Returns the same formula with the ranges updated. If an array of tokens was supplied, then a new array is returned.
240
+ ## Returns
173
241
 
174
- ##### Parameters
242
+ [`Token`](#fxtype-aliasestokenmd)[]
175
243
 
176
- | Name | Type | Default | Description |
177
- | ------------------- | -------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- |
178
- | formula | `string` \| `Array<Token>` | | A string (an Excel formula) or a token list that should be adjusted. |
179
- | [options] | `object` | `{}` | Options |
180
- | [options].addBounds | `boolean` | `false` | Fill in any undefined bounds of range objects. Top to 0, bottom to 1048575, left to 0, and right to 16383. |
181
- | [options].thisRow | `boolean` | `false` | Enforces using the `[#This Row]` instead of the `@` shorthand when serializing structured ranges. |
182
- | [options].xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
244
+ A token list with ranges adjusted.
183
245
 
184
- ##### Returns
246
+ ## See
185
247
 
186
- `string` | `Array<Token>` – A formula string or token list (depending on which was input)
248
+ [OptsFixRanges](#fxtype-aliasesoptsfixrangesmd)
187
249
 
188
- ---
189
250
 
190
- ### <a id="fromCol" href="#fromCol">#</a> fromCol( columnString ) ⇒ `number`
251
+ <a name="fxfunctionsfromcolmd"></a>
191
252
 
192
- Convert a column string representation to a 0 based offset number (`"C"` = `2`).
253
+ # fromCol()
193
254
 
194
- The method expects a valid column identifier made up of _only_ A-Z letters, which may be either upper or lower case. Other input will return garbage.
255
+ ```ts
256
+ function fromCol(columnString: string): number;
257
+ ```
195
258
 
196
- ##### Parameters
259
+ Convert a column string representation to a 0 based
260
+ offset number (`"C"` = `2`).
197
261
 
198
- | Name | Type | Description |
199
- | ------------ | -------- | ---------------------------- |
200
- | columnString | `string` | The column string identifier |
262
+ The method expects a valid column identifier made up of _only_
263
+ A-Z letters, which may be either upper or lower case. Other input will
264
+ return garbage.
201
265
 
202
- ##### Returns
266
+ ## Parameters
203
267
 
204
- `number` Zero based column index number
268
+ | Parameter | Type | Description |
269
+ | ------ | ------ | ------ |
270
+ | `columnString` | `string` | The column string identifier |
205
271
 
206
- ---
272
+ ## Returns
207
273
 
208
- ### <a id="isError" href="#isError">#</a> isError( token ) ⇒ `boolean`
274
+ `number`
209
275
 
210
- Determines whether the specified token is an error.
276
+ Zero based column index number
211
277
 
212
- Returns `true` if the input is a token of type ERROR (`#VALUE!`). In all other cases `false` is returned.
213
278
 
214
- ##### Parameters
279
+ <a name="fxfunctionsisarraynodemd"></a>
215
280
 
216
- | Name | Type | Description |
217
- | ----- | ----- | ----------- |
218
- | token | `any` | The token |
281
+ # isArrayNode()
219
282
 
220
- ##### Returns
283
+ ```ts
284
+ function isArrayNode(node?: Node): node is ArrayExpression;
285
+ ```
221
286
 
222
- `boolean` True if the specified token is error, False otherwise.
287
+ Determines whether the specified node is a ArrayExpression.
223
288
 
224
- ---
289
+ ## Parameters
225
290
 
226
- ### <a id="isFunction" href="#isFunction">#</a> isFunction( token ) `boolean`
291
+ | Parameter | Type | Description |
292
+ | ------ | ------ | ------ |
293
+ | `node?` | [`Node`](#fxtype-aliasesnodemd) | An AST node. |
227
294
 
228
- Determines whether the specified token is a function.
295
+ ## Returns
229
296
 
230
- Returns `true` if the input is a token of type FUNCTION. In all other cases `false` is returned.
297
+ `node is ArrayExpression`
231
298
 
232
- ##### Parameters
299
+ True if the specified token is a ArrayExpression, False otherwise.
233
300
 
234
- | Name | Type | Description |
235
- | ----- | ----- | ----------- |
236
- | token | `any` | The token |
237
301
 
238
- ##### Returns
302
+ <a name="fxfunctionsisbinarynodemd"></a>
239
303
 
240
- `boolean` – True if the specified token is function, False otherwise.
304
+ # isBinaryNode()
241
305
 
242
- ---
306
+ ```ts
307
+ function isBinaryNode(node?: Node): node is BinaryExpression;
308
+ ```
243
309
 
244
- ### <a id="isFxPrefix" href="#isFxPrefix">#</a> isFxPrefix( token ) `boolean`
310
+ Determines whether the specified node is a BinaryExpression.
245
311
 
246
- Returns `true` if the input is a token of type FX_PREFIX (leading `=` in formula). In all other cases `false` is returned.
312
+ ## Parameters
247
313
 
248
- ##### Parameters
314
+ | Parameter | Type | Description |
315
+ | ------ | ------ | ------ |
316
+ | `node?` | [`Node`](#fxtype-aliasesnodemd) | An AST node. |
249
317
 
250
- | Name | Type | Description |
251
- | ----- | ----- | ----------- |
252
- | token | `any` | The token |
318
+ ## Returns
253
319
 
254
- ##### Returns
320
+ `node is BinaryExpression`
255
321
 
256
- `boolean` – True if the specified token is effects prefix, False otherwise.
322
+ True if the specified token is a BinaryExpression, False otherwise.
257
323
 
258
- ---
259
324
 
260
- ### <a id="isLiteral" href="#isLiteral">#</a> isLiteral( token ) ⇒ `boolean`
325
+ <a name="fxfunctionsiscallnodemd"></a>
261
326
 
262
- Determines whether the specified token is a literal.
327
+ # isCallNode()
263
328
 
264
- Returns `true` if the input is a token of type BOOLEAN (`TRUE` or `FALSE`), ERROR (`#VALUE!`), NUMBER (123.4), or STRING (`"lorem ipsum"`). In all other cases `false` is returned.
329
+ ```ts
330
+ function isCallNode(node?: Node): node is CallExpression;
331
+ ```
265
332
 
266
- ##### Parameters
333
+ Determines whether the specified node is a CallExpression.
267
334
 
268
- | Name | Type | Description |
269
- | ----- | ----- | ----------- |
270
- | token | `any` | The token |
335
+ ## Parameters
271
336
 
272
- ##### Returns
337
+ | Parameter | Type | Description |
338
+ | ------ | ------ | ------ |
339
+ | `node?` | [`Node`](#fxtype-aliasesnodemd) | An AST node. |
273
340
 
274
- `boolean` – True if the specified token is literal, False otherwise.
341
+ ## Returns
275
342
 
276
- ---
343
+ `node is CallExpression`
277
344
 
278
- ### <a id="isOperator" href="#isOperator">#</a> isOperator( token ) `boolean`
345
+ True if the specified token is a CallExpression, False otherwise.
279
346
 
280
- Determines whether the specified token is an operator.
281
347
 
282
- Returns `true` if the input is a token of type OPERATOR (`+` or `:`). In all other cases `false` is returned.
348
+ <a name="fxfunctionsiserrormd"></a>
283
349
 
284
- ##### Parameters
350
+ # isError()
285
351
 
286
- | Name | Type | Description |
287
- | ----- | ----- | ----------- |
288
- | token | `any` | The token |
352
+ ```ts
353
+ function isError(token?: Pick<Token, "type">): boolean;
354
+ ```
289
355
 
290
- ##### Returns
356
+ Determines whether the specified token is an error.
291
357
 
292
- `boolean` – True if the specified token is operator, False otherwise.
358
+ Returns `true` if the input is a token of type ERROR (`#VALUE!`). In all
359
+ other cases `false` is returned.
293
360
 
294
- ---
361
+ ## Parameters
295
362
 
296
- ### <a id="isRange" href="#isRange">#</a> isRange( token ) `boolean`
363
+ | Parameter | Type | Description |
364
+ | ------ | ------ | ------ |
365
+ | `token?` | `Pick`\<[`Token`](#fxtype-aliasestokenmd), `"type"`\> | The token |
297
366
 
298
- Determines whether the specified token is a range.
367
+ ## Returns
299
368
 
300
- Returns `true` if the input is a token that has a type of either REF_RANGE (`A1` or `A1:B2`), REF_TERNARY (`A1:A`, `A1:1`, `1:A1`, or `A:A1`), or REF_BEAM (`A:A` or `1:1`). In all other cases `false` is returned.
369
+ `boolean`
301
370
 
302
- ##### Parameters
371
+ True if the specified token is error, False otherwise.
303
372
 
304
- | Name | Type | Description |
305
- | ----- | ----- | ----------- |
306
- | token | `any` | A token |
307
373
 
308
- ##### Returns
374
+ <a name="fxfunctionsiserrornodemd"></a>
309
375
 
310
- `boolean` – True if the specified token is range, False otherwise.
376
+ # isErrorNode()
311
377
 
312
- ---
378
+ ```ts
379
+ function isErrorNode(node?: Node): node is ErrorLiteral;
380
+ ```
313
381
 
314
- ### <a id="isReference" href="#isReference">#</a> isReference( token ) `boolean`
382
+ Determines whether the specified node is an ErrorLiteral.
315
383
 
316
- Determines whether the specified token is a reference.
384
+ ## Parameters
317
385
 
318
- Returns `true` if the input is a token of type REF_RANGE (`A1` or `A1:B2`), REF_TERNARY (`A1:A`, `A1:1`, `1:A1`, or `A:A1`), REF_BEAM (`A:A` or `1:1`), or REF_NAMED (`myrange`). In all other cases `false` is returned.
386
+ | Parameter | Type | Description |
387
+ | ------ | ------ | ------ |
388
+ | `node?` | [`Node`](#fxtype-aliasesnodemd) | An AST node. |
319
389
 
320
- ##### Parameters
390
+ ## Returns
321
391
 
322
- | Name | Type | Description |
323
- | ----- | ----- | ----------- |
324
- | token | `any` | The token |
392
+ `node is ErrorLiteral`
325
393
 
326
- ##### Returns
394
+ True if the specified token is an ErrorLiteral, False otherwise.
327
395
 
328
- `boolean` – True if the specified token is reference, False otherwise.
329
396
 
330
- ---
397
+ <a name="fxfunctionsisexpressionnodemd"></a>
331
398
 
332
- ### <a id="isWhitespace" href="#isWhitespace">#</a> isWhitespace( token ) ⇒ `boolean`
399
+ # isExpressionNode()
333
400
 
334
- Determines whether the specified token is whitespace.
401
+ ```ts
402
+ function isExpressionNode(node?: Node): node is AstExpression;
403
+ ```
335
404
 
336
- Returns `true` if the input is a token of type WHITESPACE (` `) or NEWLINE (`\n`). In all other cases `false` is returned.
405
+ Determines whether the specified node is a AstExpression.
337
406
 
338
- ##### Parameters
407
+ ## Parameters
339
408
 
340
- | Name | Type | Description |
341
- | ----- | ----- | ----------- |
342
- | token | `any` | The token |
409
+ | Parameter | Type | Description |
410
+ | ------ | ------ | ------ |
411
+ | `node?` | [`Node`](#fxtype-aliasesnodemd) | An AST node. |
343
412
 
344
- ##### Returns
413
+ ## Returns
345
414
 
346
- `boolean` – True if the specified token is whitespace, False otherwise.
415
+ `node is AstExpression`
347
416
 
348
- ---
417
+ True if the specified token is a AstExpression, False otherwise.
349
418
 
350
- ### <a id="mergeRefTokens" href="#mergeRefTokens">#</a> mergeRefTokens( tokenlist ) ⇒ `Array<Token>`
351
419
 
352
- Merges context with reference tokens as possible in a list of tokens.
420
+ <a name="fxfunctionsisfunctionmd"></a>
353
421
 
354
- When given a tokenlist, this function returns a new list with ranges returned as whole references (`Sheet1!A1:B2`) rather than separate tokens for each part: (`Sheet1`,`!`,`A1`,`:`,`B2`).
422
+ # isFunction()
355
423
 
356
- ##### Parameters
424
+ ```ts
425
+ function isFunction(token?: Pick<Token, "type">): boolean;
426
+ ```
357
427
 
358
- | Name | Type | Description |
359
- | --------- | -------------- | -------------------------------------- |
360
- | tokenlist | `Array<Token>` | An array of tokens (from `tokenize()`) |
428
+ Determines whether the specified token is a function.
361
429
 
362
- ##### Returns
430
+ Returns `true` if the input is a token of type FUNCTION.
431
+ In all other cases `false` is returned.
363
432
 
364
- `Array<Token>` – A new list of tokens with range parts merged.
433
+ ## Parameters
365
434
 
366
- ---
435
+ | Parameter | Type | Description |
436
+ | ------ | ------ | ------ |
437
+ | `token?` | `Pick`\<[`Token`](#fxtype-aliasestokenmd), `"type"`\> | The token |
367
438
 
368
- ### <a id="parse" href="#parse">#</a> parse( formula, _[options = `{}`]_ ) ⇒ [`AstExpression`](#AstExpression)
439
+ ## Returns
369
440
 
370
- Parses a string formula or list of tokens into an AST.
441
+ `boolean`
371
442
 
372
- The parser requires `mergeRefs` to have been `true` in tokenlist options, because it does not recognize reference context tokens.
443
+ True if the specified token is function, False otherwise.
373
444
 
374
- The AST Abstract Syntax Tree's format is documented in [AST_format.md](./AST_format.md)
375
445
 
376
- **See also:** [nodeTypes](#nodeTypes).
446
+ <a name="fxfunctionsisfxprefixmd"></a>
377
447
 
378
- ##### Parameters
448
+ # isFxPrefix()
379
449
 
380
- | Name | Type | Default | Description |
381
- | --------------------------- | -------------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
382
- | formula | `string` \| `Array<Token>` | | An Excel formula string (an Excel expression) or an array of tokens. |
383
- | [options] | `object` | `{}` | Options |
384
- | [options].allowNamed | `boolean` | `true` | Enable parsing names as well as ranges. |
385
- | [options].allowTernary | `boolean` | `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. |
386
- | [options].looseRefCalls | `boolean` | `false` | Permits any function call where otherwise only functions that return references would be permitted. |
387
- | [options].negativeNumbers | `boolean` | `true` | Merges unary minuses with their immediately following number tokens (`-`,`1`) => `-1` (alternatively these will be unary operations in the tree). |
388
- | [options].permitArrayCalls | `boolean` | `false` | Function calls are allowed as elements of arrays. This is a feature in Google Sheets while Excel does not allow it. |
389
- | [options].permitArrayRanges | `boolean` | `false` | Ranges are allowed as elements of arrays. This is a feature in Google Sheets while Excel does not allow it. |
390
- | [options].r1c1 | `boolean` | `false` | Ranges are expected to be in the R1C1 style format rather than the more popular A1 style. |
391
- | [options].withLocation | `boolean` | `false` | Nodes will include source position offsets to the tokens: `{ loc: [ start, end ] }` |
392
- | [options].xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
450
+ ```ts
451
+ function isFxPrefix(token?: Pick<Token, "type">): boolean;
452
+ ```
393
453
 
394
- ##### Returns
454
+ Returns `true` if the input is a token of type FX_PREFIX (leading `=` in
455
+ formula). In all other cases `false` is returned.
395
456
 
396
- [`AstExpression`](#AstExpression) – An AST of nodes
457
+ ## Parameters
397
458
 
398
- ---
459
+ | Parameter | Type | Description |
460
+ | ------ | ------ | ------ |
461
+ | `token?` | `Pick`\<[`Token`](#fxtype-aliasestokenmd), `"type"`\> | The token |
399
462
 
400
- ### <a id="parseA1Ref" href="#parseA1Ref">#</a> parseA1Ref( refString, _[options = `{}`]_ ) ⇒ [`ReferenceA1`](#ReferenceA1) | `null`
463
+ ## Returns
401
464
 
402
- Parse a string reference into an object representing it.
465
+ `boolean`
403
466
 
404
- ```js
405
- parseA1Ref('Sheet1!A$1:$B2');
406
- // => {
407
- // context: [ 'Sheet1' ],
408
- // range: {
409
- // top: 0,
410
- // left: 0,
411
- // bottom: 1,
412
- // right: 1
413
- // $top: true,
414
- // $left: false,
415
- // $bottom: false,
416
- // $right: true
417
- // }
418
- // }
467
+ True if the specified token is effects prefix, False otherwise.
468
+
469
+
470
+ <a name="fxfunctionsisidentifiernodemd"></a>
471
+
472
+ # isIdentifierNode()
473
+
474
+ ```ts
475
+ function isIdentifierNode(node?: Node): node is Identifier;
419
476
  ```
420
477
 
421
- For A:A or A1:A style ranges, `null` will be used for any dimensions that the syntax does not specify:
478
+ Determines whether the specified node is an Identifier.
422
479
 
423
- ##### Parameters
480
+ ## Parameters
424
481
 
425
- | Name | Type | Default | Description |
426
- | ---------------------- | --------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
427
- | refString | `string` | | An A1-style reference string |
428
- | [options] | `object` | `{}` | Options |
429
- | [options].allowNamed | `boolean` | `true` | Enable parsing names as well as ranges. |
430
- | [options].allowTernary | `boolean` | `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. |
431
- | [options].xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
482
+ | Parameter | Type | Description |
483
+ | ------ | ------ | ------ |
484
+ | `node?` | [`Node`](#fxtype-aliasesnodemd) | An AST node. |
432
485
 
433
- ##### Returns
486
+ ## Returns
434
487
 
435
- [`ReferenceA1`](#ReferenceA1) | `null` – An object representing a valid reference or null if it is invalid.
488
+ `node is Identifier`
436
489
 
437
- ---
490
+ True if the specified token is an Identifier, False otherwise.
438
491
 
439
- ### <a id="parseR1C1Ref" href="#parseR1C1Ref">#</a> parseR1C1Ref( refString, _[options = `{}`]_ ) ⇒ [`ReferenceR1C1`](#ReferenceR1C1) | `null`
440
492
 
441
- Parse a string reference into an object representing it.
493
+ <a name="fxfunctionsislambdanodemd"></a>
442
494
 
443
- ```js
444
- parseR1C1Ref('Sheet1!R[9]C9:R[9]C9');
445
- // => {
446
- // context: [ 'Sheet1' ],
447
- // range: {
448
- // r0: 9,
449
- // c0: 8,
450
- // r1: 9,
451
- // c1: 8,
452
- // $c0: true,
453
- // $c1: true
454
- // $r0: false,
455
- // $r1: false
456
- // }
457
- // }
495
+ # isLambdaNode()
496
+
497
+ ```ts
498
+ function isLambdaNode(node?: Node): node is LambdaExpression;
458
499
  ```
459
500
 
460
- ##### Parameters
501
+ Determines whether the specified node is a LambdaExpression.
461
502
 
462
- | Name | Type | Default | Description |
463
- | ---------------------- | --------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
464
- | refString | `string` | | An R1C1-style reference string |
465
- | [options] | `object` | `{}` | Options |
466
- | [options].allowNamed | `boolean` | `true` | Enable parsing names as well as ranges. |
467
- | [options].allowTernary | `boolean` | `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. |
468
- | [options].xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
503
+ ## Parameters
469
504
 
470
- ##### Returns
505
+ | Parameter | Type | Description |
506
+ | ------ | ------ | ------ |
507
+ | `node?` | [`Node`](#fxtype-aliasesnodemd) | An AST node. |
471
508
 
472
- [`ReferenceR1C1`](#ReferenceR1C1) | `null` – An object representing a valid reference or null if it is invalid.
509
+ ## Returns
473
510
 
474
- ---
511
+ `node is LambdaExpression`
475
512
 
476
- ### <a id="parseStructRef" href="#parseStructRef">#</a> parseStructRef( ref, _[options = `{}`]_ ) [`ReferenceStruct`](#ReferenceStruct) | `null`
513
+ True if the specified token is a LambdaExpression, False otherwise.
477
514
 
478
- Parse a structured reference string into an object representing it.
479
515
 
480
- ```js
481
- parseStructRef('workbook.xlsx!tableName[[#Data],[Column1]:[Column2]]');
482
- // => {
483
- // context: [ 'workbook.xlsx' ],
484
- // sections: [ 'data' ],
485
- // columns: [ 'my column', '@foo' ],
486
- // table: 'tableName',
487
- // }
516
+ <a name="fxfunctionsisletdeclaratornodemd"></a>
517
+
518
+ # isLetDeclaratorNode()
519
+
520
+ ```ts
521
+ function isLetDeclaratorNode(node?: Node): node is LetDeclarator;
488
522
  ```
489
523
 
490
- For A:A or A1:A style ranges, `null` will be used for any dimensions that the syntax does not specify:
524
+ Determines whether the specified node is a LetDeclarator.
491
525
 
492
- ##### Parameters
526
+ ## Parameters
493
527
 
494
- | Name | Type | Default | Description |
495
- | -------------- | --------- | ------- | ------------------------------------------------------------------------------------------------------------------------- |
496
- | ref | `string` | | A structured reference string |
497
- | [options] | `object` | `{}` | Options |
498
- | [options].xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
528
+ | Parameter | Type | Description |
529
+ | ------ | ------ | ------ |
530
+ | `node?` | [`Node`](#fxtype-aliasesnodemd) | An AST node. |
499
531
 
500
- ##### Returns
532
+ ## Returns
501
533
 
502
- [`ReferenceStruct`](#ReferenceStruct) | `null` – An object representing a valid reference or null if it is invalid.
534
+ `node is LetDeclarator`
503
535
 
504
- ---
536
+ True if the specified token is a LetDeclarator, False otherwise.
505
537
 
506
- ### <a id="stringifyA1Ref" href="#stringifyA1Ref">#</a> stringifyA1Ref( refObject, _[options = `{}`]_ ) ⇒ `string`
507
538
 
508
- Get an A1-style string representation of a reference object.
539
+ <a name="fxfunctionsisletnodemd"></a>
509
540
 
510
- ```js
511
- stringifyA1Ref({
512
- context: [ 'Sheet1' ],
513
- range: {
514
- top: 0,
515
- left: 0,
516
- bottom: 1,
517
- right: 1,
518
- $top: true,
519
- $left: false,
520
- $bottom: false,
521
- $right: true
522
- }
523
- });
524
- // => 'Sheet1!A$1:$B2'
541
+ # isLetNode()
542
+
543
+ ```ts
544
+ function isLetNode(node?: Node): node is LetExpression;
525
545
  ```
526
546
 
527
- ##### Parameters
547
+ Determines whether the specified node is a LetExpression.
528
548
 
529
- | Name | Type | Default | Description |
530
- | -------------- | ----------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- |
531
- | refObject | [`ReferenceA1`](#ReferenceA1) | | A reference object |
532
- | [options] | `object` | `{}` | Options |
533
- | [options].xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
549
+ ## Parameters
534
550
 
535
- ##### Returns
551
+ | Parameter | Type | Description |
552
+ | ------ | ------ | ------ |
553
+ | `node?` | [`Node`](#fxtype-aliasesnodemd) | An AST node. |
536
554
 
537
- `string` – The reference in A1-style string format
555
+ ## Returns
538
556
 
539
- ---
557
+ `node is LetExpression`
540
558
 
541
- ### <a id="stringifyR1C1Ref" href="#stringifyR1C1Ref">#</a> stringifyR1C1Ref( refObject, _[options = `{}`]_ ) `string`
559
+ True if the specified token is a LetExpression, False otherwise.
542
560
 
543
- Get an R1C1-style string representation of a reference object.
544
561
 
545
- ```js
546
- stringifyR1C1Ref({
547
- context: [ 'Sheet1' ],
548
- range: {
549
- r0: 9,
550
- c0: 8,
551
- r1: 9,
552
- c1: 8,
553
- $c0: true,
554
- $c1: true
555
- $r0: false,
556
- $r1: false
557
- }
558
- });
559
- // => 'Sheet1!R[9]C9:R[9]C9'
562
+ <a name="fxfunctionsisliteralmd"></a>
563
+
564
+ # isLiteral()
565
+
566
+ ```ts
567
+ function isLiteral(token?: Pick<Token, "type">): boolean;
560
568
  ```
561
569
 
562
- ##### Parameters
570
+ Determines whether the specified token is a literal.
563
571
 
564
- | Name | Type | Default | Description |
565
- | -------------- | --------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- |
566
- | refObject | [`ReferenceR1C1`](#ReferenceR1C1) | | A reference object |
567
- | [options] | `object` | `{}` | Options |
568
- | [options].xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
572
+ Returns `true` if the input is a token of type BOOLEAN (`TRUE` or `FALSE`),
573
+ ERROR (`#VALUE!`), NUMBER (123.4), or STRING (`"lorem ipsum"`). In all other
574
+ cases `false` is returned.
569
575
 
570
- ##### Returns
576
+ ## Parameters
571
577
 
572
- `string` The reference in R1C1-style string format
578
+ | Parameter | Type | Description |
579
+ | ------ | ------ | ------ |
580
+ | `token?` | `Pick`\<[`Token`](#fxtype-aliasestokenmd), `"type"`\> | The token |
573
581
 
574
- ---
582
+ ## Returns
575
583
 
576
- ### <a id="stringifyStructRef" href="#stringifyStructRef">#</a> stringifyStructRef( refObject, _[options = `{}`]_ ) ⇒ `string`
584
+ `boolean`
577
585
 
578
- Get a string representation of a structured reference object.
586
+ True if the specified token is literal, False otherwise.
579
587
 
580
- ```js
581
- stringifyStructRef({
582
- context: [ 'workbook.xlsx' ],
583
- sections: [ 'data' ],
584
- columns: [ 'my column', '@foo' ],
585
- table: 'tableName',
586
- });
587
- // => 'workbook.xlsx!tableName[[#Data],[Column1]:[Column2]]'
588
+
589
+ <a name="fxfunctionsisliteralnodemd"></a>
590
+
591
+ # isLiteralNode()
592
+
593
+ ```ts
594
+ function isLiteralNode(node?: Node): node is Literal;
588
595
  ```
589
596
 
590
- ##### Parameters
597
+ Determines whether the specified node is a Literal.
591
598
 
592
- | Name | Type | Default | Description |
593
- | ----------------- | ------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- |
594
- | refObject | [`ReferenceStruct`](#ReferenceStruct) | | A structured reference object |
595
- | [options] | `object` | `{}` | Options |
596
- | [options].thisRow | `boolean` | `false` | Enforces using the `[#This Row]` instead of the `@` shorthand when serializing structured ranges. |
597
- | [options].xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
599
+ ## Parameters
598
600
 
599
- ##### Returns
601
+ | Parameter | Type | Description |
602
+ | ------ | ------ | ------ |
603
+ | `node?` | [`Node`](#fxtype-aliasesnodemd) | An AST node. |
600
604
 
601
- `string` – The structured reference in string format
605
+ ## Returns
602
606
 
603
- ---
607
+ `node is Literal`
604
608
 
605
- ### <a id="toCol" href="#toCol">#</a> toCol( columnIndex ) `string`
609
+ True if the specified token is a Literal, False otherwise.
606
610
 
607
- Convert a 0 based offset number to a column string representation (`2` = `"C"`).
608
611
 
609
- The method expects a number between 0 and 16383. Other input will return garbage.
612
+ <a name="fxfunctionsisoperatormd"></a>
610
613
 
611
- ##### Parameters
614
+ # isOperator()
612
615
 
613
- | Name | Type | Description |
614
- | ----------- | -------- | ------------------------------ |
615
- | columnIndex | `number` | Zero based column index number |
616
+ ```ts
617
+ function isOperator(token?: Pick<Token, "type">): boolean;
618
+ ```
616
619
 
617
- ##### Returns
620
+ Determines whether the specified token is an operator.
618
621
 
619
- `string` The column string identifier
622
+ Returns `true` if the input is a token of type OPERATOR (`+` or `:`). In all
623
+ other cases `false` is returned.
620
624
 
621
- ---
625
+ ## Parameters
622
626
 
623
- ### <a id="tokenize" href="#tokenize">#</a> tokenize( formula, _[options = `{}`]_ ) ⇒ `Array<Token>`
627
+ | Parameter | Type | Description |
628
+ | ------ | ------ | ------ |
629
+ | `token?` | `Pick`\<[`Token`](#fxtype-aliasestokenmd), `"type"`\> | The token |
624
630
 
625
- Breaks a string formula into a list of tokens.
631
+ ## Returns
626
632
 
627
- The returned output will be an array of objects representing the tokens:
633
+ `boolean`
628
634
 
629
- ```js
630
- [
631
- { type: FX_PREFIX, value: '=' },
632
- { type: FUNCTION, value: 'SUM' },
633
- { type: OPERATOR, value: '(' },
634
- { type: REF_RANGE, value: 'A1:B2' },
635
- { type: OPERATOR, value: ')' }
636
- ]
635
+ True if the specified token is operator, False otherwise.
636
+
637
+
638
+ <a name="fxfunctionsisrangemd"></a>
639
+
640
+ # isRange()
641
+
642
+ ```ts
643
+ function isRange(token?: Pick<Token, "type">): boolean;
637
644
  ```
638
645
 
639
- Token types may be found as an Object as the [`tokenTypes` export](#tokenTypes) on the package (`import {tokenTypes} from '@borgar/fx';`).
646
+ Determines whether the specified token is a range.
640
647
 
641
- To support syntax highlighting as you type, `STRING` tokens are allowed to be "unterminated". For example, the incomplete formula `="Hello world` would be tokenized as:
648
+ Returns `true` if the input is a token that has a type of either REF_RANGE
649
+ (`A1` or `A1:B2`), REF_TERNARY (`A1:A`, `A1:1`, `1:A1`, or `A:A1`), or
650
+ REF_BEAM (`A:A` or `1:1`). In all other cases `false` is returned.
642
651
 
643
- ```js
644
- [
645
- { type: FX_PREFIX, value: '=' },
646
- { type: STRING, value: '"Hello world', unterminated: true },
647
- ]
652
+ ## Parameters
653
+
654
+ | Parameter | Type | Description |
655
+ | ------ | ------ | ------ |
656
+ | `token?` | `Pick`\<[`Token`](#fxtype-aliasestokenmd), `"type"`\> | A token |
657
+
658
+ ## Returns
659
+
660
+ `boolean`
661
+
662
+ True if the specified token is range, False otherwise.
663
+
664
+
665
+ <a name="fxfunctionsisreferencemd"></a>
666
+
667
+ # isReference()
668
+
669
+ ```ts
670
+ function isReference(token?: Pick<Token, "type">): boolean;
648
671
  ```
649
672
 
650
- **See also:** [tokenTypes](#tokenTypes).
673
+ Determines whether the specified token is a reference.
651
674
 
652
- ##### Parameters
675
+ Returns `true` if the input is a token of type REF_RANGE (`A1` or `A1:B2`),
676
+ REF_TERNARY (`A1:A`, `A1:1`, `1:A1`, or `A:A1`), REF_BEAM (`A:A` or `1:1`),
677
+ or REF_NAMED (`myrange`). In all other cases `false` is returned.
653
678
 
654
- | Name | Type | Default | Description |
655
- | ------------------------- | --------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
656
- | formula | `string` | | An Excel formula string (an Excel expression) or an array of tokens. |
657
- | [options] | `object` | `{}` | Options |
658
- | [options].allowTernary | `boolean` | `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. |
659
- | [options].mergeRefs | `boolean` | `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) |
660
- | [options].negativeNumbers | `boolean` | `true` | Merges unary minuses with their immediately following number tokens (`-`,`1`) => `-1` (alternatively these will be unary operations in the tree). |
661
- | [options].r1c1 | `boolean` | `false` | Ranges are expected to be in the R1C1 style format rather than the more popular A1 style. |
662
- | [options].withLocation | `boolean` | `true` | Nodes will include source position offsets to the tokens: `{ loc: [ start, end ] }` |
663
- | [options].xlsx | `boolean` | `false` | Enables a `[1]Sheet1!A1` or `[1]!name` syntax form for external workbooks found only in XLSX files. |
679
+ ## Parameters
664
680
 
665
- ##### Returns
681
+ | Parameter | Type | Description |
682
+ | ------ | ------ | ------ |
683
+ | `token?` | `Pick`\<[`Token`](#fxtype-aliasestokenmd), `"type"`\> | The token |
666
684
 
667
- `Array<Token>` – An AST of nodes
685
+ ## Returns
668
686
 
669
- ---
687
+ `boolean`
670
688
 
671
- ### <a id="translateToA1" href="#translateToA1">#</a> translateToA1( formula, anchorCell, _[options = `{}`]_ ) ⇒ `string` | `Array<Token>`
689
+ True if the specified token is reference, False otherwise.
672
690
 
673
- Translates ranges in a formula or list of tokens from relative R1C1 syntax to absolute A1 syntax.
674
691
 
675
- Returns the same formula with the ranges translated. If an array of tokens was supplied, then the same array is returned.
692
+ <a name="fxfunctionsisreferencenodemd"></a>
676
693
 
677
- ```js
678
- translateToA1("=SUM(RC[1],R2C5,Sheet!R3C5)", "D10");
679
- // => "=SUM(E10,$E$2,Sheet!$E$3)");
694
+ # isReferenceNode()
695
+
696
+ ```ts
697
+ function isReferenceNode(node?: Node): node is ReferenceIdentifier;
680
698
  ```
681
699
 
682
- If an input range is -1,-1 relative rows/columns and the anchor is A1, the resulting range will (by default) wrap around to the bottom of the sheet resulting in the range XFD1048576. This may not be what you want so may set `wrapEdges` to false which will instead turn the range into a `#REF!` error.
700
+ Determines whether the specified node is a ReferenceIdentifier.
683
701
 
684
- ```js
685
- translateToA1("=R[-1]C[-1]", "A1");
686
- // => "=XFD1048576");
702
+ ## Parameters
687
703
 
688
- translateToA1("=R[-1]C[-1]", "A1", { wrapEdges: false });
689
- // => "=#REF!");
704
+ | Parameter | Type | Description |
705
+ | ------ | ------ | ------ |
706
+ | `node?` | [`Node`](#fxtype-aliasesnodemd) | An AST node. |
707
+
708
+ ## Returns
709
+
710
+ `node is ReferenceIdentifier`
711
+
712
+ True if the specified token is a ReferenceIdentifier, False otherwise.
713
+
714
+
715
+ <a name="fxfunctionsisunarynodemd"></a>
716
+
717
+ # isUnaryNode()
718
+
719
+ ```ts
720
+ function isUnaryNode(node?: Node): node is UnaryExpression;
690
721
  ```
691
722
 
692
- Note that if you are passing in a list of tokens that was not created using `mergeRefs` and you disable edge wrapping (or you simply set both options to false), you can end up with a formula such as `=#REF!:B2` or `=Sheet3!#REF!:F3`. These are valid formulas in the Excel formula language and Excel will accept them, but they are not supported in Google Sheets.
723
+ Determines whether the specified node is a UnaryExpression.
693
724
 
694
- ##### Parameters
725
+ ## Parameters
695
726
 
696
- | Name | Type | Default | Description |
697
- | ---------------------- | -------------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
698
- | formula | `string` \| `Array<Token>` | | A string (an Excel formula) or a token list that should be adjusted. |
699
- | anchorCell | `string` | | A simple string reference to an A1 cell ID (`AF123` or`$C$5`). |
700
- | [options] | `object` | `{}` | The options |
701
- | [options].allowTernary | `boolean` | `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. |
702
- | [options].mergeRefs | `boolean` | `true` | Should ranges be treated as whole references (`Sheet1!A1:B2`) or as separate tokens for each part: (`Sheet1`,`!`,`A1`,`:`,`B2`). |
703
- | [options].wrapEdges | `boolean` | `true` | Wrap out-of-bounds ranges around sheet edges rather than turning them to #REF! errors |
704
- | [options].xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
727
+ | Parameter | Type | Description |
728
+ | ------ | ------ | ------ |
729
+ | `node?` | [`Node`](#fxtype-aliasesnodemd) | An AST node. |
705
730
 
706
- ##### Returns
731
+ ## Returns
707
732
 
708
- `string` | `Array<Token>` – A formula string or token list (depending on which was input)
733
+ `node is UnaryExpression`
709
734
 
710
- ---
735
+ True if the specified token is a UnaryExpression, False otherwise.
711
736
 
712
- ### <a id="translateToR1C1" href="#translateToR1C1">#</a> translateToR1C1( formula, anchorCell, _[options = `{}`]_ ) ⇒ `string` | `Array<Token>`
713
737
 
714
- Translates ranges in a formula or list of tokens from absolute A1 syntax to relative R1C1 syntax.
738
+ <a name="fxfunctionsiswhitespacemd"></a>
715
739
 
716
- Returns the same formula with the ranges translated. If an array of tokens was supplied, then the same array is returned.
740
+ # isWhitespace()
717
741
 
718
- ```js
719
- translateToR1C1("=SUM(E10,$E$2,Sheet!$E$3)", "D10");
720
- // => "=SUM(RC[1],R2C5,Sheet!R3C5)");
742
+ ```ts
743
+ function isWhitespace(token?: Pick<Token, "type">): boolean;
721
744
  ```
722
745
 
723
- ##### Parameters
746
+ Determines whether the specified token is whitespace.
724
747
 
725
- | Name | Type | Default | Description |
726
- | ---------------------- | -------------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
727
- | formula | `string` \| `Array<Token>` | | A string (an Excel formula) or a token list that should be adjusted. |
728
- | anchorCell | `string` | | A simple string reference to an A1 cell ID (`AF123` or`$C$5`). |
729
- | [options] | `object` | `{}` | The options |
730
- | [options].allowTernary | `boolean` | `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. |
731
- | [options].xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
748
+ Returns `true` if the input is a token of type WHITESPACE (` `) or
749
+ NEWLINE (`\n`). In all other cases `false` is returned.
732
750
 
733
- ##### Returns
751
+ ## Parameters
734
752
 
735
- `string` | `Array<Token>` A formula string or token list (depending on which was input)
753
+ | Parameter | Type | Description |
754
+ | ------ | ------ | ------ |
755
+ | `token?` | `Pick`\<[`Token`](#fxtype-aliasestokenmd), `"type"`\> | The token |
736
756
 
737
- ---
757
+ ## Returns
738
758
 
739
- ## Constants
759
+ `boolean`
740
760
 
741
- ### <a id="nodeTypes" href="#nodeTypes">#</a> nodeTypes = `Readonly<Record<string, string>>`
761
+ True if the specified token is whitespace, False otherwise.
742
762
 
743
- A dictionary of the types used to identify AST node variants.
744
763
 
745
- **See also:** [parse](#parse).
764
+ <a name="fxfunctionsmergereftokensmd"></a>
746
765
 
747
- ##### Properties
766
+ # mergeRefTokens()
748
767
 
749
- | Name | Type | Description |
750
- | ---------- | -------- | ---------------------------------------------------------------- |
751
- | ARRAY | `string` | An array expression (`{1,2;3,4}`) |
752
- | BINARY | `string` | A binary operation (`10+10`) |
753
- | CALL | `string` | A function call expression (`SUM(1,2)`) |
754
- | ERROR | `string` | An error literal (`#VALUE!`) |
755
- | IDENTIFIER | `string` | A function name identifier (`SUM`) |
756
- | LITERAL | `string` | A literal (number, string, or boolean) (`123`, `"foo"`, `false`) |
757
- | REFERENCE | `string` | A range identifier (`A1`) |
758
- | UNARY | `string` | A unary operation (`10%`) |
768
+ ```ts
769
+ function mergeRefTokens(tokenlist: Token[]): Token[];
770
+ ```
759
771
 
760
- ---
772
+ Merges context with reference tokens as possible in a list of tokens.
761
773
 
762
- ### <a id="tokenTypes" href="#tokenTypes">#</a> tokenTypes = `Readonly<Record<string, string>>`
774
+ When given a tokenlist, this function returns a new list with ranges returned
775
+ as whole references (`Sheet1!A1:B2`) rather than separate tokens for each
776
+ part: (`Sheet1`,`!`,`A1`,`:`,`B2`).
763
777
 
764
- A dictionary of the types used to identify token variants.
778
+ ## Parameters
765
779
 
766
- **See also:** [tokenize](#tokenize).
780
+ | Parameter | Type | Description |
781
+ | ------ | ------ | ------ |
782
+ | `tokenlist` | [`Token`](#fxtype-aliasestokenmd)[] | An array of tokens. |
767
783
 
768
- ##### Properties
784
+ ## Returns
769
785
 
770
- | Name | Type | Description |
771
- | ------------- | -------- | ---------------------------------------------------------------- |
772
- | BOOLEAN | `string` | Boolean literal (`TRUE`) |
773
- | CONTEXT | `string` | Reference context ([Workbook.xlsx]Sheet1) |
774
- | CONTEXT_QUOTE | `string` | Quoted reference context (`'[My workbook.xlsx]Sheet1'`) |
775
- | ERROR | `string` | Error literal (`#VALUE!`) |
776
- | FUNCTION | `string` | Function name (`SUM`) |
777
- | FX_PREFIX | `string` | A leading equals sign at the start of a formula (`=`) |
778
- | NEWLINE | `string` | Newline character (`\n`) |
779
- | NUMBER | `string` | Number literal (`123.4`, `-1.5e+2`) |
780
- | OPERATOR | `string` | Newline (`\n`) |
781
- | REF_BEAM | `string` | A range "beam" identifier (`A:A` or `1:1`) |
782
- | REF_NAMED | `string` | A name / named range identifier (`income`) |
783
- | REF_RANGE | `string` | A range identifier (`A1`) |
784
- | REF_STRUCT | `string` | A structured reference identifier (`table[[Column1]:[Column2]]`) |
785
- | REF_TERNARY | `string` | A ternary range identifier (`B2:B`) |
786
- | STRING | `string` | String literal (`"Lorem ipsum"`) |
787
- | UNKNOWN | `string` | Any unidentifiable range of characters. |
788
- | WHITESPACE | `string` | Whitespace character sequence (` `) |
786
+ [`Token`](#fxtype-aliasestokenmd)[]
789
787
 
790
- ---
788
+ A new list of tokens with range parts merged.
791
789
 
792
- ## Types
793
790
 
794
- ### <a id="AstExpression" href="#AstExpression">#</a> AstExpression = [`ReferenceIdentifier`](#ReferenceIdentifier) | [`Literal`](#Literal) | [`ErrorLiteral`](#ErrorLiteral) | [`UnaryExpression`](#UnaryExpression) | [`BinaryExpression`](#BinaryExpression) | [`CallExpression`](#CallExpression) | [`MatrixExpression`](#MatrixExpression) | [`LambdaExpression`](#LambdaExpression) | [`LetExpression`](#LetExpression)
791
+ <a name="fxfunctionsparsemd"></a>
795
792
 
796
- ---
793
+ # parse()
797
794
 
798
- ### <a id="BinaryExpression" href="#BinaryExpression">#</a> BinaryExpression = `Node`
795
+ ```ts
796
+ function parse(tokenlist: Token[], options: OptsParse): AstExpression;
797
+ ```
799
798
 
800
- ##### Properties
799
+ Parses a string formula or list of tokens into an AST.
801
800
 
802
- | Name | Type |
803
- | --------- | -------------------------------------------------------------------------------------------------------------------------------------- |
804
- | arguments | `Array<AstExpression>` |
805
- | [loc] | [`SourceLocation`](#SourceLocation) |
806
- | operator | `"="` \| `"<"` \| `">"` \| `"<="` \| `">="` \| `"<>"` \| `"-"` \| `"+"` \| `"*"` \| `"/"` \| `"^"` \| `":"` \| `" "` \| `","` \| `"&"` |
807
- | type | `"BinaryExpression"` |
801
+ The parser assumes `mergeRefs` and `negativeNumbers` were `true` when the tokens were generated.
802
+ It does not yet recognize reference context tokens or know how to deal with unary minuses in
803
+ arrays.
808
804
 
809
- ---
805
+ The AST Abstract Syntax Tree's format is documented in
806
+ [AST_format.md](./AST_format.md).
810
807
 
811
- ### <a id="CallExpression" href="#CallExpression">#</a> CallExpression = `Node`
808
+ ## Parameters
812
809
 
813
- ##### Properties
810
+ | Parameter | Type | Description |
811
+ | ------ | ------ | ------ |
812
+ | `tokenlist` | [`Token`](#fxtype-aliasestokenmd)[] | An array of tokens. |
813
+ | `options` | [`OptsParse`](#fxtype-aliasesoptsparsemd) | Options for the parsers behavior. |
814
814
 
815
- | Name | Type |
816
- | --------- | ----------------------------------- |
817
- | arguments | `Array<AstExpression>` |
818
- | callee | [`Identifier`](#Identifier) |
819
- | [loc] | [`SourceLocation`](#SourceLocation) |
820
- | type | `"CallExpression"` |
815
+ ## Returns
821
816
 
822
- ---
817
+ [`AstExpression`](#fxtype-aliasesastexpressionmd)
823
818
 
824
- ### <a id="ErrorLiteral" href="#ErrorLiteral">#</a> ErrorLiteral = `Node`
819
+ An AST of nodes.
825
820
 
826
- ##### Properties
821
+ ## See
827
822
 
828
- | Name | Type |
829
- | ----- | ----------------------------------- |
830
- | [loc] | [`SourceLocation`](#SourceLocation) |
831
- | raw | `string` |
832
- | type | `"ErrorLiteral"` |
833
- | value | `string` |
823
+ - [OptsParse](#fxtype-aliasesoptsparsemd)
824
+ - [nodeTypes](#fxvariablesnodetypesmd)
825
+ - [tokenize](#fxfunctionstokenizemd)
834
826
 
835
- ---
836
827
 
837
- ### <a id="Identifier" href="#Identifier">#</a> Identifier = `Node`
828
+ <a name="fxfunctionsparsea1rangemd"></a>
838
829
 
839
- ##### Properties
830
+ # parseA1Range()
840
831
 
841
- | Name | Type |
842
- | ----- | ----------------------------------- |
843
- | [loc] | [`SourceLocation`](#SourceLocation) |
844
- | name | `string` |
845
- | type | `"Identifier"` |
832
+ ```ts
833
+ function parseA1Range(rangeString: string, allowTernary?: boolean): RangeA1;
834
+ ```
846
835
 
847
- ---
836
+ Parse A1-style range string into a RangeA1 object.
848
837
 
849
- ### <a id="LambdaExpression" href="#LambdaExpression">#</a> LambdaExpression = `Node`
838
+ ## Parameters
850
839
 
851
- ##### Properties
840
+ | Parameter | Type | Default value | Description |
841
+ | ------ | ------ | ------ | ------ |
842
+ | `rangeString` | `string` | `undefined` | A1-style range string. |
843
+ | `allowTernary?` | `boolean` | `true` | Permit ternary ranges like A2:A or B2:2. |
852
844
 
853
- | Name | Type |
854
- | ------ | ------------------------------------------- |
855
- | body | `null` \| [`AstExpression`](#AstExpression) |
856
- | [loc] | [`SourceLocation`](#SourceLocation) |
857
- | params | `Array<Identifier>` |
858
- | type | `"LambdaExpression"` |
845
+ ## Returns
859
846
 
860
- ---
847
+ [`RangeA1`](#fxtype-aliasesrangea1md)
861
848
 
862
- ### <a id="LetDeclarator" href="#LetDeclarator">#</a> LetDeclarator = `Node`
849
+ A reference object.
863
850
 
864
- ##### Properties
865
851
 
866
- | Name | Type |
867
- | ----- | ------------------------------------------- |
868
- | id | [`Identifier`](#Identifier) |
869
- | init | `null` \| [`AstExpression`](#AstExpression) |
870
- | [loc] | [`SourceLocation`](#SourceLocation) |
871
- | type | `"LetDeclarator"` |
852
+ <a name="fxfunctionsparsea1refmd"></a>
872
853
 
873
- ---
854
+ # parseA1Ref()
874
855
 
875
- ### <a id="LetExpression" href="#LetExpression">#</a> LetExpression = `Node`
856
+ ```ts
857
+ function parseA1Ref(refString: string, options: OptsParseA1Ref):
858
+ | ReferenceA1
859
+ | ReferenceName;
860
+ ```
876
861
 
877
- ##### Properties
862
+ Parse a string reference into an object representing it.
878
863
 
879
- | Name | Type |
880
- | ------------ | ------------------------------------------- |
881
- | body | `null` \| [`AstExpression`](#AstExpression) |
882
- | declarations | `Array<LetDeclarator>` |
883
- | [loc] | [`SourceLocation`](#SourceLocation) |
884
- | type | `"LetExpression"` |
864
+ ```js
865
+ parseA1Ref('Sheet1!A$1:$B2');
866
+ // => {
867
+ // context: [ 'Sheet1' ],
868
+ // range: {
869
+ // top: 0,
870
+ // left: 0,
871
+ // bottom: 1,
872
+ // right: 1
873
+ // $top: true,
874
+ // $left: false,
875
+ // $bottom: false,
876
+ // $right: true
877
+ // }
878
+ // }
879
+ ```
885
880
 
886
- ---
881
+ For A:A or A1:A style ranges, `null` will be used for any dimensions that the
882
+ syntax does not specify.
887
883
 
888
- ### <a id="Literal" href="#Literal">#</a> Literal = `Node`
884
+ ## Parameters
889
885
 
890
- ##### Properties
886
+ | Parameter | Type | Description |
887
+ | ------ | ------ | ------ |
888
+ | `refString` | `string` | An A1-style reference string. |
889
+ | `options` | [`OptsParseA1Ref`](#fxtype-aliasesoptsparsea1refmd) | Options. |
891
890
 
892
- | Name | Type |
893
- | ----- | ----------------------------------- |
894
- | [loc] | [`SourceLocation`](#SourceLocation) |
895
- | raw | `string` |
896
- | type | `"Literal"` |
897
- | value | `string` \| `number` \| `boolean` |
891
+ ## Returns
898
892
 
899
- ---
893
+ \| [`ReferenceA1`](#fxtype-aliasesreferencea1md)
894
+ \| [`ReferenceName`](#fxtype-aliasesreferencenamemd)
900
895
 
901
- ### <a id="MatrixExpression" href="#MatrixExpression">#</a> MatrixExpression = `Node`
896
+ An object representing a valid reference or `undefined` if it is invalid.
902
897
 
903
- ##### Properties
898
+ ## See
904
899
 
905
- | Name | Type |
906
- | --------- | ------------------------------------------------------------------------------- |
907
- | arguments | `Array<Array<(ReferenceIdentifier | Literal | ErrorLiteral | CallExpression)>>` |
908
- | [loc] | [`SourceLocation`](#SourceLocation) |
909
- | type | `"ArrayExpression"` |
900
+ [OptsParseA1Ref](#fxtype-aliasesoptsparsea1refmd)
910
901
 
911
- ---
912
902
 
913
- ### <a id="RangeA1" href="#RangeA1">#</a> RangeA1
903
+ <a name="fxfunctionsparser1c1rangemd"></a>
914
904
 
915
- A range in A1 style coordinates.
905
+ # parseR1C1Range()
916
906
 
917
- ##### Properties
907
+ ```ts
908
+ function parseR1C1Range(rangeString: string): RangeR1C1;
909
+ ```
918
910
 
919
- | Name | Type | Description |
920
- | --------- | -------------------------------- | ---------------------------------------------------------------------------------------------- |
921
- | [$bottom] | `boolean` \| `null` | Signifies that bottom is a "locked" value |
922
- | [$left] | `boolean` \| `null` | Signifies that left is a "locked" value |
923
- | [$right] | `boolean` \| `null` | Signifies that right is a "locked" value |
924
- | [$top] | `boolean` \| `null` | Signifies that top is a "locked" value |
925
- | [bottom] | `number` \| `null` | Bottom row of the range |
926
- | [left] | `number` \| `null` | Left column of the range |
927
- | [right] | `number` \| `null` | Right column of the range |
928
- | [top] | `number` \| `null` | Top row of the range |
929
- | [trim] | `"head"` \| `"tail"` \| `"both"` | Should empty rows and columns at the top/left or bottom/right be discarded when range is read? |
911
+ Parse R1C1-style range string into a RangeR1C1 object.
930
912
 
931
- ---
913
+ ## Parameters
932
914
 
933
- ### <a id="RangeR1C1" href="#RangeR1C1">#</a> RangeR1C1
915
+ | Parameter | Type | Description |
916
+ | ------ | ------ | ------ |
917
+ | `rangeString` | `string` | R1C1-style range string. |
934
918
 
935
- A range in R1C1 style coordinates.
919
+ ## Returns
936
920
 
937
- ##### Properties
921
+ [`RangeR1C1`](#fxtype-aliasesranger1c1md)
938
922
 
939
- | Name | Type | Description |
940
- | ----- | ------------------- | -------------------------------------- |
941
- | [$c0] | `boolean` \| `null` | Signifies that c0 is an absolute value |
942
- | [$c1] | `boolean` \| `null` | Signifies that c1 is an absolute value |
943
- | [$r0] | `boolean` \| `null` | Signifies that r0 is an absolute value |
944
- | [$r1] | `boolean` \| `null` | Signifies that r1 is an absolute value |
945
- | [c0] | `number` \| `null` | Left column of the range |
946
- | [c1] | `number` \| `null` | Right column of the range |
947
- | [r0] | `number` \| `null` | Top row of the range |
948
- | [r1] | `number` \| `null` | Bottom row of the range |
923
+ A reference object.
949
924
 
950
- ---
951
925
 
952
- ### <a id="ReferenceA1" href="#ReferenceA1">#</a> ReferenceA1
926
+ <a name="fxfunctionsparser1c1refmd"></a>
953
927
 
954
- A reference containing an A1 style range. See [Prefixes.md] for documentation on how scopes work in Fx.
928
+ # parseR1C1Ref()
955
929
 
956
- ##### Properties
930
+ ```ts
931
+ function parseR1C1Ref(refString: string, options?: OptsParseR1C1Ref):
932
+ | ReferenceName
933
+ | ReferenceR1C1;
934
+ ```
957
935
 
958
- | Name | Type | Description |
959
- | -------------- | --------------------- | ---------------------------------------- |
960
- | [context] | `Array<string>` | A collection of scopes for the reference |
961
- | [range] | [`RangeA1`](#RangeA1) | The reference's range |
962
- | [sheetName] | `string` | A context sheet scope |
963
- | [workbookName] | `string` | A context workbook scope |
936
+ Parse a string reference into an object representing it.
964
937
 
965
- ---
938
+ ```js
939
+ parseR1C1Ref('Sheet1!R[9]C9:R[9]C9');
940
+ // => {
941
+ // context: [ 'Sheet1' ],
942
+ // range: {
943
+ // r0: 9,
944
+ // c0: 8,
945
+ // r1: 9,
946
+ // c1: 8,
947
+ // $c0: true,
948
+ // $c1: true
949
+ // $r0: false,
950
+ // $r1: false
951
+ // }
952
+ // }
953
+ ```
966
954
 
967
- ### <a id="ReferenceIdentifier" href="#ReferenceIdentifier">#</a> ReferenceIdentifier = `Node`
955
+ ## Parameters
968
956
 
969
- ##### Properties
957
+ | Parameter | Type | Description |
958
+ | ------ | ------ | ------ |
959
+ | `refString` | `string` | An R1C1-style reference string. |
960
+ | `options?` | [`OptsParseR1C1Ref`](#fxtype-aliasesoptsparser1c1refmd) | Options. |
970
961
 
971
- | Name | Type |
972
- | ----- | ---------------------------------------------- |
973
- | kind | `"name"` \| `"range"` \| `"beam"` \| `"table"` |
974
- | [loc] | [`SourceLocation`](#SourceLocation) |
975
- | type | `"ReferenceIdentifier"` |
976
- | value | `string` |
962
+ ## Returns
977
963
 
978
- ---
964
+ \| [`ReferenceName`](#fxtype-aliasesreferencenamemd)
965
+ \| [`ReferenceR1C1`](#fxtype-aliasesreferencer1c1md)
979
966
 
980
- ### <a id="ReferenceR1C1" href="#ReferenceR1C1">#</a> ReferenceR1C1
967
+ An object representing a valid reference or `undefined` if it is invalid.
981
968
 
982
- A reference containing a R1C1 style range. See [Prefixes.md] for documentation on how scopes work in Fx.
969
+ ## See
983
970
 
984
- ##### Properties
971
+ [OptsParseR1C1Ref](#fxtype-aliasesoptsparser1c1refmd)
985
972
 
986
- | Name | Type | Description |
987
- | -------------- | ------------------------- | ---------------------------------------- |
988
- | [context] | `Array<string>` | A collection of scopes for the reference |
989
- | [range] | [`RangeR1C1`](#RangeR1C1) | The reference's range |
990
- | [sheetName] | `string` | A context sheet scope |
991
- | [workbookName] | `string` | A context workbook scope |
992
973
 
993
- ---
974
+ <a name="fxfunctionsparsestructrefmd"></a>
994
975
 
995
- ### <a id="ReferenceStruct" href="#ReferenceStruct">#</a> ReferenceStruct
976
+ # parseStructRef()
996
977
 
997
- A reference containing a table slice definition. See [Prefixes.md] for documentation on how scopes work in Fx.
978
+ ```ts
979
+ function parseStructRef(ref: string): ReferenceStruct;
980
+ ```
998
981
 
999
- ##### Properties
982
+ Parse a structured reference string into an object representing it.
1000
983
 
1001
- | Name | Type | Description |
1002
- | -------------- | --------------- | ---------------------------------------- |
1003
- | [columns] | `Array<string>` | The sections this reference targets |
1004
- | [context] | `Array<string>` | A collection of scopes for the reference |
1005
- | [sections] | `Array<string>` | The sections this reference targets |
1006
- | [sheetName] | `string` | A context sheet scope |
1007
- | [table] | `string` | The table this reference targets |
1008
- | [workbookName] | `string` | A context workbook scope |
984
+ ```js
985
+ parseStructRef('workbook.xlsx!tableName[[#Data],[Column1]:[Column2]]');
986
+ // => {
987
+ // context: [ 'workbook.xlsx' ],
988
+ // sections: [ 'data' ],
989
+ // columns: [ 'my column', '@foo' ],
990
+ // table: 'tableName',
991
+ // }
992
+ ```
1009
993
 
1010
- ---
994
+ For A:A or A1:A style ranges, `null` will be used for any dimensions that the
995
+ syntax does not specify:
1011
996
 
1012
- ### <a id="SourceLocation" href="#SourceLocation">#</a> SourceLocation = `Array<number>`
997
+ See [References.md](./References.md).
1013
998
 
1014
- ---
999
+ ## Parameters
1015
1000
 
1016
- ### <a id="Token" href="#Token">#</a> Token extends `Record<string, any>`
1001
+ | Parameter | Type | Description |
1002
+ | ------ | ------ | ------ |
1003
+ | `ref` | `string` | A structured reference string |
1017
1004
 
1018
- A formula language token.
1005
+ ## Returns
1019
1006
 
1020
- ##### Properties
1007
+ [`ReferenceStruct`](#fxtype-aliasesreferencestructmd)
1021
1008
 
1022
- | Name | Type | Description |
1023
- | -------------- | --------------- | -------------------------------------- |
1024
- | [loc] | `Array<number>` | Source position offsets to the token |
1025
- | type | `string` | The type of the token |
1026
- | [unterminated] | `boolean` | Signifies an unterminated string token |
1027
- | value | `string` | The value of the token |
1009
+ An object representing a valid reference or `undefined` if it is invalid.
1028
1010
 
1029
- ---
1030
1011
 
1031
- ### <a id="TokenEnhanced" href="#TokenEnhanced">#</a> TokenEnhanced extends [`Token`](#Token)
1012
+ <a name="fxfunctionsstringifya1refmd"></a>
1032
1013
 
1033
- A token with extra meta data.
1014
+ # stringifyA1Ref()
1034
1015
 
1035
- ##### Properties
1016
+ ```ts
1017
+ function stringifyA1Ref(refObject:
1018
+ | ReferenceA1
1019
+ | ReferenceName): string;
1020
+ ```
1036
1021
 
1037
- | Name | Type | Description |
1038
- | --------- | --------- | ----------------------------------------------------------------- |
1039
- | [depth] | `number` | This token's level of nesting inside parentheses |
1040
- | [error] | `boolean` | Token is of unknown type or a paren without a match |
1041
- | [groupId] | `string` | The ID of a group which this token belongs (e.g. matching parens) |
1042
- | index | `number` | A zero based position in a token list |
1022
+ Get an A1-style string representation of a reference object.
1023
+
1024
+ ```js
1025
+ stringifyA1Ref({
1026
+ context: [ 'Sheet1' ],
1027
+ range: {
1028
+ top: 0,
1029
+ left: 0,
1030
+ bottom: 1,
1031
+ right: 1,
1032
+ $top: true,
1033
+ $left: false,
1034
+ $bottom: false,
1035
+ $right: true
1036
+ }
1037
+ });
1038
+ // => 'Sheet1!A$1:$B2'
1039
+ ```
1040
+
1041
+ ## Parameters
1042
+
1043
+ | Parameter | Type | Description |
1044
+ | ------ | ------ | ------ |
1045
+ | `refObject` | \| [`ReferenceA1`](#fxtype-aliasesreferencea1md) \| [`ReferenceName`](#fxtype-aliasesreferencenamemd) | A reference object. |
1046
+
1047
+ ## Returns
1048
+
1049
+ `string`
1050
+
1051
+ The reference in A1-style string format.
1052
+
1053
+
1054
+ <a name="fxfunctionsstringifyr1c1refmd"></a>
1055
+
1056
+ # stringifyR1C1Ref()
1057
+
1058
+ ```ts
1059
+ function stringifyR1C1Ref(refObject:
1060
+ | ReferenceName
1061
+ | ReferenceR1C1): string;
1062
+ ```
1063
+
1064
+ Get an R1C1-style string representation of a reference object.
1065
+
1066
+ ```js
1067
+ stringifyR1C1Ref({
1068
+ context: [ 'Sheet1' ],
1069
+ range: {
1070
+ r0: 9,
1071
+ c0: 8,
1072
+ r1: 9,
1073
+ c1: 8,
1074
+ $c0: true,
1075
+ $c1: true
1076
+ $r0: false,
1077
+ $r1: false
1078
+ }
1079
+ });
1080
+ // => 'Sheet1!R[9]C9:R[9]C9'
1081
+ ```
1082
+
1083
+ ## Parameters
1084
+
1085
+ | Parameter | Type | Description |
1086
+ | ------ | ------ | ------ |
1087
+ | `refObject` | \| [`ReferenceName`](#fxtype-aliasesreferencenamemd) \| [`ReferenceR1C1`](#fxtype-aliasesreferencer1c1md) | A reference object. |
1088
+
1089
+ ## Returns
1090
+
1091
+ `string`
1092
+
1093
+ The reference in R1C1-style string format.
1094
+
1095
+
1096
+ <a name="fxfunctionsstringifystructrefmd"></a>
1097
+
1098
+ # stringifyStructRef()
1099
+
1100
+ ```ts
1101
+ function stringifyStructRef(refObject: ReferenceStruct, options?: OptsStringifyStructRef): string;
1102
+ ```
1103
+
1104
+ Returns a string representation of a structured reference object.
1105
+
1106
+ ```js
1107
+ stringifyStructRef({
1108
+ context: [ 'workbook.xlsx' ],
1109
+ sections: [ 'data' ],
1110
+ columns: [ 'my column', '@foo' ],
1111
+ table: 'tableName',
1112
+ });
1113
+ // => 'workbook.xlsx!tableName[[#Data],[Column1]:[Column2]]'
1114
+ ```
1115
+
1116
+ ## Parameters
1117
+
1118
+ | Parameter | Type | Description |
1119
+ | ------ | ------ | ------ |
1120
+ | `refObject` | [`ReferenceStruct`](#fxtype-aliasesreferencestructmd) | A structured reference object. |
1121
+ | `options?` | [`OptsStringifyStructRef`](#fxtype-aliasesoptsstringifystructrefmd) | Options. |
1122
+
1123
+ ## Returns
1124
+
1125
+ `string`
1126
+
1127
+ The given structured reference in string format.
1128
+
1129
+ ## See
1130
+
1131
+ [OptsStringifyStructRef](#fxtype-aliasesoptsstringifystructrefmd)
1132
+
1133
+
1134
+ <a name="fxfunctionsstringifytokensmd"></a>
1135
+
1136
+ # stringifyTokens()
1137
+
1138
+ ```ts
1139
+ function stringifyTokens(tokens: Token[]): string;
1140
+ ```
1141
+
1142
+ Collapses a list of tokens into a formula string.
1143
+
1144
+ ## Parameters
1145
+
1146
+ | Parameter | Type | Description |
1147
+ | ------ | ------ | ------ |
1148
+ | `tokens` | [`Token`](#fxtype-aliasestokenmd)[] | A list of tokens. |
1149
+
1150
+ ## Returns
1151
+
1152
+ `string`
1153
+
1154
+ A formula string.
1155
+
1156
+
1157
+ <a name="fxfunctionstocolmd"></a>
1158
+
1159
+ # toCol()
1160
+
1161
+ ```ts
1162
+ function toCol(columnIndex: number): string;
1163
+ ```
1164
+
1165
+ Convert a 0 based offset number to a column string
1166
+ representation (`0` = `"A"`, `2` = `"C"`).
1167
+
1168
+ The method expects a number between 0 and 16383. Other input will
1169
+ return garbage.
1170
+
1171
+ ## Parameters
1172
+
1173
+ | Parameter | Type | Description |
1174
+ | ------ | ------ | ------ |
1175
+ | `columnIndex` | `number` | Zero based column index number |
1176
+
1177
+ ## Returns
1178
+
1179
+ `string`
1180
+
1181
+ The column string identifier
1182
+
1183
+
1184
+ <a name="fxfunctionstokenizemd"></a>
1185
+
1186
+ # tokenize()
1187
+
1188
+ ```ts
1189
+ function tokenize(formula: string, options?: OptsTokenize): Token[];
1190
+ ```
1191
+
1192
+ Breaks a string formula into a list of tokens.
1193
+
1194
+ The returned output will be an array of objects representing the tokens:
1195
+
1196
+ ```js
1197
+ [
1198
+ { type: FX_PREFIX, value: '=' },
1199
+ { type: FUNCTION, value: 'SUM' },
1200
+ { type: OPERATOR, value: '(' },
1201
+ { type: REF_RANGE, value: 'A1:B2' },
1202
+ { type: OPERATOR, value: ')' }
1203
+ ]
1204
+ ```
1205
+
1206
+ A collection of token types may be found as an object as the [tokenTypes](#fxvariablestokentypesmd)
1207
+ export on the package.
1208
+
1209
+ _Warning:_ To support syntax highlighting as you type, `STRING` tokens are allowed to be
1210
+ "unterminated". For example, the incomplete formula `="Hello world` would be
1211
+ tokenized as:
1212
+
1213
+ ```js
1214
+ [
1215
+ { type: FX_PREFIX, value: '=' },
1216
+ { type: STRING, value: '"Hello world', unterminated: true },
1217
+ ]
1218
+ ```
1219
+
1220
+ Parsers will need to handle this.
1221
+
1222
+ ## Parameters
1223
+
1224
+ | Parameter | Type | Description |
1225
+ | ------ | ------ | ------ |
1226
+ | `formula` | `string` | An Excel formula string (an Excel expression). |
1227
+ | `options?` | [`OptsTokenize`](#fxtype-aliasesoptstokenizemd) | Options |
1228
+
1229
+ ## Returns
1230
+
1231
+ [`Token`](#fxtype-aliasestokenmd)[]
1232
+
1233
+ An array of Tokens
1234
+
1235
+ ## See
1236
+
1237
+ - [OptsTokenize](#fxtype-aliasesoptstokenizemd)
1238
+ - [tokenTypes](#fxvariablestokentypesmd)
1239
+
1240
+
1241
+ <a name="fxfunctionstranslateformulatoa1md"></a>
1242
+
1243
+ # translateFormulaToA1()
1244
+
1245
+ ```ts
1246
+ function translateFormulaToA1(
1247
+ formula: string,
1248
+ anchorCell: string,
1249
+ options: OptsTranslateFormulaToA1): string;
1250
+ ```
1251
+
1252
+ Translates ranges in a formula from relative R1C1 syntax to absolute A1 syntax.
1253
+
1254
+ ```js
1255
+ translateToA1("=SUM(RC[1],R2C5,Sheet!R3C5)", "D10");
1256
+ // => "=SUM(E10,$E$2,Sheet!$E$3)");
1257
+ ```
1258
+
1259
+ If an input range is -1,-1 relative rows/columns and the anchor is A1, the
1260
+ resulting range will (by default) wrap around to the bottom of the sheet
1261
+ resulting in the range XFD1048576. This may not be what you want so you can set
1262
+ `{ wrapEdges }` to false which will instead turn the range into a `#REF!` error.
1263
+
1264
+ ```js
1265
+ translateToA1("=R[-1]C[-1]", "A1");
1266
+ // => "=XFD1048576");
1267
+
1268
+ translateToA1("=R[-1]C[-1]", "A1", { wrapEdges: false });
1269
+ // => "=#REF!");
1270
+ ```
1271
+
1272
+ ## Parameters
1273
+
1274
+ | Parameter | Type | Description |
1275
+ | ------ | ------ | ------ |
1276
+ | `formula` | `string` | An Excel formula string that should be adjusted. |
1277
+ | `anchorCell` | `string` | A simple string reference to an A1 cell ID (`AF123` or`$C$5`). |
1278
+ | `options` | [`OptsTranslateFormulaToA1`](#fxtype-aliasesoptstranslateformulatoa1md) | Translation options. |
1279
+
1280
+ ## Returns
1281
+
1282
+ `string`
1283
+
1284
+ A formula string.
1285
+
1286
+ ## See
1287
+
1288
+ [OptsTranslateFormulaToA1](#fxtype-aliasesoptstranslateformulatoa1md)
1289
+
1290
+
1291
+ <a name="fxfunctionstranslateformulator1c1md"></a>
1292
+
1293
+ # translateFormulaToR1C1()
1294
+
1295
+ ```ts
1296
+ function translateFormulaToR1C1(
1297
+ formula: string,
1298
+ anchorCell: string,
1299
+ options?: OptsTranslateToR1C1): string;
1300
+ ```
1301
+
1302
+ Translates ranges in a formula from absolute A1 syntax to relative R1C1 syntax.
1303
+
1304
+ ```js
1305
+ translateFormulaToR1C1("=SUM(E10,$E$2,Sheet!$E$3)", "D10");
1306
+ // => "=SUM(RC[1],R2C5,Sheet!R3C5)");
1307
+ ```
1308
+
1309
+ ## Parameters
1310
+
1311
+ | Parameter | Type | Description |
1312
+ | ------ | ------ | ------ |
1313
+ | `formula` | `string` | An Excel formula that should be adjusted. |
1314
+ | `anchorCell` | `string` | A simple string reference to an A1 cell ID (`AF123` or`$C$5`). |
1315
+ | `options?` | [`OptsTranslateToR1C1`](#fxtype-aliasesoptstranslatetor1c1md) | The options |
1316
+
1317
+ ## Returns
1318
+
1319
+ `string`
1320
+
1321
+ A formula string.
1322
+
1323
+ ## See
1324
+
1325
+ [OptsTranslateToR1C1](#fxtype-aliasesoptstranslatetor1c1md)
1326
+
1327
+
1328
+ <a name="fxfunctionstranslatetokenstoa1md"></a>
1329
+
1330
+ # translateTokensToA1()
1331
+
1332
+ ```ts
1333
+ function translateTokensToA1(
1334
+ tokens: Token[],
1335
+ anchorCell: string,
1336
+ options: OptsTranslateTokensToA1): Token[];
1337
+ ```
1338
+
1339
+ Translates ranges in a list of tokens from relative R1C1 syntax to absolute A1 syntax.
1340
+
1341
+ ```js
1342
+ translateToA1("=SUM(RC[1],R2C5,Sheet!R3C5)", "D10");
1343
+ // => "=SUM(E10,$E$2,Sheet!$E$3)");
1344
+ ```
1345
+
1346
+ If an input range is -1,-1 relative rows/columns and the anchor is A1, the
1347
+ resulting range will (by default) wrap around to the bottom of the sheet
1348
+ resulting in the range XFD1048576. This may not be what you want so may set
1349
+ `{ wrapEdges }` to false which will instead turn the range into a `#REF!` error.
1350
+
1351
+ ```js
1352
+ translateToA1("=R[-1]C[-1]", "A1");
1353
+ // => "=XFD1048576");
1354
+
1355
+ translateToA1("=R[-1]C[-1]", "A1", { wrapEdges: false });
1356
+ // => "=#REF!");
1357
+ ```
1358
+
1359
+ Note that if you are passing in a list of tokens that was not created using
1360
+ `mergeRefs` and you disable edge wrapping (or you simply set both options
1361
+ to false), you can end up with a formula such as `=#REF!:B2` or
1362
+ `=Sheet3!#REF!:F3`. These are valid formulas in the Excel formula language
1363
+ and Excel will accept them, but they are not supported in Google Sheets.
1364
+
1365
+ ## Parameters
1366
+
1367
+ | Parameter | Type | Description |
1368
+ | ------ | ------ | ------ |
1369
+ | `tokens` | [`Token`](#fxtype-aliasestokenmd)[] | A token list that should be adjusted. |
1370
+ | `anchorCell` | `string` | A simple string reference to an A1 cell ID (`AF123` or`$C$5`). |
1371
+ | `options` | [`OptsTranslateTokensToA1`](#fxtype-aliasesoptstranslatetokenstoa1md) | Translation options. |
1372
+
1373
+ ## Returns
1374
+
1375
+ [`Token`](#fxtype-aliasestokenmd)[]
1376
+
1377
+ A token list.
1378
+
1379
+ ## See
1380
+
1381
+ [OptsTranslateTokensToA1](#fxtype-aliasesoptstranslatetokenstoa1md)
1382
+
1383
+
1384
+ <a name="fxfunctionstranslatetokenstor1c1md"></a>
1385
+
1386
+ # translateTokensToR1C1()
1387
+
1388
+ ```ts
1389
+ function translateTokensToR1C1(tokens: Token[], anchorCell: string): Token[];
1390
+ ```
1391
+
1392
+ Translates ranges in a list of tokens from absolute A1 syntax to relative R1C1 syntax.
1393
+
1394
+ ```js
1395
+ translateFormulaToR1C1("=SUM(E10,$E$2,Sheet!$E$3)", "D10");
1396
+ // => "=SUM(RC[1],R2C5,Sheet!R3C5)");
1397
+ ```
1398
+
1399
+ ## Parameters
1400
+
1401
+ | Parameter | Type | Description |
1402
+ | ------ | ------ | ------ |
1403
+ | `tokens` | [`Token`](#fxtype-aliasestokenmd)[] | A token list that should be adjusted. |
1404
+ | `anchorCell` | `string` | A simple string reference to an A1 cell ID (`AF123` or`$C$5`). |
1405
+
1406
+ ## Returns
1407
+
1408
+ [`Token`](#fxtype-aliasestokenmd)[]
1409
+
1410
+ A token list.
1411
+
1412
+
1413
+ <a name="fxtype-aliasesarrayexpressionmd"></a>
1414
+
1415
+ # ArrayExpression
1416
+
1417
+ ```ts
1418
+ type ArrayExpression = {
1419
+ elements: (
1420
+ | ReferenceIdentifier
1421
+ | Literal
1422
+ | ErrorLiteral
1423
+ | CallExpression)[][];
1424
+ loc?: SourceLocation;
1425
+ type: "ArrayExpression";
1426
+ } & Node;
1427
+ ```
1428
+
1429
+ An array expression. Excel does not have empty or sparse arrays and restricts array elements to
1430
+ literals. Google Sheets allows `ReferenceIdentifier`s and `CallExpression`s as elements of
1431
+ arrays, the fx parser has options for this but they are off by default.
1432
+
1433
+ ## Type Declaration
1434
+
1435
+ | Name | Type | Description |
1436
+ | ------ | ------ | ------ |
1437
+ | `elements` | ( \| [`ReferenceIdentifier`](#fxtype-aliasesreferenceidentifiermd) \| [`Literal`](#fxtype-aliasesliteralmd) \| [`ErrorLiteral`](#fxtype-aliaseserrorliteralmd) \| [`CallExpression`](#fxtype-aliasescallexpressionmd))[][] | The elements of the array. |
1438
+ | `loc?` | [`SourceLocation`](#fxtype-aliasessourcelocationmd) | The original source position of the node. |
1439
+ | `type` | `"ArrayExpression"` | The type of this AST node. |
1440
+
1441
+
1442
+ <a name="fxtype-aliasesastexpressionmd"></a>
1443
+
1444
+ # AstExpression
1445
+
1446
+ ```ts
1447
+ type AstExpression =
1448
+ | ReferenceIdentifier
1449
+ | Literal
1450
+ | ErrorLiteral
1451
+ | UnaryExpression
1452
+ | BinaryExpression
1453
+ | CallExpression
1454
+ | ArrayExpression
1455
+ | LambdaExpression
1456
+ | LetExpression;
1457
+ ```
1458
+
1459
+ Represents an evaluate-able expression.
1460
+
1461
+
1462
+ <a name="fxtype-aliasesbinaryexpressionmd"></a>
1463
+
1464
+ # BinaryExpression
1465
+
1466
+ ```ts
1467
+ type BinaryExpression = {
1468
+ arguments: AstExpression[];
1469
+ loc?: SourceLocation;
1470
+ operator: BinaryOperator;
1471
+ type: "BinaryExpression";
1472
+ } & Node;
1473
+ ```
1474
+
1475
+ A binary operator expression.
1476
+
1477
+ ## Type Declaration
1478
+
1479
+ | Name | Type | Description |
1480
+ | ------ | ------ | ------ |
1481
+ | `arguments` | [`AstExpression`](#fxtype-aliasesastexpressionmd)[] | The arguments for the operator. |
1482
+ | `loc?` | [`SourceLocation`](#fxtype-aliasessourcelocationmd) | The original source position of the node. |
1483
+ | `operator` | [`BinaryOperator`](#fxtype-aliasesbinaryoperatormd) | The expression's operator. |
1484
+ | `type` | `"BinaryExpression"` | The type of this AST node. |
1485
+
1486
+
1487
+ <a name="fxtype-aliasesbinaryoperatormd"></a>
1488
+
1489
+ # BinaryOperator
1490
+
1491
+ ```ts
1492
+ type BinaryOperator =
1493
+ | "="
1494
+ | "<"
1495
+ | ">"
1496
+ | "<="
1497
+ | ">="
1498
+ | "<>"
1499
+ | "-"
1500
+ | "+"
1501
+ | "*"
1502
+ | "/"
1503
+ | "^"
1504
+ | ":"
1505
+ | " "
1506
+ | ","
1507
+ | "&";
1508
+ ```
1509
+
1510
+ A binary operator token.
1511
+
1512
+ Note that Excels union operator is whitespace so a parser must take care to normalize this to
1513
+ a single space.
1514
+
1515
+
1516
+ <a name="fxtype-aliasescallexpressionmd"></a>
1517
+
1518
+ # CallExpression
1519
+
1520
+ ```ts
1521
+ type CallExpression = {
1522
+ arguments: AstExpression[];
1523
+ callee: Identifier;
1524
+ loc?: SourceLocation;
1525
+ type: "CallExpression";
1526
+ } & Node;
1527
+ ```
1528
+
1529
+ A function call expression.
1530
+
1531
+ ## Type Declaration
1532
+
1533
+ | Name | Type | Description |
1534
+ | ------ | ------ | ------ |
1535
+ | `arguments` | [`AstExpression`](#fxtype-aliasesastexpressionmd)[] | The arguments for the function. |
1536
+ | `callee` | [`Identifier`](#fxtype-aliasesidentifiermd) | The function being called. |
1537
+ | `loc?` | [`SourceLocation`](#fxtype-aliasessourcelocationmd) | The original source position of the node. |
1538
+ | `type` | `"CallExpression"` | The type of this AST node. |
1539
+
1540
+
1541
+ <a name="fxtype-aliaseserrorliteralmd"></a>
1542
+
1543
+ # ErrorLiteral
1544
+
1545
+ ```ts
1546
+ type ErrorLiteral = {
1547
+ loc?: SourceLocation;
1548
+ raw: string;
1549
+ type: "ErrorLiteral";
1550
+ value: string;
1551
+ } & Node;
1552
+ ```
1553
+
1554
+ An Error expression.
1555
+
1556
+ ## Type Declaration
1557
+
1558
+ | Name | Type | Description |
1559
+ | ------ | ------ | ------ |
1560
+ | `loc?` | [`SourceLocation`](#fxtype-aliasessourcelocationmd) | The original source position of the node. |
1561
+ | `raw` | `string` | The untouched literal source. |
1562
+ | `type` | `"ErrorLiteral"` | The type of this AST node. |
1563
+ | `value` | `string` | The value of the error. |
1564
+
1565
+
1566
+ <a name="fxtype-aliasesidentifiermd"></a>
1567
+
1568
+ # Identifier
1569
+
1570
+ ```ts
1571
+ type Identifier = {
1572
+ loc?: SourceLocation;
1573
+ name: string;
1574
+ type: "Identifier";
1575
+ } & Node;
1576
+ ```
1577
+
1578
+ An identifier. These appear on `CallExpression`, `LambdaExpression`, and `LetExpression`
1579
+ and will always be a static string representing the name of a function call or parameter.
1580
+
1581
+ ## Type Declaration
1582
+
1583
+ | Name | Type | Description |
1584
+ | ------ | ------ | ------ |
1585
+ | `loc?` | [`SourceLocation`](#fxtype-aliasessourcelocationmd) | The original source position of the node. |
1586
+ | `name` | `string` | The identifying name. |
1587
+ | `type` | `"Identifier"` | The type of this AST node. |
1588
+
1589
+
1590
+ <a name="fxtype-aliaseslambdaexpressionmd"></a>
1591
+
1592
+ # LambdaExpression
1593
+
1594
+ ```ts
1595
+ type LambdaExpression = {
1596
+ body: AstExpression | null;
1597
+ loc?: SourceLocation;
1598
+ params: Identifier[];
1599
+ type: "LambdaExpression";
1600
+ } & Node;
1601
+ ```
1602
+
1603
+ A LAMBDA expression.
1604
+
1605
+ ## Type Declaration
1606
+
1607
+ | Name | Type | Description |
1608
+ | ------ | ------ | ------ |
1609
+ | `body` | [`AstExpression`](#fxtype-aliasesastexpressionmd) \| `null` | The LAMBDA's expression. |
1610
+ | `loc?` | [`SourceLocation`](#fxtype-aliasessourcelocationmd) | The original source position of the node. |
1611
+ | `params` | [`Identifier`](#fxtype-aliasesidentifiermd)[] | The LAMBDA's parameters. |
1612
+ | `type` | `"LambdaExpression"` | The type of this AST node. |
1613
+
1614
+
1615
+ <a name="fxtype-aliasesletdeclaratormd"></a>
1616
+
1617
+ # LetDeclarator
1618
+
1619
+ ```ts
1620
+ type LetDeclarator = {
1621
+ id: Identifier;
1622
+ init: AstExpression | null;
1623
+ loc?: SourceLocation;
1624
+ type: "LetDeclarator";
1625
+ } & Node;
1626
+ ```
1627
+
1628
+ A LET parameter declaration.
1629
+
1630
+ ## Type Declaration
1631
+
1632
+ | Name | Type | Description |
1633
+ | ------ | ------ | ------ |
1634
+ | `id` | [`Identifier`](#fxtype-aliasesidentifiermd) | The name of the variable. |
1635
+ | `init` | [`AstExpression`](#fxtype-aliasesastexpressionmd) \| `null` | The variable's initializing expression. |
1636
+ | `loc?` | [`SourceLocation`](#fxtype-aliasessourcelocationmd) | The original source position of the node. |
1637
+ | `type` | `"LetDeclarator"` | The type of this AST node. |
1638
+
1639
+
1640
+ <a name="fxtype-aliasesletexpressionmd"></a>
1641
+
1642
+ # LetExpression
1643
+
1644
+ ```ts
1645
+ type LetExpression = {
1646
+ body: AstExpression | null;
1647
+ declarations: LetDeclarator[];
1648
+ loc?: SourceLocation;
1649
+ type: "LetExpression";
1650
+ } & Node;
1651
+ ```
1652
+
1653
+ A LET expression.
1654
+
1655
+ ## Type Declaration
1656
+
1657
+ | Name | Type | Description |
1658
+ | ------ | ------ | ------ |
1659
+ | `body` | [`AstExpression`](#fxtype-aliasesastexpressionmd) \| `null` | The LET's scoped expression. |
1660
+ | `declarations` | [`LetDeclarator`](#fxtype-aliasesletdeclaratormd)[] | The LET's variable declarations. |
1661
+ | `loc?` | [`SourceLocation`](#fxtype-aliasessourcelocationmd) | The original source position of the node. |
1662
+ | `type` | `"LetExpression"` | The type of this AST node. |
1663
+
1664
+
1665
+ <a name="fxtype-aliasesliteralmd"></a>
1666
+
1667
+ # Literal
1668
+
1669
+ ```ts
1670
+ type Literal = {
1671
+ loc?: SourceLocation;
1672
+ raw: string;
1673
+ type: "Literal";
1674
+ value: string | number | boolean;
1675
+ } & Node;
1676
+ ```
1677
+
1678
+ A literal token. Captures numbers, strings, and booleans.
1679
+ Literal errors have their own variant type.
1680
+
1681
+ ## Type Declaration
1682
+
1683
+ | Name | Type | Description |
1684
+ | ------ | ------ | ------ |
1685
+ | `loc?` | [`SourceLocation`](#fxtype-aliasessourcelocationmd) | The original source position of the node. |
1686
+ | `raw` | `string` | The untouched literal source. |
1687
+ | `type` | `"Literal"` | The type of this AST node. |
1688
+ | `value` | `string` \| `number` \| `boolean` | The value of the literal. |
1689
+
1690
+
1691
+ <a name="fxtype-aliasesnodemd"></a>
1692
+
1693
+ # Node
1694
+
1695
+ ```ts
1696
+ type Node = {
1697
+ loc?: SourceLocation;
1698
+ type: string;
1699
+ };
1700
+ ```
1701
+
1702
+ All AST nodes are represented by `Node` objects.
1703
+ They may have any prototype inheritance but implement the same basic interface.
1704
+
1705
+ The `type` field is a string representing the AST variant type.
1706
+ Each subtype of Node is documented below with the specific string of its `type` field.
1707
+ You can use this field to determine which interface a node implements.
1708
+
1709
+ ## Properties
1710
+
1711
+ | Property | Type | Description |
1712
+ | ------ | ------ | ------ |
1713
+ | <a id="loc"></a> `loc?` | [`SourceLocation`](#fxtype-aliasessourcelocationmd) | The original source position of the node. |
1714
+ | <a id="type"></a> `type` | `string` | The type of this AST node. |
1715
+
1716
+
1717
+ <a name="fxtype-aliasesoptsfixrangesmd"></a>
1718
+
1719
+ # OptsFixRanges
1720
+
1721
+ ```ts
1722
+ type OptsFixRanges = {
1723
+ addBounds?: boolean;
1724
+ thisRow?: boolean;
1725
+ };
1726
+ ```
1727
+
1728
+ Options for [fixTokenRanges](#fxfunctionsfixtokenrangesmd) and [fixFormulaRanges](#fxfunctionsfixformularangesmd).
1729
+
1730
+ ## Properties
1731
+
1732
+ | Property | Type | Default value | Description |
1733
+ | ------ | ------ | ------ | ------ |
1734
+ | <a id="addbounds"></a> `addBounds?` | `boolean` | `false` | Fill in any undefined bounds of range objects. Top to 0, bottom to 1048575, left to 0, and right to 16383. |
1735
+ | <a id="thisrow"></a> `thisRow?` | `boolean` | `false` | Enforces using the `[#This Row]` instead of the `@` shorthand when serializing structured ranges. |
1736
+
1737
+
1738
+ <a name="fxtype-aliasesoptsparsemd"></a>
1739
+
1740
+ # OptsParse
1741
+
1742
+ ```ts
1743
+ type OptsParse = {
1744
+ looseRefCalls?: boolean;
1745
+ permitArrayCalls?: boolean;
1746
+ permitArrayRanges?: boolean;
1747
+ };
1748
+ ```
1749
+
1750
+ Options for [parse](#fxfunctionsparsemd).
1751
+
1752
+ ## Properties
1753
+
1754
+ | Property | Type | Default value | Description |
1755
+ | ------ | ------ | ------ | ------ |
1756
+ | <a id="looserefcalls"></a> `looseRefCalls?` | `boolean` | `false` | Permits any function call where otherwise only functions that return references would be permitted. |
1757
+ | <a id="permitarraycalls"></a> `permitArrayCalls?` | `boolean` | `false` | Function calls are allowed as elements of arrays. This is a feature in Google Sheets while Excel does not allow it. |
1758
+ | <a id="permitarrayranges"></a> `permitArrayRanges?` | `boolean` | `false` | Ranges are allowed as elements of arrays. This is a feature in Google Sheets while Excel does not allow it. |
1759
+
1760
+
1761
+ <a name="fxtype-aliasesoptsparsea1refmd"></a>
1762
+
1763
+ # OptsParseA1Ref
1764
+
1765
+ ```ts
1766
+ type OptsParseA1Ref = {
1767
+ allowNamed?: boolean;
1768
+ allowTernary?: boolean;
1769
+ };
1770
+ ```
1771
+
1772
+ Options for [parseA1Ref](#fxfunctionsparsea1refmd).
1773
+
1774
+ ## Properties
1775
+
1776
+ | Property | Type | Default value | Description |
1777
+ | ------ | ------ | ------ | ------ |
1778
+ | <a id="allownamed"></a> `allowNamed?` | `boolean` | `true` | Enable parsing names as well as ranges. |
1779
+ | <a id="allowternary"></a> `allowTernary?` | `boolean` | `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](./References.md). |
1780
+
1781
+
1782
+ <a name="fxtype-aliasesoptsparser1c1refmd"></a>
1783
+
1784
+ # OptsParseR1C1Ref
1785
+
1786
+ ```ts
1787
+ type OptsParseR1C1Ref = {
1788
+ allowNamed?: boolean;
1789
+ allowTernary?: boolean;
1790
+ };
1791
+ ```
1792
+
1793
+ Options for [parseR1C1Ref](#fxfunctionsparser1c1refmd).
1794
+
1795
+ ## Properties
1796
+
1797
+ | Property | Type | Default value | Description |
1798
+ | ------ | ------ | ------ | ------ |
1799
+ | <a id="allownamed"></a> `allowNamed?` | `boolean` | `true` | Enable parsing names as well as ranges. |
1800
+ | <a id="allowternary"></a> `allowTernary?` | `boolean` | `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](./References.md). |
1801
+
1802
+
1803
+ <a name="fxtype-aliasesoptsstringifystructrefmd"></a>
1804
+
1805
+ # OptsStringifyStructRef
1806
+
1807
+ ```ts
1808
+ type OptsStringifyStructRef = {
1809
+ thisRow?: boolean;
1810
+ };
1811
+ ```
1812
+
1813
+ Options for [stringifyStructRef](#fxfunctionsstringifystructrefmd)
1814
+
1815
+ ## Properties
1816
+
1817
+ | Property | Type | Default value | Description |
1818
+ | ------ | ------ | ------ | ------ |
1819
+ | <a id="thisrow"></a> `thisRow?` | `boolean` | `false` | Enforces using the `[#This Row]` instead of the `@` shorthand when serializing structured ranges. |
1820
+
1821
+
1822
+ <a name="fxtype-aliasesoptstokenizemd"></a>
1823
+
1824
+ # OptsTokenize
1825
+
1826
+ ```ts
1827
+ type OptsTokenize = {
1828
+ allowTernary?: boolean;
1829
+ mergeRefs?: boolean;
1830
+ negativeNumbers?: boolean;
1831
+ r1c1?: boolean;
1832
+ withLocation?: boolean;
1833
+ };
1834
+ ```
1835
+
1836
+ Options for [tokenize](#fxfunctionstokenizemd).
1837
+
1838
+ ## Properties
1839
+
1840
+ | Property | Type | Default value | Description |
1841
+ | ------ | ------ | ------ | ------ |
1842
+ | <a id="allowternary"></a> `allowTernary?` | `boolean` | `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](./References.md). |
1843
+ | <a id="mergerefs"></a> `mergeRefs?` | `boolean` | `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) |
1844
+ | <a id="negativenumbers"></a> `negativeNumbers?` | `boolean` | `true` | Merges unary minuses with their immediately following number tokens (`-`,`1`) => `-1` (alternatively these will be unary operations in the tree). |
1845
+ | <a id="r1c1"></a> `r1c1?` | `boolean` | `false` | Ranges are expected to be in the R1C1 style format rather than the more popular A1 style. |
1846
+ | <a id="withlocation"></a> `withLocation?` | `boolean` | `true` | Nodes will include source position offsets to the tokens: `{ loc: [ start, end ] }` |
1847
+
1848
+
1849
+ <a name="fxtype-aliasesoptstranslateformulatoa1md"></a>
1850
+
1851
+ # OptsTranslateFormulaToA1
1852
+
1853
+ ```ts
1854
+ type OptsTranslateFormulaToA1 = {
1855
+ allowTernary?: boolean;
1856
+ mergeRefs?: boolean;
1857
+ wrapEdges?: boolean;
1858
+ };
1859
+ ```
1860
+
1861
+ Options for [translateFormulaToA1](#fxfunctionstranslateformulatoa1md).
1862
+
1863
+ ## Properties
1864
+
1865
+ | Property | Type | Default value | Description |
1866
+ | ------ | ------ | ------ | ------ |
1867
+ | <a id="allowternary"></a> `allowTernary?` | `boolean` | `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. |
1868
+ | <a id="mergerefs"></a> `mergeRefs?` | `boolean` | `true` | Should ranges be treated as whole references (`Sheet1!A1:B2`) or as separate tokens for each part: (`Sheet1`,`!`,`A1`,`:`,`B2`). |
1869
+ | <a id="wrapedges"></a> `wrapEdges?` | `boolean` | `true` | Wrap out-of-bounds ranges around sheet edges rather than turning them to #REF! errors. |
1870
+
1871
+
1872
+ <a name="fxtype-aliasesoptstranslatetor1c1md"></a>
1873
+
1874
+ # OptsTranslateToR1C1
1875
+
1876
+ ```ts
1877
+ type OptsTranslateToR1C1 = {
1878
+ allowTernary?: boolean;
1879
+ };
1880
+ ```
1881
+
1882
+ Options for [translateFormulaToR1C1](#fxfunctionstranslateformulator1c1md).
1883
+
1884
+ ## Properties
1885
+
1886
+ | Property | Type | Default value | Description |
1887
+ | ------ | ------ | ------ | ------ |
1888
+ | <a id="allowternary"></a> `allowTernary?` | `boolean` | `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](./References.md). |
1889
+
1890
+
1891
+ <a name="fxtype-aliasesoptstranslatetokenstoa1md"></a>
1892
+
1893
+ # OptsTranslateTokensToA1
1894
+
1895
+ ```ts
1896
+ type OptsTranslateTokensToA1 = {
1897
+ wrapEdges?: boolean;
1898
+ };
1899
+ ```
1900
+
1901
+ Options for [translateTokensToA1](#fxfunctionstranslatetokenstoa1md)
1902
+
1903
+ ## Properties
1904
+
1905
+ | Property | Type | Default value | Description |
1906
+ | ------ | ------ | ------ | ------ |
1907
+ | <a id="wrapedges"></a> `wrapEdges?` | `boolean` | `true` | Wrap out-of-bounds ranges around sheet edges rather than turning them to #REF! errors. |
1908
+
1909
+
1910
+ <a name="fxtype-aliasesrangea1md"></a>
1911
+
1912
+ # RangeA1
1913
+
1914
+ ```ts
1915
+ type RangeA1 = {
1916
+ $bottom?: boolean | null;
1917
+ $left?: boolean | null;
1918
+ $right?: boolean | null;
1919
+ $top?: boolean | null;
1920
+ bottom?: number | null;
1921
+ left: number | null;
1922
+ right?: number | null;
1923
+ top: number | null;
1924
+ trim?: "head" | "tail" | "both" | null;
1925
+ };
1926
+ ```
1927
+
1928
+ A range in A1 style coordinates.
1929
+
1930
+ ## Properties
1931
+
1932
+ | Property | Type | Description |
1933
+ | ------ | ------ | ------ |
1934
+ | <a id="bottom"></a> `$bottom?` | `boolean` \| `null` | Signifies that bottom is a "locked" value |
1935
+ | <a id="left"></a> `$left?` | `boolean` \| `null` | Signifies that left is a "locked" value |
1936
+ | <a id="right"></a> `$right?` | `boolean` \| `null` | Signifies that right is a "locked" value |
1937
+ | <a id="top"></a> `$top?` | `boolean` \| `null` | Signifies that top is a "locked" value |
1938
+ | <a id="bottom-1"></a> `bottom?` | `number` \| `null` | Bottom row of the range |
1939
+ | <a id="left-1"></a> `left` | `number` \| `null` | Left column of the range |
1940
+ | <a id="right-1"></a> `right?` | `number` \| `null` | Right column of the range |
1941
+ | <a id="top-1"></a> `top` | `number` \| `null` | Top row of the range |
1942
+ | <a id="trim"></a> `trim?` | `"head"` \| `"tail"` \| `"both"` \| `null` | Should empty rows and columns at the top/left or bottom/right be discarded when range is read? |
1943
+
1944
+
1945
+ <a name="fxtype-aliasesranger1c1md"></a>
1946
+
1947
+ # RangeR1C1
1948
+
1949
+ ```ts
1950
+ type RangeR1C1 = {
1951
+ $c0?: boolean | null;
1952
+ $c1?: boolean | null;
1953
+ $r0?: boolean | null;
1954
+ $r1?: boolean | null;
1955
+ c0?: number | null;
1956
+ c1?: number | null;
1957
+ r0?: number | null;
1958
+ r1?: number | null;
1959
+ trim?: "head" | "tail" | "both" | null;
1960
+ };
1961
+ ```
1962
+
1963
+ A range in R1C1 style coordinates.
1964
+
1965
+ ## Properties
1966
+
1967
+ | Property | Type | Description |
1968
+ | ------ | ------ | ------ |
1969
+ | <a id="c0"></a> `$c0?` | `boolean` \| `null` | Signifies that c0 is an absolute value |
1970
+ | <a id="c1"></a> `$c1?` | `boolean` \| `null` | Signifies that c1 is an absolute value |
1971
+ | <a id="r0"></a> `$r0?` | `boolean` \| `null` | Signifies that r0 is an absolute value |
1972
+ | <a id="r1"></a> `$r1?` | `boolean` \| `null` | Signifies that r1 is an absolute value |
1973
+ | <a id="c0-1"></a> `c0?` | `number` \| `null` | Left column of the range |
1974
+ | <a id="c1-1"></a> `c1?` | `number` \| `null` | Right column of the range |
1975
+ | <a id="r0-1"></a> `r0?` | `number` \| `null` | Top row of the range |
1976
+ | <a id="r1-1"></a> `r1?` | `number` \| `null` | Bottom row of the range |
1977
+ | <a id="trim"></a> `trim?` | `"head"` \| `"tail"` \| `"both"` \| `null` | Should empty rows and columns at the top/left or bottom/right be discarded when range is read? |
1978
+
1979
+
1980
+ <a name="fxtype-aliasesreferencea1md"></a>
1981
+
1982
+ # ReferenceA1
1983
+
1984
+ ```ts
1985
+ type ReferenceA1 = {
1986
+ context?: string[];
1987
+ range: RangeA1;
1988
+ };
1989
+ ```
1990
+
1991
+ A reference containing an A1 style range. See [Prefixes.md](Prefixes.md) for
1992
+ documentation on how scopes work in Fx.
1993
+
1994
+ ## Properties
1995
+
1996
+ | Property | Type | Description |
1997
+ | ------ | ------ | ------ |
1998
+ | <a id="context"></a> `context?` | `string`[] | A collection of scopes for the reference |
1999
+ | <a id="range"></a> `range` | [`RangeA1`](#fxtype-aliasesrangea1md) | The reference's range |
2000
+
2001
+
2002
+ <a name="fxtype-aliasesreferencea1xlsxmd"></a>
2003
+
2004
+ # ReferenceA1Xlsx
2005
+
2006
+ ```ts
2007
+ type ReferenceA1Xlsx = {
2008
+ range: RangeA1;
2009
+ sheetName?: string;
2010
+ workbookName?: string;
2011
+ };
2012
+ ```
2013
+
2014
+ A reference containing an A1 style range. See [Prefixes.md] for
2015
+ documentation on how scopes work in Fx.
2016
+
2017
+ ## Properties
2018
+
2019
+ | Property | Type | Description |
2020
+ | ------ | ------ | ------ |
2021
+ | <a id="range"></a> `range` | [`RangeA1`](#fxtype-aliasesrangea1md) | The reference's range |
2022
+ | <a id="sheetname"></a> `sheetName?` | `string` | A context sheet scope |
2023
+ | <a id="workbookname"></a> `workbookName?` | `string` | A context workbook scope |
2024
+
2025
+
2026
+ <a name="fxtype-aliasesreferenceidentifiermd"></a>
2027
+
2028
+ # ReferenceIdentifier
2029
+
2030
+ ```ts
2031
+ type ReferenceIdentifier = {
2032
+ kind: "name" | "range" | "beam" | "table";
2033
+ loc?: SourceLocation;
2034
+ type: "ReferenceIdentifier";
2035
+ value: string;
2036
+ } & Node;
2037
+ ```
2038
+
2039
+ An identifier for a range or a name.
2040
+
2041
+ ## Type Declaration
2042
+
2043
+ | Name | Type | Description |
2044
+ | ------ | ------ | ------ |
2045
+ | `kind` | `"name"` \| `"range"` \| `"beam"` \| `"table"` | The kind of reference the value holds. |
2046
+ | `loc?` | [`SourceLocation`](#fxtype-aliasessourcelocationmd) | The original source position of the node. |
2047
+ | `type` | `"ReferenceIdentifier"` | The type of this AST node. |
2048
+ | `value` | `string` | The untouched reference value. |
2049
+
2050
+
2051
+ <a name="fxtype-aliasesreferencenamemd"></a>
2052
+
2053
+ # ReferenceName
2054
+
2055
+ ```ts
2056
+ type ReferenceName = {
2057
+ context?: string[];
2058
+ name: string;
2059
+ };
2060
+ ```
2061
+
2062
+ A reference containing a name. See [Prefixes.md] for
2063
+ documentation on how scopes work in Fx.
2064
+
2065
+ ## Properties
2066
+
2067
+ | Property | Type | Description |
2068
+ | ------ | ------ | ------ |
2069
+ | <a id="context"></a> `context?` | `string`[] | A collection of scopes for the reference |
2070
+ | <a id="name"></a> `name` | `string` | The reference's name |
2071
+
2072
+
2073
+ <a name="fxtype-aliasesreferencenamexlsxmd"></a>
2074
+
2075
+ # ReferenceNameXlsx
2076
+
2077
+ ```ts
2078
+ type ReferenceNameXlsx = {
2079
+ name: string;
2080
+ sheetName?: string;
2081
+ workbookName?: string;
2082
+ };
2083
+ ```
2084
+
2085
+ A reference containing a name. See [Prefixes.md] for
2086
+ documentation on how scopes work in Fx.
2087
+
2088
+ ## Properties
2089
+
2090
+ | Property | Type | Description |
2091
+ | ------ | ------ | ------ |
2092
+ | <a id="name"></a> `name` | `string` | The reference's name |
2093
+ | <a id="sheetname"></a> `sheetName?` | `string` | A context sheet scope |
2094
+ | <a id="workbookname"></a> `workbookName?` | `string` | A context workbook scope |
2095
+
2096
+
2097
+ <a name="fxtype-aliasesreferencer1c1md"></a>
2098
+
2099
+ # ReferenceR1C1
2100
+
2101
+ ```ts
2102
+ type ReferenceR1C1 = {
2103
+ context?: string[];
2104
+ range: RangeR1C1;
2105
+ };
2106
+ ```
2107
+
2108
+ A reference containing a R1C1 style range. See [Prefixes.md] for
2109
+ documentation on how scopes work in Fx.
2110
+
2111
+ ## Properties
2112
+
2113
+ | Property | Type | Description |
2114
+ | ------ | ------ | ------ |
2115
+ | <a id="context"></a> `context?` | `string`[] | A collection of scopes for the reference |
2116
+ | <a id="range"></a> `range` | [`RangeR1C1`](#fxtype-aliasesranger1c1md) | The reference's range |
2117
+
2118
+
2119
+ <a name="fxtype-aliasesreferencer1c1xlsxmd"></a>
2120
+
2121
+ # ReferenceR1C1Xlsx
2122
+
2123
+ ```ts
2124
+ type ReferenceR1C1Xlsx = {
2125
+ range: RangeR1C1;
2126
+ sheetName?: string;
2127
+ workbookName?: string;
2128
+ };
2129
+ ```
2130
+
2131
+ A reference containing a R1C1 style range. See [Prefixes.md] for
2132
+ documentation on how scopes work in Fx.
2133
+
2134
+ ## Properties
2135
+
2136
+ | Property | Type | Description |
2137
+ | ------ | ------ | ------ |
2138
+ | <a id="range"></a> `range` | [`RangeR1C1`](#fxtype-aliasesranger1c1md) | The reference's range |
2139
+ | <a id="sheetname"></a> `sheetName?` | `string` | A context sheet scope |
2140
+ | <a id="workbookname"></a> `workbookName?` | `string` | A context workbook scope |
2141
+
2142
+
2143
+ <a name="fxtype-aliasesreferencestructmd"></a>
2144
+
2145
+ # ReferenceStruct
2146
+
2147
+ ```ts
2148
+ type ReferenceStruct = {
2149
+ columns?: string[];
2150
+ context?: string[];
2151
+ sections?: string[];
2152
+ table?: string;
2153
+ };
2154
+ ```
2155
+
2156
+ A reference containing a table slice definition. See [Prefixes.md] for
2157
+ documentation on how scopes work in Fx.
2158
+
2159
+ ## Properties
2160
+
2161
+ | Property | Type | Description |
2162
+ | ------ | ------ | ------ |
2163
+ | <a id="columns"></a> `columns?` | `string`[] | The sections this reference targets |
2164
+ | <a id="context"></a> `context?` | `string`[] | A collection of scopes for the reference |
2165
+ | <a id="sections"></a> `sections?` | `string`[] | The sections this reference targets |
2166
+ | <a id="table"></a> `table?` | `string` | The table this reference targets |
2167
+
2168
+
2169
+ <a name="fxtype-aliasesreferencestructxlsxmd"></a>
2170
+
2171
+ # ReferenceStructXlsx
2172
+
2173
+ ```ts
2174
+ type ReferenceStructXlsx = {
2175
+ columns?: string[];
2176
+ sections?: string[];
2177
+ sheetName?: string;
2178
+ table?: string;
2179
+ workbookName?: string;
2180
+ };
2181
+ ```
2182
+
2183
+ A reference containing a table slice definition. See [Prefixes.md] for
2184
+ documentation on how scopes work in Fx.
2185
+
2186
+ ## Properties
2187
+
2188
+ | Property | Type | Description |
2189
+ | ------ | ------ | ------ |
2190
+ | <a id="columns"></a> `columns?` | `string`[] | The sections this reference targets |
2191
+ | <a id="sections"></a> `sections?` | `string`[] | The sections this reference targets |
2192
+ | <a id="sheetname"></a> `sheetName?` | `string` | A context sheet scope |
2193
+ | <a id="table"></a> `table?` | `string` | The table this reference targets |
2194
+ | <a id="workbookname"></a> `workbookName?` | `string` | A context workbook scope |
2195
+
2196
+
2197
+ <a name="fxtype-aliasessourcelocationmd"></a>
2198
+
2199
+ # SourceLocation
2200
+
2201
+ ```ts
2202
+ type SourceLocation = number[];
2203
+ ```
2204
+
2205
+ Represents the source location information of the node.
2206
+ If the node contains no information about the source location, the field is `null`;
2207
+ otherwise it is an array consisting of a two numbers: A start offset (the position of
2208
+ the first character of the parsed source region) and an end offset (the position of
2209
+ the first character after the parsed source region).
2210
+
2211
+
2212
+ <a name="fxtype-aliasestokenmd"></a>
2213
+
2214
+ # Token
2215
+
2216
+ ```ts
2217
+ type Token = Record<string, unknown> & {
2218
+ loc?: number[];
2219
+ type: string;
2220
+ unterminated?: boolean;
2221
+ value: string;
2222
+ };
2223
+ ```
2224
+
2225
+ A formula language token.
2226
+
2227
+ ## Type Declaration
2228
+
2229
+ | Name | Type | Description |
2230
+ | ------ | ------ | ------ |
2231
+ | `loc?` | `number`[] | Source position offsets to the token |
2232
+ | `type` | `string` | The type of the token |
2233
+ | `unterminated?` | `boolean` | Signifies an unterminated string token |
2234
+ | `value` | `string` | The value of the token |
2235
+
2236
+
2237
+ <a name="fxtype-aliasestokenenhancedmd"></a>
2238
+
2239
+ # TokenEnhanced
2240
+
2241
+ ```ts
2242
+ type TokenEnhanced = Token & {
2243
+ depth?: number;
2244
+ error?: boolean;
2245
+ groupId?: string;
2246
+ index: number;
2247
+ };
2248
+ ```
2249
+
2250
+ A token with extra meta data.
2251
+
2252
+ ## Type Declaration
2253
+
2254
+ | Name | Type | Description |
2255
+ | ------ | ------ | ------ |
2256
+ | `depth?` | `number` | This token's level of nesting inside parentheses |
2257
+ | `error?` | `boolean` | Token is of unknown type or a paren without a match |
2258
+ | `groupId?` | `string` | The ID of a group which this token belongs (e.g. matching parens) |
2259
+ | `index` | `number` | A zero based position in a token list |
2260
+
2261
+
2262
+ <a name="fxtype-aliasesunaryexpressionmd"></a>
2263
+
2264
+ # UnaryExpression
2265
+
2266
+ ```ts
2267
+ type UnaryExpression = {
2268
+ arguments: AstExpression[];
2269
+ loc?: SourceLocation;
2270
+ operator: UnaryOperator;
2271
+ type: "UnaryExpression";
2272
+ } & Node;
2273
+ ```
2274
+
2275
+ A unary operator expression.
2276
+
2277
+ ## Type Declaration
2278
+
2279
+ | Name | Type | Description |
2280
+ | ------ | ------ | ------ |
2281
+ | `arguments` | [`AstExpression`](#fxtype-aliasesastexpressionmd)[] | The arguments for the operator. |
2282
+ | `loc?` | [`SourceLocation`](#fxtype-aliasessourcelocationmd) | The original source position of the node. |
2283
+ | `operator` | [`UnaryOperator`](#fxtype-aliasesunaryoperatormd) | The expression's operator. |
2284
+ | `type` | `"UnaryExpression"` | The type of this AST node. |
2285
+
2286
+
2287
+ <a name="fxtype-aliasesunaryoperatormd"></a>
2288
+
2289
+ # UnaryOperator
2290
+
2291
+ ```ts
2292
+ type UnaryOperator = "+" | "-" | "%" | "#" | "@";
2293
+ ```
2294
+
2295
+ A unary operator token.
2296
+
2297
+
2298
+ <a name="fxvariablesmax_colsmd"></a>
2299
+
2300
+ # MAX\_COLS
2301
+
2302
+ ```ts
2303
+ const MAX_COLS: number;
2304
+ ```
2305
+
2306
+ The maximum number of columns a spreadsheet reference may hold (16383).
2307
+
2308
+
2309
+ <a name="fxvariablesmax_rowsmd"></a>
2310
+
2311
+ # MAX\_ROWS
2312
+
2313
+ ```ts
2314
+ const MAX_ROWS: number;
2315
+ ```
2316
+
2317
+ The maximum number of rows a spreadsheet reference may hold (1048575).
2318
+
2319
+
2320
+ <a name="fxvariablesnodetypesmd"></a>
2321
+
2322
+ # nodeTypes
2323
+
2324
+ ```ts
2325
+ const nodeTypes: Readonly<{
2326
+ ARRAY: "ArrayExpression";
2327
+ BINARY: "BinaryExpression";
2328
+ CALL: "CallExpression";
2329
+ ERROR: "ErrorLiteral";
2330
+ IDENTIFIER: "Identifier";
2331
+ LAMBDA: "LambdaExpression";
2332
+ LET: "LetExpression";
2333
+ LET_DECL: "LetDeclarator";
2334
+ LITERAL: "Literal";
2335
+ REFERENCE: "ReferenceIdentifier";
2336
+ UNARY: "UnaryExpression";
2337
+ }>;
2338
+ ```
2339
+
2340
+ A dictionary of the types used to identify AST node variants.
2341
+
2342
+
2343
+ <a name="fxvariablestokentypesmd"></a>
2344
+
2345
+ # tokenTypes
2346
+
2347
+ ```ts
2348
+ const tokenTypes: Readonly<{
2349
+ BOOLEAN: "bool";
2350
+ CONTEXT: "context";
2351
+ CONTEXT_QUOTE: "context_quote";
2352
+ ERROR: "error";
2353
+ FUNCTION: "func";
2354
+ FX_PREFIX: "fx_prefix";
2355
+ NEWLINE: "newline";
2356
+ NUMBER: "number";
2357
+ OPERATOR: "operator";
2358
+ REF_BEAM: "range_beam";
2359
+ REF_NAMED: "range_named";
2360
+ REF_RANGE: "range";
2361
+ REF_STRUCT: "structured";
2362
+ REF_TERNARY: "range_ternary";
2363
+ STRING: "string";
2364
+ UNKNOWN: "unknown";
2365
+ WHITESPACE: "whitespace";
2366
+ }>;
2367
+ ```
2368
+
2369
+ A dictionary of the types used to identify token variants.
2370
+
2371
+
2372
+ <a name="fxxlsxreadmemd"></a>
2373
+
2374
+ # fx/xlsx
2375
+
2376
+ A tokenizer, parser, and other utilities to work with Excel formula code.
2377
+
2378
+ The xslx entry-point methods expect and return the variant of references that uses properties.
2379
+ If you are not using xlsx files you should use the [fx](#fxreadmemd) variant methods.
2380
+
2381
+ See [Prefixes.md](./Prefixes.md) for documentation on how scopes work in Fx.
2382
+
2383
+ ## Functions
2384
+
2385
+ - [addTokenMeta](#fxxlsxfunctionsaddtokenmetamd)
2386
+ - [fixFormulaRanges](#fxxlsxfunctionsfixformularangesmd)
2387
+ - [fixTokenRanges](#fxxlsxfunctionsfixtokenrangesmd)
2388
+ - [parseA1Ref](#fxxlsxfunctionsparsea1refmd)
2389
+ - [parseR1C1Ref](#fxxlsxfunctionsparser1c1refmd)
2390
+ - [parseStructRef](#fxxlsxfunctionsparsestructrefmd)
2391
+ - [stringifyA1Ref](#fxxlsxfunctionsstringifya1refmd)
2392
+ - [stringifyR1C1Ref](#fxxlsxfunctionsstringifyr1c1refmd)
2393
+ - [stringifyStructRef](#fxxlsxfunctionsstringifystructrefmd)
2394
+ - [tokenize](#fxxlsxfunctionstokenizemd)
2395
+
2396
+ ## References
2397
+
2398
+ ### addA1RangeBounds
2399
+
2400
+ Re-exports [addA1RangeBounds](#fxfunctionsadda1rangeboundsmd)
2401
+
2402
+ ***
2403
+
2404
+ ### ArrayExpression
2405
+
2406
+ Re-exports [ArrayExpression](#fxtype-aliasesarrayexpressionmd)
2407
+
2408
+ ***
2409
+
2410
+ ### AstExpression
2411
+
2412
+ Re-exports [AstExpression](#fxtype-aliasesastexpressionmd)
2413
+
2414
+ ***
2415
+
2416
+ ### BinaryExpression
2417
+
2418
+ Re-exports [BinaryExpression](#fxtype-aliasesbinaryexpressionmd)
2419
+
2420
+ ***
2421
+
2422
+ ### BinaryOperator
2423
+
2424
+ Re-exports [BinaryOperator](#fxtype-aliasesbinaryoperatormd)
2425
+
2426
+ ***
2427
+
2428
+ ### CallExpression
2429
+
2430
+ Re-exports [CallExpression](#fxtype-aliasescallexpressionmd)
2431
+
2432
+ ***
2433
+
2434
+ ### ErrorLiteral
2435
+
2436
+ Re-exports [ErrorLiteral](#fxtype-aliaseserrorliteralmd)
2437
+
2438
+ ***
2439
+
2440
+ ### fromCol
2441
+
2442
+ Re-exports [fromCol](#fxfunctionsfromcolmd)
2443
+
2444
+ ***
2445
+
2446
+ ### Identifier
2447
+
2448
+ Re-exports [Identifier](#fxtype-aliasesidentifiermd)
2449
+
2450
+ ***
2451
+
2452
+ ### isArrayNode
2453
+
2454
+ Re-exports [isArrayNode](#fxfunctionsisarraynodemd)
2455
+
2456
+ ***
2457
+
2458
+ ### isBinaryNode
2459
+
2460
+ Re-exports [isBinaryNode](#fxfunctionsisbinarynodemd)
2461
+
2462
+ ***
2463
+
2464
+ ### isCallNode
2465
+
2466
+ Re-exports [isCallNode](#fxfunctionsiscallnodemd)
2467
+
2468
+ ***
2469
+
2470
+ ### isError
2471
+
2472
+ Re-exports [isError](#fxfunctionsiserrormd)
2473
+
2474
+ ***
2475
+
2476
+ ### isErrorNode
2477
+
2478
+ Re-exports [isErrorNode](#fxfunctionsiserrornodemd)
2479
+
2480
+ ***
2481
+
2482
+ ### isExpressionNode
2483
+
2484
+ Re-exports [isExpressionNode](#fxfunctionsisexpressionnodemd)
2485
+
2486
+ ***
2487
+
2488
+ ### isFunction
2489
+
2490
+ Re-exports [isFunction](#fxfunctionsisfunctionmd)
2491
+
2492
+ ***
2493
+
2494
+ ### isFxPrefix
2495
+
2496
+ Re-exports [isFxPrefix](#fxfunctionsisfxprefixmd)
2497
+
2498
+ ***
2499
+
2500
+ ### isIdentifierNode
2501
+
2502
+ Re-exports [isIdentifierNode](#fxfunctionsisidentifiernodemd)
2503
+
2504
+ ***
2505
+
2506
+ ### isLambdaNode
2507
+
2508
+ Re-exports [isLambdaNode](#fxfunctionsislambdanodemd)
2509
+
2510
+ ***
2511
+
2512
+ ### isLetDeclaratorNode
2513
+
2514
+ Re-exports [isLetDeclaratorNode](#fxfunctionsisletdeclaratornodemd)
2515
+
2516
+ ***
2517
+
2518
+ ### isLetNode
2519
+
2520
+ Re-exports [isLetNode](#fxfunctionsisletnodemd)
2521
+
2522
+ ***
2523
+
2524
+ ### isLiteral
2525
+
2526
+ Re-exports [isLiteral](#fxfunctionsisliteralmd)
2527
+
2528
+ ***
2529
+
2530
+ ### isLiteralNode
2531
+
2532
+ Re-exports [isLiteralNode](#fxfunctionsisliteralnodemd)
2533
+
2534
+ ***
2535
+
2536
+ ### isOperator
2537
+
2538
+ Re-exports [isOperator](#fxfunctionsisoperatormd)
2539
+
2540
+ ***
2541
+
2542
+ ### isRange
2543
+
2544
+ Re-exports [isRange](#fxfunctionsisrangemd)
2545
+
2546
+ ***
2547
+
2548
+ ### isReference
2549
+
2550
+ Re-exports [isReference](#fxfunctionsisreferencemd)
2551
+
2552
+ ***
2553
+
2554
+ ### isReferenceNode
2555
+
2556
+ Re-exports [isReferenceNode](#fxfunctionsisreferencenodemd)
2557
+
2558
+ ***
2559
+
2560
+ ### isUnaryNode
2561
+
2562
+ Re-exports [isUnaryNode](#fxfunctionsisunarynodemd)
2563
+
2564
+ ***
2565
+
2566
+ ### isWhitespace
2567
+
2568
+ Re-exports [isWhitespace](#fxfunctionsiswhitespacemd)
2569
+
2570
+ ***
2571
+
2572
+ ### LambdaExpression
2573
+
2574
+ Re-exports [LambdaExpression](#fxtype-aliaseslambdaexpressionmd)
2575
+
2576
+ ***
2577
+
2578
+ ### LetDeclarator
2579
+
2580
+ Re-exports [LetDeclarator](#fxtype-aliasesletdeclaratormd)
2581
+
2582
+ ***
2583
+
2584
+ ### LetExpression
2585
+
2586
+ Re-exports [LetExpression](#fxtype-aliasesletexpressionmd)
2587
+
2588
+ ***
2589
+
2590
+ ### Literal
2591
+
2592
+ Re-exports [Literal](#fxtype-aliasesliteralmd)
2593
+
2594
+ ***
2595
+
2596
+ ### MAX\_COLS
2597
+
2598
+ Re-exports [MAX_COLS](#fxvariablesmax_colsmd)
2599
+
2600
+ ***
2601
+
2602
+ ### MAX\_ROWS
2603
+
2604
+ Re-exports [MAX_ROWS](#fxvariablesmax_rowsmd)
2605
+
2606
+ ***
2607
+
2608
+ ### mergeRefTokens
2609
+
2610
+ Re-exports [mergeRefTokens](#fxfunctionsmergereftokensmd)
2611
+
2612
+ ***
2613
+
2614
+ ### Node
2615
+
2616
+ Re-exports [Node](#fxtype-aliasesnodemd)
2617
+
2618
+ ***
2619
+
2620
+ ### nodeTypes
2621
+
2622
+ Re-exports [nodeTypes](#fxvariablesnodetypesmd)
2623
+
2624
+ ***
2625
+
2626
+ ### OptsFixRanges
2627
+
2628
+ Re-exports [OptsFixRanges](#fxtype-aliasesoptsfixrangesmd)
2629
+
2630
+ ***
2631
+
2632
+ ### OptsParse
2633
+
2634
+ Re-exports [OptsParse](#fxtype-aliasesoptsparsemd)
2635
+
2636
+ ***
2637
+
2638
+ ### OptsParseA1Ref
2639
+
2640
+ Re-exports [OptsParseA1Ref](#fxtype-aliasesoptsparsea1refmd)
2641
+
2642
+ ***
2643
+
2644
+ ### OptsParseR1C1Ref
2645
+
2646
+ Re-exports [OptsParseR1C1Ref](#fxtype-aliasesoptsparser1c1refmd)
2647
+
2648
+ ***
2649
+
2650
+ ### OptsStringifyStructRef
2651
+
2652
+ Re-exports [OptsStringifyStructRef](#fxtype-aliasesoptsstringifystructrefmd)
2653
+
2654
+ ***
2655
+
2656
+ ### OptsTokenize
2657
+
2658
+ Re-exports [OptsTokenize](#fxtype-aliasesoptstokenizemd)
2659
+
2660
+ ***
2661
+
2662
+ ### OptsTranslateFormulaToA1
2663
+
2664
+ Re-exports [OptsTranslateFormulaToA1](#fxtype-aliasesoptstranslateformulatoa1md)
2665
+
2666
+ ***
2667
+
2668
+ ### OptsTranslateTokensToA1
2669
+
2670
+ Re-exports [OptsTranslateTokensToA1](#fxtype-aliasesoptstranslatetokenstoa1md)
2671
+
2672
+ ***
2673
+
2674
+ ### OptsTranslateToR1C1
2675
+
2676
+ Re-exports [OptsTranslateToR1C1](#fxtype-aliasesoptstranslatetor1c1md)
2677
+
2678
+ ***
2679
+
2680
+ ### parse
2681
+
2682
+ Re-exports [parse](#fxfunctionsparsemd)
2683
+
2684
+ ***
2685
+
2686
+ ### parseA1Range
2687
+
2688
+ Re-exports [parseA1Range](#fxfunctionsparsea1rangemd)
2689
+
2690
+ ***
2691
+
2692
+ ### parseR1C1Range
2693
+
2694
+ Re-exports [parseR1C1Range](#fxfunctionsparser1c1rangemd)
2695
+
2696
+ ***
2697
+
2698
+ ### RangeA1
2699
+
2700
+ Re-exports [RangeA1](#fxtype-aliasesrangea1md)
2701
+
2702
+ ***
2703
+
2704
+ ### RangeR1C1
2705
+
2706
+ Re-exports [RangeR1C1](#fxtype-aliasesranger1c1md)
2707
+
2708
+ ***
2709
+
2710
+ ### ReferenceA1
2711
+
2712
+ Re-exports [ReferenceA1](#fxtype-aliasesreferencea1md)
2713
+
2714
+ ***
2715
+
2716
+ ### ReferenceA1Xlsx
2717
+
2718
+ Re-exports [ReferenceA1Xlsx](#fxtype-aliasesreferencea1xlsxmd)
2719
+
2720
+ ***
2721
+
2722
+ ### ReferenceIdentifier
2723
+
2724
+ Re-exports [ReferenceIdentifier](#fxtype-aliasesreferenceidentifiermd)
2725
+
2726
+ ***
2727
+
2728
+ ### ReferenceName
2729
+
2730
+ Re-exports [ReferenceName](#fxtype-aliasesreferencenamemd)
2731
+
2732
+ ***
2733
+
2734
+ ### ReferenceNameXlsx
2735
+
2736
+ Re-exports [ReferenceNameXlsx](#fxtype-aliasesreferencenamexlsxmd)
2737
+
2738
+ ***
2739
+
2740
+ ### ReferenceR1C1
2741
+
2742
+ Re-exports [ReferenceR1C1](#fxtype-aliasesreferencer1c1md)
2743
+
2744
+ ***
2745
+
2746
+ ### ReferenceR1C1Xlsx
2747
+
2748
+ Re-exports [ReferenceR1C1Xlsx](#fxtype-aliasesreferencer1c1xlsxmd)
2749
+
2750
+ ***
2751
+
2752
+ ### ReferenceStruct
2753
+
2754
+ Re-exports [ReferenceStruct](#fxtype-aliasesreferencestructmd)
2755
+
2756
+ ***
2757
+
2758
+ ### ReferenceStructXlsx
2759
+
2760
+ Re-exports [ReferenceStructXlsx](#fxtype-aliasesreferencestructxlsxmd)
2761
+
2762
+ ***
2763
+
2764
+ ### SourceLocation
2765
+
2766
+ Re-exports [SourceLocation](#fxtype-aliasessourcelocationmd)
2767
+
2768
+ ***
2769
+
2770
+ ### stringifyTokens
2771
+
2772
+ Re-exports [stringifyTokens](#fxfunctionsstringifytokensmd)
2773
+
2774
+ ***
2775
+
2776
+ ### toCol
2777
+
2778
+ Re-exports [toCol](#fxfunctionstocolmd)
2779
+
2780
+ ***
2781
+
2782
+ ### Token
2783
+
2784
+ Re-exports [Token](#fxtype-aliasestokenmd)
2785
+
2786
+ ***
2787
+
2788
+ ### TokenEnhanced
2789
+
2790
+ Re-exports [TokenEnhanced](#fxtype-aliasestokenenhancedmd)
2791
+
2792
+ ***
2793
+
2794
+ ### tokenTypes
2795
+
2796
+ Re-exports [tokenTypes](#fxvariablestokentypesmd)
2797
+
2798
+ ***
2799
+
2800
+ ### translateFormulaToA1
2801
+
2802
+ Re-exports [translateFormulaToA1](#fxfunctionstranslateformulatoa1md)
2803
+
2804
+ ***
2805
+
2806
+ ### translateFormulaToR1C1
2807
+
2808
+ Re-exports [translateFormulaToR1C1](#fxfunctionstranslateformulator1c1md)
2809
+
2810
+ ***
2811
+
2812
+ ### translateTokensToA1
2813
+
2814
+ Re-exports [translateTokensToA1](#fxfunctionstranslatetokenstoa1md)
2815
+
2816
+ ***
2817
+
2818
+ ### translateTokensToR1C1
2819
+
2820
+ Re-exports [translateTokensToR1C1](#fxfunctionstranslatetokenstor1c1md)
2821
+
2822
+ ***
2823
+
2824
+ ### UnaryExpression
2825
+
2826
+ Re-exports [UnaryExpression](#fxtype-aliasesunaryexpressionmd)
2827
+
2828
+ ***
2829
+
2830
+ ### UnaryOperator
2831
+
2832
+ Re-exports [UnaryOperator](#fxtype-aliasesunaryoperatormd)
2833
+
2834
+
2835
+ <a name="fxxlsxfunctionsaddtokenmetamd"></a>
2836
+
2837
+ # addTokenMeta()
2838
+
2839
+ ```ts
2840
+ function addTokenMeta(tokenlist: Token[], context?: {
2841
+ sheetName?: string;
2842
+ workbookName?: string;
2843
+ }): TokenEnhanced[];
2844
+ ```
2845
+
2846
+ Runs through a list of tokens and adds extra attributes such as matching
2847
+ parens and ranges.
2848
+
2849
+ The `context` parameter defines default reference attributes:
2850
+ `{ workbookName: 'report.xlsx', sheetName: 'Sheet1' }`.
2851
+ If supplied, these are used to match `A1` to `Sheet1!A1`.
2852
+
2853
+ All tokens will be tagged with a `.depth` number value to indicating the
2854
+ level of nesting in parentheses as well as an `.index` number indicating
2855
+ their zero based position in the list.
2856
+
2857
+ The returned output will be the same array of tokens but the following
2858
+ properties will added to tokens (as applicable):
2859
+
2860
+ #### Parentheses ( )
2861
+
2862
+ Matching parens will be tagged with `.groupId` string identifier as well as
2863
+ a `.depth` number value (indicating the level of nesting).
2864
+
2865
+ Closing parens without a counterpart will be tagged with `.error`
2866
+ (boolean true).
2867
+
2868
+ #### Curly brackets { }
2869
+
2870
+ Matching curly brackets will be tagged with `.groupId` string identifier.
2871
+ These may not be nested in Excel.
2872
+
2873
+ Closing curly brackets without a counterpart will be tagged with `.error`
2874
+ (boolean `true`).
2875
+
2876
+ #### Ranges (`REF_RANGE` or `REF_BEAM` type tokens)
2877
+
2878
+ All ranges will be tagged with `.groupId` string identifier regardless of
2879
+ the number of times they occur.
2880
+
2881
+ #### Tokens of type `UNKNOWN`
2882
+
2883
+ All will be tagged with `.error` (boolean `true`).
2884
+
2885
+ ## Parameters
2886
+
2887
+ | Parameter | Type | Description |
2888
+ | ------ | ------ | ------ |
2889
+ | `tokenlist` | [`Token`](#fxtype-aliasestokenmd)[] | An array of tokens (from `tokenize()`) |
2890
+ | `context?` | \{ `sheetName?`: `string`; `workbookName?`: `string`; \} | A contest used to match `A1` to `Sheet1!A1`. |
2891
+ | `context.sheetName?` | `string` | An implied sheet name ('Sheet1') |
2892
+ | `context.workbookName?` | `string` | An implied workbook name ('report.xlsx') |
2893
+
2894
+ ## Returns
2895
+
2896
+ [`TokenEnhanced`](#fxtype-aliasestokenenhancedmd)[]
2897
+
2898
+ The input array with the enchanced tokens
2899
+
2900
+
2901
+ <a name="fxxlsxfunctionsfixformularangesmd"></a>
2902
+
2903
+ # fixFormulaRanges()
2904
+
2905
+ ```ts
2906
+ function fixFormulaRanges(formula: string, options?: OptsFixRanges & OptsTokenize): string;
2907
+ ```
2908
+
2909
+ Normalizes A1 style ranges and structured references in a formula.
2910
+
2911
+ Internally it uses [fixTokenRanges](#fxfunctionsfixtokenrangesmd) so see it's documentation for details.
2912
+
2913
+ Returns the same formula with the ranges updated. If an array of tokens was
2914
+ supplied, then a new array is returned.
2915
+
2916
+ ## Parameters
2917
+
2918
+ | Parameter | Type | Description |
2919
+ | ------ | ------ | ------ |
2920
+ | `formula` | `string` | A string (an Excel formula) or a token list that should be adjusted. |
2921
+ | `options?` | [`OptsFixRanges`](#fxtype-aliasesoptsfixrangesmd) & [`OptsTokenize`](#fxtype-aliasesoptstokenizemd) | Options |
2922
+
2923
+ ## Returns
2924
+
2925
+ `string`
2926
+
2927
+ A formula string with ranges adjusted
2928
+
2929
+ ## See
2930
+
2931
+ [OptsFixRanges](#fxtype-aliasesoptsfixrangesmd) & [OptsTokenize](#fxtype-aliasesoptstokenizemd)
2932
+
2933
+
2934
+ <a name="fxxlsxfunctionsfixtokenrangesmd"></a>
2935
+
2936
+ # fixTokenRanges()
2937
+
2938
+ ```ts
2939
+ function fixTokenRanges(tokens: Token[], options?: OptsFixRanges): Token[];
2940
+ ```
2941
+
2942
+ Normalizes A1 style ranges and structured references in a list of tokens.
2943
+
2944
+ It ensures that that the top and left coordinates of an A1 range are on the
2945
+ left-hand side of a colon operator:
2946
+
2947
+ ```
2948
+ B2:A1 → A1:B2
2949
+ 1:A1 → A1:1
2950
+ A:A1 → A1:A
2951
+ B:A → A:B
2952
+ 2:1 → 1:2
2953
+ A1:A1 → A1
2954
+ ```
2955
+
2956
+ When `{ addBounds }` option is set to true, the missing bounds are also added.
2957
+ This can be done to ensure Excel compatible ranges. The fixes then additionally include:
2958
+
2959
+ ```
2960
+ 1:A1 → A1:1 → 1:1
2961
+ A:A1 → A1:A → A:A
2962
+ A1:A → A:A
2963
+ A1:1 → A:1
2964
+ B2:B → B2:1048576
2965
+ B2:2 → B2:XFD2
2966
+ ```
2967
+
2968
+ Structured ranges are normalized to have consistent order and capitalization
2969
+ of sections as well as removing redundant ones.
2970
+
2971
+ Returns a new array of tokens with values and position data updated.
2972
+
2973
+ ## Parameters
2974
+
2975
+ | Parameter | Type | Description |
2976
+ | ------ | ------ | ------ |
2977
+ | `tokens` | [`Token`](#fxtype-aliasestokenmd)[] | A list of tokens to be adjusted. |
2978
+ | `options?` | [`OptsFixRanges`](#fxtype-aliasesoptsfixrangesmd) | Options. |
2979
+
2980
+ ## Returns
2981
+
2982
+ [`Token`](#fxtype-aliasestokenmd)[]
2983
+
2984
+ A token list with ranges adjusted.
2985
+
2986
+ ## See
2987
+
2988
+ [OptsFixRanges](#fxtype-aliasesoptsfixrangesmd)
2989
+
2990
+
2991
+ <a name="fxxlsxfunctionsparsea1refmd"></a>
2992
+
2993
+ # parseA1Ref()
2994
+
2995
+ ```ts
2996
+ function parseA1Ref(refString: string, options: OptsParseA1Ref):
2997
+ | ReferenceA1Xlsx
2998
+ | ReferenceNameXlsx;
2999
+ ```
3000
+
3001
+ Parse a string reference into an object representing it.
3002
+
3003
+ ```js
3004
+ parseA1Ref('Sheet1!A$1:$B2');
3005
+ // => {
3006
+ // workbookName: '',
3007
+ // sheetName: 'Sheet1',
3008
+ // range: {
3009
+ // top: 0,
3010
+ // left: 0,
3011
+ // bottom: 1,
3012
+ // right: 1
3013
+ // $top: true,
3014
+ // $left: false,
3015
+ // $bottom: false,
3016
+ // $right: true
3017
+ // }
3018
+ // }
3019
+ ```
3020
+
3021
+ For A:A or A1:A style ranges, `null` will be used for any dimensions that the
3022
+ syntax does not specify.
3023
+
3024
+ ## Parameters
3025
+
3026
+ | Parameter | Type | Description |
3027
+ | ------ | ------ | ------ |
3028
+ | `refString` | `string` | An A1-style reference string. |
3029
+ | `options` | [`OptsParseA1Ref`](#fxtype-aliasesoptsparsea1refmd) | Options. |
3030
+
3031
+ ## Returns
3032
+
3033
+ \| [`ReferenceA1Xlsx`](#fxtype-aliasesreferencea1xlsxmd)
3034
+ \| [`ReferenceNameXlsx`](#fxtype-aliasesreferencenamexlsxmd)
3035
+
3036
+ An object representing a valid reference or `undefined` if it is invalid.
3037
+
3038
+ ## See
3039
+
3040
+ [OptsParseA1Ref](#fxtype-aliasesoptsparsea1refmd)
3041
+
3042
+
3043
+ <a name="fxxlsxfunctionsparser1c1refmd"></a>
3044
+
3045
+ # parseR1C1Ref()
3046
+
3047
+ ```ts
3048
+ function parseR1C1Ref(refString: string, options?: OptsParseR1C1Ref):
3049
+ | ReferenceNameXlsx
3050
+ | ReferenceR1C1Xlsx;
3051
+ ```
3052
+
3053
+ Parse a string reference into an object representing it.
3054
+
3055
+ ```js
3056
+ parseR1C1Ref('Sheet1!R[9]C9:R[9]C9');
3057
+ // => {
3058
+ // context: [ 'Sheet1' ],
3059
+ // range: {
3060
+ // r0: 9,
3061
+ // c0: 8,
3062
+ // r1: 9,
3063
+ // c1: 8,
3064
+ // $c0: true,
3065
+ // $c1: true
3066
+ // $r0: false,
3067
+ // $r1: false
3068
+ // }
3069
+ // }
3070
+ ```
3071
+
3072
+ ## Parameters
3073
+
3074
+ | Parameter | Type | Description |
3075
+ | ------ | ------ | ------ |
3076
+ | `refString` | `string` | An R1C1-style reference string. |
3077
+ | `options?` | [`OptsParseR1C1Ref`](#fxtype-aliasesoptsparser1c1refmd) | Options. |
3078
+
3079
+ ## Returns
3080
+
3081
+ \| [`ReferenceNameXlsx`](#fxtype-aliasesreferencenamexlsxmd)
3082
+ \| [`ReferenceR1C1Xlsx`](#fxtype-aliasesreferencer1c1xlsxmd)
3083
+
3084
+ An object representing a valid reference or `undefined` if it is invalid.
3085
+
3086
+ ## See
3087
+
3088
+ [OptsParseR1C1Ref](#fxtype-aliasesoptsparser1c1refmd)
3089
+
3090
+
3091
+ <a name="fxxlsxfunctionsparsestructrefmd"></a>
3092
+
3093
+ # parseStructRef()
3094
+
3095
+ ```ts
3096
+ function parseStructRef(ref: string): ReferenceStructXlsx;
3097
+ ```
3098
+
3099
+ Parse a structured reference string into an object representing it.
3100
+
3101
+ ```js
3102
+ parseStructRef('[workbook.xlsx]!tableName[[#Data],[Column1]:[Column2]]');
3103
+ // => {
3104
+ // workbookName: 'workbook.xlsx',
3105
+ // sections: [ 'data' ],
3106
+ // columns: [ 'my column', '@foo' ],
3107
+ // table: 'tableName',
3108
+ // }
3109
+ ```
3110
+
3111
+ For A:A or A1:A style ranges, `null` will be used for any dimensions that the
3112
+ syntax does not specify:
3113
+
3114
+ See [References.md](./References.md).
3115
+
3116
+ ## Parameters
3117
+
3118
+ | Parameter | Type | Description |
3119
+ | ------ | ------ | ------ |
3120
+ | `ref` | `string` | A structured reference string |
3121
+
3122
+ ## Returns
3123
+
3124
+ [`ReferenceStructXlsx`](#fxtype-aliasesreferencestructxlsxmd)
3125
+
3126
+ An object representing a valid reference or null if it is invalid.
3127
+
3128
+
3129
+ <a name="fxxlsxfunctionsstringifya1refmd"></a>
3130
+
3131
+ # stringifyA1Ref()
3132
+
3133
+ ```ts
3134
+ function stringifyA1Ref(refObject:
3135
+ | ReferenceA1Xlsx
3136
+ | ReferenceNameXlsx): string;
3137
+ ```
3138
+
3139
+ Get an A1-style string representation of a reference object.
3140
+
3141
+ ```js
3142
+ stringifyA1Ref({
3143
+ sheetName: 'Sheet1',
3144
+ range: {
3145
+ top: 0,
3146
+ left: 0,
3147
+ bottom: 1,
3148
+ right: 1,
3149
+ $top: true,
3150
+ $left: false,
3151
+ $bottom: false,
3152
+ $right: true
3153
+ }
3154
+ });
3155
+ // => 'Sheet1!A$1:$B2'
3156
+ ```
3157
+
3158
+ ## Parameters
3159
+
3160
+ | Parameter | Type | Description |
3161
+ | ------ | ------ | ------ |
3162
+ | `refObject` | \| [`ReferenceA1Xlsx`](#fxtype-aliasesreferencea1xlsxmd) \| [`ReferenceNameXlsx`](#fxtype-aliasesreferencenamexlsxmd) | A reference object. |
3163
+
3164
+ ## Returns
3165
+
3166
+ `string`
3167
+
3168
+ The reference in A1-style string format.
3169
+
3170
+
3171
+ <a name="fxxlsxfunctionsstringifyr1c1refmd"></a>
3172
+
3173
+ # stringifyR1C1Ref()
3174
+
3175
+ ```ts
3176
+ function stringifyR1C1Ref(refObject:
3177
+ | ReferenceNameXlsx
3178
+ | ReferenceR1C1Xlsx): string;
3179
+ ```
3180
+
3181
+ Get an R1C1-style string representation of a reference object.
3182
+
3183
+ ```js
3184
+ stringifyR1C1Ref({
3185
+ sheetName: 'Sheet1',
3186
+ range: {
3187
+ r0: 9,
3188
+ c0: 8,
3189
+ r1: 9,
3190
+ c1: 8,
3191
+ $c0: true,
3192
+ $c1: true
3193
+ $r0: false,
3194
+ $r1: false
3195
+ }
3196
+ });
3197
+ // => 'Sheet1!R[9]C9:R[9]C9'
3198
+ ```
3199
+
3200
+ ## Parameters
3201
+
3202
+ | Parameter | Type | Description |
3203
+ | ------ | ------ | ------ |
3204
+ | `refObject` | \| [`ReferenceNameXlsx`](#fxtype-aliasesreferencenamexlsxmd) \| [`ReferenceR1C1Xlsx`](#fxtype-aliasesreferencer1c1xlsxmd) | A reference object. |
3205
+
3206
+ ## Returns
3207
+
3208
+ `string`
3209
+
3210
+ The reference in R1C1-style string format.
3211
+
3212
+
3213
+ <a name="fxxlsxfunctionsstringifystructrefmd"></a>
3214
+
3215
+ # stringifyStructRef()
3216
+
3217
+ ```ts
3218
+ function stringifyStructRef(refObject: ReferenceStructXlsx, options?: OptsStringifyStructRef): string;
3219
+ ```
3220
+
3221
+ Returns a string representation of a structured reference object.
3222
+
3223
+ ```js
3224
+ stringifyStructRef({
3225
+ workbookName: 'workbook.xlsx',
3226
+ sheetName: '',
3227
+ sections: [ 'data' ],
3228
+ columns: [ 'my column', '@foo' ],
3229
+ table: 'tableName',
3230
+ });
3231
+ // => 'workbook.xlsx!tableName[[#Data],[Column1]:[Column2]]'
3232
+ ```
3233
+
3234
+ ## Parameters
3235
+
3236
+ | Parameter | Type | Description |
3237
+ | ------ | ------ | ------ |
3238
+ | `refObject` | [`ReferenceStructXlsx`](#fxtype-aliasesreferencestructxlsxmd) | A structured reference object. |
3239
+ | `options?` | [`OptsStringifyStructRef`](#fxtype-aliasesoptsstringifystructrefmd) | Options. |
3240
+
3241
+ ## Returns
3242
+
3243
+ `string`
3244
+
3245
+ The given structured reference in string format.
3246
+
3247
+
3248
+ <a name="fxxlsxfunctionstokenizemd"></a>
3249
+
3250
+ # tokenize()
3251
+
3252
+ ```ts
3253
+ function tokenize(formula: string, options?: OptsTokenize): Token[];
3254
+ ```
3255
+
3256
+ Breaks a string formula into a list of tokens.
3257
+
3258
+ The returned output will be an array of objects representing the tokens:
3259
+
3260
+ ```js
3261
+ [
3262
+ { type: FX_PREFIX, value: '=' },
3263
+ { type: FUNCTION, value: 'SUM' },
3264
+ { type: OPERATOR, value: '(' },
3265
+ { type: REF_RANGE, value: 'A1:B2' },
3266
+ { type: OPERATOR, value: ')' }
3267
+ ]
3268
+ ```
3269
+
3270
+ A collection of token types may be found as an object as the [tokenTypes](#fxvariablestokentypesmd)
3271
+ export on the package.
3272
+
3273
+ _Warning:_ To support syntax highlighting as you type, `STRING` tokens are allowed to be
3274
+ "unterminated". For example, the incomplete formula `="Hello world` would be
3275
+ tokenized as:
3276
+
3277
+ ```js
3278
+ [
3279
+ { type: FX_PREFIX, value: '=' },
3280
+ { type: STRING, value: '"Hello world', unterminated: true },
3281
+ ]
3282
+ ```
1043
3283
 
1044
- ---
3284
+ ## Parameters
1045
3285
 
1046
- ### <a id="UnaryExpression" href="#UnaryExpression">#</a> UnaryExpression = `Node`
3286
+ | Parameter | Type | Description |
3287
+ | ------ | ------ | ------ |
3288
+ | `formula` | `string` | An Excel formula string (an Excel expression). |
3289
+ | `options?` | [`OptsTokenize`](#fxtype-aliasesoptstokenizemd) | Options |
1047
3290
 
1048
- ##### Properties
3291
+ ## Returns
1049
3292
 
1050
- | Name | Type |
1051
- | --------- | ----------------------------------------- |
1052
- | arguments | `Array<AstExpression>` |
1053
- | [loc] | [`SourceLocation`](#SourceLocation) |
1054
- | operator | `"+"` \| `"-"` \| `"%"` \| `"#"` \| `"@"` |
1055
- | type | `"UnaryExpression"` |
3293
+ [`Token`](#fxtype-aliasestokenmd)[]
1056
3294
 
1057
- ---
3295
+ An array of Tokens
1058
3296
 
3297
+ ## See
1059
3298
 
3299
+ - [OptsTokenize](#fxtype-aliasesoptstokenizemd)
3300
+ - [tokenTypes](#fxvariablestokentypesmd)