Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

got ; workingn instead of ,

  • Loading branch information...
commit 785adb56d40fbf0c51f13e6763e59ddfe9339321 1 parent 1271808
@josh3ennett authored
Showing with 24 additions and 21 deletions.
  1. +19 −21 src/ExcelFormulaUtilities.js
  2. +5 −0 test/ExcelFormulaUtilities.test.js
View
40 src/ExcelFormulaUtilities.js
@@ -13,15 +13,11 @@
*
* Based on Ewbi's Go Calc Prototype Excel Formula Parser. [http://ewbi.blogs.com/develops/2004/12/excel_formula_p.html]
*/
-(function () {
- if (typeof window === 'undefined') {
- window = root;
- }
-
- var excelFormulaUtilities = window.excelFormulaUtilities = window.excelFormulaUtilities || {},
- core = window.excelFormulaUtilities.core,
- formatStr = window.excelFormulaUtilities.string.formatStr,
- trim = window.excelFormulaUtilities.string.trim,
+(function (root) {
+ var excelFormulaUtilities = root.excelFormulaUtilities = root.excelFormulaUtilities || {},
+ core = root.excelFormulaUtilities.core,
+ formatStr = root.excelFormulaUtilities.string.formatStr,
+ trim = root.excelFormulaUtilities.string.trim,
types = {},
TOK_TYPE_NOOP = types.TOK_TYPE_NOOP = "noop",
@@ -49,7 +45,7 @@
TOK_SUBTYPE_INTERSECT = types.TOK_SUBTYPE_INTERSECT = "intersect",
TOK_SUBTYPE_UNION = types.TOK_SUBTYPE_UNION = "union";
- window.excelFormulaUtilities.isUs = typeof window.excelFormulaUtilities.isUs === 'boolean' ? window.excelFormulaUtilities.isUs : true;
+ root.excelFormulaUtilities.isEu = typeof root.excelFormulaUtilities.isEu === 'boolean' ? root.excelFormulaUtilities.isEu : false;
/**
@@ -322,26 +318,28 @@
}
if (currentChar() === ";" ) {
- if(window.excelFormulaUtilities.isUS){
+ if(root.excelFormulaUtilities.isEu){
+ // If is EU then handle ; as list seperators
if (token.length > 0) {
tokens.add(token, TOK_TYPE_OPERAND);
token = "";
}
- tokens.addRef(tokenStack.pop());
- tokens.add(",", TOK_TYPE_ARGUMENT);
- tokenStack.push(tokens.add("ARRAYROW", TOK_TYPE_FUNCTION, TOK_SUBTYPE_START));
+ if (tokenStack.type() !== TOK_TYPE_FUNCTION) {
+ tokens.add(currentChar(), TOK_TYPE_OP_IN, TOK_SUBTYPE_UNION);
+ } else {
+ tokens.add(currentChar(), TOK_TYPE_ARGUMENT);
+ }
offset += 1;
continue;
} else {
+ // Else if not Eu handle ; as array row seperator
if (token.length > 0) {
tokens.add(token, TOK_TYPE_OPERAND);
token = "";
}
- if (tokenStack.type() !== TOK_TYPE_FUNCTION) {
- tokens.add(currentChar(), TOK_TYPE_OP_IN, TOK_SUBTYPE_UNION);
- } else {
- tokens.add(currentChar(), TOK_TYPE_ARGUMENT);
- }
+ tokens.addRef(tokenStack.pop());
+ tokens.add(",", TOK_TYPE_ARGUMENT);
+ tokenStack.push(tokens.add("ARRAYROW", TOK_TYPE_FUNCTION, TOK_SUBTYPE_START));
offset += 1;
continue;
}
@@ -418,7 +416,7 @@
}
// function, subexpression, array parameters
- if (currentChar() === "," && window.excelFormulaUtilities.isUs) {
+ if (currentChar() === "," && !root.excelFormulaUtilities.isEu) {
if (token.length > 0) {
tokens.add(token, TOK_TYPE_OPERAND);
token = "";
@@ -1183,5 +1181,5 @@
excelFormulaUtilities.getTokens = getTokens;
-}());
+}(window|| module.exports || {}));
View
5 test/ExcelFormulaUtilities.test.js
@@ -1,5 +1,7 @@
QUnit.module("base26");
+window.excelFormulaUtilities.isEu = false;
+
test("fromBase26", function(){
var input = 'AAA';
var expected = '702';
@@ -65,9 +67,11 @@ test("formatFormula", function() {
expected = 'TEST(\n\t1,\n\t,\n\t,\n\t1\n)';
equal(excelFormulaUtilities.formatFormula(inputFormula), expected, "multiple commas.");
+ window.excelFormulaUtilities.isEu = true;
inputFormula = 'IF(A1="yes"; "yes"; "no")';
expected = 'IF(\n\tA1 = "yes";\n\t"yes";\n\t"no"\n)';
equal(excelFormulaUtilities.formatFormula(inputFormula), expected, "Test with ; instead of ,");
+ window.excelFormulaUtilities.isEu = false;
});
@@ -136,6 +140,7 @@ test("formula2JavaScript", function() {
inputFormula = 'SUM(AA1:BB2)';
expected = '(AA1+AB1+AC1+AD1+AE1+AF1+AG1+AH1+AI1+AJ1+AK1+AL1+AM1+AN1+AO1+AP1+AQ1+AR1+AS1+AT1+AU1+AV1+AW1+AX1+AY1+AZ1+BA1+BB1+AA2+AB2+AC2+AD2+AE2+AF2+AG2+AH2+AI2+AJ2+AK2+AL2+AM2+AN2+AO2+AP2+AQ2+AR2+AS2+AT2+AU2+AV2+AW2+AX2+AY2+AZ2+BA2+BB2)';
equal(excelFormulaUtilities.formula2JavaScript(inputFormula), expected, inputFormula + " -- Test for issue #6 https://github.com/joshatjben/excelFormulaUtilitiesJS/issues/6");
+
inputFormula = '=FOO(A1:B3)';
expected = 'foo([A1,B1,A2,B2,A3,B3])';
Please sign in to comment.
Something went wrong with that request. Please try again.