@borgar/fx 4.7.1 → 4.9.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/lib/sr.js CHANGED
@@ -241,9 +241,11 @@ function toSentenceCase (str) {
241
241
  * @param {ReferenceStruct} refObject A structured reference object
242
242
  * @param {object} [options={}] Options
243
243
  * @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)
244
+ * @param {boolean} [options.thisRow=false] Enforces using the `[#This Row]` instead of the `@` shorthand when serializing structured ranges.
244
245
  * @returns {string} The structured reference in string format
245
246
  */
246
- export function stringifyStructRef (refObject, { xlsx = false } = {}) {
247
+ export function stringifyStructRef (refObject, options = {}) {
248
+ const { xlsx, thisRow } = options;
247
249
  let s = xlsx
248
250
  ? stringifyPrefixAlt(refObject)
249
251
  : stringifyPrefix(refObject);
@@ -263,8 +265,8 @@ export function stringifyStructRef (refObject, { xlsx = false } = {}) {
263
265
  }
264
266
  else {
265
267
  s += '[';
266
- // single [#this row] sections get normalized to an @
267
- const singleAt = numSections === 1 && refObject.sections[0].toLowerCase() === 'this row';
268
+ // single [#this row] sections get normalized to an @ by default
269
+ const singleAt = !thisRow && numSections === 1 && refObject.sections[0].toLowerCase() === 'this row';
268
270
  if (singleAt) {
269
271
  s += '@';
270
272
  }
package/lib/sr.spec.js CHANGED
@@ -278,3 +278,53 @@ test('structured references parse and serialize in xlsx mode', t => {
278
278
  t.end();
279
279
  });
280
280
 
281
+ test.only('longform serialize (in xlsx mode)', t => {
282
+ // thisRow should have no effect when parsing
283
+ t.isSREqual('Table2[[#This Row],[col1]]', {
284
+ table: 'Table2',
285
+ columns: [ 'col1' ],
286
+ sections: [ 'this row' ]
287
+ }, { xlsx: true, thisRow: true });
288
+
289
+ t.isSREqual('Table2[[#This Row],[col1]]', {
290
+ table: 'Table2',
291
+ columns: [ 'col1' ],
292
+ sections: [ 'this row' ]
293
+ }, { xlsx: true, thisRow: false });
294
+
295
+ t.isSREqual('Table2[[#This Row],[col1]]', {
296
+ table: 'Table2',
297
+ columns: [ 'col1' ],
298
+ sections: [ 'this row' ]
299
+ }, { xlsx: false, thisRow: true });
300
+
301
+ t.isSREqual('Table2[[#This Row],[col1]]', {
302
+ table: 'Table2',
303
+ columns: [ 'col1' ],
304
+ sections: [ 'this row' ]
305
+ }, { xlsx: false, thisRow: false });
306
+
307
+ // thisRow should mean we don't see @'s in output
308
+ t.is(
309
+ stringifyStructRef({
310
+ table: 'Table2',
311
+ columns: [ 'col1' ],
312
+ sections: [ 'this row' ]
313
+ }, { xlsx: true, thisRow: true }),
314
+ 'Table2[[#This row],[col1]]',
315
+ 'Table2[[#This row],[col1]] (xlsx mode)'
316
+ );
317
+
318
+ t.is(
319
+ stringifyStructRef({
320
+ table: 'Table2',
321
+ columns: [ 'col1' ],
322
+ sections: [ 'this row' ]
323
+ }, { xlsx: false, thisRow: true }),
324
+ 'Table2[[#This row],[col1]]',
325
+ 'Table2[[#This row],[col1]] (non xlsx mode)'
326
+ );
327
+
328
+ t.end();
329
+ });
330
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@borgar/fx",
3
- "version": "4.7.1",
3
+ "version": "4.9.0",
4
4
  "description": "Utilities for working with Excel formulas",
5
5
  "main": "dist/fx.js",
6
6
  "types": "dist/fx.d.ts",