@borgar/fx 2.1.0 → 2.1.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/dist/fx.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";function t(t){return t.split(/(\d+|[a-zA-Z]+)/).every((t=>{const e=parseInt(t,36);return!!isNaN(e)||(isFinite(t)?e<=2183880786:e<=43321)}))}const e={R:1048577,"R[":1048576,C:16385,"C[":16384};function r(t){const r=/([RC]\[?)(-?\d+)/gi;let n;for(;null!==(n=r.exec(t));){const t=e[n[1]],r=parseInt(n[2],10);if(r>=t||r<=-t)return!1}return!0}const n="range",o="range-beam",a=/^#(NAME\?|FIELD!|CALC!|VALUE!|REF!|DIV\/0!|NULL!|NUM!|N\/A|GETTING_DATA\b|SPILL!|UNKNOWN!|FIELD\b|CALC\b|SYNTAX\?|ERROR!)/i,i=/^(<=|>=|<>|[-+/*^%&<>=]|[{},;]|[()]|@|:|!|#)/,l=/^(TRUE|FALSE)\b/i,u=/^[A-Z_]+[A-Z\d_.]+(?=\s*\()/i,c=/^\n+/,p=/^[ \f\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/,s=/^"(?:""|[^"])*("|$)/,f=/^'(?:''|[^'])*('|$)/,$=/^\[(?:[^\]])+(\]|$)/,h=/^([^ \t\n$!"`'#%&(){}<>,;:^@|~=*+-]+)(?=!)/,g=/^\$?[A-Z]{1,3}:\$?[A-Z]{1,3}/i,m=/^\$?[1-9][0-9]{0,6}:\$?[1-9][0-9]{0,6}/i,b=/^\$?[A-Z]{1,3}\$?[1-9][0-9]{0,6}/i,d="(?:R(?:\\[[+-]?\\d+\\]|[1-9][0-9]{0,6})?)",v="(?:C(?:\\[[+-]?\\d+\\]|[1-9][0-9]{0,4})?)",R=new RegExp(`^${v}(:${v})?(?=\\W|$)`,"i"),x=new RegExp(`^${d}(:${d})?(?=\\W|$)`,"i"),N=new RegExp(`^(?:(?=[RC])${d}${v})`,"i"),A=/^(?:\d+(\.\d+)?(?:[eE][+-]?\d+)?|\d+)/,E=/^[A-Z\d\\_.?]+/i,C=[["error",a],["operator",i],["bool",l],["function",u],["newline",c],["whitespace",p],["string",s],["path-quote",f],["path-brace",$],["path-prefix",h],[n,b,t],[o,g,t],[o,m,t],["number",A],["range-named",E]],y=[["error",a],["operator",i],["bool",l],["function",u],["newline",c],["whitespace",p],["string",s],["path-quote",f],["path-brace",$],["path-prefix",h],[n,N,r],[o,x,r],[o,R,r],["number",A],["range-named",E]],I=[["operator",/^[!:]/],["path-quote",f],["path-brace",$],["path-prefix",h],[n,b,t],[o,g,t],[o,m,t],["range-named",E]],w=[["operator",/^!/],["path-quote",f],["path-brace",$],["path-prefix",h],[n,N,r],[o,x,r],[o,R,r],["range-named",E]],k=(t,e)=>t&&t.type===e,T=t=>t&&":"===t.value,L=t=>t&&"!"===t.value,O={emitRanges:!1,mergeRanges:!0,negativeNumbers:!1,r1c1:!1};function M(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{emitRanges:a,mergeRanges:i,negativeNumbers:l}=Object.assign({},O,r),u=[];let c=0;const p=t=>u[u.length-t],s=t=>{const e=u.filter((t=>!k(t,"whitespace")&&!k(t,"newline")));return e[e.length-t]};if(/^=/.test(t)){const t={type:"fx-prefix",value:"=",...a?{range:[0,1]}:{}};c++,u.push(t)}for(;c<t.length;){const r=c,f=t.slice(c);let $="",h="";for(let t=0;t<e.length;t++){const[r,n,o]=e[t],a=n.exec(f);if(a&&(!o||o(a[0]))){$=r,h=a[0],c+=a[0].length;break}}$||($="unknown",h=t[c],c++);let g={type:$,value:h,...a?{range:[r,c]}:{}};if(("string"!==$||h.endsWith('"'))&&("path-brace"!==$||h.endsWith("]"))&&("path-quote"!==$||h.endsWith("'"))||(g.unterminated=!0),l&&"number"===$){const t=p(1);if(t&&k(t,"operator")&&"-"===t.value){const t=s(2);(!t||k(t,"fx-prefix")||k(t,"operator")&&!["%","}",")","#"].includes(t.value))&&(u.pop(),g.value="-"+h)}}if(i&&($===n||"range-named"===$||$===o)){const t=[];if(T(p(1))&&k(p(2),n)&&$===n&&t.unshift(...u.splice(-2,2)),L(p(1)))if(k(p(2),"path-quote")||k(p(2),"path-brace"))t.unshift(...u.splice(-2,2));else if(k(p(2),"path-prefix")){const e=k(p(3),"path-brace")?3:2;t.unshift(...u.splice(-e,e))}t.length&&(g={type:$,value:t.map((t=>t.value)).join("")+h,...a?{range:[t[0].range[0],c]}:{}})}u.push(g)}return u}function _(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=e.r1c1?y:C;return M(t,r,e)}const Z=t=>t.slice(1,-1).replace(/''/g,"'"),S=t=>t&&":"===t.value&&{},U=t=>t&&t.type===n&&{r0:t.value},W=t=>t&&t.type===n&&{r1:t.value},q=t=>t&&"!"===t.value&&{},F=t=>t&&t.type===o&&{r0:t.value},P=t=>t&&"path-prefix"===t.type&&/^[^:\\/?*[\]]{0,31}$/.test(t.value)&&{sheetName:t.value},G=t=>t&&"path-brace"===t.type&&{workbookName:t.value.slice(1,-1)},X=t=>t&&"range-named"===t.type&&{name:t.value},j=t=>{if(t&&"path-quote"===t.type){const e=/(?:\[(.+?)\])?([^[\]]+?)$/.exec(Z(t.value));if(e){const[,t,r]=e;if(!r||/^[^:\\/?*[\]]{0,31}$/.test(r))return{workbookName:t||"",sheetName:r||""}}}},D=[[U],[U,S,W],[F],[j,q,U],[j,q,U,S,W],[j,q,F],[P,q,U],[P,q,U,S,W],[P,q,F],[G,P,q,U],[G,P,q,U,S,W],[G,P,q,F]],B=D.concat([[X],[t=>t&&"path-prefix"===t.type&&{workbookName:t.value},q,X],[t=>t&&"path-quote"===t.type&&{workbookName:Z(t.value)},q,X]]);function H(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];const n=M(t,r,{emitRanges:!1,mergeRanges:!1}),o={sheetName:"",workbookName:"",r0:"",r1:"",name:""};n.length&&"fx-prefix"===n[0].type&&n.shift();const a=e?B:D;for(let t=0;t<a.length;t++){const e={...o};if(a[t].length===n.length){if(a[t].every(((t,r)=>{const o=t(n[r]);return Object.assign(e,o),o})))return e}}return null}function z(t){const e=(t||"").toUpperCase();let r=0,n=0;for(;n!==e.length;++n){const t=e.charCodeAt(n);t>=65&&t<=90&&(r=26*r+t-64)}return r-1}function K(t){let e=t,r="";for(;e>=0;)r=String.fromCharCode(e%26+65)+r,e=Math.floor(e/26)-1;return r}function V(t){return+t-1}function Q(t){return String(t+1)}function Y(t){const{top:e,left:r,bottom:n,right:o}=t;return{top:e,left:r,bottom:n,right:o,$left:!1,$right:!1,$top:!1,$bottom:!1}}function J(t){const e=t=>t?"$":"",{top:r,left:n,bottom:o,right:a,$left:i,$right:l,$top:u,$bottom:c}=t;return 0===r&&1048575===o?e(i)+K(n)+":"+e(l)+K(a):0===n&&16383===a?e(u)+Q(r)+":"+e(c)+Q(o):null==a||null==o||a===n&&o===r?e(i)+K(n)+e(u)+Q(r):e(i)+K(n)+e(u)+Q(r)+":"+e(l)+K(a)+e(c)+Q(o)}function tt(t){let e,r=0,n=0,o=1048575,a=16383,i=!1,l=!1,u=!1,c=!1;if(e=/^(\$?)([A-Z]{1,3}):(\$?)([A-Z]{1,3})$/.exec(t)){const t=z(e[2]),p=z(e[4]);return n=Math.min(t,p),a=Math.max(t,p),l=!!e[t<=p?1:3],c=!!e[t<=p?3:1],i=!0,u=!0,{top:r,left:n,bottom:o,right:a,$top:i,$left:l,$bottom:u,$right:c}}if(e=/^(\$?)([1-9]\d{0,6}):(\$?)([1-9]\d{0,6})$/.exec(t)){const t=V(e[2]),p=V(e[4]);return r=Math.min(t,p),o=Math.max(t,p),i=!!e[t<=p?1:3],u=!!e[t<=p?3:1],l=!0,c=!0,{top:r,left:n,bottom:o,right:a,$top:i,$left:l,$bottom:u,$right:c}}{const[p,s]=t.split(":");if(e=/^(\$?)([A-Z]{1,3})(\$?)([1-9]\d{0,6})$/i.exec(p))return n=z(e[2]),r=V(e[4]),l=!!e[1],i=!!e[3],s&&(e=/^(\$?)([A-Z]{1,3})(\$?)([1-9]\d{0,6})$/i.exec(s))?(a=z(e[2]),o=V(e[4]),c=!!e[1],u=!!e[3],o<r&&([r,o,i,u]=[o,r,u,i]),a<n&&([n,a,l,c]=[a,n,c,l])):(o=r,a=n,u=i,c=l),{top:r,left:n,bottom:o,right:a,$top:i,$left:l,$bottom:u,$right:c}}return null}function et(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const r=H(t,e,I);if(r&&(r.r0||r.name)){let t=null;return r.r0&&(t=r.r1?tt(r.r0+":"+r.r1):tt(r.r0)),r.name||t?(r.range=t,delete r.r0,delete r.r1,r):null}return null}var rt={fromCol:z,toCol:K,toRelative:Y,toAbsolute:function(t){const{top:e,left:r,bottom:n,right:o}=t;return{top:e,left:r,bottom:n,right:o,$left:!0,$right:!0,$top:!0,$bottom:!0}},to:J,from:tt,parse:et};function nt(){let t=1;return()=>"fxg"+t++}function ot(t,e){return e?String(t+1):t?"["+t+"]":""}function at(t){const{r0:e,c0:r,r1:n,c1:o,$c0:a,$c1:i,$r0:l,$r1:u}=t;if(0===e&&1048575===n){const t=ot(r,a),e=ot(o,i);return"C"+(t===e?t:t+":C"+e)}if(0===r&&16383===o){const t=ot(e,l),r=ot(n,u);return"R"+(t===r?t:t+":R"+r)}const c=ot(e,l),p=ot(n,u),s=ot(r,a),f=ot(o,i);return c!==p||s!==f?"R"+c+"C"+s+":R"+p+"C"+f:"R"+c+"C"+s}function it(t){let e=0,r=0,n=1048575,o=16383,a=!1,i=!1,l=!1,u=!1;const c=/^R(?:\[([+-]?\d+)\]|(\d+))?/.exec(t);c?(c[1]?e=parseInt(c[1],10):c[2]&&(e=parseInt(c[2],10)-1,a=!0),n=e,l=a,t=t.slice(c[0].length)):(a=!0,l=!0);const p=/^C(?:\[([+-]?\d+)\]|(\d+))?/.exec(t);return p?(p[1]?r=parseInt(p[1],10):p[2]&&(r=parseInt(p[2],10)-1,i=!0),o=r,u=i,t=t.slice(p[0].length)):(i=!0,u=!0),!c&&!p||t.length?null:{r0:e,c0:r,r1:n,c1:o,$r0:a,$c0:i,$r1:l,$c1:u}}function lt(t){const[e,r]=t.split(":",2),n=it(e);if(!n)return null;if(n&&r){const t=it(r);if(!t)return null;n.r1=t.r1,n.c1=t.c1,n.$r1=t.$r1,n.$c1=t.$c1}return n}var ut={to:at,from:lt,parse:function(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const r=H(t,e,w);if(r&&(r.r0||r.name)){const t=r.r1?lt(r.r0+":"+r.r1):lt(r.r0);return r.name||t?(r.range=t,delete r.r0,delete r.r1,r):null}return null}};function ct(t,e,r,n){let o=t;return e||(o=r+t,o<0&&(o=n+o+1),o>n&&(o-=n+1)),o}const pt={OPERATOR:"operator",BOOLEAN:"bool",ERROR:"error",NUMBER:"number",FUNCTION:"function",NEWLINE:"newline",WHITESPACE:"whitespace",STRING:"string",PATH_QUOTE:"path-quote",PATH_BRACE:"path-brace",PATH_PREFIX:"path-prefix",RANGE:n,RANGE_BEAM:o,RANGE_NAMED:"range-named",FX_PREFIX:"fx-prefix",UNKNOWN:"unknown"};exports.MAX_COLS=16383,exports.MAX_ROWS=1048575,exports.a1=rt,exports.addMeta=function(t){let{sheetName:e="",workbookName:r=""}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const a=[];let i=null;const l={},u=nt();return t.forEach(((t,c)=>{if(t.index=c,t.depth=a.length,"("===t.value)t.depth=a.length+1,a.push(t);else if(")"===t.value){const e=a.pop();if(e){const r=u();t.groupId=r,t.depth=e.depth,e.groupId=r}else t.error=!0}else if("{"===t.value)i?t.error=!0:i=t;else if("}"===t.value){if(i){const e=u();t.groupId=e,i.groupId=e}else t.error=!0;i=null}else if(t.type===n||t.type===o){const n=et(t.value,!1),o=n&&`[${n.workbookName||r}]${n.sheetName||e}!${n.range?J(Y(n.range)):n.name}`.toLowerCase();o&&(o in l?t.groupId=l[o]:(t.groupId=u(),l[o]=t.groupId))}else"unknown"===t.type&&(t.error=!0)})),t},exports.rc=ut,exports.tokenTypes=pt,exports.tokenize=_,exports.translateToA1=function(t,e){const r=tt(e),a="string"==typeof t,i=a?_(t,{emitRanges:!1,mergeRanges:!1,r1c1:!0}):t;return i.forEach((t=>{if(t.type===n||t.type===o){const e={},n=lt(t.value),o=ct(n.r0,n.$r0,r.top,1048575),a=ct(n.r1,n.$r1,r.top,1048575);o>a?(e.top=a,e.$top=n.$r1,e.bottom=o,e.$bottom=n.$r0):(e.top=o,e.$top=n.$r0,e.bottom=a,e.$bottom=n.$r1);const i=ct(n.c0,n.$c0,r.left,16383),l=ct(n.c1,n.$c1,r.left,16383);i>l?(e.left=l,e.$left=n.$c1,e.right=i,e.$right=n.$c0):(e.left=i,e.$left=n.$c0,e.right=l,e.$right=n.$c1),t.value=J(e)}})),a?i.map((t=>t.value)).join(""):i},exports.translateToRC=function(t,e){const{top:r,left:a}=tt(e),i="string"==typeof t,l=i?_(t,{emitRanges:!1,mergeRanges:!1,r1c2:!1}):t;return l.forEach((t=>{if(t.type===n){const e={},n=tt(t.value);e.r0=n.$top?n.top:n.top-r,e.$r0=n.$top,e.r1=n.$bottom?n.bottom:n.bottom-r,e.$r1=n.$bottom,e.c0=n.$left?n.left:n.left-a,e.$c0=n.$left,e.c1=n.$right?n.right:n.right-a,e.$c1=n.$right,t.value=at(e)}else if(t.type===o){const e={},n=tt(t.value);e.r0=n.$top?n.top:n.top-r,e.$r0=n.$top,e.r1=n.$bottom?n.bottom:n.bottom-r,e.$r1=n.$bottom,e.c0=n.$left?n.left:n.left-a,e.$c0=n.$left,e.c1=n.$right?n.right:n.right-a,e.$c1=n.$right,t.value=at(e)}})),i?l.map((t=>t.value)).join(""):l};
1
+ "use strict";function t(t){return t.split(/(\d+|[a-zA-Z]+)/).every((t=>{const e=parseInt(t,36);return!!isNaN(e)||(isFinite(t)?e<=2183880786:e<=43321)}))}const e={R:1048577,"R[":1048576,C:16385,"C[":16384};function r(t){const r=/([RC]\[?)(-?\d+)/gi;let n;for(;null!==(n=r.exec(t));){const t=e[n[1]],r=parseInt(n[2],10);if(r>=t||r<=-t)return!1}return!0}const n="range",o="range-beam",a=/^#(NAME\?|FIELD!|CALC!|VALUE!|REF!|DIV\/0!|NULL!|NUM!|N\/A|GETTING_DATA\b|SPILL!|UNKNOWN!|FIELD\b|CALC\b|SYNTAX\?|ERROR!)/i,i=/^(<=|>=|<>|[-+/*^%&<>=]|[{},;]|[()]|@|:|!|#)/,l=/^(TRUE|FALSE)\b/i,u=/^[A-Z_]+[A-Z\d_.]+(?=\s*\()/i,c=/^\n+/,p=/^[ \f\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/,s=/^"(?:""|[^"])*("|$)/,f=/^'(?:''|[^'])*('|$)/,$=/^\[(?:[^\]])+(\]|$)/,h=/^([^ \t\n$!"`'#%&(){}<>,;:^@|~=*+-]+)(?=!)/,g=/^\$?[A-Z]{1,3}:\$?[A-Z]{1,3}/i,m=/^\$?[1-9][0-9]{0,6}:\$?[1-9][0-9]{0,6}/i,b=/^\$?[A-Z]{1,3}\$?[1-9][0-9]{0,6}/i,d="(?:R(?:\\[[+-]?\\d+\\]|[1-9][0-9]{0,6})?)",v="(?:C(?:\\[[+-]?\\d+\\]|[1-9][0-9]{0,4})?)",R=new RegExp(`^${v}(:${v})?(?=\\W|$)`,"i"),x=new RegExp(`^${d}(:${d})?(?=\\W|$)`,"i"),N=new RegExp(`^(?:(?=[RC])${d}${v})`,"i"),A=/^(?:\d+(\.\d+)?(?:[eE][+-]?\d+)?|\d+)/,E=/^[A-Z\d\\_.?]+/i,C=[["error",a],["operator",i],["bool",l],["function",u],["newline",c],["whitespace",p],["string",s],["path-quote",f],["path-brace",$],["path-prefix",h],[n,b,t],[o,g,t],[o,m,t],["number",A],["range-named",E]],y=[["error",a],["operator",i],["bool",l],["function",u],["newline",c],["whitespace",p],["string",s],["path-quote",f],["path-brace",$],["path-prefix",h],[n,N,r],[o,x,r],[o,R,r],["number",A],["range-named",E]],I=[["operator",/^[!:]/],["path-quote",f],["path-brace",$],["path-prefix",h],[n,b,t],[o,g,t],[o,m,t],["range-named",E]],w=[["operator",/^!/],["path-quote",f],["path-brace",$],["path-prefix",h],[n,N,r],[o,x,r],[o,R,r],["range-named",E]],k=(t,e)=>t&&t.type===e,T=t=>t&&":"===t.value,L=t=>t&&"!"===t.value,O={emitRanges:!1,mergeRanges:!0,negativeNumbers:!1,r1c1:!1};function M(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{emitRanges:a,mergeRanges:i,negativeNumbers:l}=Object.assign({},O,r),u=[];let c=0;const p=t=>u[u.length-t],s=t=>{const e=u.filter((t=>!k(t,"whitespace")&&!k(t,"newline")));return e[e.length-t]};if(/^=/.test(t)){const t={type:"fx-prefix",value:"=",...a?{range:[0,1]}:{}};c++,u.push(t)}for(;c<t.length;){const r=c,f=t.slice(c);let $="",h="";for(let t=0;t<e.length;t++){const[r,n,o]=e[t],a=n.exec(f);if(a&&(!o||o(a[0]))){$=r,h=a[0],c+=a[0].length;break}}$||($="unknown",h=t[c],c++);let g={type:$,value:h,...a?{range:[r,c]}:{}};if(("string"!==$||'"'!==h&&h.endsWith('"'))&&("path-brace"!==$||h.endsWith("]"))&&("path-quote"!==$||"'"!==h&&h.endsWith("'"))||(g.unterminated=!0),l&&"number"===$){const t=p(1);if(t&&k(t,"operator")&&"-"===t.value){const t=s(2);(!t||k(t,"fx-prefix")||k(t,"operator")&&!["%","}",")","#"].includes(t.value))&&(u.pop(),g.value="-"+h)}}if(i&&($===n||"range-named"===$||$===o)){const t=[];if(T(p(1))&&k(p(2),n)&&$===n&&t.unshift(...u.splice(-2,2)),L(p(1)))if(k(p(2),"path-quote")||k(p(2),"path-brace"))t.unshift(...u.splice(-2,2));else if(k(p(2),"path-prefix")){const e=k(p(3),"path-brace")?3:2;t.unshift(...u.splice(-e,e))}t.length&&(g={type:$,value:t.map((t=>t.value)).join("")+h,...a?{range:[t[0].range[0],c]}:{}})}u.push(g)}return u}function _(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=e.r1c1?y:C;return M(t,r,e)}const Z=t=>t.slice(1,-1).replace(/''/g,"'"),S=t=>t&&":"===t.value&&{},U=t=>t&&t.type===n&&{r0:t.value},W=t=>t&&t.type===n&&{r1:t.value},q=t=>t&&"!"===t.value&&{},F=t=>t&&t.type===o&&{r0:t.value},P=t=>t&&"path-prefix"===t.type&&/^[^:\\/?*[\]]{0,31}$/.test(t.value)&&{sheetName:t.value},G=t=>t&&"path-brace"===t.type&&{workbookName:t.value.slice(1,-1)},X=t=>t&&"range-named"===t.type&&{name:t.value},j=t=>{if(t&&"path-quote"===t.type){const e=/(?:\[(.+?)\])?([^[\]]+?)$/.exec(Z(t.value));if(e){const[,t,r]=e;if(!r||/^[^:\\/?*[\]]{0,31}$/.test(r))return{workbookName:t||"",sheetName:r||""}}}},D=[[U],[U,S,W],[F],[j,q,U],[j,q,U,S,W],[j,q,F],[P,q,U],[P,q,U,S,W],[P,q,F],[G,P,q,U],[G,P,q,U,S,W],[G,P,q,F]],B=D.concat([[X],[t=>t&&"path-prefix"===t.type&&{workbookName:t.value},q,X],[t=>t&&"path-quote"===t.type&&{workbookName:Z(t.value)},q,X]]);function H(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];const n=M(t,r,{emitRanges:!1,mergeRanges:!1}),o={sheetName:"",workbookName:"",r0:"",r1:"",name:""};n.length&&"fx-prefix"===n[0].type&&n.shift();const a=e?B:D;for(let t=0;t<a.length;t++){const e={...o};if(a[t].length===n.length){if(a[t].every(((t,r)=>{const o=t(n[r]);return Object.assign(e,o),o})))return e}}return null}function z(t){const e=(t||"").toUpperCase();let r=0,n=0;for(;n!==e.length;++n){const t=e.charCodeAt(n);t>=65&&t<=90&&(r=26*r+t-64)}return r-1}function K(t){let e=t,r="";for(;e>=0;)r=String.fromCharCode(e%26+65)+r,e=Math.floor(e/26)-1;return r}function V(t){return+t-1}function Q(t){return String(t+1)}function Y(t){const{top:e,left:r,bottom:n,right:o}=t;return{top:e,left:r,bottom:n,right:o,$left:!1,$right:!1,$top:!1,$bottom:!1}}function J(t){const e=t=>t?"$":"",{top:r,left:n,bottom:o,right:a,$left:i,$right:l,$top:u,$bottom:c}=t;return 0===r&&1048575===o?e(i)+K(n)+":"+e(l)+K(a):0===n&&16383===a?e(u)+Q(r)+":"+e(c)+Q(o):null==a||null==o||a===n&&o===r?e(i)+K(n)+e(u)+Q(r):e(i)+K(n)+e(u)+Q(r)+":"+e(l)+K(a)+e(c)+Q(o)}function tt(t){let e,r=0,n=0,o=1048575,a=16383,i=!1,l=!1,u=!1,c=!1;if(e=/^(\$?)([A-Z]{1,3}):(\$?)([A-Z]{1,3})$/.exec(t)){const t=z(e[2]),p=z(e[4]);return n=Math.min(t,p),a=Math.max(t,p),l=!!e[t<=p?1:3],c=!!e[t<=p?3:1],i=!0,u=!0,{top:r,left:n,bottom:o,right:a,$top:i,$left:l,$bottom:u,$right:c}}if(e=/^(\$?)([1-9]\d{0,6}):(\$?)([1-9]\d{0,6})$/.exec(t)){const t=V(e[2]),p=V(e[4]);return r=Math.min(t,p),o=Math.max(t,p),i=!!e[t<=p?1:3],u=!!e[t<=p?3:1],l=!0,c=!0,{top:r,left:n,bottom:o,right:a,$top:i,$left:l,$bottom:u,$right:c}}{const[p,s]=t.split(":");if(e=/^(\$?)([A-Z]{1,3})(\$?)([1-9]\d{0,6})$/i.exec(p))return n=z(e[2]),r=V(e[4]),l=!!e[1],i=!!e[3],s&&(e=/^(\$?)([A-Z]{1,3})(\$?)([1-9]\d{0,6})$/i.exec(s))?(a=z(e[2]),o=V(e[4]),c=!!e[1],u=!!e[3],o<r&&([r,o,i,u]=[o,r,u,i]),a<n&&([n,a,l,c]=[a,n,c,l])):(o=r,a=n,u=i,c=l),{top:r,left:n,bottom:o,right:a,$top:i,$left:l,$bottom:u,$right:c}}return null}function et(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const r=H(t,e,I);if(r&&(r.r0||r.name)){let t=null;return r.r0&&(t=r.r1?tt(r.r0+":"+r.r1):tt(r.r0)),r.name||t?(r.range=t,delete r.r0,delete r.r1,r):null}return null}var rt={fromCol:z,toCol:K,toRelative:Y,toAbsolute:function(t){const{top:e,left:r,bottom:n,right:o}=t;return{top:e,left:r,bottom:n,right:o,$left:!0,$right:!0,$top:!0,$bottom:!0}},to:J,from:tt,parse:et};function nt(){let t=1;return()=>"fxg"+t++}function ot(t,e){return e?String(t+1):t?"["+t+"]":""}function at(t){const{r0:e,c0:r,r1:n,c1:o,$c0:a,$c1:i,$r0:l,$r1:u}=t;if(0===e&&1048575===n){const t=ot(r,a),e=ot(o,i);return"C"+(t===e?t:t+":C"+e)}if(0===r&&16383===o){const t=ot(e,l),r=ot(n,u);return"R"+(t===r?t:t+":R"+r)}const c=ot(e,l),p=ot(n,u),s=ot(r,a),f=ot(o,i);return c!==p||s!==f?"R"+c+"C"+s+":R"+p+"C"+f:"R"+c+"C"+s}function it(t){let e=0,r=0,n=1048575,o=16383,a=!1,i=!1,l=!1,u=!1;const c=/^R(?:\[([+-]?\d+)\]|(\d+))?/.exec(t);c?(c[1]?e=parseInt(c[1],10):c[2]&&(e=parseInt(c[2],10)-1,a=!0),n=e,l=a,t=t.slice(c[0].length)):(a=!0,l=!0);const p=/^C(?:\[([+-]?\d+)\]|(\d+))?/.exec(t);return p?(p[1]?r=parseInt(p[1],10):p[2]&&(r=parseInt(p[2],10)-1,i=!0),o=r,u=i,t=t.slice(p[0].length)):(i=!0,u=!0),!c&&!p||t.length?null:{r0:e,c0:r,r1:n,c1:o,$r0:a,$c0:i,$r1:l,$c1:u}}function lt(t){const[e,r]=t.split(":",2),n=it(e);if(!n)return null;if(n&&r){const t=it(r);if(!t)return null;n.r1=t.r1,n.c1=t.c1,n.$r1=t.$r1,n.$c1=t.$c1}return n}var ut={to:at,from:lt,parse:function(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const r=H(t,e,w);if(r&&(r.r0||r.name)){const t=r.r1?lt(r.r0+":"+r.r1):lt(r.r0);return r.name||t?(r.range=t,delete r.r0,delete r.r1,r):null}return null}};function ct(t,e,r,n){let o=t;return e||(o=r+t,o<0&&(o=n+o+1),o>n&&(o-=n+1)),o}const pt={OPERATOR:"operator",BOOLEAN:"bool",ERROR:"error",NUMBER:"number",FUNCTION:"function",NEWLINE:"newline",WHITESPACE:"whitespace",STRING:"string",PATH_QUOTE:"path-quote",PATH_BRACE:"path-brace",PATH_PREFIX:"path-prefix",RANGE:n,RANGE_BEAM:o,RANGE_NAMED:"range-named",FX_PREFIX:"fx-prefix",UNKNOWN:"unknown"};exports.MAX_COLS=16383,exports.MAX_ROWS=1048575,exports.a1=rt,exports.addMeta=function(t){let{sheetName:e="",workbookName:r=""}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const a=[];let i=null;const l={},u=nt();return t.forEach(((t,c)=>{if(t.index=c,t.depth=a.length,"("===t.value)t.depth=a.length+1,a.push(t);else if(")"===t.value){const e=a.pop();if(e){const r=u();t.groupId=r,t.depth=e.depth,e.groupId=r}else t.error=!0}else if("{"===t.value)i?t.error=!0:i=t;else if("}"===t.value){if(i){const e=u();t.groupId=e,i.groupId=e}else t.error=!0;i=null}else if(t.type===n||t.type===o){const n=et(t.value,!1),o=n&&`[${n.workbookName||r}]${n.sheetName||e}!${n.range?J(Y(n.range)):n.name}`.toLowerCase();o&&(o in l?t.groupId=l[o]:(t.groupId=u(),l[o]=t.groupId))}else"unknown"===t.type&&(t.error=!0)})),t},exports.rc=ut,exports.tokenTypes=pt,exports.tokenize=_,exports.translateToA1=function(t,e){const r=tt(e),a="string"==typeof t,i=a?_(t,{emitRanges:!1,mergeRanges:!1,r1c1:!0}):t;return i.forEach((t=>{if(t.type===n||t.type===o){const e={},n=lt(t.value),o=ct(n.r0,n.$r0,r.top,1048575),a=ct(n.r1,n.$r1,r.top,1048575);o>a?(e.top=a,e.$top=n.$r1,e.bottom=o,e.$bottom=n.$r0):(e.top=o,e.$top=n.$r0,e.bottom=a,e.$bottom=n.$r1);const i=ct(n.c0,n.$c0,r.left,16383),l=ct(n.c1,n.$c1,r.left,16383);i>l?(e.left=l,e.$left=n.$c1,e.right=i,e.$right=n.$c0):(e.left=i,e.$left=n.$c0,e.right=l,e.$right=n.$c1),t.value=J(e)}})),a?i.map((t=>t.value)).join(""):i},exports.translateToRC=function(t,e){const{top:r,left:a}=tt(e),i="string"==typeof t,l=i?_(t,{emitRanges:!1,mergeRanges:!1,r1c2:!1}):t;return l.forEach((t=>{if(t.type===n){const e={},n=tt(t.value);e.r0=n.$top?n.top:n.top-r,e.$r0=n.$top,e.r1=n.$bottom?n.bottom:n.bottom-r,e.$r1=n.$bottom,e.c0=n.$left?n.left:n.left-a,e.$c0=n.$left,e.c1=n.$right?n.right:n.right-a,e.$c1=n.$right,t.value=at(e)}else if(t.type===o){const e={},n=tt(t.value);e.r0=n.$top?n.top:n.top-r,e.$r0=n.$top,e.r1=n.$bottom?n.bottom:n.bottom-r,e.$r1=n.$bottom,e.c0=n.$left?n.left:n.left-a,e.$c0=n.$left,e.c1=n.$right?n.right:n.right-a,e.$c1=n.$right,t.value=at(e)}})),i?l.map((t=>t.value)).join(""):l};
2
2
  //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZnguanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
package/lib/lexer-test.js CHANGED
@@ -1338,6 +1338,10 @@ test('tokenize strings', t => {
1338
1338
  // we should be able to highlight things that are still being typed
1339
1339
  // so open-ended STRING, PATH_BRACE, and PATH_QUOTE tokens at the
1340
1340
  // end of output are tagged.
1341
+ t.isTokens('="', [
1342
+ { type: FX_PREFIX, value: '=' },
1343
+ { type: STRING, value: '"', unterminated: true }
1344
+ ]);
1341
1345
  t.isTokens('="incomple', [
1342
1346
  { type: FX_PREFIX, value: '=' },
1343
1347
  { type: STRING, value: '"incomple', unterminated: true }
@@ -1346,6 +1350,10 @@ test('tokenize strings', t => {
1346
1350
  { type: FX_PREFIX, value: '=' },
1347
1351
  { type: PATH_BRACE, value: '[Foo', unterminated: true }
1348
1352
  ]);
1353
+ t.isTokens("='", [
1354
+ { type: FX_PREFIX, value: '=' },
1355
+ { type: PATH_QUOTE, value: "'", unterminated: true }
1356
+ ]);
1349
1357
  t.isTokens("='Sheet name", [
1350
1358
  { type: FX_PREFIX, value: '=' },
1351
1359
  { type: PATH_QUOTE, value: "'Sheet name", unterminated: true }
package/lib/lexer.js CHANGED
@@ -75,13 +75,13 @@ export function getTokens (fx, tokenHandlers, options = {}) {
75
75
  ...(emitRanges ? { range: [ startPos, pos ] } : {})
76
76
  };
77
77
 
78
- if (tokenType === STRING && !tokenValue.endsWith('"')) {
78
+ if (tokenType === STRING && (tokenValue === '"' || !tokenValue.endsWith('"'))) {
79
79
  token.unterminated = true;
80
80
  }
81
81
  else if (tokenType === PATH_BRACE && !tokenValue.endsWith(']')) {
82
82
  token.unterminated = true;
83
83
  }
84
- else if (tokenType === PATH_QUOTE && !tokenValue.endsWith("'")) {
84
+ else if (tokenType === PATH_QUOTE && (tokenValue === "'" || !tokenValue.endsWith("'"))) {
85
85
  token.unterminated = true;
86
86
  }
87
87
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@borgar/fx",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "Utilities for working with Excel formulas",
5
5
  "main": "dist/fx.js",
6
6
  "module": "lib/index.js",