@borgar/fx 4.5.0 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "parser": "@babel/eslint-parser",
3
- "extends": [ "@borgar/eslint-config" ],
3
+ "extends": [ "@borgar/eslint-config", "@borgar/eslint-config/jsdoc" ],
4
4
  "env": {
5
5
  "es6": true,
6
6
  "node": true,
@@ -11,19 +11,10 @@
11
11
  "requireConfigFile": false,
12
12
  },
13
13
  "rules": {
14
- "max-len": [ "error", {
15
- "code": 120,
16
- "comments": 80,
17
- "tabWidth": 2,
18
- "ignoreUrls": true,
19
- "ignoreStrings": true,
20
- "ignoreTemplateLiterals": true,
21
- "ignoreRegExpLiterals": true,
22
- "ignorePattern": "^\\s*\\*\\s*@(param|return|property)\\s"
23
- } ],
24
14
  "no-trailing-spaces": [ "error", {
25
15
  "ignoreComments": true
26
- } ]
16
+ } ],
17
+ "jsdoc/no-undefined-types": "off"
27
18
  },
28
19
  "globals": {
29
20
  "Promise"
package/dist/fx.d.ts CHANGED
@@ -31,7 +31,7 @@
31
31
  * @param range The range part of a reference object.
32
32
  * @returns same range with missing bounds filled in.
33
33
  */
34
- export declare function addA1RangeBounds(range: object): object;
34
+ export declare function addA1RangeBounds(range: RangeA1): RangeA1;
35
35
 
36
36
  /**
37
37
  * Runs through a list of tokens and adds extra attributes such as matching
@@ -66,12 +66,12 @@ export declare function addA1RangeBounds(range: object): object;
66
66
  * @param [context.workbookName=''] An implied workbook name ('report.xlsx')
67
67
  * @returns The input array with the enchanced tokens
68
68
  */
69
- export declare function addTokenMeta(tokenlist: Array<object>, context?: {
69
+ export declare function addTokenMeta(tokenlist: Array<Token>, context?: {
70
70
  /** An implied sheet name ('Sheet1') */
71
71
  sheetName?: string;
72
72
  /** An implied workbook name ('report.xlsx') */
73
73
  workbookName?: string;
74
- }): Array<object>;
74
+ }): Array<TokenEnhanced>;
75
75
 
76
76
  /**
77
77
  * Normalizes A1 style ranges and structured references in a formula or list of
@@ -104,21 +104,21 @@ export declare function addTokenMeta(tokenlist: Array<object>, context?: {
104
104
  * @param [options.xlsx=false] Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md)
105
105
  * @returns A formula string or token list (depending on which was input)
106
106
  */
107
- export declare function fixRanges(formula: (string | Array<object>), options?: {
107
+ export declare function fixRanges(formula: (string | Array<Token>), options?: {
108
108
  /** Fill in any undefined bounds of range objects. Top to 0, bottom to 1048575, left to 0, and right to 16383. */
109
109
  addBounds?: boolean;
110
110
  /** Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) */
111
111
  xlsx?: boolean;
112
- }): (string | Array<object>);
112
+ }): (string | Array<Token>);
113
113
 
114
114
  /**
115
115
  * Parse a simple string reference to an A1 range into a range object.
116
116
  * Will accept `A1`, `A2`, `A:A`, or `1:1`.
117
117
  *
118
118
  * @param rangeString A range string
119
- * @returns An object representing a valid reference or null if it is invalid.
119
+ * @returns An object representing a valid range or null if it is invalid.
120
120
  */
121
- declare function fromA1(rangeString: string): (object | null);
121
+ declare function fromA1(rangeString: string): (RangeA1 | null);
122
122
 
123
123
  /**
124
124
  * Convert a column string representation to a 0 based
@@ -138,7 +138,7 @@ export declare function fromCol(columnString: string): number;
138
138
  * @param rangeString A range string
139
139
  * @returns An object representing a valid reference or null if it is invalid.
140
140
  */
141
- declare function fromR1C1(rangeString: string): (object | null);
141
+ declare function fromR1C1(rangeString: string): (RangeR1C1 | null);
142
142
 
143
143
  /**
144
144
  * Determines whether the specified token is an error.
@@ -148,7 +148,7 @@ declare function fromR1C1(rangeString: string): (object | null);
148
148
  * @param token The token
149
149
  * @returns True if the specified token is error, False otherwise.
150
150
  */
151
- export declare function isError(token: object): boolean;
151
+ export declare function isError(token: any): boolean;
152
152
 
153
153
  /**
154
154
  * Determines whether the specified token is a function.
@@ -158,7 +158,7 @@ export declare function isError(token: object): boolean;
158
158
  * @param token The token
159
159
  * @returns True if the specified token is function, False otherwise.
160
160
  */
161
- export declare function isFunction(token: object): boolean;
161
+ export declare function isFunction(token: any): boolean;
162
162
 
163
163
  /**
164
164
  * Returns `true` if the input is a token of type FX_PREFIX (leading `=` in
@@ -167,7 +167,7 @@ export declare function isFunction(token: object): boolean;
167
167
  * @param token The token
168
168
  * @returns True if the specified token is effects prefix, False otherwise.
169
169
  */
170
- export declare function isFxPrefix(token: object): boolean;
170
+ export declare function isFxPrefix(token: any): boolean;
171
171
 
172
172
  /**
173
173
  * Determines whether the specified token is a literal.
@@ -178,7 +178,7 @@ export declare function isFxPrefix(token: object): boolean;
178
178
  * @param token The token
179
179
  * @returns True if the specified token is literal, False otherwise.
180
180
  */
181
- export declare function isLiteral(token: object): boolean;
181
+ export declare function isLiteral(token: any): boolean;
182
182
 
183
183
  /**
184
184
  * Determines whether the specified token is an operator.
@@ -188,7 +188,7 @@ export declare function isLiteral(token: object): boolean;
188
188
  * @param token The token
189
189
  * @returns True if the specified token is operator, False otherwise.
190
190
  */
191
- export declare function isOperator(token: object): boolean;
191
+ export declare function isOperator(token: any): boolean;
192
192
 
193
193
  /**
194
194
  * Determines whether the specified token is a range.
@@ -199,7 +199,7 @@ export declare function isOperator(token: object): boolean;
199
199
  * @param token A token
200
200
  * @returns True if the specified token is range, False otherwise.
201
201
  */
202
- export declare function isRange(token: object): boolean;
202
+ export declare function isRange(token: any): boolean;
203
203
 
204
204
  /**
205
205
  * Determines whether the specified token is a reference.
@@ -210,7 +210,7 @@ export declare function isRange(token: object): boolean;
210
210
  * @param token The token
211
211
  * @returns True if the specified token is reference, False otherwise.
212
212
  */
213
- export declare function isReference(token: object): boolean;
213
+ export declare function isReference(token: any): boolean;
214
214
 
215
215
  /**
216
216
  * Determines whether the specified token is whitespace.
@@ -220,7 +220,7 @@ export declare function isReference(token: object): boolean;
220
220
  * @param token The token
221
221
  * @returns True if the specified token is whitespace, False otherwise.
222
222
  */
223
- export declare function isWhitespace(token: object): boolean;
223
+ export declare function isWhitespace(token: any): boolean;
224
224
 
225
225
  /**
226
226
  * Merges context with reference tokens as possible in a list of tokens.
@@ -231,7 +231,7 @@ export declare function isWhitespace(token: object): boolean;
231
231
  * @param tokenlist An array of tokens (from `tokenize()`)
232
232
  * @returns A new list of tokens with range parts merged.
233
233
  */
234
- export declare function mergeRefTokens(tokenlist: Array<object>): Array<any>;
234
+ export declare function mergeRefTokens(tokenlist: Array<Token>): Array<Token>;
235
235
 
236
236
  /**
237
237
  * Parses a string formula or list of tokens into an AST.
@@ -252,7 +252,7 @@ export declare function mergeRefTokens(tokenlist: Array<object>): Array<any>;
252
252
  * @param [options.xlsx=false] Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md)
253
253
  * @returns An AST of nodes
254
254
  */
255
- export declare function parse(formula: (string | Array<object>), options?: {
255
+ export declare function parse(formula: (string | Array<Token>), options?: {
256
256
  /** Enable parsing names as well as ranges. */
257
257
  allowNamed?: boolean;
258
258
  /** Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`. These are supported by Google Sheets but not Excel. See: References.md. */
@@ -306,7 +306,7 @@ export declare function parseA1Ref(refString: string, options?: {
306
306
  allowTernary?: boolean;
307
307
  /** Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) */
308
308
  xlsx?: boolean;
309
- }): (object | null);
309
+ }): (ReferenceA1 | null);
310
310
 
311
311
  /**
312
312
  * Parse a string reference into an object representing it.
@@ -341,7 +341,7 @@ export declare function parseR1C1Ref(refString: string, options?: {
341
341
  allowTernary?: boolean;
342
342
  /** Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) */
343
343
  xlsx?: boolean;
344
- }): (object | null);
344
+ }): (ReferenceR1C1 | null);
345
345
 
346
346
  /**
347
347
  * Parse a structured reference string into an object representing it.
@@ -365,7 +365,7 @@ export declare function parseR1C1Ref(refString: string, options?: {
365
365
  export declare function parseStructRef(ref: string, options?: {
366
366
  /** Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) */
367
367
  xlsx?: boolean;
368
- }): (object | null);
368
+ }): (ReferenceStruct | null);
369
369
 
370
370
  /**
371
371
  * Get an A1-style string representation of a reference object.
@@ -391,10 +391,10 @@ export declare function parseStructRef(ref: string, options?: {
391
391
  * @param [options.xlsx=false] Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md)
392
392
  * @returns The reference in A1-style string format
393
393
  */
394
- export declare function stringifyA1Ref(refObject: object, options?: {
394
+ export declare function stringifyA1Ref(refObject: ReferenceA1, options?: {
395
395
  /** Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) */
396
396
  xlsx?: boolean;
397
- }): object;
397
+ }): string;
398
398
 
399
399
  /**
400
400
  * Get an R1C1-style string representation of a reference object.
@@ -420,10 +420,10 @@ export declare function stringifyA1Ref(refObject: object, options?: {
420
420
  * @param [options.xlsx=false] Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md)
421
421
  * @returns The reference in R1C1-style string format
422
422
  */
423
- export declare function stringifyR1C1Ref(refObject: object, options?: {
423
+ export declare function stringifyR1C1Ref(refObject: ReferenceR1C1, options?: {
424
424
  /** Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) */
425
425
  xlsx?: boolean;
426
- }): object;
426
+ }): string;
427
427
 
428
428
  /**
429
429
  * Get a string representation of a structured reference object.
@@ -442,10 +442,10 @@ export declare function stringifyR1C1Ref(refObject: object, options?: {
442
442
  * @param [options.xlsx=false] Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md)
443
443
  * @returns The structured reference in string format
444
444
  */
445
- export declare function stringifyStructRef(refObject: object, options?: {
445
+ export declare function stringifyStructRef(refObject: ReferenceStruct, options?: {
446
446
  /** Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) */
447
447
  xlsx?: boolean;
448
- }): object;
448
+ }): string;
449
449
 
450
450
  /**
451
451
  * Stringify a range object into A1 syntax.
@@ -453,7 +453,7 @@ export declare function stringifyStructRef(refObject: object, options?: {
453
453
  * @param range A range object
454
454
  * @returns An A1-style string represenation of a range
455
455
  */
456
- declare function toA1(range: object): string;
456
+ declare function toA1(range: RangeA1): string;
457
457
 
458
458
  /**
459
459
  * Convert a 0 based offset number to a column string
@@ -472,7 +472,7 @@ export declare function toCol(columnIndex: number): string;
472
472
  * @param range A range object
473
473
  * @returns An R1C1-style string represenation of a range
474
474
  */
475
- declare function toR1C1(range: object): string;
475
+ declare function toR1C1(range: RangeR1C1): string;
476
476
 
477
477
  /**
478
478
  * Breaks a string formula into a list of tokens.
@@ -522,7 +522,7 @@ export declare function tokenize(formula: string, options?: {
522
522
  withLocation?: boolean;
523
523
  /** Enables a `[1]Sheet1!A1` or `[1]!name` syntax form for external workbooks found only in XLSX files. */
524
524
  xlsx?: boolean;
525
- }): Array<object>;
525
+ }): Array<Token>;
526
526
 
527
527
  /**
528
528
  * Translates ranges in a formula or list of tokens from relative R1C1 syntax to
@@ -558,7 +558,7 @@ export declare function tokenize(formula: string, options?: {
558
558
  * @param [options.xlsx=false] Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md)
559
559
  * @returns A formula string or token list (depending on which was input)
560
560
  */
561
- export declare function translateToA1(formula: (string | Array<object>), anchorCell: string, options?: {
561
+ export declare function translateToA1(formula: (string | Array<Token>), anchorCell: string, options?: {
562
562
  /** Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`. These are supported by Google Sheets but not Excel. See: References.md. */
563
563
  allowTernary?: boolean;
564
564
  /** Should ranges be treated as whole references (`Sheet1!A1:B2`) or as separate tokens for each part: (`Sheet1`,`!`,`A1`,`:`,`B2`). */
@@ -567,7 +567,7 @@ export declare function translateToA1(formula: (string | Array<object>), anchorC
567
567
  wrapEdges?: boolean;
568
568
  /** Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) */
569
569
  xlsx?: boolean;
570
- }): (string | Array<object>);
570
+ }): (string | Array<Token>);
571
571
 
572
572
  /**
573
573
  * Translates ranges in a formula or list of tokens from absolute A1 syntax to
@@ -586,12 +586,12 @@ export declare function translateToA1(formula: (string | Array<object>), anchorC
586
586
  * @param [options.xlsx=false] Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md)
587
587
  * @returns A formula string or token list (depending on which was input)
588
588
  */
589
- export declare function translateToR1C1(formula: (string | Array<object>), anchorCell: string, options?: {
589
+ export declare function translateToR1C1(formula: (string | Array<Token>), anchorCell: string, options?: {
590
590
  /** Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`. These are supported by Google Sheets but not Excel. See: References.md. */
591
591
  allowTernary?: boolean;
592
592
  /** Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) */
593
593
  xlsx?: boolean;
594
- }): (string | Array<object>);
594
+ }): (string | Array<Token>);
595
595
 
596
596
  /** A dictionary of the types used to identify AST node variants. */
597
597
  export declare const nodeTypes: Readonly<{
@@ -651,3 +651,116 @@ export declare const tokenTypes: Readonly<{
651
651
  WHITESPACE: string;
652
652
  }>;
653
653
 
654
+ /** A range in A1 style coordinates. */
655
+ export declare type RangeA1 = {
656
+ /** Signifies that bottom is a "locked" value */
657
+ $bottom?: (boolean | null);
658
+ /** Signifies that left is a "locked" value */
659
+ $left?: (boolean | null);
660
+ /** Signifies that right is a "locked" value */
661
+ $right?: (boolean | null);
662
+ /** Signifies that top is a "locked" value */
663
+ $top?: (boolean | null);
664
+ /** Bottom row of the range */
665
+ bottom?: (number | null);
666
+ /** Left column of the range */
667
+ left?: (number | null);
668
+ /** Right column of the range */
669
+ right?: (number | null);
670
+ /** Top row of the range */
671
+ top?: (number | null);
672
+ };
673
+
674
+ /** A range in R1C1 style coordinates. */
675
+ export declare type RangeR1C1 = {
676
+ /** Signifies that c0 is an absolute value */
677
+ $c0?: (boolean | null);
678
+ /** Signifies that c1 is an absolute value */
679
+ $c1?: (boolean | null);
680
+ /** Signifies that r0 is an absolute value */
681
+ $r0?: (boolean | null);
682
+ /** Signifies that r1 is an absolute value */
683
+ $r1?: (boolean | null);
684
+ /** Left column of the range */
685
+ c0?: (number | null);
686
+ /** Right column of the range */
687
+ c1?: (number | null);
688
+ /** Top row of the range */
689
+ r0?: (number | null);
690
+ /** Bottom row of the range */
691
+ r1?: (number | null);
692
+ };
693
+
694
+ /**
695
+ * A reference containing an A1 style range. See [Prefixes.md] for
696
+ * documentation on how scopes work in Fx.
697
+ */
698
+ export declare type ReferenceA1 = {
699
+ /** A collection of scopes for the reference */
700
+ context?: Array<string>;
701
+ /** The reference's range */
702
+ range?: RangeA1;
703
+ /** A context sheet scope */
704
+ sheetName?: string;
705
+ /** A context workbook scope */
706
+ workbookName?: string;
707
+ };
708
+
709
+ /**
710
+ * A reference containing a R1C1 style range. See [Prefixes.md] for
711
+ * documentation on how scopes work in Fx.
712
+ */
713
+ export declare type ReferenceR1C1 = {
714
+ /** A collection of scopes for the reference */
715
+ context?: Array<string>;
716
+ /** The reference's range */
717
+ range?: RangeR1C1;
718
+ /** A context sheet scope */
719
+ sheetName?: string;
720
+ /** A context workbook scope */
721
+ workbookName?: string;
722
+ };
723
+
724
+ /**
725
+ * A reference containing a table slice definition. See [Prefixes.md] for
726
+ * documentation on how scopes work in Fx.
727
+ */
728
+ export declare type ReferenceStruct = {
729
+ /** The sections this reference targets */
730
+ columns?: Array<string>;
731
+ /** A collection of scopes for the reference */
732
+ context?: Array<string>;
733
+ /** The sections this reference targets */
734
+ sections?: Array<string>;
735
+ /** A context sheet scope */
736
+ sheetName?: string;
737
+ /** The table this reference targets */
738
+ table?: string;
739
+ /** A context workbook scope */
740
+ workbookName?: string;
741
+ };
742
+
743
+ /** A formula language token. */
744
+ export declare type Token = Record<string,any> & {
745
+ /** Source position offsets to the token */
746
+ loc?: Array<number>;
747
+ /** The type of the token */
748
+ type: string;
749
+ /** Signifies an unterminated string token */
750
+ unterminated?: boolean;
751
+ /** The value of the token */
752
+ value: string;
753
+ };
754
+
755
+ /** A token with extra meta data. */
756
+ export declare type TokenEnhanced = Token & {
757
+ /** This token's level of nesting inside parentheses */
758
+ depth?: number;
759
+ /** Token is of unknown type or a paren without a match */
760
+ error?: boolean;
761
+ /** The ID of a group which this token belongs (e.g. matching parens) */
762
+ groupId?: string;
763
+ /** A zero based position in a token list */
764
+ index: number;
765
+ };
766
+