spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[Text.LEN] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-10-08 15:54:24
stats
8 file(s) changed, 59 insertions(+), 6 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 da37b9e..cf70de2 100644
  3--- a/DOCS.md
  4+++ b/DOCS.md
  5@@ -2423,3 +2423,11 @@
  6 @returns {string} 
  7 @constructor
  8 ```
  9+
 10+### LEN 
 11+
 12+```
 13+  Returns the length of a string including spaces. 
 14+@param value - The text whose length is to be determined. 
 15+@constructor
 16+```
 17diff --git a/TODO.md b/TODO.md
 18index d172c6a..eec33bb 100644
 19--- a/TODO.md
 20+++ b/TODO.md
 21@@ -41,7 +41,6 @@ Many of these formulas can be written by allowing the Sheet and Parser to return
 22 ### Easy formulas to write
 23 * CLEAN
 24 * LEFT
 25-* LEN
 26 * MID
 27 * PROPER
 28 * REGEXEXTRACT - May be difficult considering language differences.
 29diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
 30index 6728ac9..50fde0f 100644
 31--- a/dist/Formulas/AllFormulas.js
 32+++ b/dist/Formulas/AllFormulas.js
 33@@ -229,6 +229,7 @@ exports.ROMAN = Text_1.ROMAN;
 34 exports.TEXT = Text_1.TEXT;
 35 exports.FIND = Text_1.FIND;
 36 exports.JOIN = Text_1.JOIN;
 37+exports.LEN = Text_1.LEN;
 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 34e8627..08f66c7 100644
 43--- a/dist/Formulas/Text.js
 44+++ b/dist/Formulas/Text.js
 45@@ -745,3 +745,14 @@ var JOIN = function (delimiter) {
 46     return values.join(delimiter);
 47 };
 48 exports.JOIN = JOIN;
 49+/**
 50+ * Returns the length of a string including spaces.
 51+ * @param value - The text whose length is to be determined.
 52+ * @constructor
 53+ */
 54+var LEN = function (value) {
 55+    ArgsChecker_1.ArgsChecker.checkLength(arguments, 1, "LEN");
 56+    value = TypeConverter_1.TypeConverter.firstValueAsString(value);
 57+    return value.length;
 58+};
 59+exports.LEN = LEN;
 60diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
 61index f5bb3f2..e4de41e 100644
 62--- a/src/Formulas/AllFormulas.ts
 63+++ b/src/Formulas/AllFormulas.ts
 64@@ -236,7 +236,8 @@ import {
 65   ROMAN,
 66   TEXT,
 67   FIND,
 68-  JOIN
 69+  JOIN,
 70+  LEN
 71 } from "./Text"
 72 import {
 73   DATE,
 74@@ -533,5 +534,6 @@ export {
 75   HYPGEOMDIST,
 76   ZTEST,
 77   FIND,
 78-  JOIN
 79+  JOIN,
 80+  LEN
 81 }
 82\ No newline at end of file
 83diff --git a/src/Formulas/Text.ts b/src/Formulas/Text.ts
 84index e9c28aa..245b128 100644
 85--- a/src/Formulas/Text.ts
 86+++ b/src/Formulas/Text.ts
 87@@ -777,6 +777,17 @@ let JOIN = function (delimiter, ...values) {
 88   return values.join(delimiter);
 89 };
 90 
 91+/**
 92+ * Returns the length of a string including spaces.
 93+ * @param value - The text whose length is to be determined.
 94+ * @constructor
 95+ */
 96+let LEN = function (value) {
 97+  ArgsChecker.checkLength(arguments, 1, "LEN");
 98+  value = TypeConverter.firstValueAsString(value);
 99+  return value.length;
100+};
101+
102 export {
103   ARABIC,
104   CHAR,
105@@ -791,5 +802,6 @@ export {
106   ROMAN,
107   TEXT,
108   FIND,
109-  JOIN
110+  JOIN,
111+  LEN
112 }
113\ No newline at end of file
114diff --git a/tests/Formulas/TextTest.ts b/tests/Formulas/TextTest.ts
115index f695ce1..357c8dc 100644
116--- a/tests/Formulas/TextTest.ts
117+++ b/tests/Formulas/TextTest.ts
118@@ -12,7 +12,8 @@ import {
119   ROMAN,
120   TEXT,
121   FIND,
122-  JOIN
123+  JOIN,
124+  LEN
125 } from "../../src/Formulas/Text";
126 import * as ERRORS from "../../src/Errors";
127 import {
128@@ -387,3 +388,18 @@ test("JOIN", function(){
129     JOIN.apply(this, [2])
130   }, ERRORS.NA_ERROR);
131 });
132+
133+test("LEN", function(){
134+  assertEquals(LEN("soup"), 4);
135+  assertEquals(LEN("jja sdkj lkasj lkajlskaj dlj lask"), 33);
136+  assertEquals(LEN(""), 0);
137+  assertEquals(LEN(4), 1);
138+  assertEquals(LEN(44), 2);
139+  assertEquals(LEN(true), 4);
140+  catchAndAssertEquals(function() {
141+    LEN.apply(this, [])
142+  }, ERRORS.NA_ERROR);
143+  catchAndAssertEquals(function() {
144+    LEN.apply(this, [2, 4])
145+  }, ERRORS.NA_ERROR);
146+});
147diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
148index 7da4ab8..66dcd8e 100644
149--- a/tests/SheetFormulaTest.ts
150+++ b/tests/SheetFormulaTest.ts
151@@ -1053,6 +1053,10 @@ test("Sheet JOIN", function(){
152   assertFormulaEquals('=JOIN([","], [1, 2, 3])', "1,2,3");
153 });
154 
155+test("Sheet LEN", function(){
156+  assertFormulaEquals('=LEN("soup")', 4);
157+});
158+
159 test("Sheet parsing error", function(){
160   assertFormulaEqualsError('= 10e', PARSE_ERROR);
161   assertFormulaEqualsError('= SUM(', PARSE_ERROR);