spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[Text.JOIN] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-10-08 01:19:56
stats
8 file(s) changed, 65 insertions(+), 3 deletions(-)
files
DOCS.md
TODO.md
dist/Formulas/AllFormulas.js
dist/Formulas/Text.js
src/Formulas/AllFormulas.ts
src/Formulas/Text.ts
tests/Formulas/TextTest.ts
tests/SheetFormulaTest.ts
  1diff --git a/DOCS.md b/DOCS.md
  2index 3ac35be..da37b9e 100644
  3--- a/DOCS.md
  4+++ b/DOCS.md
  5@@ -2413,3 +2413,13 @@
  6 @returns {number} 
  7 @constructor
  8 ```
  9+
 10+### JOIN 
 11+
 12+```
 13+  Concatenates the values of one or more arrays using a specified delimiter. 
 14+@param delimiter - The string to place between the values. 
 15+@param values - The values to be appended using the delimiter. 
 16+@returns {string} 
 17+@constructor
 18+```
 19diff --git a/TODO.md b/TODO.md
 20index 49b421e..d172c6a 100644
 21--- a/TODO.md
 22+++ b/TODO.md
 23@@ -40,7 +40,6 @@ Many of these formulas can be written by allowing the Sheet and Parser to return
 24 
 25 ### Easy formulas to write
 26 * CLEAN
 27-* JOIN
 28 * LEFT
 29 * LEN
 30 * MID
 31diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
 32index 3326bf4..6728ac9 100644
 33--- a/dist/Formulas/AllFormulas.js
 34+++ b/dist/Formulas/AllFormulas.js
 35@@ -228,6 +228,7 @@ exports.T = Text_1.T;
 36 exports.ROMAN = Text_1.ROMAN;
 37 exports.TEXT = Text_1.TEXT;
 38 exports.FIND = Text_1.FIND;
 39+exports.JOIN = Text_1.JOIN;
 40 var Date_1 = require("./Date");
 41 exports.DATE = Date_1.DATE;
 42 exports.DATEVALUE = Date_1.DATEVALUE;
 43diff --git a/dist/Formulas/Text.js b/dist/Formulas/Text.js
 44index e3e9833..34e8627 100644
 45--- a/dist/Formulas/Text.js
 46+++ b/dist/Formulas/Text.js
 47@@ -727,3 +727,21 @@ var FIND = function (searchFor, searchIn, startAt) {
 48     throw new Errors_1.ValueError("For FIND cannot find '" + searchFor + "' within '" + searchIn + "'.");
 49 };
 50 exports.FIND = FIND;
 51+/**
 52+ * Concatenates the values of one or more arrays using a specified delimiter.
 53+ * @param delimiter - The string to place between the values.
 54+ * @param values - The values to be appended using the delimiter.
 55+ * @returns {string}
 56+ * @constructor
 57+ */
 58+var JOIN = function (delimiter) {
 59+    var values = [];
 60+    for (var _i = 1; _i < arguments.length; _i++) {
 61+        values[_i - 1] = arguments[_i];
 62+    }
 63+    ArgsChecker_1.ArgsChecker.checkAtLeastLength(arguments, 2, "JOIN");
 64+    delimiter = TypeConverter_1.TypeConverter.firstValueAsString(delimiter);
 65+    values = Filter_1.Filter.flattenAndThrow(values);
 66+    return values.join(delimiter);
 67+};
 68+exports.JOIN = JOIN;
 69diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
 70index ab5ad6c..f5bb3f2 100644
 71--- a/src/Formulas/AllFormulas.ts
 72+++ b/src/Formulas/AllFormulas.ts
 73@@ -235,7 +235,8 @@ import {
 74   T,
 75   ROMAN,
 76   TEXT,
 77-  FIND
 78+  FIND,
 79+  JOIN
 80 } from "./Text"
 81 import {
 82   DATE,
 83@@ -531,5 +532,6 @@ export {
 84   SUBTOTAL,
 85   HYPGEOMDIST,
 86   ZTEST,
 87-  FIND
 88+  FIND,
 89+  JOIN
 90 }
 91\ No newline at end of file
 92diff --git a/src/Formulas/Text.ts b/src/Formulas/Text.ts
 93index 6a68e4f..e9c28aa 100644
 94--- a/src/Formulas/Text.ts
 95+++ b/src/Formulas/Text.ts
 96@@ -763,6 +763,20 @@ let FIND = function (searchFor, searchIn, startAt?) {
 97   throw new ValueError("For FIND cannot find '" + searchFor + "' within '" + searchIn + "'.");
 98 };
 99 
100+/**
101+ * Concatenates the values of one or more arrays using a specified delimiter.
102+ * @param delimiter - The string to place between the values.
103+ * @param values - The values to be appended using the delimiter.
104+ * @returns {string}
105+ * @constructor
106+ */
107+let JOIN = function (delimiter, ...values) {
108+  ArgsChecker.checkAtLeastLength(arguments, 2, "JOIN");
109+  delimiter = TypeConverter.firstValueAsString(delimiter);
110+  values = Filter.flattenAndThrow(values);
111+  return values.join(delimiter);
112+};
113+
114 export {
115   ARABIC,
116   CHAR,
117@@ -776,5 +790,6 @@ export {
118   T,
119   ROMAN,
120   TEXT,
121-  FIND
122+  FIND,
123+  JOIN
124 }
125\ No newline at end of file
126diff --git a/tests/Formulas/TextTest.ts b/tests/Formulas/TextTest.ts
127index 79282a6..f695ce1 100644
128--- a/tests/Formulas/TextTest.ts
129+++ b/tests/Formulas/TextTest.ts
130@@ -11,7 +11,8 @@ import {
131   T,
132   ROMAN,
133   TEXT,
134-  FIND
135+  FIND,
136+  JOIN
137 } from "../../src/Formulas/Text";
138 import * as ERRORS from "../../src/Errors";
139 import {
140@@ -375,3 +376,14 @@ test("FIND", function(){
141     FIND.apply(this, [2, 3, 4, 5])
142   }, ERRORS.NA_ERROR);
143 });
144+
145+test("JOIN", function(){
146+  assertEquals(JOIN(",", [1, 2, 3, 4, 5]), "1,2,3,4,5");
147+  assertEquals(JOIN(",", 1, 2, 3, 4, 5), "1,2,3,4,5");
148+  assertEquals(JOIN(",", 1, [2], [3, 4, 5]), "1,2,3,4,5");
149+  assertEquals(JOIN("", [1, 2, 3, 4, 5]), "12345");
150+  assertEquals(JOIN(true, [1, 2, 3, 4, 5]), "1TRUE2TRUE3TRUE4TRUE5");
151+  catchAndAssertEquals(function() {
152+    JOIN.apply(this, [2])
153+  }, ERRORS.NA_ERROR);
154+});
155diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
156index 35416e6..7da4ab8 100644
157--- a/tests/SheetFormulaTest.ts
158+++ b/tests/SheetFormulaTest.ts
159@@ -1049,6 +1049,10 @@ test("Sheet FIND", function(){
160   assertFormulaEquals('=FIND("s", "soup")', 1);
161 });
162 
163+test("Sheet JOIN", function(){
164+  assertFormulaEquals('=JOIN([","], [1, 2, 3])', "1,2,3");
165+});
166+
167 test("Sheet parsing error", function(){
168   assertFormulaEqualsError('= 10e', PARSE_ERROR);
169   assertFormulaEqualsError('= SUM(', PARSE_ERROR);