spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[ISBLANK] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-07-09 18:26:48
stats
8 file(s) changed, 74 insertions(+), 5 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/SheetFormulaTest.ts
  1diff --git a/DOCS.md b/DOCS.md
  2index 8b21433..66c91b8 100644
  3--- a/DOCS.md
  4+++ b/DOCS.md
  5@@ -629,6 +629,15 @@
  6 @param value - Contains either the addrereference of the cell in which the error occurs, or the error directly. Eg: `=ERRORTYPE(NA())` 
  7 @constructor TODO: This formula, while written correctly in javascript, needs to be called inside of a try-catch-block inside the ParserSheet. Otherwise the errors thrown by nested formulas break through. Eg: `=ERRORTYPE(NA())`, NA bubbles up. Once this is done, we should test it inside SheetFormulaTest.ts
  8 ```
  9+
 10+### ISBLANK 
 11+
 12+```
 13+  Returns TRUE if the reference to a cell is blank. This function is used to determine if the content of a cell is empty. A cell with a formula inside is not empty. If an error occurs, the function returns a logical or numerical value. 
 14+@param value - The content to be tested. 
 15+@returns {boolean} 
 16+@constructor
 17+```
 18 ## Logical
 19 
 20 
 21diff --git a/TODO.md b/TODO.md
 22index 6a31622..d4dec21 100644
 23--- a/TODO.md
 24+++ b/TODO.md
 25@@ -38,7 +38,6 @@ See documentation for ERROR.TYPE for more information.
 26 ### Meta-Formulas to write
 27 Many of these formulas can be written by allowing the Sheet and Parser to return Cell objects in addition to primitive types. There are some memory issues with doing this. If a user calls something like `ISNA(A1:A99999)` we really only need the first cell. So we should return cell objects in some cases, but it would be easier in most cases to have context aware formulas, so if they need a cell, or a reference, we simply skip looking up a reference, and instead return a reference, or just a single cell. One way to do this would be to have formula functions, and then on the side have formula args. So before we lookup a large range of cells, we can check to see if it needs all of them, or if it just cares about the first one. So for `ISNA` we could look at `FormulaArgs.ISNA[0]` to get `Value` so we know that it needs only a single argument that is not an array, so if we call it with `ISNA(A1:A99999)`, it would really only lookup `A1`. This might be premature optimization however.
 28 
 29-* ISBLANK - Requires changes to Parser/Sheet. If we fetch a cell, and it is "blank", return true. Could be implemented by adding a field to cells indicating if they're blank. Right now empty cells are causing errors because they don't exist. We should allow users to fetch empty cells, they should just be considered blank, or undefined, or null.
 30 * ISERR - Requires changes to Parser/Sheet to either wrap enclosed functions in try-catch, or fetch actual cell value, and check it's error field.
 31 * ISERROR - See ISERR.
 32 * ISFORMULA - Requires changes to Parser/Sheet to fetch a cell, and check the formula field to see if it contains a formula.
 33diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
 34index f2f3312..a9b4979 100644
 35--- a/dist/Formulas/AllFormulas.js
 36+++ b/dist/Formulas/AllFormulas.js
 37@@ -90,6 +90,7 @@ exports.ISURL = Info_1.ISURL;
 38 exports.N = Info_1.N;
 39 exports.ISREF = Info_1.ISREF;
 40 exports.ERRORTYPE = Info_1.ERRORTYPE;
 41+exports.ISBLANK = Info_1.ISBLANK;
 42 var Lookup_1 = require("./Lookup");
 43 exports.CHOOSE = Lookup_1.CHOOSE;
 44 var Logical_1 = require("./Logical");
 45diff --git a/dist/Formulas/Info.js b/dist/Formulas/Info.js
 46index 3255d8a..0d17632 100644
 47--- a/dist/Formulas/Info.js
 48+++ b/dist/Formulas/Info.js
 49@@ -144,6 +144,7 @@ exports.ISREF = ISREF;
 50  * Once this is done, we should test it inside SheetFormulaTest.ts
 51  */
 52 var ERRORTYPE = function (value) {
 53+    ArgsChecker_1.ArgsChecker.checkLength(arguments, 1, "ERRORTYPE");
 54     value = TypeConverter_1.TypeConverter.firstValue(value);
 55     if (value instanceof Cell_1.Cell) {
 56         if (value.hasError()) {
 57@@ -178,3 +179,19 @@ var ERRORTYPE = function (value) {
 58     }
 59 };
 60 exports.ERRORTYPE = ERRORTYPE;
 61+/**
 62+ * Returns TRUE if the reference to a cell is blank. This function is used to determine if the content of a cell is
 63+ * empty. A cell with a formula inside is not empty. If an error occurs, the function returns a logical or numerical
 64+ * value.
 65+ * @param value - The content to be tested.
 66+ * @returns {boolean}
 67+ * @constructor
 68+ */
 69+var ISBLANK = function (value) {
 70+    ArgsChecker_1.ArgsChecker.checkLength(arguments, 1, "ISBLANK");
 71+    if (value instanceof Cell_1.Cell) {
 72+        return value.isBlank();
 73+    }
 74+    return value === undefined;
 75+};
 76+exports.ISBLANK = ISBLANK;
 77diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
 78index 8fc6d51..81bbbdc 100644
 79--- a/src/Formulas/AllFormulas.ts
 80+++ b/src/Formulas/AllFormulas.ts
 81@@ -89,7 +89,8 @@ import {
 82   ISURL,
 83   N,
 84   ISREF,
 85-  ERRORTYPE
 86+  ERRORTYPE,
 87+  ISBLANK
 88 } from "./Info";
 89 import {
 90   CHOOSE
 91@@ -429,5 +430,6 @@ export {
 92   BINOMDIST,
 93   COVAR,
 94   ISREF,
 95-  ERRORTYPE
 96+  ERRORTYPE,
 97+  ISBLANK
 98 }
 99\ No newline at end of file
100diff --git a/src/Formulas/Info.ts b/src/Formulas/Info.ts
101index 55bd0d3..0a9de85 100644
102--- a/src/Formulas/Info.ts
103+++ b/src/Formulas/Info.ts
104@@ -11,6 +11,7 @@ import {
105 import {
106   Cell
107 } from "../Cell";
108+import {Filter} from "../Utilities/Filter";
109 
110 
111 /**
112@@ -160,6 +161,7 @@ var ISREF = function (value) {
113  * Once this is done, we should test it inside SheetFormulaTest.ts
114  */
115 var ERRORTYPE = function (value) {
116+  ArgsChecker.checkLength(arguments, 1, "ERRORTYPE");
117   value = TypeConverter.firstValue(value);
118   if (value instanceof Cell) {
119     if (value.hasError()) {
120@@ -193,6 +195,23 @@ var ERRORTYPE = function (value) {
121 };
122 
123 
124+/**
125+ * Returns TRUE if the reference to a cell is blank. This function is used to determine if the content of a cell is
126+ * empty. A cell with a formula inside is not empty. If an error occurs, the function returns a logical or numerical
127+ * value.
128+ * @param value - The content to be tested.
129+ * @returns {boolean}
130+ * @constructor
131+ */
132+var ISBLANK = function (value) {
133+  ArgsChecker.checkLength(arguments, 1, "ISBLANK");
134+  if (value instanceof Cell) {
135+    return value.isBlank();
136+  }
137+  return value === undefined;
138+};
139+
140+
141 export {
142   NA,
143   ISTEXT,
144@@ -203,5 +222,6 @@ export {
145   ISURL,
146   N,
147   ISREF,
148-  ERRORTYPE
149+  ERRORTYPE,
150+  ISBLANK
151 }
152\ No newline at end of file
153diff --git a/tests/Formulas/InfoTest.ts b/tests/Formulas/InfoTest.ts
154index 8a7ae71..ecd4d6c 100644
155--- a/tests/Formulas/InfoTest.ts
156+++ b/tests/Formulas/InfoTest.ts
157@@ -8,7 +8,8 @@ import {
158   ISURL,
159   N,
160   ISREF,
161-  ERRORTYPE
162+  ERRORTYPE,
163+  ISBLANK
164 } from "../../src/Formulas/Info";
165 import * as ERRORS from "../../src/Errors";
166 import {
167@@ -150,3 +151,15 @@ test("ERRORTYPE", function(){
168     ERRORTYPE(10);
169   }, ERRORS.NA_ERROR);
170 });
171+
172+
173+test("ISBLANK", function(){
174+  assertEquals(ISBLANK(10), false);
175+  assertEquals(ISBLANK([]), false);
176+  assertEquals(ISBLANK(undefined), true);
177+  assertEquals(ISBLANK(Cell.BuildFrom("A1", 10)), false);
178+  assertEquals(ISBLANK(new Cell("A1")), true);
179+  catchAndAssertEquals(function() {
180+    ISBLANK.apply(this, [])
181+  }, ERRORS.NA_ERROR);
182+});
183diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
184index bc6f782..b88f502 100644
185--- a/tests/SheetFormulaTest.ts
186+++ b/tests/SheetFormulaTest.ts
187@@ -835,6 +835,11 @@ test("Sheet ISREF", function(){
188   assertFormulaEquals('=ISREF(100)', false);
189 });
190 
191+test("Sheet ISBLANK", function(){
192+  assertFormulaEquals('=ISBLANK(10)', false);
193+  assertFormulaEquals('=ISBLANK(N10)', true);
194+});
195+
196 test("Sheet *", function(){
197   assertFormulaEquals('= 10 * 10', 100);
198   assertFormulaEquals('= 10 * 0', 0);