spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[ISEMAIL] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-06-30 15:05:22
stats
8 file(s) changed, 65 insertions(+), 8 deletions(-)
files
DOCS.md
TODO.md
dist/Formulas/AllFormulas.js
dist/Formulas/Info.js
src/Formulas/AllFormulas.ts
src/Formulas/Info.ts
tests/Formulas/InfoTest.ts
tests/Utilities/FilterTest.ts
  1diff --git a/DOCS.md b/DOCS.md
  2index 6772131..26296ba 100644
  3--- a/DOCS.md
  4+++ b/DOCS.md
  5@@ -585,6 +585,15 @@
  6 @returns {boolean} 
  7 @constructor
  8 ```
  9+
 10+### ISEMAIL 
 11+
 12+```
 13+  Returns true if input is a valid email. Valid domains are Original top-level domains and Country code top-level domains, 
 14+@param value - Value to check whether it is an email or not. 
 15+@returns {boolean} 
 16+@constructor
 17+```
 18 ## Logical
 19 
 20 
 21diff --git a/TODO.md b/TODO.md
 22index c381230..f6e3e20 100644
 23--- a/TODO.md
 24+++ b/TODO.md
 25@@ -26,9 +26,8 @@ For example 64 tbs to a qt.
 26 ### Formulas to write
 27 
 28 * ERROR.TYPE - Requires changes to parser.js
 29-* ISBLANK - May require changes to parser.js
 30-* ISEMAIL
 31-* ISERR
 32+* ISBLANK - Requires changes to parser.js
 33+* ISERR - Requires changes to parser.js
 34 * ISERROR - Requires changes to parser.js
 35 * ISFORMULA - Requires changes to parser.js
 36 * ISNA - Requires changes to parser.js
 37diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
 38index df51afe..b1c1cfd 100644
 39--- a/dist/Formulas/AllFormulas.js
 40+++ b/dist/Formulas/AllFormulas.js
 41@@ -82,6 +82,7 @@ exports.ISTEXT = Info_1.ISTEXT;
 42 exports.ISLOGICAL = Info_1.ISLOGICAL;
 43 exports.ISNUMBER = Info_1.ISNUMBER;
 44 exports.ISNONTEXT = Info_1.ISNONTEXT;
 45+exports.ISEMAIL = Info_1.ISEMAIL;
 46 var Lookup_1 = require("./Lookup");
 47 exports.CHOOSE = Lookup_1.CHOOSE;
 48 var Logical_1 = require("./Logical");
 49diff --git a/dist/Formulas/Info.js b/dist/Formulas/Info.js
 50index 743a4d4..a9c027b 100644
 51--- a/dist/Formulas/Info.js
 52+++ b/dist/Formulas/Info.js
 53@@ -56,3 +56,19 @@ var ISNUMBER = function (value) {
 54     return typeof TypeConverter_1.TypeConverter.firstValue(value) === "number";
 55 };
 56 exports.ISNUMBER = ISNUMBER;
 57+/**
 58+ * Returns true if input is a valid email. Valid domains are Original top-level domains and Country code top-level
 59+ * domains,
 60+ * @param value - Value to check whether it is an email or not.
 61+ * @returns {boolean}
 62+ * @constructor
 63+ */
 64+var ISEMAIL = function (value) {
 65+    ArgsChecker_1.ArgsChecker.checkLength(arguments, 1, "ISEMAIL");
 66+    if (typeof value !== "string") {
 67+        return false;
 68+    }
 69+    var EMAIL_REGEX = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|gov|mil||edu||int|biz|info|mobi|name|aero|jobs|museum|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bl|bm|bn|bo|bq|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mf|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|za|zm|zw)\b/;
 70+    return EMAIL_REGEX.test(value);
 71+};
 72+exports.ISEMAIL = ISEMAIL;
 73diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
 74index b4385c9..610867b 100644
 75--- a/src/Formulas/AllFormulas.ts
 76+++ b/src/Formulas/AllFormulas.ts
 77@@ -81,7 +81,8 @@ import {
 78   ISTEXT,
 79   ISLOGICAL,
 80   ISNUMBER,
 81-  ISNONTEXT
 82+  ISNONTEXT,
 83+  ISEMAIL
 84 } from "./Info";
 85 import {
 86   CHOOSE
 87@@ -383,5 +384,6 @@ export {
 88   MIRR,
 89   IRR,
 90   IPMT,
 91-  FV
 92+  FV,
 93+  ISEMAIL
 94 }
 95\ No newline at end of file
 96diff --git a/src/Formulas/Info.ts b/src/Formulas/Info.ts
 97index f369500..7243245 100644
 98--- a/src/Formulas/Info.ts
 99+++ b/src/Formulas/Info.ts
100@@ -67,10 +67,28 @@ var ISNUMBER = function (value) {
101 };
102 
103 
104+/**
105+ * Returns true if input is a valid email. Valid domains are Original top-level domains and Country code top-level
106+ * domains,
107+ * @param value - Value to check whether it is an email or not.
108+ * @returns {boolean}
109+ * @constructor
110+ */
111+var ISEMAIL = function (value) {
112+  ArgsChecker.checkLength(arguments, 1, "ISEMAIL");
113+  if (typeof value !== "string") {
114+    return false;
115+  }
116+  const EMAIL_REGEX = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|gov|mil||edu||int|biz|info|mobi|name|aero|jobs|museum|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bl|bm|bn|bo|bq|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mf|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|za|zm|zw)\b/;
117+  return EMAIL_REGEX.test(value);
118+};
119+
120+
121 export {
122   NA,
123   ISTEXT,
124   ISLOGICAL,
125   ISNUMBER,
126-  ISNONTEXT
127+  ISNONTEXT,
128+  ISEMAIL
129 }
130\ No newline at end of file
131diff --git a/tests/Formulas/InfoTest.ts b/tests/Formulas/InfoTest.ts
132index c157726..de88146 100644
133--- a/tests/Formulas/InfoTest.ts
134+++ b/tests/Formulas/InfoTest.ts
135@@ -3,7 +3,8 @@ import {
136   ISTEXT,
137   ISLOGICAL,
138   ISNUMBER,
139-  ISNONTEXT
140+  ISNONTEXT,
141+  ISEMAIL
142 } from "../../src/Formulas/Info";
143 import * as ERRORS from "../../src/Errors";
144 import {
145@@ -58,3 +59,15 @@ test("ISNONTEXT", function(){
146     ISNONTEXT.apply(this, []);
147   }, ERRORS.NA_ERROR);
148 });
149+
150+test("ISEMAIL", function(){
151+  assertEquals(ISEMAIL("str"), false);
152+  assertEquals(ISEMAIL("[email protected]"), true);
153+  assertEquals(ISEMAIL("[email protected]"), true);
154+  assertEquals(ISEMAIL("[email protected]"), true);
155+  assertEquals(ISEMAIL("[email protected]"), true);
156+  assertEquals(ISEMAIL("[email protected]"), true);
157+  catchAndAssertEquals(function() {
158+    ISEMAIL.apply(this, []);
159+  }, ERRORS.NA_ERROR);
160+});
161diff --git a/tests/Utilities/FilterTest.ts b/tests/Utilities/FilterTest.ts
162index 4c97989..3233b0c 100644
163--- a/tests/Utilities/FilterTest.ts
164+++ b/tests/Utilities/FilterTest.ts
165@@ -16,7 +16,6 @@ test("Filter.flatten", function () {
166 
167 
168 test("Filter.filterOutNonNumberValues", function () {
169-  // TODO: This function seems to be questionable. Look at where it's used and if it can be made more specific.
170   assertArrayEquals(Filter.filterOutNonNumberValues([0, 1, 2, 3, undefined, "0"]), [0, 1, 2, 3, undefined]);
171   assertArrayEquals(Filter.filterOutNonNumberValues([0, 1, 2, 3, 4, 5, 6, 7]), [0, 1, 2, 3, 4, 5, 6, 7]);
172 });