spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[T] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-07-11 00:19:33
stats
8 file(s) changed, 61 insertions(+), 5 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 1cc745c..84b2980 100644
  3--- a/DOCS.md
  4+++ b/DOCS.md
  5@@ -2043,3 +2043,11 @@
  6 @param value - Text to convert. 
  7 @constructor
  8 ```
  9+
 10+### T 
 11+
 12+```
 13+  Returns string arguments as text, or the empty string if the value is not text. 
 14+@param value - Value to return. 
 15+@constructor
 16+```
 17diff --git a/TODO.md b/TODO.md
 18index 5ce3f92..5de4a06 100644
 19--- a/TODO.md
 20+++ b/TODO.md
 21@@ -104,7 +104,6 @@ Many of these formulas can be written by allowing the Sheet and Parser to return
 22 * SEARCHB
 23 * SPLIT
 24 * SUBSTITUTE
 25-* T
 26 * TEXT
 27 * VALUE
 28 * LOGEST
 29diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
 30index cf0a251..282528e 100644
 31--- a/dist/Formulas/AllFormulas.js
 32+++ b/dist/Formulas/AllFormulas.js
 33@@ -191,6 +191,7 @@ exports.CONVERT = Text_1.CONVERT;
 34 exports.TRIM = Text_1.TRIM;
 35 exports.LOWER = Text_1.LOWER;
 36 exports.UPPER = Text_1.UPPER;
 37+exports.T = Text_1.T;
 38 var Date_1 = require("./Date");
 39 exports.DATE = Date_1.DATE;
 40 exports.DATEVALUE = Date_1.DATEVALUE;
 41diff --git a/dist/Formulas/Text.js b/dist/Formulas/Text.js
 42index 84e9562..17cd668 100644
 43--- a/dist/Formulas/Text.js
 44+++ b/dist/Formulas/Text.js
 45@@ -442,3 +442,17 @@ var UPPER = function (value) {
 46     return text.toUpperCase();
 47 };
 48 exports.UPPER = UPPER;
 49+/**
 50+ * Returns string arguments as text, or the empty string if the value is not text.
 51+ * @param value - Value to return.
 52+ * @constructor
 53+ */
 54+var T = function (value) {
 55+    ArgsChecker_1.ArgsChecker.checkLength(arguments, 1, "T");
 56+    var v = TypeConverter_1.TypeConverter.firstValue(value);
 57+    if (typeof v === "string") {
 58+        return v;
 59+    }
 60+    return "";
 61+};
 62+exports.T = T;
 63diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
 64index 86b8bee..1e65db2 100644
 65--- a/src/Formulas/AllFormulas.ts
 66+++ b/src/Formulas/AllFormulas.ts
 67@@ -197,7 +197,8 @@ import {
 68   CONVERT,
 69   TRIM,
 70   LOWER,
 71-  UPPER
 72+  UPPER,
 73+  T
 74 } from "./Text"
 75 import {
 76   DATE,
 77@@ -445,5 +446,6 @@ export {
 78   IFERROR,
 79   TYPE,
 80   COLUMN,
 81-  ROW
 82+  ROW,
 83+  T
 84 }
 85\ No newline at end of file
 86diff --git a/src/Formulas/Text.ts b/src/Formulas/Text.ts
 87index c5d5437..53fa1ae 100644
 88--- a/src/Formulas/Text.ts
 89+++ b/src/Formulas/Text.ts
 90@@ -462,6 +462,21 @@ var UPPER = function (value) {
 91   return text.toUpperCase();
 92 };
 93 
 94+
 95+/**
 96+ * Returns string arguments as text, or the empty string if the value is not text.
 97+ * @param value - Value to return.
 98+ * @constructor
 99+ */
100+var T = function (value) {
101+  ArgsChecker.checkLength(arguments, 1, "T");
102+  var v = TypeConverter.firstValue(value);
103+  if (typeof v === "string") {
104+    return v;
105+  }
106+  return "";
107+};
108+
109 export {
110   ARABIC,
111   CHAR,
112@@ -471,5 +486,6 @@ export {
113   CONVERT,
114   TRIM,
115   LOWER,
116-  UPPER
117+  UPPER,
118+  T
119 }
120\ No newline at end of file
121diff --git a/tests/Formulas/TextTest.ts b/tests/Formulas/TextTest.ts
122index 9adfc8b..de81d38 100644
123--- a/tests/Formulas/TextTest.ts
124+++ b/tests/Formulas/TextTest.ts
125@@ -7,7 +7,8 @@ import {
126   CONVERT,
127   TRIM,
128   LOWER,
129-  UPPER
130+  UPPER,
131+  T
132 } from "../../src/Formulas/Text";
133 import * as ERRORS from "../../src/Errors";
134 import {
135@@ -176,3 +177,14 @@ test("UPPER", function(){
136     UPPER.apply(this, ["test", 5]);
137   }, ERRORS.NA_ERROR);
138 });
139+
140+
141+test("T", function(){
142+  assertEquals(T("test"), "test");
143+  assertEquals(T(["test"]), "test");
144+  assertEquals(T(5), "");
145+  assertEquals(T(false), "");
146+  catchAndAssertEquals(function() {
147+    T.apply(this, []);
148+  }, ERRORS.NA_ERROR);
149+});
150diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
151index 1fe1496..0087a24 100644
152--- a/tests/SheetFormulaTest.ts
153+++ b/tests/SheetFormulaTest.ts
154@@ -877,6 +877,10 @@ test("Sheet ROW", function(){
155   assertFormulaEqualsDependsOnReference('D2', 10, '=ROW(D2)', 2);
156 });
157 
158+test("Sheet T", function(){
159+  assertFormulaEquals('=T(10)', "");
160+  assertFormulaEquals('=T("str")', "str");
161+});
162 
163 test("Sheet *", function(){
164   assertFormulaEquals('= 10 * 10', 100);