@borgar/fx 4.2.0 → 4.3.1
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/.jsdoc/publish.js +30 -8
- package/dist/fx.js +1 -1
- package/docs/API.md +74 -24
- package/docs/Prefixes.md +82 -0
- package/lib/a1.js +11 -5
- package/lib/a1.spec.js +143 -7
- package/lib/addTokenMeta.js +8 -15
- package/lib/addTokenMeta.spec.js +24 -2
- package/lib/fixRanges.js +15 -8
- package/lib/fixRanges.spec.js +19 -0
- package/lib/lexer-srefs.spec.js +9 -1
- package/lib/lexer.js +1 -0
- package/lib/lexer.spec.js +72 -0
- package/lib/lexerParts.js +33 -6
- package/lib/parseRef.js +77 -15
- package/lib/parseRef.spec.js +60 -0
- package/lib/parser.js +3 -2
- package/lib/parser.spec.js +11 -0
- package/lib/rc.js +11 -5
- package/lib/rc.spec.js +145 -12
- package/lib/sr.js +24 -10
- package/lib/sr.spec.js +93 -7
- package/lib/stringifyPrefix.js +18 -0
- package/lib/translate-toA1.spec.js +23 -3
- package/lib/translate-toRC.spec.js +31 -2
- package/lib/translate.js +16 -11
- package/package.json +2 -2
package/.jsdoc/publish.js
CHANGED
|
@@ -4,7 +4,7 @@ function formatType (d, inTable = false) {
|
|
|
4
4
|
return d.names?.map(n => `\`${n}\``).join(inTable ? ' \\| ' : ' | ') || '';
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
function formatArguments (args) {
|
|
7
|
+
function formatArguments (args, showDefaults = true) {
|
|
8
8
|
let inOpt = false;
|
|
9
9
|
let r = args.reduce((a, d, i) => {
|
|
10
10
|
if (d.name.includes('.')) {
|
|
@@ -22,7 +22,7 @@ function formatArguments (args) {
|
|
|
22
22
|
inOpt = true;
|
|
23
23
|
}
|
|
24
24
|
a += d.name;
|
|
25
|
-
if (d.defaultvalue) {
|
|
25
|
+
if (showDefaults && d.defaultvalue) {
|
|
26
26
|
a += ' = `' + d.defaultvalue + '`';
|
|
27
27
|
}
|
|
28
28
|
return a;
|
|
@@ -101,6 +101,23 @@ function formatHeading (text, level = 2) {
|
|
|
101
101
|
return '#'.repeat(level || 1) + ' ' + text;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
function formatIndexLink (name, text) {
|
|
105
|
+
return `[${text.replace(/([[\]])/g, '\\$1')}](#${name})`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const formatIndex = {
|
|
109
|
+
function: d => {
|
|
110
|
+
return '- ' + formatIndexLink(d.name,
|
|
111
|
+
`${d.name}( ${formatArguments(d.params, false)} )`
|
|
112
|
+
);
|
|
113
|
+
},
|
|
114
|
+
constant: d => {
|
|
115
|
+
return '- ' + formatIndexLink(d.name,
|
|
116
|
+
`${d.name}`
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
104
121
|
const format = {
|
|
105
122
|
function: d => {
|
|
106
123
|
return [
|
|
@@ -151,6 +168,7 @@ exports.publish = (data, { destination }) => {
|
|
|
151
168
|
});
|
|
152
169
|
|
|
153
170
|
let output = [];
|
|
171
|
+
const index = [];
|
|
154
172
|
|
|
155
173
|
Object.keys(categories)
|
|
156
174
|
.sort()
|
|
@@ -158,6 +176,8 @@ exports.publish = (data, { destination }) => {
|
|
|
158
176
|
const heading = categoryHeadings[kind];
|
|
159
177
|
if (heading == null) { return; }
|
|
160
178
|
// emit category heading
|
|
179
|
+
if (index.length) { index.push(''); }
|
|
180
|
+
index.push('**' + heading + '**', '');
|
|
161
181
|
output.push(formatHeading(heading, 2));
|
|
162
182
|
// emit all members belonging to that category
|
|
163
183
|
docs
|
|
@@ -176,17 +196,19 @@ exports.publish = (data, { destination }) => {
|
|
|
176
196
|
console.error('Unsupported member type ' + d.kind);
|
|
177
197
|
process.exit(1);
|
|
178
198
|
}
|
|
199
|
+
index.push(formatIndex[d.kind](d));
|
|
179
200
|
output.push(...format[d.kind](d));
|
|
180
201
|
});
|
|
181
202
|
});
|
|
182
203
|
|
|
183
|
-
output = output
|
|
184
|
-
.map(d => d.trim())
|
|
185
|
-
.filter(Boolean);
|
|
186
|
-
|
|
187
|
-
// console.log(docs.map(d => d.name).sort());
|
|
188
204
|
if (destination === 'console') {
|
|
189
|
-
|
|
205
|
+
const outText = (
|
|
206
|
+
index.map(d => d.trim()).join('\n') +
|
|
207
|
+
'\n\n' +
|
|
208
|
+
output.map(d => d.trim()).filter(Boolean).join('\n\n') +
|
|
209
|
+
'\n'
|
|
210
|
+
);
|
|
211
|
+
console.log(outText);
|
|
190
212
|
}
|
|
191
213
|
else {
|
|
192
214
|
console.error('This template only supports output to the console. Use the option "-d console" when you run JSDoc.');
|
package/dist/fx.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const e="operator",t="error",n="context",l="range_beam",r="range_ternary",o="range_named",u="structured",i="unknown",c="UnaryExpression",s="BinaryExpression",a="ReferenceIdentifier",f="CallExpression";function p(e){const t=/(?:\[(.+?)\])?([^[\]]+?)$/.exec(e);if(t){const[,e,n]=t;return{context:[e,n].filter(Boolean)}}}const h=e=>e&&":"===e.value&&{},g=e=>e&&"range"===e.type&&{r0:e.value},d=e=>e&&e.type===r&&{r0:e.value},$=e=>e&&"range"===e.type&&{r1:e.value},y=t=>t&&t.type===e&&"!"===t.value&&{},x=e=>e&&e.type===l&&{r0:e.value},v=e=>e&&e.type===u&&{struct:e.value},m=e=>e&&e.type===n?p(e.value):e&&"context_quote"===e.type?p(e.value.slice(1,-1).replace(/''/g,"'")):void 0,E=e=>e&&e.type===o&&{name:e.value},R=[[d],[g,h,$],[g],[x],[m,y,d],[m,y,g,h,$],[m,y,g],[m,y,x]],w=R.concat([[E],[m,y,E],[v],[E,v],[m,y,E,v]]);function C(e,t){const n={withLocation:!1,mergeRefs:!1,allowTernary:!1,allowNamed:!0,r1c1:!1,...t},l=Ae(e,$e,n),r={context:[],r0:"",r1:"",name:""};l.length&&"fx_prefix"===l[0].type&&l.shift();const o=n.allowNamed?w:R;for(let e=0;e<o.length;e++){const t={...r};if(o[e].length===l.length){const n=o[e].every(((e,n)=>{const r=e(l[n]);return Object.assign(t,r),r}));if(n)return t}}return null}const A=/[^0-9A-Za-z._¡¤§¨ª\u00ad¯-\uffff]/;function N(e){let t="",n=0,l=0;const r=e.context||[];for(let e=r.length;e>-1;e--){const o=r[e];if(o){t=(l%2?"["+o+"]":o)+t,n+=A.test(o),l++}}return n&&(t="'"+t.replace(/'/g,"''")+"'"),t?t+"!":t}const b=(e,t,n)=>Math.min(Math.max(t,e),n),T=(e,t)=>(t?"$":"")+O(e),I=(e,t)=>(t?"$":"")+String(e+1);function L(e){const t=e||"",n=t.length;let l=0;if(n>2){const e=t.charCodeAt(n-3);l+=676*(1+e-(e>95?32:0)-65)}if(n>1){const e=t.charCodeAt(n-2);l+=26*(1+e-(e>95?32:0)-65)}if(n){const e=t.charCodeAt(n-1);l+=e-(e>95?32:0)-65}return l}function O(e){return(e>=702?String.fromCharCode(((e-702)/676-0)%26+65):"")+(e>=26?String.fromCharCode(Math.floor((e/26-1)%26+65)):"")+String.fromCharCode(e%26+65)}function _(e){const t=/^(?=.)(\$(?=\D))?([A-Za-z]{0,3})?(\$)?([1-9][0-9]{0,6})?$/.exec(e);return t&&(t[2]||t[4])?[t[4]?(n=t[4],+n-1):null,t[2]?L(t[2]):null,!!t[3],!!t[1]]:null;var n}function U(e){let t=null,n=null,l=null,r=null,o=!1,u=!1,i=!1,c=!1;const[s,a,f]=e.split(":");if(f)return null;const p=_(s),h=a?_(a):null;if(!p||a&&!h)return null;if(null!=p[0]&&null!=p[1]?[t,n,o,u]=p:null==p[0]&&null!=p[1]?[,n,,u]=p:null!=p[0]&&null==p[1]&&([t,,o]=p),a)null!=h[0]&&null!=h[1]?[l,r,i,c]=h:null==h[0]&&null!=h[1]?[,r,,c]=h:null!=h[0]&&null==h[1]&&([l,,i]=h);else{if(null==t||null==n)return null;l=t,r=n,i=o,c=u}return null!=r&&(null==n||null!=n&&r<n)&&([n,r,u,c]=[r,n,c,u]),null!=l&&(null==t||null!=t&&l<t)&&([t,l,o,i]=[l,t,i,o]),{top:t,left:n,bottom:l,right:r,$top:o,$left:u,$bottom:i,$right:c}}function F(e){let{allowNamed:t=!0,allowTernary:n=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const l=C(e,{allowNamed:t,allowTernary:n,r1c1:!1});if(l&&(l.r0||l.name)){let e=null;return l.r0&&(e=U(l.r1?l.r0+":"+l.r1:l.r0)),l.name||e?(l.range=e,delete l.r0,delete l.r1,l):null}return null}function S(e){return N(e)+(e.name?e.name:function(e){let{top:t,left:n,bottom:l,right:r}=e;const{$left:o,$right:u,$top:i,$bottom:c}=e,s=null==n,a=null==r,f=null==t,p=null==l;return t=b(0,0|t,1048575),n=b(0,0|n,16383),!s&&!f&&a&&p?(l=t,r=n):(l=b(0,0|l,1048575),r=b(0,0|r,16383)),0===t&&l>=1048575||f&&p?T(n,o)+":"+T(r,u):0===n&&r>=16383||s&&a?I(t,i)+":"+I(l,c):s||f||a||!p?s||!f||a||p?s||f||!a||p?!s||f||a||p?r!==n||l!==t||u!==o||c!==i?T(n,o)+I(t,i)+":"+T(r,u)+I(l,c):T(n,o)+I(t,i):T(r,u)+I(t,i)+":"+I(l,c):T(n,o)+I(t,i)+":"+I(l,c):T(n,o)+I(l,c)+":"+T(r,u):T(n,o)+I(t,i)+":"+T(r,u)}(e.range))}function M(e){return null==e.top&&(e.top=0,e.$top=!1),null==e.bottom&&(e.bottom=1048575,e.$bottom=!1),null==e.left&&(e.left=0,e.$left=!1),null==e.right&&(e.right=16383,e.$right=!1),e}const k=/^\[('['#@[\]]|[^'#@[\]])+\]/i,D=/^([^#@[\]:]+)/i,j={headers:1,data:2,totals:4,all:8,"this row":16,"@":16},z=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return Object.freeze(t)},W={0:z(),1:z("headers"),2:z("data"),4:z("totals"),8:z("all"),16:z("this row"),3:z("headers","data"),6:z("data","totals")},q=function(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=k.exec(e);if(n){const e=n[0].slice(1,-1).replace(/'(['#@[\]])/g,"$1");return[n[0],e]}return t&&(n=D.exec(e),n)?[n[0],n[0]]:null};function B(e){const t=[];let n,l,r=0,o=e,u=0;if(!(n=/^(\[\s*)/.exec(o)))return null;if(l=/^\[#([a-z ]+)\]/i.exec(o)){const e=l[1].toLowerCase();if(r+=l[0].length,!j[e])return null;u|=j[e]}else if(l=q(o,!1))r+=l[0].length,t.push(l[1].trim());else{let l=!0;for(o=o.slice(n[1].length),r+=n[1].length;l&&(n=/^\[#([a-z ]+)\](\s*,\s*)?/i.exec(o));){const e=n[1].toLowerCase();if(!j[e])return null;u|=j[e],o=o.slice(n[0].length),r+=n[0].length,l=!!n[2]}if(l&&(n=/^@/.exec(o))&&(u|=j["@"],o=o.slice(1),r+=1,l="]"!==o[0]),!(u in W))return null;const i=l?q(e.slice(r)):null;if(i){if(r+=i[0].length,t.push(i[1].trim()),o=e.slice(r),":"===o[0]){o=o.slice(1),r++;const e=q(o);if(!e)return null;r+=e[0].length,t.push(e[1].trim())}l=!1}for(;" "===e[r];)r++;if(l||"]"!==e[r])return null;r++}const i=W[u];return{columns:t,sections:i?i.concat():i,length:r,token:e.slice(0,r)}}function Z(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=C(e,t);if(n&&n.struct){const e=B(n.struct);if(e&&e.length===n.struct.length)return{context:n.context,table:n.name,columns:e.columns,sections:e.sections}}return null}function P(e){return e.replace(/([[\]#'@])/g,"'$1")}function X(e){return e[0].toUpperCase()+e.slice(1).toLowerCase()}function H(e){let t=N(e);e.table&&(t+=e.table);const n=e.columns?.length??0,l=e.sections?.length??0;if(1!==l||n)if(l||1!==n){t+="[";const o=1===l&&"this row"===e.sections[0].toLowerCase();o?t+="@":l&&(t+=e.sections.map((e=>`[#${X(e)}]`)).join(","),n&&(t+=",")),o&&1===e.columns.length&&(r=e.columns[0],/^[a-zA-Z0-9\u00a1-\uffff]+$/.test(r))?t+=P(e.columns[0]):n&&(t+=e.columns.slice(0,2).map((e=>`[${P(e)}]`)).join(":")),t+="]"}else t+=`[${P(e.columns[0])}]`;else t+=`[#${X(e.sections[0])}]`;var r;return t}const Y=/^(\[(?:[^\]])+\])?([0-9A-Za-z._¡¤§¨ª\u00ad¯-\uffff]+)(?=!)/,G=/^'(?:''|[^'])*('|$)(?=!)/,K="\\$?[A-Z]{1,3}\\$?[1-9][0-9]{0,6}",V="\\$?[A-Z]{1,3}",Q="\\$?[1-9][0-9]{0,6}",J=new RegExp(`^${V}:${V}`,"i"),ee=new RegExp(`^${Q}:${Q}`,"i"),te=new RegExp(`^${K}`,"i"),ne=new RegExp(`^((${V}|${Q}):${K}|${K}:(${V}|${Q}))(?![\\w($.])`,"i"),le="(?:R(?:\\[[+-]?\\d+\\]|[1-9][0-9]{0,6})?)",re="(?:C(?:\\[[+-]?\\d+\\]|[1-9][0-9]{0,4})?)",oe=new RegExp(`^${re}(:${re})?(?=\\W|$)`,"i"),ue=new RegExp(`^${le}(:${le})?(?=\\W|$)`,"i"),ie=new RegExp(`^(?:(?=[RC])${le}${re})`,"i"),ce=new RegExp(`^(${le}${re}(:${re}|:${le})(?![[\\d])|(${le}|${re})(:${le}${re}))(?=\\W|$)`,"i"),se=/^(?![CR]\b)[a-zA-Z\\_\u00a1-\uffff][a-zA-Z0-9\\_.?\u00a1-\uffff]{0,254}/i;function ae(e,t){return n=>{const l=t.exec(n);if(l)return{type:e,value:l[0]}}}function fe(e){const t=B(e);if(t){let n=t.length;for(;" "===e[n];)n++;if("!"!==e[n])return{type:u,value:t.token}}return null}const pe=/([RC])(\[?)(-?\d+)/gi,he=/(\d+|[a-zA-Z]+)/gi;function ge(e,t){let n,o;if(t.r1c1){if(t.allowTernary&&(n=ce.exec(e))?o={type:r,value:n[0]}:(n=ie.exec(e))?o={type:"range",value:n[0]}:((n=ue.exec(e))||(n=oe.exec(e)))&&(o={type:l,value:n[0]}),o){for(pe.lastIndex=0;null!==(n=pe.exec(o.value));){const e=("R"===n[1]?1048575:16383)+(n[2]?1:0),t=parseInt(n[3],10);if(t>=e||t<=-e)return null}return o}}else if(t.allowTernary&&(n=ne.exec(e))?o={type:r,value:n[0]}:(n=J.exec(e))||(n=ee.exec(e))?o={type:l,value:n[0]}:(n=te.exec(e))&&(o={type:"range",value:n[0]}),o){for(he.lastIndex=0;null!==(n=he.exec(o.value));)if(/^\d/.test(n[1])){if(parseInt(n[1],10)-1>1048575)return null}else if(L(n[1])>16383)return null;return o}}const de=[ae(t,/^#(NAME\?|FIELD!|CALC!|VALUE!|REF!|DIV\/0!|NULL!|NUM!|N\/A|GETTING_DATA\b|SPILL!|UNKNOWN!|FIELD\b|CALC\b|SYNTAX\?|ERROR!|CONNECT!|BLOCKED!|EXTERNAL!)/i),ae(e,/^(<=|>=|<>|[-+/*^%&<>=]|[{},;]|[()]|@|:|!|#)/),ae("func",/^[A-Z_]+[A-Z\d_.]*(?=\()/i),ae("bool",/^(TRUE|FALSE)\b/i),ae("newline",/^\n+/),ae("whitespace",/^[ \f\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/),ae("string",/^"(?:""|[^"])*("|$)/),ae("context_quote",G),ae(n,Y),ge,fe,ae("number",/^(?:\d+(\.\d+)?(?:[eE][+-]?\d+)?|\d+)/),ae(o,se)],$e=[function(t,n){return n.r1c1?"!"===t[0]?{type:e,value:t[0]}:null:"!"===t[0]||":"===t[0]?{type:e,value:t[0]}:null},ae("context_quote",G),ae(n,Y),ge,fe,ae(o,se)],ye={};function xe(e,t){if(e.length){const n=e[0];t[n]=t[n]||{},xe(e.slice(1),t[n])}else t.$=!0}[["range",":","range"],["range"],[l],[r],[n,"!","range",":","range"],[n,"!","range"],[n,"!",l],[n,"!",r],["context_quote","!","range",":","range"],["context_quote","!","range"],["context_quote","!",l],["context_quote","!",r],[o],[n,"!",o],["context_quote","!",o],[u],[o,u],[n,"!",o,u],["context_quote","!",o,u]].forEach((e=>xe(e.concat().reverse(),ye)));const ve=function(t,n,l){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;const o=t[l-r];if(o){const u=o.type===e?o.value:o.type;if(u in n)return ve(t,n[u],l,r+1)}return n.$?r:0};function me(e){const t=[];for(let n=e.length-1;n>=0;n--){let l=e[n];const r=ve(e,ye,n);if(r){const t=e.slice(n-r+1,n+1);l={...l},l.value=t.map((e=>e.value)).join(""),l.loc&&t[0].loc&&(l.loc[0]=t[0].loc[0]),n-=r-1}t.unshift(l)}return t}const Ee=(e,t)=>e&&e.type===t,Re={withLocation:!1,mergeRefs:!0,allowTernary:!1,negativeNumbers:!0,r1c1:!1},we=e=>e.type===o||"func"===e.type,Ce=t=>!Ee(t,e)||"%"===t.value||"}"===t.value||")"===t.value||"#"===t.value;function Ae(t,n){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const r=Object.assign({},Re,l),{withLocation:o,mergeRefs:u,negativeNumbers:c}=r,s=[];let a=0,f=null,p=null,h=null;const g=e=>{const t=e.type===i,n=h&&h.type===i;h&&(t&&n||t&&we(h)||n&&we(e))?(h.value+=e.value,h.type=i,o&&(h.loc[1]=e.loc[1])):(s.push(e),h=e,"whitespace"!==e.type&&"newline"!==e.type&&(p=f,f=e))};if(/^=/.test(t)){a++,g({type:"fx_prefix",value:"=",...o?{loc:[0,1]}:{}})}for(;a<t.length;){const l=a,u=t.slice(a);let d="",$="";for(let e=0;e<n.length;e++){const t=n[e](u,r);if(t){d=t.type,$=t.value,a+=$.length;break}}d||(d=i,$=t[a],a++);const y={type:d,value:$,...o?{loc:[l,a]}:{}};if("string"===d){const e=$.length;if('""'===$);else if('"'===$||'"'!==$[e-1])y.unterminated=!0;else if('""'!==$&&'"'===$[e-2]){let t=e-1;for(;'"'===$[t];)t--;!(t+1)^(e-t+1)%2==0&&(y.unterminated=!0)}}if(c&&"number"===d){const t=h;if(t&&Ee(t,e)&&"-"===t.value&&(!p||Ee(p,"fx_prefix")||!Ce(p))){const e=s.pop();y.value="-"+$,o&&(y.loc[0]=e.loc[0]),f=p,h=s[s.length-1]}}g(y)}return u?me(s):s}function Ne(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return Ae(e,de,t)}function be(e){return!!e&&("range"===e.type||e.type===l||e.type===r)}function Te(e){return!!e&&("range"===e.type||e.type===l||e.type===r||e.type===u||e.type===o)}function Ie(e){return!!e&&("bool"===e.type||e.type===t||"number"===e.type||"string"===e.type)}function Le(e){return!!e&&e.type===t}function Oe(e){return!!e&&("whitespace"===e.type||"newline"===e.type)}function _e(e){return!!e&&"func"===e.type}function Ue(e){return!!e&&"fx_prefix"===e.type}function Fe(t){return!!t&&t.type===e}const Se="(END)",Me=["ANCHORARRAY","CHOOSE","DROP","IF","IFS","INDEX","INDIRECT","LAMBDA","LET","OFFSET","REDUCE","SINGLE","SWITCH","TAKE","XLOOKUP"],ke=e=>!!e&&(e.type===a||("ErrorLiteral"===e.type||e.type===t)&&"#REF!"===e.value||e.type===s&&(":"===e.operator||" "===e.operator||","===e.operator)||e.type===f&&Me.includes(e.callee.name.toUpperCase())),De={};let je,ze,We,qe=!1,Be=!1;function Ze(e){const t=new Error(e);throw t.source=ze.map((e=>e.value)).join(""),t.sourceOffset=ze.slice(0,We).reduce(((e,t)=>e+t.value),"").length,t}function Pe(){let e,t=We;do{e=ze[++t]}while(e&&(Oe(e)||Fe(e)&&"("===e.value));return(e=>{const t=(e&&e.value)+"";return!(!Te(e)&&(!Fe(e)||":"!==t&&","!==t&&t.trim())&&(!_e(e)||!Me.includes(t.toUpperCase()))&&(!Le(e)||"#REF!"!==t))})(e)}function Xe(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(e&&e!==je.id&&Ze(`Expected ${e} but got ${je.id}`),Oe(ze[We])){if(!(ke(t)&&Pe()))for(;Oe(ze[We]);)We++}if(We>=ze.length)return void(je=De[Se]);const n=ze[We];let l;We+=1,n.unterminated&&Ze("Encountered an unterminated token");let r=n.type;return Fe(n)?(l=De[n.value],l||Ze(`Unknown operator ${n.value}`)):Oe(n)?l=De["(WHITESPACE)"]:Ie(n)?l=De.Literal:Te(n)?(l=De[a],r=a):_e(n)?l=De["(FUNCTION)"]:Ze(`Unexpected ${n.type} token: ${n.value}`),je=Object.create(l),je.type=r,je.value=n.value,n.loc&&(je.loc=[...n.loc]),je}function He(e){let t=je;Xe(null,t);let n=t.nud();for(;e<je.lbp;)t=je,Xe(null,t),n=t.led(n);return n}const Ye={nud:()=>Ze("Invalid syntax"),led:()=>Ze("Missing operator")};function Ge(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=De[e];return n?t>=n.lbp&&(n.lbp=t):(n={...Ye},n.id=e,n.value=e,n.lbp=t,De[e]=n),n}function Ke(e,t,n){const l=Ge(e,t);return l.led=n||function(e){this.type=s,this.operator=this.value,delete this.value;const n=He(t);return this.arguments=[e,n],this.loc&&(this.loc=[e.loc[0],n.loc[1]]),this},l}function Ve(e,t){const n=Ge(e,0);return n.lbp=70,n.led=t||function(e){return this.type=c,this.operator=this.value,delete this.value,this.arguments=[e],this.loc&&(this.loc[0]=e.loc[0]),this},n}function Qe(e,t){const n=Ge(e);return n.nud=t||function(){this.type=c,this.operator=this.value,delete this.value;const e=He(70);return this.arguments=[e],this.loc&&(this.loc[1]=e.loc[1]),this},n}function Je(e,t){return Ke(e,t,(function(n){ke(n)||Ze(`Unexpected ${e} operator`);const l=He(t);return ke(l)||Ze(`Unexpected ${je.type} following ${this.id}`),this.type=s,this.operator=this.value.trim()?this.value:" ",delete this.value,this.arguments=[n,l],this.loc&&(this.loc=[n.loc[0],l.loc[1]]),this}))}Ge(Se),Je(":",80);const et=Je(",",80);Je("(WHITESPACE)",80);const tt=e=>{const t=et.lbp>0;return null!=e&&(et.lbp=e?80:0),t};function nt(){let e=1;return()=>"fxg"+e++}function lt(e,t){return null==e&&null==t||e===t}function rt(e,t){if(Array.isArray(e)!==Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!lt(e[n],t[n]))return!1;return!0}function ot(e,t){return!e&&!t||String(e).toLowerCase()===String(t).toLowerCase()}function ut(e,t){if((e.name||t.name)&&e.name!==t.name)return!1;if(e.columns||t.columns){if(e.table!==t.table)return!1;if(!rt(e.columns,t.columns))return!1;if(!rt(e.sections,t.sections))return!1}return!!(!e.range&&!t.range||lt(e.range.top,t.range.top)&<(e.range.bottom,t.range.bottom)&<(e.range.left,t.range.left)&<(e.range.right,t.range.right))&&!(!ot(e.context[0],t.context[0])||!ot(e.context[1],t.context[1]))}function it(e,t,n){if(e.context.length){if(1===e.context.length){const l=e.context[0];e.context=l===t||l===n?[n,t]:[n,l]}}else e.context=[n,t];return e}Ve("%"),Ve("#",(function(e){return ke(e)||Ze("# expects a reference"),this.type=c,this.operator=this.value,delete this.value,this.arguments=[e],this})),Qe("+"),Qe("-"),Qe("@"),Ke("^",50),Ke("*",40),Ke("/",40),Ke("+",30),Ke("-",30),Ke("&",20),Ke("=",10),Ke("<",10),Ke(">",10),Ke("<=",10),Ke(">=",10),Ke("<>",10),Ge("Literal").nud=function(){const{type:e,value:n}=this;if(this.type="Literal",this.raw=n,"number"===e)this.value=+n;else if("bool"===e)this.value="TRUE"===n.toUpperCase();else if(e===t)this.type="ErrorLiteral",this.value=n.toUpperCase();else{if("string"!==e)throw new Error("Unsupported literal type: "+e);this.value=n.slice(1,-1).replace(/""/g,'"')}return this},Ge(a).nud=function(){return this.type=a,this},Ge(")"),Qe("(",(function(){const e=tt(!0),t=He(0);return Xe(")",t),tt(e),t})),Ge("(FUNCTION)").nud=function(){return this},Ke("(",90,(function(e){"(FUNCTION)"!==e.id&&Ze("Cannot call a "+e.type);const t=[];let n=!1;if(")"!==je.id){const e=tt(!1);for(;")"!==je.id;)if(Oe(je)&&Xe(),","===je.id)t.push(null),n=!0,Xe();else{const e=He(0);t.push(e),n=!1,","===je.id&&(Xe(","),n=!0)}tt(e)}n&&t.push(null);const l=je;return delete this.value,this.type=f,this.callee={type:"Identifier",name:e.value},e.loc&&(this.callee.loc=[...e.loc]),this.arguments=t,e.loc&&(this.loc=[e.loc[0],l.loc[1]]),Xe(")",this),this})),Ge("}"),Ge(";"),Qe("{",(function(){"}"===je.id&&Ze("Unexpected empty array");let e=[],t=!1;const n=[e],l=tt(!1);for(;!t;){if(Oe(je)&&Xe(),Ie(je))e.push(De.Literal.nud.call(je)),Xe();else if(qe&&ke(je))e.push(De[a].nud.call(je)),Xe();else if(Be&&_e(je)){const t=He(0);e.push(t)}else Ze(`Unexpected ${je.type} in array: ${je.value}`);","===je.id?Xe(","):";"===je.id?(Xe(";"),e=[],n.push(e)):t=!0}const r=je;return Xe("}"),tt(l),this.type="ArrayExpression",this.elements=n,this.loc&&(this.loc[1]=r.loc[1]),delete this.value,this}));const ct=(e,t,n)=>Math.min(Math.max(t,e),n);function st(e,t){return t?String(e+1):e?"["+e+"]":""}function at(e){let t=null,n=null,l=null,r=null;const o=/^R(?:\[([+-]?\d+)\]|(\d+))?/.exec(e);o&&(o[1]?(t=parseInt(o[1],10),l=!1):o[2]?(t=parseInt(o[2],10)-1,l=!0):(t=0,l=!1),e=e.slice(o[0].length));const u=/^C(?:\[([+-]?\d+)\]|(\d+))?/.exec(e);return u&&(u[1]?(n=parseInt(u[1],10),r=!1):u[2]?(n=parseInt(u[2],10)-1,r=!0):(n=0,r=!1),e=e.slice(u[0].length)),!o&&!u||e.length?null:[t,n,l,r]}function ft(e){let t=null;const[n,l]=e.split(":",2),r=at(n);if(r){const[e,n,o,u]=r;if(!l)return null!=e&&null==n?{r0:e,c0:null,r1:e,c1:null,$r0:o,$c0:!1,$r1:o,$c1:!1}:null==e&&null!=n?{r0:null,c0:n,r1:null,c1:n,$r0:!1,$c0:u,$r1:!1,$c1:u}:{r0:e||0,c0:n||0,r1:e||0,c1:n||0,$r0:o||!1,$c0:u||!1,$r1:o||!1,$c1:u||!1};{const r=at(l);if(!r)return null;{t={};const[l,i,c,s]=r;null!=e&&null!=l?(t.r0=o===c?Math.min(e,l):e,t.$r0=o,t.r1=o===c?Math.max(e,l):l,t.$r1=c):null!=e&&null==l?(t.r0=e,t.$r0=o,t.r1=null,t.$r1=o):null==e&&null!=l?(t.r0=l,t.$r0=c,t.r1=null,t.$r1=c):null==e&&null==l&&(t.r0=null,t.$r0=!1,t.r1=null,t.$r1=!1),null!=n&&null!=i?(t.c0=u===s?Math.min(n,i):n,t.$c0=u,t.c1=u===s?Math.max(n,i):i,t.$c1=s):null!=n&&null==i?(t.c0=n,t.$c0=u,t.c1=null,t.$c1=u):null==n&&null!=i?(t.c0=i,t.$c0=s,t.c1=null,t.$c1=s):null==n&&null==i&&(t.c0=null,t.$c0=!1,t.c1=null,t.$c1=!1)}}}return t}function pt(e){let{allowNamed:t=!0,allowTernary:n=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const l=C(e,{allowNamed:t,allowTernary:n,r1c1:!0});if(l&&(l.r0||l.name)){const e=l.r1?ft(l.r0+":"+l.r1):ft(l.r0);return l.name||e?(l.range=e,delete l.r0,delete l.r1,l):null}return null}function ht(e){return N(e)+(e.name?e.name:function(e){let{r0:t,c0:n,r1:l,c1:r}=e;const{$c0:o,$c1:u,$r0:i,$r1:c}=e,s=null==t,a=null==n;let f=null==l,p=null==r;if(t=ct(i?0:-1048575,0|t,1048575),n=ct(o?0:-16383,0|n,16383),!s&&f&&!a&&p?(l=t,f=!1,r=n,p=!1):(l=ct(c?0:-1048575,0|l,1048575),r=ct(u?0:-16383,0|r,16383)),0===t&&l>=1048575||s&&f){const e=st(n,o),t=st(r,u);return"C"+(e===t?e:e+":C"+t)}if(0===n&&r>=16383||a&&p){const e=st(t,i),n=st(l,c);return"R"+(e===n?e:e+":R"+n)}const h=st(t,i),g=st(l,c),d=st(n,o),$=st(r,u);return s||f||a||p?(s?"":"R"+h)+(a?"":"C"+d)+":"+(f?"":"R"+g)+(p?"":"C"+$):h!==g||d!==$?"R"+h+"C"+d+":R"+g+"C"+$:"R"+h+"C"+d}(e.range))}const gt=(e,t,n)=>null==t?null:e?t:t-n,dt={withLocation:!1,mergeRefs:!1,allowTernary:!0,r1c1:!1};function $t(e,t,n,l){let r=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],o=e;if(null!=o&&!t){if(o=n+e,o<0){if(!r)return NaN;o=l+o+1}if(o>l){if(!r)return NaN;o-=l+1}}return o}const yt={wrapEdges:!0,mergeRefs:!0};const xt=Object.freeze({OPERATOR:e,BOOLEAN:"bool",ERROR:t,NUMBER:"number",FUNCTION:"func",NEWLINE:"newline",WHITESPACE:"whitespace",STRING:"string",CONTEXT:n,CONTEXT_QUOTE:"context_quote",REF_RANGE:"range",REF_BEAM:l,REF_TERNARY:r,REF_NAMED:o,REF_STRUCT:u,FX_PREFIX:"fx_prefix",UNKNOWN:i}),vt=Object.freeze({UNARY:c,BINARY:s,REFERENCE:a,LITERAL:"Literal",ERROR:"ErrorLiteral",CALL:f,ARRAY:"ArrayExpression",IDENTIFIER:"Identifier"});exports.MAX_COLS=16383,exports.MAX_ROWS=1048575,exports.addA1RangeBounds=M,exports.addTokenMeta=function(e){let{sheetName:t="",workbookName:n=""}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const o=[];let c=null;const s=nt(),a=[],f=()=>o.length+(c?1:0);return e.forEach(((e,p)=>{if(e.index=p,e.depth=f(),"("===e.value)o.push(e),e.depth=f();else if(")"===e.value){const t=o.pop();if(t){const n=s();e.groupId=n,e.depth=t.depth,t.groupId=n}else e.error=!0}else if("{"===e.value)c?e.error=!0:(c=e,e.depth=f());else if("}"===e.value){if(c){const t=s();e.groupId=t,e.depth=c.depth,c.groupId=t}else e.error=!0;c=null}else if("range"===e.type||e.type===l||e.type===r||e.type===u){const l=e.type===u?Z(e.value,{allowTernary:!0}):F(e.value,{allowTernary:!0});if(l&&(l.range||l.columns)){l.source=e.value,it(l,t,n);const r=a.find((e=>ut(e,l)));r?e.groupId=r.groupId:(l.groupId=s(),e.groupId=l.groupId,a.push(l))}}else e.type===i&&(e.error=!0)})),e},exports.fixRanges=function e(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{addBounds:!1};if("string"==typeof t)return e(Ne(t,n),n).map((e=>e.value)).join("");if(!Array.isArray(t))throw new Error("fixRanges expects an array of tokens");const{addBounds:l,r1c1:r}=n;if(r)throw new Error("fixRanges does not have an R1C1 mode");let o=0;return t.map((e=>{const t={...e};e.loc&&(t.loc=[...e.loc]);let n=0;if(t.type===u){const e=H(Z(t.value));n=e.length-t.value.length,t.value=e}else if(be(t)){const e=F(t.value,{allowTernary:!0}),r=e.range;l&&M(r);const o=S(e);n=o.length-t.value.length,t.value=o}return o||n?(t.loc&&(t.loc[0]+=o),o+=n,t.loc&&(t.loc[1]+=o)):o+=n,t}))},exports.fromCol=L,exports.isError=Le,exports.isFunction=_e,exports.isFxPrefix=Ue,exports.isLiteral=Ie,exports.isOperator=Fe,exports.isRange=be,exports.isReference=Te,exports.isWhitespace=Oe,exports.mergeRefTokens=me,exports.nodeTypes=vt,exports.parse=function(e,t){if("string"==typeof e)ze=Ne(e,{withLocation:!0,...t,mergeRefs:!0});else{if(!Array.isArray(e))throw new Error("Parse requires a string or array of tokens.");ze=e}for(qe=t?.permitArrayRanges,Be=t?.permitArrayCalls,We=0;Oe(ze[We])||Ue(ze[We]);)We++;Xe(),tt(!0);const n=He(0);return Xe(Se),n},exports.parseA1Ref=F,exports.parseR1C1Ref=pt,exports.parseStructRef=Z,exports.stringifyA1Ref=S,exports.stringifyR1C1Ref=ht,exports.stringifyStructRef=H,exports.toCol=O,exports.tokenTypes=xt,exports.tokenize=Ne,exports.translateToA1=function(e,n){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:yt;const r=U(n),o="string"==typeof e,u={...yt,...l},i=o?Ne(e,{withLocation:!1,mergeRefs:u.mergeRefs,allowTernary:!0,r1c1:!0}):e;let c=0;return i.forEach((e=>{if(be(e)){const n=e.value,l=pt(n,{allowTernary:!0}),o=l.range,i={},s=$t(o.r0,o.$r0,r.top,1048575,u.wrapEdges),a=$t(o.r1,o.$r1,r.top,1048575,u.wrapEdges);s>a?(i.top=a,i.$top=o.$r1,i.bottom=s,i.$bottom=o.$r0):(i.top=s,i.$top=o.$r0,i.bottom=a,i.$bottom=o.$r1);const f=$t(o.c0,o.$c0,r.left,16383,u.wrapEdges),p=$t(o.c1,o.$c1,r.left,16383,u.wrapEdges);f>p?(i.left=p,i.$left=o.$c1,i.right=f,i.$right=o.$c0):(i.left=f,i.$left=o.$c0,i.right=p,i.$right=o.$c1),isNaN(s)||isNaN(a)||isNaN(f)||isNaN(p)?(e.type=t,e.value="#REF!",delete e.groupId):(l.range=i,e.value=S(l)),e.loc&&(e.loc[0]+=c,c+=e.value.length-n.length,e.loc[1]+=c)}else c&&e.loc&&(e.loc[0]+=c,e.loc[1]+=c)})),o?i.map((e=>e.value)).join(""):i},exports.translateToR1C1=function(e,t){const{top:n,left:l}=U(t),r="string"==typeof e,o=r?Ne(e,dt):e;let u=0;return o.forEach((e=>{if(be(e)){const t=e.value,r=F(t,{allowTernary:!0}),o=r.range,i={};i.r0=gt(o.$top,o.top,n),i.r1=gt(o.$bottom,o.bottom,n),i.c0=gt(o.$left,o.left,l),i.c1=gt(o.$right,o.right,l),i.$r0=o.$top,i.$r1=o.$bottom,i.$c0=o.$left,i.$c1=o.$right,r.range=i,e.value=ht(r),e.loc&&(e.loc[0]+=u,u+=e.value.length-t.length,e.loc[1]+=u)}else u&&e.loc&&(e.loc[0]+=u,e.loc[1]+=u)})),r?o.map((e=>e.value)).join(""):o};
|
|
1
|
+
"use strict";const e="operator",t="error",n="range_beam",l="range_ternary",r="range_named",o="structured",u="unknown",s="UnaryExpression",i="BinaryExpression",c="ReferenceIdentifier",a="CallExpression";function f(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=!1,l="";const r=[],o=()=>{l&&r.push(t?l:{value:l,braced:n}),l=""};for(let t=0;t<e.length;t++){const r=e[t];"["===r?(o(),n=!0):"]"===r?(o(),n=!1):l+=r}return o(),r}function p(e){return{context:f(e,!0)}}function h(e){const t={},n=f(e);if(n.length>1)t.workbookName=n[n.length-2].value,t.sheetName=n[n.length-1].value;else if(1===n.length){const e=n[0];e.braced?t.workbookName=e.value:t.sheetName=e.value}return t}const g=e=>e&&":"===e.value&&{},x=e=>e&&"range"===e.type&&{r0:e.value},d=e=>e&&e.type===l&&{r0:e.value},m=e=>e&&"range"===e.type&&{r1:e.value},$=t=>t&&t.type===e&&"!"===t.value&&{},y=e=>e&&e.type===n&&{r0:e.value},v=e=>e&&e.type===o&&{struct:e.value},E=(e,t)=>{const n=t.xlsx?h:p;return e&&"context"===e.type?n(e.value):e&&"context_quote"===e.type?n(e.value.slice(1,-1).replace(/''/g,"'")):void 0},R=e=>e&&e.type===r&&{name:e.value},w=[[d],[x,g,m],[x],[y],[E,$,d],[E,$,x,g,m],[E,$,x],[E,$,y]],N=w.concat([[R],[E,$,R],[v],[R,v],[E,$,R,v]]);function b(e,t){const n={withLocation:!1,mergeRefs:!1,allowTernary:!1,allowNamed:!0,r1c1:!1,xlsx:!1,...t},l=Oe(e,we,n),r=n.xlsx?{workbookName:"",sheetName:"",r0:"",r1:"",name:""}:{context:[],r0:"",r1:"",name:""};l.length&&"fx_prefix"===l[0].type&&l.shift();const o=n.allowNamed?N:w;for(let e=0;e<o.length;e++){const t={...r};if(o[e].length===l.length){const r=o[e].every(((e,r)=>{const o=e(l[r],n);return Object.assign(t,o),o}));if(r)return t}}return null}const C=/[^0-9A-Za-z._¡¤§¨ª\u00ad¯-\uffff]/;function A(e){let t="",n=0,l=0;const r=e.context||[];for(let e=r.length;e>-1;e--){const o=r[e];if(o){t=(l%2?"["+o+"]":o)+t,n+=C.test(o),l++}}return n&&(t="'"+t.replace(/'/g,"''")+"'"),t?t+"!":t}function T(e){let t="",n=0;const{workbookName:l,sheetName:r}=e;return l&&(t+="["+l+"]",n+=C.test(l)),r&&(t+=r,n+=C.test(r)),n&&(t="'"+t.replace(/'/g,"''")+"'"),t?t+"!":t}const I=(e,t,n)=>Math.min(Math.max(t,e),n),L=(e,t)=>(t?"$":"")+_(e),k=(e,t)=>(t?"$":"")+String(e+1);function O(e){const t=e||"",n=t.length;let l=0;if(n>2){const e=t.charCodeAt(n-3);l+=676*(1+e-(e>95?32:0)-65)}if(n>1){const e=t.charCodeAt(n-2);l+=26*(1+e-(e>95?32:0)-65)}if(n){const e=t.charCodeAt(n-1);l+=e-(e>95?32:0)-65}return l}function _(e){return(e>=702?String.fromCharCode(((e-702)/676-0)%26+65):"")+(e>=26?String.fromCharCode(Math.floor((e/26-1)%26+65)):"")+String.fromCharCode(e%26+65)}function U(e){let{top:t,left:n,bottom:l,right:r}=e;const{$left:o,$right:u,$top:s,$bottom:i}=e,c=null==n,a=null==r,f=null==t,p=null==l;return t=I(0,0|t,1048575),n=I(0,0|n,16383),!c&&!f&&a&&p?(l=t,r=n):(l=I(0,0|l,1048575),r=I(0,0|r,16383)),0===t&&l>=1048575||f&&p?L(n,o)+":"+L(r,u):0===n&&r>=16383||c&&a?k(t,s)+":"+k(l,i):c||f||a||!p?c||!f||a||p?c||f||!a||p?!c||f||a||p?r!==n||l!==t||u!==o||i!==s?L(n,o)+k(t,s)+":"+L(r,u)+k(l,i):L(n,o)+k(t,s):L(r,u)+k(t,s)+":"+k(l,i):L(n,o)+k(t,s)+":"+k(l,i):L(n,o)+k(l,i)+":"+L(r,u):L(n,o)+k(t,s)+":"+L(r,u)}function F(e){const t=/^(?=.)(\$(?=\D))?([A-Za-z]{0,3})?(\$)?([1-9][0-9]{0,6})?$/.exec(e);return t&&(t[2]||t[4])?[t[4]?(n=t[4],+n-1):null,t[2]?O(t[2]):null,!!t[3],!!t[1]]:null;var n}function S(e){let t=null,n=null,l=null,r=null,o=!1,u=!1,s=!1,i=!1;const[c,a,f]=e.split(":");if(f)return null;const p=F(c),h=a?F(a):null;if(!p||a&&!h)return null;if(null!=p[0]&&null!=p[1]?[t,n,o,u]=p:null==p[0]&&null!=p[1]?[,n,,u]=p:null!=p[0]&&null==p[1]&&([t,,o]=p),a)null!=h[0]&&null!=h[1]?[l,r,s,i]=h:null==h[0]&&null!=h[1]?[,r,,i]=h:null!=h[0]&&null==h[1]&&([l,,s]=h);else{if(null==t||null==n)return null;l=t,r=n,s=o,i=u}return null!=r&&(null==n||null!=n&&r<n)&&([n,r,u,i]=[r,n,i,u]),null!=l&&(null==t||null!=t&&l<t)&&([t,l,o,s]=[l,t,s,o]),{top:t,left:n,bottom:l,right:r,$top:o,$left:u,$bottom:s,$right:i}}function M(e){let{allowNamed:t=!0,allowTernary:n=!1,xlsx:l=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=b(e,{allowNamed:t,allowTernary:n,xlsx:l,r1c1:!1});if(r&&(r.r0||r.name)){let e=null;return r.r0&&(e=S(r.r1?r.r0+":"+r.r1:r.r0)),r.name||e?(r.range=e,delete r.r0,delete r.r1,r):null}return null}function D(e){let{xlsx:t=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=t?T(e):A(e);return n+(e.name?e.name:U(e.range))}function j(e){return null==e.top&&(e.top=0,e.$top=!1),null==e.bottom&&(e.bottom=1048575,e.$bottom=!1),null==e.left&&(e.left=0,e.$left=!1),null==e.right&&(e.right=16383,e.$right=!1),e}const z=/^\[('['#@[\]]|[^'#@[\]])+\]/i,W=/^([^#@[\]:]+)/i,Z={headers:1,data:2,totals:4,all:8,"this row":16,"@":16},q=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return Object.freeze(t)},B={0:q(),1:q("headers"),2:q("data"),4:q("totals"),8:q("all"),16:q("this row"),3:q("headers","data"),6:q("data","totals")},P=function(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=z.exec(e);if(n){const e=n[0].slice(1,-1).replace(/'(['#@[\]])/g,"$1");return[n[0],e]}return t&&(n=W.exec(e),n)?[n[0],n[0]]:null};function X(e){const t=[];let n,l,r=0,o=e,u=0;if(!(n=/^(\[\s*)/.exec(o)))return null;if(l=/^\[#([a-z ]+)\]/i.exec(o)){const e=l[1].toLowerCase();if(r+=l[0].length,!Z[e])return null;u|=Z[e]}else if(l=P(o,!1))r+=l[0].length,t.push(l[1].trim());else{let l=!0;for(o=o.slice(n[1].length),r+=n[1].length;l&&(n=/^\[#([a-z ]+)\](\s*,\s*)?/i.exec(o));){const e=n[1].toLowerCase();if(!Z[e])return null;u|=Z[e],o=o.slice(n[0].length),r+=n[0].length,l=!!n[2]}if(l&&(n=/^@/.exec(o))&&(u|=Z["@"],o=o.slice(1),r+=1,l="]"!==o[0]),!(u in B))return null;const s=l?P(e.slice(r)):null;if(s){if(r+=s[0].length,t.push(s[1].trim()),o=e.slice(r),":"===o[0]){o=o.slice(1),r++;const e=P(o);if(!e)return null;r+=e[0].length,t.push(e[1].trim())}l=!1}for(;" "===e[r];)r++;if(l||"]"!==e[r])return null;r++}const s=B[u];return{columns:t,sections:s?s.concat():s,length:r,token:e.slice(0,r)}}function H(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{xlsx:!1};const n=b(e,t);if(n&&n.struct){const e=X(n.struct);if(e&&e.length===n.struct.length)return t.xlsx?{workbookName:n.workbookName,sheetName:n.sheetName,table:n.name,columns:e.columns,sections:e.sections}:{context:n.context,table:n.name,columns:e.columns,sections:e.sections}}return null}function Y(e){return e.replace(/([[\]#'@])/g,"'$1")}function G(e){return!/^[a-zA-Z0-9\u00a1-\uffff]+$/.test(e)}function K(e){return e[0].toUpperCase()+e.slice(1).toLowerCase()}function V(e){let{xlsx:t=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t?T(e):A(e);e.table&&(n+=e.table);const l=e.columns?.length??0,r=e.sections?.length??0;if(1!==r||l)if(r||1!==l){n+="[";const t=1===r&&"this row"===e.sections[0].toLowerCase();t?n+="@":r&&(n+=e.sections.map((e=>`[#${K(e)}]`)).join(","),l&&(n+=",")),t&&1===e.columns.length&&!G(e.columns[0])?n+=Y(e.columns[0]):l&&(n+=e.columns.slice(0,2).map((e=>`[${Y(e)}]`)).join(":")),n+="]"}else n+=`[${Y(e.columns[0])}]`;else n+=`[#${K(e.sections[0])}]`;return n}const Q=/^(?!!)(\[(?:[^\]])+\])?([0-9A-Za-z._¡¤§¨ª\u00ad¯-\uffff]+)?(?=!)/,J=/^'(?:''|[^'])*('|$)(?=!)/,ee="\\$?[A-Z]{1,3}\\$?[1-9][0-9]{0,6}",te="\\$?[A-Z]{1,3}",ne="\\$?[1-9][0-9]{0,6}",le=new RegExp(`^${te}:${te}`,"i"),re=new RegExp(`^${ne}:${ne}`,"i"),oe=new RegExp(`^${ee}`,"i"),ue=new RegExp(`^((${te}|${ne}):${ee}|${ee}:(${te}|${ne}))(?![\\w($.])`,"i"),se="(?:R(?:\\[[+-]?\\d+\\]|[1-9][0-9]{0,6})?)",ie="(?:C(?:\\[[+-]?\\d+\\]|[1-9][0-9]{0,4})?)",ce=new RegExp(`^${ie}(:${ie})?(?=\\W|$)`,"i"),ae=new RegExp(`^${se}(:${se})?(?=\\W|$)`,"i"),fe=new RegExp(`^(?:(?=[RC])${se}${ie})`,"i"),pe=new RegExp(`^(${se}${ie}(:${ie}|:${se})(?![[\\d])|(${se}|${ie})(:${se}${ie}))(?=\\W|$)`,"i"),he=/^(?![CR]\b)[a-zA-Z\\_\u00a1-\uffff][a-zA-Z0-9\\_.?\u00a1-\uffff]{0,254}/i;function ge(e,t){return n=>{const l=t.exec(n);if(l)return{type:e,value:l[0]}}}const xe=/^'(?:[^[\]]+?)?(?:\[(.+?)\])?(?:[^[\]]+?)'$/,de=/^'\[(.+?)\]'$/;function me(e,t){const n=J.exec(e);if(n){const e=n[0];if(t.xlsx&&de.test(e)||xe.test(e))return{type:"context_quote",value:e}}const l=Q.exec(e);if(l){const[,e,n]=l;if(e&&n||n||e&&!n&&t.xlsx)return{type:"context",value:l[0]}}}function $e(e){const t=X(e);if(t){let n=t.length;for(;" "===e[n];)n++;if("!"!==e[n])return{type:o,value:t.token}}return null}const ye=/([RC])(\[?)(-?\d+)/gi,ve=/(\d+|[a-zA-Z]+)/gi;function Ee(e,t){let r,o;if(t.r1c1){if(t.allowTernary&&(r=pe.exec(e))?o={type:l,value:r[0]}:(r=fe.exec(e))?o={type:"range",value:r[0]}:((r=ae.exec(e))||(r=ce.exec(e)))&&(o={type:n,value:r[0]}),o){for(ye.lastIndex=0;null!==(r=ye.exec(o.value));){const e=("R"===r[1]?1048575:16383)+(r[2]?1:0),t=parseInt(r[3],10);if(t>=e||t<=-e)return null}return o}}else if(t.allowTernary&&(r=ue.exec(e))?o={type:l,value:r[0]}:(r=le.exec(e))||(r=re.exec(e))?o={type:n,value:r[0]}:(r=oe.exec(e))&&(o={type:"range",value:r[0]}),o){for(ve.lastIndex=0;null!==(r=ve.exec(o.value));)if(/^\d/.test(r[1])){if(parseInt(r[1],10)-1>1048575)return null}else if(O(r[1])>16383)return null;return o}}const Re=[ge(t,/^#(NAME\?|FIELD!|CALC!|VALUE!|REF!|DIV\/0!|NULL!|NUM!|N\/A|GETTING_DATA\b|SPILL!|UNKNOWN!|FIELD\b|CALC\b|SYNTAX\?|ERROR!|CONNECT!|BLOCKED!|EXTERNAL!)/i),ge(e,/^(<=|>=|<>|[-+/*^%&<>=]|[{},;]|[()]|@|:|!|#)/),ge("func",/^[A-Z_]+[A-Z\d_.]*(?=\()/i),ge("bool",/^(TRUE|FALSE)\b/i),ge("newline",/^\n+/),ge("whitespace",/^[ \f\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/),ge("string",/^"(?:""|[^"])*("|$)/),me,Ee,$e,ge("number",/^(?:\d+(\.\d+)?(?:[eE][+-]?\d+)?|\d+)/),ge(r,he)],we=[function(t,n){return n.r1c1?"!"===t[0]?{type:e,value:t[0]}:null:"!"===t[0]||":"===t[0]?{type:e,value:t[0]}:null},me,Ee,$e,ge(r,he)],Ne={};function be(e,t){if(e.length){const n=e[0];t[n]=t[n]||{},be(e.slice(1),t[n])}else t.$=!0}[["range",":","range"],["range"],[n],[l],["context","!","range",":","range"],["context","!","range"],["context","!",n],["context","!",l],["context_quote","!","range",":","range"],["context_quote","!","range"],["context_quote","!",n],["context_quote","!",l],[r],["context","!",r],["context_quote","!",r],[o],[r,o],["context","!",r,o],["context_quote","!",r,o]].forEach((e=>be(e.concat().reverse(),Ne)));const Ce=function(t,n,l){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;const o=t[l-r];if(o){const u=o.type===e?o.value:o.type;if(u in n)return Ce(t,n[u],l,r+1)}return n.$?r:0};function Ae(e){const t=[];for(let n=e.length-1;n>=0;n--){let l=e[n];const r=Ce(e,Ne,n);if(r){const t=e.slice(n-r+1,n+1);l={...l},l.value=t.map((e=>e.value)).join(""),l.loc&&t[0].loc&&(l.loc[0]=t[0].loc[0]),n-=r-1}t.unshift(l)}return t}const Te=(e,t)=>e&&e.type===t,Ie={withLocation:!1,mergeRefs:!0,allowTernary:!1,negativeNumbers:!0,r1c1:!1},Le=e=>e.type===r||"func"===e.type,ke=t=>!Te(t,e)||"%"===t.value||"}"===t.value||")"===t.value||"#"===t.value;function Oe(t,n){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const r=Object.assign({},Ie,l),{withLocation:o,mergeRefs:s,negativeNumbers:i}=r,c=[];let a=0,f=null,p=null,h=null;const g=e=>{const t=e.type===u,n=h&&h.type===u;h&&(t&&n||t&&Le(h)||n&&Le(e))?(h.value+=e.value,h.type=u,o&&(h.loc[1]=e.loc[1])):(c.push(e),h=e,"whitespace"!==e.type&&"newline"!==e.type&&(p=f,f=e))};if(/^=/.test(t)){a++,g({type:"fx_prefix",value:"=",...o?{loc:[0,1]}:{}})}for(;a<t.length;){const l=a,s=t.slice(a);let x="",d="";for(let e=0;e<n.length;e++){const t=n[e](s,r);if(t){x=t.type,d=t.value,a+=d.length;break}}x||(x=u,d=t[a],a++);const m={type:x,value:d,...o?{loc:[l,a]}:{}};if("string"===x){const e=d.length;if('""'===d);else if('"'===d||'"'!==d[e-1])m.unterminated=!0;else if('""'!==d&&'"'===d[e-2]){let t=e-1;for(;'"'===d[t];)t--;!(t+1)^(e-t+1)%2==0&&(m.unterminated=!0)}}if(i&&"number"===x){const t=h;if(t&&Te(t,e)&&"-"===t.value&&(!p||Te(p,"fx_prefix")||!ke(p))){const e=c.pop();m.value="-"+d,o&&(m.loc[0]=e.loc[0]),f=p,h=c[c.length-1]}}g(m)}return s?Ae(c):c}function _e(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return Oe(e,Re,t)}function Ue(e){return!!e&&("range"===e.type||e.type===n||e.type===l)}function Fe(e){return!!e&&("range"===e.type||e.type===n||e.type===l||e.type===o||e.type===r)}function Se(e){return!!e&&("bool"===e.type||e.type===t||"number"===e.type||"string"===e.type)}function Me(e){return!!e&&e.type===t}function De(e){return!!e&&("whitespace"===e.type||"newline"===e.type)}function je(e){return!!e&&"func"===e.type}function ze(e){return!!e&&"fx_prefix"===e.type}function We(t){return!!t&&t.type===e}const Ze="(END)",qe=["ANCHORARRAY","CHOOSE","DROP","IF","IFS","INDEX","INDIRECT","LAMBDA","LET","OFFSET","REDUCE","SINGLE","SWITCH","TAKE","XLOOKUP"],Be=e=>!!e&&(e.type===c||("ErrorLiteral"===e.type||e.type===t)&&"#REF!"===e.value||e.type===i&&(":"===e.operator||" "===e.operator||","===e.operator)||e.type===a&&qe.includes(e.callee.name.toUpperCase())),Pe={};let Xe,He,Ye,Ge=!1,Ke=!1;function Ve(e){const t=new Error(e);throw t.source=He.map((e=>e.value)).join(""),t.sourceOffset=He.slice(0,Ye).reduce(((e,t)=>e+t.value),"").length,t}function Qe(){let e,t=Ye;do{e=He[++t]}while(e&&(De(e)||We(e)&&"("===e.value));return(e=>{const t=(e&&e.value)+"";return!(!Fe(e)&&(!We(e)||":"!==t&&","!==t&&t.trim())&&(!je(e)||!qe.includes(t.toUpperCase()))&&(!Me(e)||"#REF!"!==t))})(e)}function Je(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(e&&e!==Xe.id&&Ve(`Expected ${e} but got ${Xe.id}`),De(He[Ye])){if(!(Be(t)&&Qe()))for(;De(He[Ye]);)Ye++}if(Ye>=He.length)return void(Xe=Pe[Ze]);const n=He[Ye];let l;Ye+=1,n.unterminated&&Ve("Encountered an unterminated token");let r=n.type;return We(n)?(l=Pe[n.value],l||Ve(`Unknown operator ${n.value}`)):De(n)?l=Pe["(WHITESPACE)"]:Se(n)?l=Pe.Literal:Fe(n)?(l=Pe[c],r=c):je(n)?l=Pe["(FUNCTION)"]:Ve(`Unexpected ${n.type} token: ${n.value}`),Xe=Object.create(l),Xe.type=r,Xe.value=n.value,n.loc&&(Xe.loc=[...n.loc]),Xe}function et(e){let t=Xe;Je(null,t);let n=t.nud();for(;e<Xe.lbp;)t=Xe,Je(null,t),n=t.led(n);return n}const tt={nud:()=>Ve("Invalid syntax"),led:()=>Ve("Missing operator")};function nt(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=Pe[e];return n?t>=n.lbp&&(n.lbp=t):(n={...tt},n.id=e,n.value=e,n.lbp=t,Pe[e]=n),n}function lt(e,t,n){const l=nt(e,t);return l.led=n||function(e){this.type=i,this.operator=this.value,delete this.value;const n=et(t);return this.arguments=[e,n],this.loc&&(this.loc=[e.loc[0],n.loc[1]]),this},l}function rt(e,t){const n=nt(e,0);return n.lbp=70,n.led=t||function(e){return this.type=s,this.operator=this.value,delete this.value,this.arguments=[e],this.loc&&(this.loc[0]=e.loc[0]),this},n}function ot(e,t){const n=nt(e);return n.nud=t||function(){this.type=s,this.operator=this.value,delete this.value;const e=et(70);return this.arguments=[e],this.loc&&(this.loc[1]=e.loc[1]),this},n}function ut(e,t){return lt(e,t,(function(n){Be(n)||Ve(`Unexpected ${e} operator`);const l=et(t);return Be(l)||Ve(`Unexpected ${Xe.type} following ${this.id}`),this.type=i,this.operator=this.value.trim()?this.value:" ",delete this.value,this.arguments=[n,l],this.loc&&(this.loc=[n.loc[0],l.loc[1]]),this}))}nt(Ze),ut(":",80);const st=ut(",",80);ut("(WHITESPACE)",80);const it=e=>{const t=st.lbp>0;return null!=e&&(st.lbp=e?80:0),t};function ct(){let e=1;return()=>"fxg"+e++}function at(e,t){return null==e&&null==t||e===t}function ft(e,t){if(Array.isArray(e)!==Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!at(e[n],t[n]))return!1;return!0}function pt(e,t){return!e&&!t||String(e).toLowerCase()===String(t).toLowerCase()}function ht(e,t){if((e.name||t.name)&&e.name!==t.name)return!1;if(e.columns||t.columns){if(e.table!==t.table)return!1;if(!ft(e.columns,t.columns))return!1;if(!ft(e.sections,t.sections))return!1}return!!(!e.range&&!t.range||at(e.range.top,t.range.top)&&at(e.range.bottom,t.range.bottom)&&at(e.range.left,t.range.left)&&at(e.range.right,t.range.right))&&!(!pt(e.workbookName,t.workbookName)||!pt(e.sheetName,t.sheetName))}function gt(e,t,n){return e.sheetName||(e.sheetName=t),e.workbookName||(e.workbookName=n),e}rt("%"),rt("#",(function(e){return Be(e)||Ve("# expects a reference"),this.type=s,this.operator=this.value,delete this.value,this.arguments=[e],this})),ot("+"),ot("-"),ot("@"),lt("^",50),lt("*",40),lt("/",40),lt("+",30),lt("-",30),lt("&",20),lt("=",10),lt("<",10),lt(">",10),lt("<=",10),lt(">=",10),lt("<>",10),nt("Literal").nud=function(){const{type:e,value:n}=this;if(this.type="Literal",this.raw=n,"number"===e)this.value=+n;else if("bool"===e)this.value="TRUE"===n.toUpperCase();else if(e===t)this.type="ErrorLiteral",this.value=n.toUpperCase();else{if("string"!==e)throw new Error("Unsupported literal type: "+e);this.value=n.slice(1,-1).replace(/""/g,'"')}return this},nt(c).nud=function(){return this.type=c,this},nt(")"),ot("(",(function(){const e=it(!0),t=et(0);return Je(")",t),it(e),t})),nt("(FUNCTION)").nud=function(){return this},lt("(",90,(function(e){"(FUNCTION)"!==e.id&&Ve("Cannot call a "+e.type);const t=[];let n=!1;if(")"!==Xe.id){const e=it(!1);for(;")"!==Xe.id;)if(De(Xe)&&Je(),","===Xe.id)t.push(null),n=!0,Je();else{const e=et(0);t.push(e),n=!1,","===Xe.id&&(Je(","),n=!0)}it(e)}n&&t.push(null);const l=Xe;return delete this.value,this.type=a,this.callee={type:"Identifier",name:e.value},e.loc&&(this.callee.loc=[...e.loc]),this.arguments=t,e.loc&&(this.loc=[e.loc[0],l.loc[1]]),Je(")",this),this})),nt("}"),nt(";"),ot("{",(function(){"}"===Xe.id&&Ve("Unexpected empty array");let e=[],t=!1;const n=[e],l=it(!1);for(;!t;){if(De(Xe)&&Je(),Se(Xe))e.push(Pe.Literal.nud.call(Xe)),Je();else if(Ge&&Be(Xe))e.push(Pe[c].nud.call(Xe)),Je();else if(Ke&&je(Xe)){const t=et(0);e.push(t)}else Ve(`Unexpected ${Xe.type} in array: ${Xe.value}`);","===Xe.id?Je(","):";"===Xe.id?(Je(";"),e=[],n.push(e)):t=!0}const r=Xe;return Je("}"),it(l),this.type="ArrayExpression",this.elements=n,this.loc&&(this.loc[1]=r.loc[1]),delete this.value,this}));const xt=(e,t,n)=>Math.min(Math.max(t,e),n);function dt(e,t){return t?String(e+1):e?"["+e+"]":""}function mt(e){let{r0:t,c0:n,r1:l,c1:r}=e;const{$c0:o,$c1:u,$r0:s,$r1:i}=e,c=null==t,a=null==n;let f=null==l,p=null==r;if(t=xt(s?0:-1048575,0|t,1048575),n=xt(o?0:-16383,0|n,16383),!c&&f&&!a&&p?(l=t,f=!1,r=n,p=!1):(l=xt(i?0:-1048575,0|l,1048575),r=xt(u?0:-16383,0|r,16383)),0===t&&l>=1048575||c&&f){const e=dt(n,o),t=dt(r,u);return"C"+(e===t?e:e+":C"+t)}if(0===n&&r>=16383||a&&p){const e=dt(t,s),n=dt(l,i);return"R"+(e===n?e:e+":R"+n)}const h=dt(t,s),g=dt(l,i),x=dt(n,o),d=dt(r,u);return c||f||a||p?(c?"":"R"+h)+(a?"":"C"+x)+":"+(f?"":"R"+g)+(p?"":"C"+d):h!==g||x!==d?"R"+h+"C"+x+":R"+g+"C"+d:"R"+h+"C"+x}function $t(e){let t=null,n=null,l=null,r=null;const o=/^R(?:\[([+-]?\d+)\]|(\d+))?/.exec(e);o&&(o[1]?(t=parseInt(o[1],10),l=!1):o[2]?(t=parseInt(o[2],10)-1,l=!0):(t=0,l=!1),e=e.slice(o[0].length));const u=/^C(?:\[([+-]?\d+)\]|(\d+))?/.exec(e);return u&&(u[1]?(n=parseInt(u[1],10),r=!1):u[2]?(n=parseInt(u[2],10)-1,r=!0):(n=0,r=!1),e=e.slice(u[0].length)),!o&&!u||e.length?null:[t,n,l,r]}function yt(e){let t=null;const[n,l]=e.split(":",2),r=$t(n);if(r){const[e,n,o,u]=r;if(!l)return null!=e&&null==n?{r0:e,c0:null,r1:e,c1:null,$r0:o,$c0:!1,$r1:o,$c1:!1}:null==e&&null!=n?{r0:null,c0:n,r1:null,c1:n,$r0:!1,$c0:u,$r1:!1,$c1:u}:{r0:e||0,c0:n||0,r1:e||0,c1:n||0,$r0:o||!1,$c0:u||!1,$r1:o||!1,$c1:u||!1};{const r=$t(l);if(!r)return null;{t={};const[l,s,i,c]=r;null!=e&&null!=l?(t.r0=o===i?Math.min(e,l):e,t.$r0=o,t.r1=o===i?Math.max(e,l):l,t.$r1=i):null!=e&&null==l?(t.r0=e,t.$r0=o,t.r1=null,t.$r1=o):null==e&&null!=l?(t.r0=l,t.$r0=i,t.r1=null,t.$r1=i):null==e&&null==l&&(t.r0=null,t.$r0=!1,t.r1=null,t.$r1=!1),null!=n&&null!=s?(t.c0=u===c?Math.min(n,s):n,t.$c0=u,t.c1=u===c?Math.max(n,s):s,t.$c1=c):null!=n&&null==s?(t.c0=n,t.$c0=u,t.c1=null,t.$c1=u):null==n&&null!=s?(t.c0=s,t.$c0=c,t.c1=null,t.$c1=c):null==n&&null==s&&(t.c0=null,t.$c0=!1,t.c1=null,t.$c1=!1)}}}return t}function vt(e){let{allowNamed:t=!0,allowTernary:n=!1,xlsx:l=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=b(e,{allowNamed:t,allowTernary:n,xlsx:l,r1c1:!0});if(r&&(r.r0||r.name)){const e=r.r1?yt(r.r0+":"+r.r1):yt(r.r0);return r.name||e?(r.range=e,delete r.r0,delete r.r1,r):null}return null}function Et(e){let{xlsx:t=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=t?T(e):A(e);return n+(e.name?e.name:mt(e.range))}const Rt=(e,t,n)=>null==t?null:e?t:t-n,wt={withLocation:!1,mergeRefs:!1,allowTernary:!0,r1c1:!1};function Nt(e,t,n,l){let r=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],o=e;if(null!=o&&!t){if(o=n+e,o<0){if(!r)return NaN;o=l+o+1}if(o>l){if(!r)return NaN;o-=l+1}}return o}const bt={wrapEdges:!0,mergeRefs:!0,xlsx:!1};const Ct=Object.freeze({OPERATOR:e,BOOLEAN:"bool",ERROR:t,NUMBER:"number",FUNCTION:"func",NEWLINE:"newline",WHITESPACE:"whitespace",STRING:"string",CONTEXT:"context",CONTEXT_QUOTE:"context_quote",REF_RANGE:"range",REF_BEAM:n,REF_TERNARY:l,REF_NAMED:r,REF_STRUCT:o,FX_PREFIX:"fx_prefix",UNKNOWN:u}),At=Object.freeze({UNARY:s,BINARY:i,REFERENCE:c,LITERAL:"Literal",ERROR:"ErrorLiteral",CALL:a,ARRAY:"ArrayExpression",IDENTIFIER:"Identifier"});exports.MAX_COLS=16383,exports.MAX_ROWS=1048575,exports.addA1RangeBounds=j,exports.addTokenMeta=function(e){let{sheetName:t="",workbookName:r=""}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=[];let i=null;const c=ct(),a=[],f=()=>s.length+(i?1:0);return e.forEach(((e,p)=>{if(e.index=p,e.depth=f(),"("===e.value)s.push(e),e.depth=f();else if(")"===e.value){const t=s.pop();if(t){const n=c();e.groupId=n,e.depth=t.depth,t.groupId=n}else e.error=!0}else if("{"===e.value)i?e.error=!0:(i=e,e.depth=f());else if("}"===e.value){if(i){const t=c();e.groupId=t,e.depth=i.depth,i.groupId=t}else e.error=!0;i=null}else if("range"===e.type||e.type===n||e.type===l||e.type===o){const n=e.type===o?H(e.value,{allowTernary:!0,xlsx:!0}):M(e.value,{allowTernary:!0,xlsx:!0});if(n&&(n.range||n.columns)){n.source=e.value,gt(n,t,r);const l=a.find((e=>ht(e,n)));l?e.groupId=l.groupId:(n.groupId=c(),e.groupId=n.groupId,a.push(n))}}else e.type===u&&(e.error=!0)})),e},exports.fixRanges=function e(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{addBounds:!1};if("string"==typeof t)return e(_e(t,n),n).map((e=>e.value)).join("");if(!Array.isArray(t))throw new Error("fixRanges expects an array of tokens");const{addBounds:l,r1c1:r,xlsx:u}=n;if(r)throw new Error("fixRanges does not have an R1C1 mode");let s=0;return t.map((e=>{const t={...e};e.loc&&(t.loc=[...e.loc]);let n=0;if(t.type===o){const e=V(H(t.value,{xlsx:u}),{xlsx:u});n=e.length-t.value.length,t.value=e}else if(Ue(t)){const e=M(t.value,{xlsx:u,allowTernary:!0}),r=e.range;l&&j(r);const o=D(e,{xlsx:u});n=o.length-t.value.length,t.value=o}return s||n?(t.loc&&(t.loc[0]+=s),s+=n,t.loc&&(t.loc[1]+=s)):s+=n,t}))},exports.fromCol=O,exports.isError=Me,exports.isFunction=je,exports.isFxPrefix=ze,exports.isLiteral=Se,exports.isOperator=We,exports.isRange=Ue,exports.isReference=Fe,exports.isWhitespace=De,exports.mergeRefTokens=Ae,exports.nodeTypes=At,exports.parse=function(e,t){if("string"==typeof e)He=_e(e,{withLocation:!0,...t,mergeRefs:!0});else{if(!Array.isArray(e))throw new Error("Parse requires a string or array of tokens.");He=e}for(Ge=t?.permitArrayRanges,Ke=t?.permitArrayCalls,Ye=0;De(He[Ye])||ze(He[Ye]);)Ye++;Je(),it(!0);const n=et(0);return Je(Ze),n},exports.parseA1Ref=M,exports.parseR1C1Ref=vt,exports.parseStructRef=H,exports.stringifyA1Ref=D,exports.stringifyR1C1Ref=Et,exports.stringifyStructRef=V,exports.toCol=_,exports.tokenTypes=Ct,exports.tokenize=_e,exports.translateToA1=function(e,n){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:bt;const r=S(n),o="string"==typeof e,u={...bt,...l},s=o?_e(e,{withLocation:!1,mergeRefs:u.mergeRefs,xlsx:u.xlsx,allowTernary:!0,r1c1:!0}):e;let i=0;const c={xlsx:u.xlsx,allowTernary:!0};return s.forEach((e=>{if(Ue(e)){const n=e.value,l=vt(n,c),o=l.range,s={},a=Nt(o.r0,o.$r0,r.top,1048575,u.wrapEdges),f=Nt(o.r1,o.$r1,r.top,1048575,u.wrapEdges);a>f?(s.top=f,s.$top=o.$r1,s.bottom=a,s.$bottom=o.$r0):(s.top=a,s.$top=o.$r0,s.bottom=f,s.$bottom=o.$r1);const p=Nt(o.c0,o.$c0,r.left,16383,u.wrapEdges),h=Nt(o.c1,o.$c1,r.left,16383,u.wrapEdges);p>h?(s.left=h,s.$left=o.$c1,s.right=p,s.$right=o.$c0):(s.left=p,s.$left=o.$c0,s.right=h,s.$right=o.$c1),isNaN(a)||isNaN(f)||isNaN(p)||isNaN(h)?(e.type=t,e.value="#REF!",delete e.groupId):(l.range=s,e.value=D(l,c)),e.loc&&(e.loc[0]+=i,i+=e.value.length-n.length,e.loc[1]+=i)}else i&&e.loc&&(e.loc[0]+=i,e.loc[1]+=i)})),o?s.map((e=>e.value)).join(""):s},exports.translateToR1C1=function(e,t){let{xlsx:n=!1}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{top:l,left:r}=S(t),o="string"==typeof e,u=o?_e(e,{...wt,xlsx:n}):e;let s=0;const i={xlsx:n,allowTernary:!0};return u.forEach((e=>{if(Ue(e)){const t=e.value,n=M(t,i),o=n.range,u={};u.r0=Rt(o.$top,o.top,l),u.r1=Rt(o.$bottom,o.bottom,l),u.c0=Rt(o.$left,o.left,r),u.c1=Rt(o.$right,o.right,r),u.$r0=o.$top,u.$r1=o.$bottom,u.$c0=o.$left,u.$c1=o.$right,n.range=u,e.value=Et(n,i),e.loc&&(e.loc[0]+=s,s+=e.value.length-t.length,e.loc[1]+=s)}else s&&e.loc&&(e.loc[0]+=s,e.loc[1]+=s)})),o?u.map((e=>e.value)).join(""):u};
|
|
2
2
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZnguanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
|
package/docs/API.md
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
|
-
#
|
|
1
|
+
# _Fx_ API
|
|
2
|
+
|
|
3
|
+
**Constants**
|
|
4
|
+
|
|
5
|
+
- [nodeTypes](#nodeTypes)
|
|
6
|
+
- [tokenTypes](#tokenTypes)
|
|
7
|
+
|
|
8
|
+
**Functions**
|
|
9
|
+
|
|
10
|
+
- [addA1RangeBounds( range )](#addA1RangeBounds)
|
|
11
|
+
- [addTokenMeta( tokenlist, _\[context\]_ )](#addTokenMeta)
|
|
12
|
+
- [fixRanges( formula, _\[options\]_ )](#fixRanges)
|
|
13
|
+
- [fromCol( columnString )](#fromCol)
|
|
14
|
+
- [isError( token )](#isError)
|
|
15
|
+
- [isFunction( token )](#isFunction)
|
|
16
|
+
- [isFxPrefix( token )](#isFxPrefix)
|
|
17
|
+
- [isLiteral( token )](#isLiteral)
|
|
18
|
+
- [isOperator( token )](#isOperator)
|
|
19
|
+
- [isRange( token )](#isRange)
|
|
20
|
+
- [isReference( token )](#isReference)
|
|
21
|
+
- [isWhitespace( token )](#isWhitespace)
|
|
22
|
+
- [mergeRefTokens( tokenlist )](#mergeRefTokens)
|
|
23
|
+
- [parse( formula, _\[options\]_ )](#parse)
|
|
24
|
+
- [parseA1Ref( refString, _\[options\]_ )](#parseA1Ref)
|
|
25
|
+
- [parseR1C1Ref( refString, _\[options\]_ )](#parseR1C1Ref)
|
|
26
|
+
- [parseStructRef( ref, _\[options\]_ )](#parseStructRef)
|
|
27
|
+
- [stringifyA1Ref( refObject, _\[options\]_ )](#stringifyA1Ref)
|
|
28
|
+
- [stringifyR1C1Ref( refObject, _\[options\]_ )](#stringifyR1C1Ref)
|
|
29
|
+
- [stringifyStructRef( refObject, _\[options\]_ )](#stringifyStructRef)
|
|
30
|
+
- [toCol( columnIndex )](#toCol)
|
|
31
|
+
- [tokenize( formula, _\[options\]_ )](#tokenize)
|
|
32
|
+
- [translateToA1( formula, anchorCell, _\[options\]_ )](#translateToA1)
|
|
33
|
+
- [translateToR1C1( formula, anchorCell, _\[options\]_ )](#translateToR1C1)
|
|
2
34
|
|
|
3
35
|
## Constants
|
|
4
36
|
|
|
@@ -143,7 +175,9 @@ All will be tagged with `.error` (boolean `true`).
|
|
|
143
175
|
|
|
144
176
|
### <a name="fixRanges" href="#fixRanges">#</a> fixRanges( formula, _[options = `{}`]_ ) ⇒ `string` | `Array.<Object>`
|
|
145
177
|
|
|
146
|
-
Normalizes A1 style ranges in a formula or list of tokens
|
|
178
|
+
Normalizes A1 style ranges and structured references in a formula or list of tokens.
|
|
179
|
+
|
|
180
|
+
It ensures that that the top and left coordinates of an A1 range are on the left-hand side of a colon operator:
|
|
147
181
|
|
|
148
182
|
`B2:A1` → `A1:B2`
|
|
149
183
|
`1:A1` → `A1:1`
|
|
@@ -161,6 +195,8 @@ When `{ addBounds: true }` is passed as an option, the missing bounds are also a
|
|
|
161
195
|
`B2:B` → `B2:1048576`
|
|
162
196
|
`B2:2` → `B2:XFD2`
|
|
163
197
|
|
|
198
|
+
Structured ranges are normalized cleaned up to have consistent order and capitalization of sections as well as removing redundant ones.
|
|
199
|
+
|
|
164
200
|
Returns the same formula with the ranges updated. If an array of tokens was supplied, then a new array is returned.
|
|
165
201
|
|
|
166
202
|
#### Parameters
|
|
@@ -170,7 +206,7 @@ Returns the same formula with the ranges updated. If an array of tokens was supp
|
|
|
170
206
|
| formula | `string` \| `Array.<Object>` | | A string (an Excel formula) or a token list that should be adjusted. |
|
|
171
207
|
| _[options]_ | `Object` | `{}` | Options |
|
|
172
208
|
| _[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. |
|
|
173
|
-
| _[options]_.
|
|
209
|
+
| _[options]_.xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
|
|
174
210
|
|
|
175
211
|
#### Returns
|
|
176
212
|
|
|
@@ -362,7 +398,7 @@ Parses a string formula or list of tokens into an AST.
|
|
|
362
398
|
|
|
363
399
|
The parser requires `mergeRefs` to have been `true` in tokenlist options, because it does not recognize reference context tokens.
|
|
364
400
|
|
|
365
|
-
The AST Abstract Syntax Tree's format is documented in [AST_format.md]
|
|
401
|
+
The AST Abstract Syntax Tree's format is documented in [AST_format.md](./AST_format.md)
|
|
366
402
|
|
|
367
403
|
**See also:** [nodeTypes](#nodeTypes).
|
|
368
404
|
|
|
@@ -378,7 +414,8 @@ The AST Abstract Syntax Tree's format is documented in [AST_format.md][./AST_for
|
|
|
378
414
|
| _[options]_.permitArrayRanges | `boolean` | `false` | Ranges are allowed as elements of arrays. This is a feature in Google Sheets while Excel does not allow it. |
|
|
379
415
|
| _[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. |
|
|
380
416
|
| _[options]_.r1c1 | `boolean` | `false` | Ranges are expected to be in the R1C1 style format rather than the more popular A1 style. |
|
|
381
|
-
| _[options]_.withLocation | `boolean` | `
|
|
417
|
+
| _[options]_.withLocation | `boolean` | `false` | Nodes will include source position offsets to the tokens: `{ loc: [ start, end ] }` |
|
|
418
|
+
| _[options]_.xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
|
|
382
419
|
|
|
383
420
|
#### Returns
|
|
384
421
|
|
|
@@ -417,6 +454,7 @@ For A:A or A1:A style ranges, `null` will be used for any dimensions that the sy
|
|
|
417
454
|
| _[options]_ | `Object` | `{}` | Options |
|
|
418
455
|
| _[options]_.allowNamed | `boolean` | `true` | Enable parsing names as well as ranges. |
|
|
419
456
|
| _[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. |
|
|
457
|
+
| _[options]_.xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
|
|
420
458
|
|
|
421
459
|
#### Returns
|
|
422
460
|
|
|
@@ -453,6 +491,7 @@ parseR1C1Ref('Sheet1!R[9]C9:R[9]C9');
|
|
|
453
491
|
| _[options]_ | `Object` | `{}` | Options |
|
|
454
492
|
| _[options]_.allowNamed | `boolean` | `true` | Enable parsing names as well as ranges. |
|
|
455
493
|
| _[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. |
|
|
494
|
+
| _[options]_.xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
|
|
456
495
|
|
|
457
496
|
#### Returns
|
|
458
497
|
|
|
@@ -482,6 +521,7 @@ For A:A or A1:A style ranges, `null` will be used for any dimensions that the sy
|
|
|
482
521
|
| ---- | ---- | ------- | ----------- |
|
|
483
522
|
| ref | `string` | | A structured reference string |
|
|
484
523
|
| _[options]_ | `Object` | `{}` | Options |
|
|
524
|
+
| _[options]_.xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
|
|
485
525
|
|
|
486
526
|
#### Returns
|
|
487
527
|
|
|
@@ -489,7 +529,7 @@ For A:A or A1:A style ranges, `null` will be used for any dimensions that the sy
|
|
|
489
529
|
|
|
490
530
|
---
|
|
491
531
|
|
|
492
|
-
### <a name="stringifyA1Ref" href="#stringifyA1Ref">#</a> stringifyA1Ref( refObject ) ⇒ `Object`
|
|
532
|
+
### <a name="stringifyA1Ref" href="#stringifyA1Ref">#</a> stringifyA1Ref( refObject, _[options = `{}`]_ ) ⇒ `Object`
|
|
493
533
|
|
|
494
534
|
Get an A1-style string representation of a reference object.
|
|
495
535
|
|
|
@@ -512,9 +552,11 @@ stringifyA1Ref({
|
|
|
512
552
|
|
|
513
553
|
#### Parameters
|
|
514
554
|
|
|
515
|
-
| Name | Type | Description |
|
|
516
|
-
| ---- | ---- | ----------- |
|
|
517
|
-
| refObject | `Object` | A reference object |
|
|
555
|
+
| Name | Type | Default | Description |
|
|
556
|
+
| ---- | ---- | ------- | ----------- |
|
|
557
|
+
| refObject | `Object` | | A reference object |
|
|
558
|
+
| _[options]_ | `Object` | `{}` | Options |
|
|
559
|
+
| _[options]_.xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
|
|
518
560
|
|
|
519
561
|
#### Returns
|
|
520
562
|
|
|
@@ -522,7 +564,7 @@ stringifyA1Ref({
|
|
|
522
564
|
|
|
523
565
|
---
|
|
524
566
|
|
|
525
|
-
### <a name="stringifyR1C1Ref" href="#stringifyR1C1Ref">#</a> stringifyR1C1Ref( refObject ) ⇒ `Object`
|
|
567
|
+
### <a name="stringifyR1C1Ref" href="#stringifyR1C1Ref">#</a> stringifyR1C1Ref( refObject, _[options = `{}`]_ ) ⇒ `Object`
|
|
526
568
|
|
|
527
569
|
Get an R1C1-style string representation of a reference object.
|
|
528
570
|
|
|
@@ -545,9 +587,11 @@ stringifyR1C1Ref({
|
|
|
545
587
|
|
|
546
588
|
#### Parameters
|
|
547
589
|
|
|
548
|
-
| Name | Type | Description |
|
|
549
|
-
| ---- | ---- | ----------- |
|
|
550
|
-
| refObject | `Object` | A reference object |
|
|
590
|
+
| Name | Type | Default | Description |
|
|
591
|
+
| ---- | ---- | ------- | ----------- |
|
|
592
|
+
| refObject | `Object` | | A reference object |
|
|
593
|
+
| _[options]_ | `Object` | `{}` | Options |
|
|
594
|
+
| _[options]_.xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
|
|
551
595
|
|
|
552
596
|
#### Returns
|
|
553
597
|
|
|
@@ -555,7 +599,7 @@ stringifyR1C1Ref({
|
|
|
555
599
|
|
|
556
600
|
---
|
|
557
601
|
|
|
558
|
-
### <a name="stringifyStructRef" href="#stringifyStructRef">#</a> stringifyStructRef( refObject ) ⇒ `Object`
|
|
602
|
+
### <a name="stringifyStructRef" href="#stringifyStructRef">#</a> stringifyStructRef( refObject, _[options = `{}`]_ ) ⇒ `Object`
|
|
559
603
|
|
|
560
604
|
Get a string representation of a structured reference object.
|
|
561
605
|
|
|
@@ -571,9 +615,11 @@ stringifyStructRef({
|
|
|
571
615
|
|
|
572
616
|
#### Parameters
|
|
573
617
|
|
|
574
|
-
| Name | Type | Description |
|
|
575
|
-
| ---- | ---- | ----------- |
|
|
576
|
-
| refObject | `Object` | A structured reference object |
|
|
618
|
+
| Name | Type | Default | Description |
|
|
619
|
+
| ---- | ---- | ------- | ----------- |
|
|
620
|
+
| refObject | `Object` | | A structured reference object |
|
|
621
|
+
| _[options]_ | `Object` | `{}` | Options |
|
|
622
|
+
| _[options]_.xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
|
|
577
623
|
|
|
578
624
|
#### Returns
|
|
579
625
|
|
|
@@ -639,6 +685,7 @@ To support syntax highlighting as you type, `STRING` tokens are allowed to be "u
|
|
|
639
685
|
| _[options]_.r1c1 | `boolean` | `false` | Ranges are expected to be in the R1C1 style format rather than the more popular A1 style. |
|
|
640
686
|
| _[options]_.withLocation | `boolean` | `true` | Nodes will include source position offsets to the tokens: `{ loc: [ start, end ] }` |
|
|
641
687
|
| _[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) |
|
|
688
|
+
| _[options]_.xlsx | `boolean` | `false` | Enables a `[1]Sheet1!A1` or `[1]!name` syntax form for external workbooks found only in XLSX files. |
|
|
642
689
|
|
|
643
690
|
#### Returns
|
|
644
691
|
|
|
@@ -650,7 +697,7 @@ To support syntax highlighting as you type, `STRING` tokens are allowed to be "u
|
|
|
650
697
|
|
|
651
698
|
Translates ranges in a formula or list of tokens from relative R1C1 syntax to absolute A1 syntax.
|
|
652
699
|
|
|
653
|
-
Returns the same formula with the ranges translated. If an array of tokens was supplied, then the same array is returned
|
|
700
|
+
Returns the same formula with the ranges translated. If an array of tokens was supplied, then the same array is returned.
|
|
654
701
|
|
|
655
702
|
```js
|
|
656
703
|
translateToA1("=SUM(RC[1],R2C5,Sheet!R3C5)", "D10");
|
|
@@ -678,6 +725,7 @@ Note that if you are passing in a list of tokens that was not created using `mer
|
|
|
678
725
|
| _[options]_ | `Object` | `{}` | The options |
|
|
679
726
|
| _[options]_.wrapEdges | `boolean` | `true` | Wrap out-of-bounds ranges around sheet edges rather than turning them to #REF! errors |
|
|
680
727
|
| _[options]_.mergeRefs | `boolean` | `true` | Should ranges be treated as whole references (`Sheet1!A1:B2`) or as separate tokens for each part: (`Sheet1`,`!`,`A1`,`:`,`B2`). |
|
|
728
|
+
| _[options]_.xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
|
|
681
729
|
|
|
682
730
|
#### Returns
|
|
683
731
|
|
|
@@ -685,11 +733,11 @@ Note that if you are passing in a list of tokens that was not created using `mer
|
|
|
685
733
|
|
|
686
734
|
---
|
|
687
735
|
|
|
688
|
-
### <a name="translateToR1C1" href="#translateToR1C1">#</a> translateToR1C1( formula, anchorCell ) ⇒ `string` | `Array.<Object>`
|
|
736
|
+
### <a name="translateToR1C1" href="#translateToR1C1">#</a> translateToR1C1( formula, anchorCell, _[options = `{}`]_ ) ⇒ `string` | `Array.<Object>`
|
|
689
737
|
|
|
690
738
|
Translates ranges in a formula or list of tokens from absolute A1 syntax to relative R1C1 syntax.
|
|
691
739
|
|
|
692
|
-
Returns the same formula with the ranges translated. If an array of tokens was supplied, then the same array is returned
|
|
740
|
+
Returns the same formula with the ranges translated. If an array of tokens was supplied, then the same array is returned.
|
|
693
741
|
|
|
694
742
|
```js
|
|
695
743
|
translateToR1C1("=SUM(E10,$E$2,Sheet!$E$3)", "D10");
|
|
@@ -698,10 +746,12 @@ translateToR1C1("=SUM(E10,$E$2,Sheet!$E$3)", "D10");
|
|
|
698
746
|
|
|
699
747
|
#### Parameters
|
|
700
748
|
|
|
701
|
-
| Name | Type | Description |
|
|
702
|
-
| ---- | ---- | ----------- |
|
|
703
|
-
| formula | `string` \| `Array.<Object>` | A string (an Excel formula) or a token list that should be adjusted. |
|
|
704
|
-
| anchorCell | `string` | A simple string reference to an A1 cell ID (`AF123` or`$C$5`). |
|
|
749
|
+
| Name | Type | Default | Description |
|
|
750
|
+
| ---- | ---- | ------- | ----------- |
|
|
751
|
+
| formula | `string` \| `Array.<Object>` | | A string (an Excel formula) or a token list that should be adjusted. |
|
|
752
|
+
| anchorCell | `string` | | A simple string reference to an A1 cell ID (`AF123` or`$C$5`). |
|
|
753
|
+
| _[options]_ | `Object` | `{}` | The options |
|
|
754
|
+
| _[options]_.xlsx | `boolean` | `false` | Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md) |
|
|
705
755
|
|
|
706
756
|
#### Returns
|
|
707
757
|
|
package/docs/Prefixes.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Reference prefix syntax
|
|
2
|
+
|
|
3
|
+
Observably, Excel has two variants of the reference syntax prefixes. It has one which it uses in it's interface and at runtime in the formula language, and a second one which is used only in XLSX files.
|
|
4
|
+
|
|
5
|
+
This document explains how the syntaxes work and how _Fx_ treats them. Quoted versions of prefixes are ignored here as they work the same and would only serve to complicate things needlessly.
|
|
6
|
+
|
|
7
|
+
Although tenuous as Excel terms, we'll work with these:
|
|
8
|
+
|
|
9
|
+
* `prefix` is the part of the reference syntax that precedes the ! symbol.
|
|
10
|
+
* `scope` is any path, workbook, or sheet that the referenced item belongs to.
|
|
11
|
+
* `context` is the collection of scopes that a reference has.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## Runtime variant (_Fx_ default)
|
|
15
|
+
|
|
16
|
+
Excel's reference prefix syntax is observed to follow the rule that given 2 or more items (scopes), the second to last will be wrapped in square brackets. This permits the forms:
|
|
17
|
+
|
|
18
|
+
* `a!`
|
|
19
|
+
* `[a]b!`
|
|
20
|
+
* `a[b]c!`
|
|
21
|
+
|
|
22
|
+
The form `[a]!` is not permitted and will yield a `#REF!` error when used (which might only be through the INDIRECT function).
|
|
23
|
+
|
|
24
|
+
This of course means that there is no designated seating for scopes other than order. And order it matters because of how Excel has chosen to resolve scopes:
|
|
25
|
+
|
|
26
|
+
* If there are 3 scopes they are used respectively as path, workbook name, sheet name.
|
|
27
|
+
* If there are 2 scopes they are used respectively as workbook name, sheet name.
|
|
28
|
+
* If there is only 1 scope Excel first tests if the scope exists as a sheet name in the current workbook (even for names), then attempts to match the scope to a workbook.
|
|
29
|
+
|
|
30
|
+
This last claim can be verified by opening two Excel workbooks, referencing a cell across them (use `INDIRECT("Other.xlsx!A1")`), and then (in the workbook the reference lives) creating a new sheet with the same name as the external workbook (e.g. `Other.xlsx`). The reference will now point to the new sheet.
|
|
31
|
+
|
|
32
|
+
Notably, the form `scope!entity` is ambiguous! A given that a workbook `Workbook.xlsx` is located at `/Users/MyName/Documents/` on your drive, and has single sheet called `Sheet1`, all of the following will resolve to the same thing:
|
|
33
|
+
|
|
34
|
+
* `A1`
|
|
35
|
+
* `Sheet1!A1`
|
|
36
|
+
* `Workbook.xlsx!A1`
|
|
37
|
+
* `[Workbook.xlsx]Sheet1!A1`
|
|
38
|
+
* `'/Users/MyName/Documents/[Workbook.xlsx]Sheet1'!A1`
|
|
39
|
+
|
|
40
|
+
However, `[Workbook.xlsx]!A1` and `[Sheet]!A1` will yield a #REF! error. This can be verified with the INDIRECT function.
|
|
41
|
+
|
|
42
|
+
There is no difference in how the syntax works between ranges, names, or tables. And there is no difference in how the syntax works in external references vs. internal ones. Excel just tries hard to normalize references and remove redundancies when a user edits a formula.
|
|
43
|
+
|
|
44
|
+
When parsing references, _Fx_ will output the scopes in order of appearance:
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
parseA1Ref('[Workbook.xlsx]Sheet1!A1');
|
|
48
|
+
/* ⇒ {
|
|
49
|
+
context: [ 'Workbook.xlsx', 'Sheet1' ],
|
|
50
|
+
range: { ... }
|
|
51
|
+
}
|
|
52
|
+
*/
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Inversely, when serializing a reference object, _Fx_ expects the `context` property to have a list of scopes.
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
## XLSX variant
|
|
59
|
+
|
|
60
|
+
When Excel saves a workbook to one of its XML formats (most commonly as .xlsx) it uses an alternative syntax for prefixes. In this variant there will at most be two parts to the prefix, and there are no ambiguities: External link indexes are wrapped in square brackets, sheet names are not:
|
|
61
|
+
|
|
62
|
+
* `a!`
|
|
63
|
+
* `[a]!`
|
|
64
|
+
* `[a]b!`
|
|
65
|
+
|
|
66
|
+
Since the XML files only ever emitted with positive integer indexes instead of workbook names, whether the syntax allows anything else is open. _Fx_ chooses to be permissive in handling this variant and allows `[Workbook.xlsx]!A1` forms as well as `[1]!A1`.
|
|
67
|
+
|
|
68
|
+
Why the formula language does not use this unambiguous and somewhat more intuitive variant rather than the above form is a question for Excel historians, likely this later form was introduced with the XML format to eliminate the ambiguity?
|
|
69
|
+
|
|
70
|
+
When parsing references in `xlsx` mode, _Fx_ will emit `workbookName` and `sheetName` properties corresponding to the bracketing:
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
parseA1Ref('[1]!A1', { xlsx: true });
|
|
74
|
+
/* ⇒ {
|
|
75
|
+
workbookName: '1',
|
|
76
|
+
sheetName: '',
|
|
77
|
+
range: { ... }
|
|
78
|
+
}
|
|
79
|
+
*/
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Inversely, when serializing a reference object, _Fx_ expects the `workbookName` and `sheetName` properties to dictate how to compose the prefix.
|
package/lib/a1.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MAX_ROWS, MAX_COLS } from './constants.js';
|
|
2
2
|
import { parseRef } from './parseRef.js';
|
|
3
|
-
import { stringifyPrefix } from './stringifyPrefix.js';
|
|
3
|
+
import { stringifyPrefix, stringifyPrefixAlt } from './stringifyPrefix.js';
|
|
4
4
|
|
|
5
5
|
const clamp = (min, val, max) => Math.min(Math.max(val, min), max);
|
|
6
6
|
const toColStr = (c, a) => (a ? '$' : '') + toCol(c);
|
|
@@ -244,10 +244,11 @@ export function fromA1 (rangeStr) {
|
|
|
244
244
|
* @param {Object} [options={}] Options
|
|
245
245
|
* @param {boolean} [options.allowNamed=true] Enable parsing names as well as ranges.
|
|
246
246
|
* @param {boolean} [options.allowTernary=false] Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`. These are supported by Google Sheets but not Excel. See: References.md.
|
|
247
|
+
* @param {boolean} [options.xlsx=false] Switches to the `[1]Sheet1!A1` or `[1]!name` prefix syntax form for external workbooks. See: [Prefixes.md](./Prefixes.md)
|
|
247
248
|
* @return {(Object|null)} An object representing a valid reference or null if it is invalid.
|
|
248
249
|
*/
|
|
249
|
-
export function parseA1Ref (refString, { allowNamed = true, allowTernary = false } = {}) {
|
|
250
|
-
const d = parseRef(refString, { allowNamed, allowTernary, r1c1: false });
|
|
250
|
+
export function parseA1Ref (refString, { allowNamed = true, allowTernary = false, xlsx = false } = {}) {
|
|
251
|
+
const d = parseRef(refString, { allowNamed, allowTernary, xlsx, r1c1: false });
|
|
251
252
|
if (d && (d.r0 || d.name)) {
|
|
252
253
|
let range = null;
|
|
253
254
|
if (d.r0) {
|
|
@@ -287,10 +288,15 @@ export function parseA1Ref (refString, { allowNamed = true, allowTernary = false
|
|
|
287
288
|
* ```
|
|
288
289
|
*
|
|
289
290
|
* @param {Object} refObject A reference object
|
|
291
|
+
* @param {Object} [options={}] Options
|
|
292
|
+
* @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)
|
|
290
293
|
* @return {Object} The reference in A1-style string format
|
|
291
294
|
*/
|
|
292
|
-
export function stringifyA1Ref (refObject) {
|
|
293
|
-
|
|
295
|
+
export function stringifyA1Ref (refObject, { xlsx = false } = {}) {
|
|
296
|
+
const prefix = xlsx
|
|
297
|
+
? stringifyPrefixAlt(refObject)
|
|
298
|
+
: stringifyPrefix(refObject);
|
|
299
|
+
return prefix + (
|
|
294
300
|
refObject.name ? refObject.name : toA1(refObject.range)
|
|
295
301
|
);
|
|
296
302
|
}
|