@borgar/fx 4.12.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 (139) 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.ts +18 -0
  36. package/lib/lexers/canEndRange.ts +25 -0
  37. package/lib/lexers/lexBoolean.ts +55 -0
  38. package/lib/lexers/lexContext.ts +104 -0
  39. package/lib/lexers/lexError.ts +15 -0
  40. package/lib/lexers/lexFunction.ts +37 -0
  41. package/lib/lexers/lexNameFuncCntx.ts +112 -0
  42. package/lib/lexers/lexNamed.ts +60 -0
  43. package/lib/lexers/lexNewLine.ts +12 -0
  44. package/lib/lexers/lexNumber.ts +48 -0
  45. package/lib/lexers/lexOperator.ts +26 -0
  46. package/lib/lexers/lexRange.ts +15 -0
  47. package/lib/lexers/lexRangeA1.ts +134 -0
  48. package/lib/lexers/lexRangeR1C1.ts +146 -0
  49. package/lib/lexers/lexRangeTrim.ts +26 -0
  50. package/lib/lexers/lexRefOp.ts +19 -0
  51. package/lib/lexers/lexString.ts +22 -0
  52. package/lib/lexers/lexStructured.ts +25 -0
  53. package/lib/lexers/lexWhitespace.ts +31 -0
  54. package/lib/lexers/sets.ts +51 -0
  55. package/lib/mergeRefTokens.spec.ts +141 -0
  56. package/lib/{mergeRefTokens.js → mergeRefTokens.ts} +47 -32
  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.ts +240 -0
  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 +46 -30
  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/dist/fx.d.ts +0 -823
  104. package/dist/fx.js +0 -2
  105. package/dist/package.json +0 -1
  106. package/lib/a1.js +0 -348
  107. package/lib/a1.spec.js +0 -458
  108. package/lib/addTokenMeta.spec.js +0 -153
  109. package/lib/astTypes.js +0 -96
  110. package/lib/extraTypes.js +0 -74
  111. package/lib/fixRanges.js +0 -104
  112. package/lib/fixRanges.spec.js +0 -170
  113. package/lib/fromCol.spec.js +0 -11
  114. package/lib/index.js +0 -134
  115. package/lib/index.spec.js +0 -67
  116. package/lib/isType.spec.js +0 -168
  117. package/lib/lexer-srefs.spec.js +0 -324
  118. package/lib/lexer.js +0 -283
  119. package/lib/lexer.spec.js +0 -1953
  120. package/lib/lexerParts.js +0 -228
  121. package/lib/mergeRefTokens.spec.js +0 -121
  122. package/lib/package.json +0 -1
  123. package/lib/parseRef.js +0 -157
  124. package/lib/parseRef.spec.js +0 -71
  125. package/lib/parseSRange.js +0 -167
  126. package/lib/parseStructRef.js +0 -48
  127. package/lib/parseStructRef.spec.js +0 -164
  128. package/lib/parser.spec.js +0 -1208
  129. package/lib/rc.js +0 -341
  130. package/lib/rc.spec.js +0 -403
  131. package/lib/stringifyStructRef.js +0 -80
  132. package/lib/stringifyStructRef.spec.js +0 -182
  133. package/lib/toCol.spec.js +0 -11
  134. package/lib/translate-toA1.spec.js +0 -214
  135. package/lib/translate-toRC.spec.js +0 -197
  136. package/lib/translate.js +0 -239
  137. package/lib/translate.spec.js +0 -21
  138. package/rollup.config.mjs +0 -22
  139. package/tsd.json +0 -12
@@ -1,167 +0,0 @@
1
- const re_SRcolumnB = /^\[('['#@[\]]|[^'#@[\]])*\]/i;
2
- const re_SRcolumnN = /^([^#@[\]:]+)/i;
3
-
4
- const keyTerms = {
5
- 'headers': 1,
6
- 'data': 2,
7
- 'totals': 4,
8
- 'all': 8,
9
- 'this row': 16,
10
- '@': 16
11
- };
12
-
13
- const fz = (...a) => Object.freeze(a);
14
-
15
- // only combinations allowed are: #data + (#headers | #totals | #data)
16
- const sectionMap = {
17
- // no terms
18
- 0: fz(),
19
- // single term
20
- 1: fz('headers'),
21
- 2: fz('data'),
22
- 4: fz('totals'),
23
- 8: fz('all'),
24
- 16: fz('this row'),
25
- // headers+data
26
- 3: fz('headers', 'data'),
27
- // totals+data
28
- 6: fz('data', 'totals')
29
- };
30
-
31
- const matchColumn = (s, allowUnbraced = true) => {
32
- let m = re_SRcolumnB.exec(s);
33
- if (m) {
34
- const value = m[0].slice(1, -1).replace(/'(['#@[\]])/g, '$1');
35
- return [ m[0], value ];
36
- }
37
- if (allowUnbraced) {
38
- m = re_SRcolumnN.exec(s);
39
- if (m) {
40
- return [ m[0], m[0] ];
41
- }
42
- }
43
- return null;
44
- };
45
-
46
- export function parseSRange (raw) {
47
- const columns = [];
48
- let pos = 0;
49
- let s = raw;
50
- let m;
51
- let m1;
52
- let terms = 0;
53
-
54
- // start of structured ref?
55
- if ((m = /^(\[\s*)/.exec(s))) {
56
- // quickly determine if this is a simple keyword or column
57
- // [#keyword]
58
- if ((m1 = /^\[#([a-z ]+)\]/i.exec(s))) {
59
- const k = m1[1].toLowerCase();
60
- pos += m1[0].length;
61
- if (keyTerms[k]) {
62
- terms |= keyTerms[k];
63
- }
64
- else {
65
- return null;
66
- }
67
- }
68
- // [column]
69
- else if ((m1 = matchColumn(s, false))) {
70
- pos += m1[0].length;
71
- if (m1[1]) {
72
- columns.push(m1[1]);
73
- }
74
- }
75
- // use the "normal" method
76
- // [[#keyword]]
77
- // [[column]]
78
- // [@]
79
- // [@column]
80
- // [@[column]]
81
- // [@column:column]
82
- // [@column:[column]]
83
- // [@[column]:column]
84
- // [@[column]:[column]]
85
- // [column:column]
86
- // [column:[column]]
87
- // [[column]:column]
88
- // [[column]:[column]]
89
- // [[#keyword],column]
90
- // [[#keyword],column:column]
91
- // [[#keyword],[#keyword],column:column]
92
- // ...
93
- else {
94
- let expect_more = true;
95
- s = s.slice(m[1].length);
96
- pos += m[1].length;
97
- // match keywords as we find them
98
- while (
99
- expect_more &&
100
- (m = /^\[#([a-z ]+)\](\s*,\s*)?/i.exec(s))
101
- ) {
102
- const k = m[1].toLowerCase();
103
- if (keyTerms[k]) {
104
- terms |= keyTerms[k];
105
- s = s.slice(m[0].length);
106
- pos += m[0].length;
107
- expect_more = !!m[2];
108
- }
109
- else {
110
- return null;
111
- }
112
- }
113
- // is there an @ specifier?
114
- if (expect_more && (m = /^@/.exec(s))) {
115
- terms |= keyTerms['@'];
116
- s = s.slice(1);
117
- pos += 1;
118
- expect_more = s[0] !== ']';
119
- }
120
- // not all keyword terms may be combined
121
- if (!(terms in sectionMap)) {
122
- return null;
123
- }
124
- // column definitions
125
- const leftCol = expect_more ? matchColumn(raw.slice(pos)) : null;
126
- if (leftCol) {
127
- pos += leftCol[0].length;
128
- columns.push(leftCol[1]);
129
- s = raw.slice(pos);
130
- if (s[0] === ':') {
131
- s = s.slice(1);
132
- pos++;
133
- const rightCol = matchColumn(s);
134
- if (rightCol) {
135
- pos += rightCol[0].length;
136
- columns.push(rightCol[1]);
137
- }
138
- else {
139
- return null;
140
- }
141
- }
142
- expect_more = false;
143
- }
144
- // advance ws
145
- while (raw[pos] === ' ') {
146
- pos++;
147
- }
148
- // close the ref
149
- if (expect_more || raw[pos] !== ']') {
150
- return null;
151
- }
152
- // step over the closing ]
153
- pos++;
154
- }
155
- }
156
- else {
157
- return null;
158
- }
159
-
160
- const sections = sectionMap[terms];
161
- return {
162
- columns,
163
- sections: sections ? sections.concat() : sections,
164
- length: pos,
165
- token: raw.slice(0, pos)
166
- };
167
- }
@@ -1,48 +0,0 @@
1
- import { parseRef } from './parseRef.js';
2
- import { parseSRange } from './parseSRange.js';
3
-
4
- /**
5
- * Parse a structured reference string into an object representing it.
6
- *
7
- * ```js
8
- * parseStructRef('workbook.xlsx!tableName[[#Data],[Column1]:[Column2]]');
9
- * // => {
10
- * // context: [ 'workbook.xlsx' ],
11
- * // sections: [ 'data' ],
12
- * // columns: [ 'my column', '@foo' ],
13
- * // table: 'tableName',
14
- * // }
15
- * ```
16
- *
17
- * For A:A or A1:A style ranges, `null` will be used for any dimensions that the
18
- * syntax does not specify:
19
- *
20
- * @tutorial References.md
21
- * @param {string} ref A structured reference string
22
- * @param {object} [options={}] Options
23
- * @param {boolean} [options.xlsx=false] Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md)
24
- * @returns {(ReferenceStruct|null)} An object representing a valid reference or null if it is invalid.
25
- */
26
- export function parseStructRef (ref, options = { xlsx: false }) {
27
- const r = parseRef(ref, options);
28
- if (r && r.struct) {
29
- const structData = parseSRange(r.struct);
30
- if (structData && structData.length === r.struct.length) {
31
- return options.xlsx
32
- ? {
33
- workbookName: r.workbookName,
34
- sheetName: r.sheetName,
35
- table: r.name,
36
- columns: structData.columns,
37
- sections: structData.sections
38
- }
39
- : {
40
- context: r.context,
41
- table: r.name,
42
- columns: structData.columns,
43
- sections: structData.sections
44
- };
45
- }
46
- }
47
- return null;
48
- }
@@ -1,164 +0,0 @@
1
- /* eslint-disable object-property-newline, object-curly-newline */
2
- import { test, Test } from 'tape';
3
- import { parseStructRef } from './parseStructRef.js';
4
-
5
- Test.prototype.isSREqual = function isSREqual (expr, expect, opts) {
6
- if (expect) {
7
- expect = opts?.xlsx
8
- ? {
9
- workbookName: '',
10
- sheetName: '',
11
- table: '',
12
- columns: [],
13
- sections: [],
14
- ...expect
15
- }
16
- : {
17
- context: [],
18
- table: '',
19
- columns: [],
20
- sections: [],
21
- ...expect
22
- };
23
- }
24
- this.deepEqual(parseStructRef(expr, opts), expect, expr);
25
- };
26
-
27
- test.only('parse structured references', t => {
28
- t.isSREqual('table[col]', {
29
- table: 'table',
30
- columns: [ 'col' ]
31
- });
32
-
33
- t.isSREqual('table[]', {
34
- table: 'table'
35
- });
36
-
37
- t.isSREqual('[#All]', {
38
- sections: [ 'all' ]
39
- });
40
-
41
- t.isSREqual('[column name]', {
42
- columns: [ 'column name' ]
43
- });
44
-
45
- t.isSREqual('[column name]!foo', null);
46
- t.isSREqual('[foo]bar', null);
47
-
48
- t.isSREqual('[[my column]]', {
49
- columns: [ 'my column' ]
50
- });
51
-
52
- t.isSREqual('[[my column]:otherColumn]', {
53
- columns: [ 'my column', 'otherColumn' ]
54
- });
55
-
56
- t.isSREqual('[ [my column]:otherColumn ]', {
57
- columns: [ 'my column', 'otherColumn ' ]
58
- });
59
-
60
- t.isSREqual('[ [my column]: otherColumn ]', {
61
- columns: [ 'my column', ' otherColumn ' ]
62
- });
63
-
64
- t.isSREqual('[ @[ my column ]: otherColumn ]', {
65
- columns: [ ' my column ', ' otherColumn ' ],
66
- sections: [ 'this row' ]
67
- });
68
-
69
- t.isSREqual('[[#Data], [my column]:otherColumn]', {
70
- columns: [ 'my column', 'otherColumn' ],
71
- sections: [ 'data' ]
72
- });
73
-
74
- t.isSREqual('[ [#Data], [my column]:[\'@foo] ]', {
75
- columns: [ 'my column', '@foo' ],
76
- sections: [ 'data' ]
77
- });
78
-
79
- t.isSREqual('workbook.xlsx!tableName[ [#Data], [my column]:[\'@foo] ]', {
80
- columns: [ 'my column', '@foo' ],
81
- sections: [ 'data' ],
82
- table: 'tableName',
83
- context: [ 'workbook.xlsx' ]
84
- });
85
-
86
- t.isSREqual('[[#Data],[#data],[#Data],[#Data],[#Totals],[#Totals],[#Totals],foo]', {
87
- columns: [ 'foo' ],
88
- sections: [ 'data', 'totals' ]
89
- });
90
-
91
- t.isSREqual("'Sheet'!Table[Column]", {
92
- columns: [ 'Column' ],
93
- table: 'Table',
94
- context: [ 'Sheet' ]
95
- });
96
-
97
- t.isSREqual("Sheet1!Table1[foo '[bar']]", {
98
- columns: [ 'foo [bar]' ],
99
- table: 'Table1',
100
- context: [ 'Sheet1' ]
101
- });
102
-
103
- t.isSREqual('[myworkbook.xlsx]Sheet1!TMP8w0habhr[#All]', {
104
- columns: [],
105
- table: 'TMP8w0habhr',
106
- context: [ 'myworkbook.xlsx', 'Sheet1' ],
107
- sections: [ 'all' ]
108
- });
109
-
110
- t.end();
111
- });
112
-
113
- test('structured references parse in xlsx mode', t => {
114
- t.isSREqual('[Workbook.xlsx]!Table[#Data]', {
115
- workbookName: 'Workbook.xlsx',
116
- table: 'Table',
117
- sections: [ 'data' ]
118
- }, { xlsx: true });
119
-
120
- t.isSREqual('[Workbook.xlsx]Sheet1!Table[#Data]', {
121
- workbookName: 'Workbook.xlsx',
122
- sheetName: 'Sheet1',
123
- table: 'Table',
124
- sections: [ 'data' ]
125
- }, { xlsx: true });
126
-
127
- t.isSREqual('Sheet1!Table[#Data]', {
128
- sheetName: 'Sheet1',
129
- table: 'Table',
130
- sections: [ 'data' ]
131
- }, { xlsx: true });
132
-
133
- t.end();
134
- });
135
-
136
- test('longform prase (in xlsx mode)', t => {
137
- // thisRow should have no effect when parsing
138
- t.isSREqual('Table2[[#This Row],[col1]]', {
139
- table: 'Table2',
140
- columns: [ 'col1' ],
141
- sections: [ 'this row' ]
142
- }, { xlsx: true, thisRow: true });
143
-
144
- t.isSREqual('Table2[[#This Row],[col1]]', {
145
- table: 'Table2',
146
- columns: [ 'col1' ],
147
- sections: [ 'this row' ]
148
- }, { xlsx: true, thisRow: false });
149
-
150
- t.isSREqual('Table2[[#This Row],[col1]]', {
151
- table: 'Table2',
152
- columns: [ 'col1' ],
153
- sections: [ 'this row' ]
154
- }, { xlsx: false, thisRow: true });
155
-
156
- t.isSREqual('Table2[[#This Row],[col1]]', {
157
- table: 'Table2',
158
- columns: [ 'col1' ],
159
- sections: [ 'this row' ]
160
- }, { xlsx: false, thisRow: false });
161
-
162
- t.end();
163
- });
164
-