spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[ISERR] formula added and tested (pending correct calling from Parser/Sheet)
author
Ben Vogt <[email protected]>
date
2017-07-09 18:36:30
stats
8 file(s) changed, 67 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 66c91b8..638059d 100644
  3--- a/DOCS.md
  4+++ b/DOCS.md
  5@@ -638,6 +638,15 @@
  6 @returns {boolean} 
  7 @constructor
  8 ```
  9+
 10+### ISERR 
 11+
 12+```
 13+  Returns TRUE if the value refers to any error value except #NA. You can use this function to control error values in certain cells. If an error occurs, the function returns a logical or numerical value. 
 14+@param value - Any value or expression in which a test is performed to determine whether an error value not equal to #NA is present. 
 15+@returns {boolean} 
 16+@constructor TODO: This formula needs to be called from inside a try-catch-block in the SheetParser, like ERROR.TYPE.
 17+```
 18 ## Logical
 19 
 20 
 21diff --git a/TODO.md b/TODO.md
 22index d4dec21..e389f96 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-* 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.
 30 * ISERROR - See ISERR.
 31 * ISFORMULA - Requires changes to Parser/Sheet to fetch a cell, and check the formula field to see if it contains a formula.
 32 * ISNA - Requires changes to Parser/Sheet for similar reasons to ISERR; check reference cell value or error field.
 33diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
 34index a9b4979..4689911 100644
 35--- a/dist/Formulas/AllFormulas.js
 36+++ b/dist/Formulas/AllFormulas.js
 37@@ -91,6 +91,7 @@ exports.N = Info_1.N;
 38 exports.ISREF = Info_1.ISREF;
 39 exports.ERRORTYPE = Info_1.ERRORTYPE;
 40 exports.ISBLANK = Info_1.ISBLANK;
 41+exports.ISERR = Info_1.ISERR;
 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 0d17632..5d180ff 100644
 47--- a/dist/Formulas/Info.js
 48+++ b/dist/Formulas/Info.js
 49@@ -195,3 +195,19 @@ var ISBLANK = function (value) {
 50     return value === undefined;
 51 };
 52 exports.ISBLANK = ISBLANK;
 53+/**
 54+ * Returns TRUE if the value refers to any error value except #N/A. You can use this function to control error values
 55+ * in certain cells. If an error occurs, the function returns a logical or numerical value.
 56+ * @param value - Any value or expression in which a test is performed to determine whether an error value not equal to
 57+ * #N/A is present.
 58+ * @returns {boolean}
 59+ * @constructor
 60+ * TODO: This formula needs to be called from inside a try-catch-block in the Sheet/Parser, like ERROR.TYPE.
 61+ */
 62+var ISERR = function (value) {
 63+    if (value instanceof Error) {
 64+        return value.name !== Errors_1.NA_ERROR;
 65+    }
 66+    return false;
 67+};
 68+exports.ISERR = ISERR;
 69diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
 70index 81bbbdc..17f4009 100644
 71--- a/src/Formulas/AllFormulas.ts
 72+++ b/src/Formulas/AllFormulas.ts
 73@@ -90,7 +90,8 @@ import {
 74   N,
 75   ISREF,
 76   ERRORTYPE,
 77-  ISBLANK
 78+  ISBLANK,
 79+  ISERR
 80 } from "./Info";
 81 import {
 82   CHOOSE
 83@@ -431,5 +432,6 @@ export {
 84   COVAR,
 85   ISREF,
 86   ERRORTYPE,
 87-  ISBLANK
 88+  ISBLANK,
 89+  ISERR
 90 }
 91\ No newline at end of file
 92diff --git a/src/Formulas/Info.ts b/src/Formulas/Info.ts
 93index 0a9de85..c23eefe 100644
 94--- a/src/Formulas/Info.ts
 95+++ b/src/Formulas/Info.ts
 96@@ -212,6 +212,23 @@ var ISBLANK = function (value) {
 97 };
 98 
 99 
100+/**
101+ * Returns TRUE if the value refers to any error value except #N/A. You can use this function to control error values
102+ * in certain cells. If an error occurs, the function returns a logical or numerical value.
103+ * @param value - Any value or expression in which a test is performed to determine whether an error value not equal to
104+ * #N/A is present.
105+ * @returns {boolean}
106+ * @constructor
107+ * TODO: This formula needs to be called from inside a try-catch-block in the Sheet/Parser, like ERROR.TYPE.
108+ */
109+var ISERR = function (value) {
110+  if (value instanceof Error) {
111+    return value.name !== NA_ERROR;
112+  }
113+  return false;
114+};
115+
116+
117 export {
118   NA,
119   ISTEXT,
120@@ -223,5 +240,6 @@ export {
121   N,
122   ISREF,
123   ERRORTYPE,
124-  ISBLANK
125+  ISBLANK,
126+  ISERR
127 }
128\ No newline at end of file
129diff --git a/tests/Formulas/InfoTest.ts b/tests/Formulas/InfoTest.ts
130index ecd4d6c..1b1f77b 100644
131--- a/tests/Formulas/InfoTest.ts
132+++ b/tests/Formulas/InfoTest.ts
133@@ -9,7 +9,8 @@ import {
134   N,
135   ISREF,
136   ERRORTYPE,
137-  ISBLANK
138+  ISBLANK,
139+  ISERR
140 } from "../../src/Formulas/Info";
141 import * as ERRORS from "../../src/Errors";
142 import {
143@@ -163,3 +164,13 @@ test("ISBLANK", function(){
144     ISBLANK.apply(this, [])
145   }, ERRORS.NA_ERROR);
146 });
147+
148+
149+test("ISERR", function(){
150+  assertEquals(ISERR(10), false);
151+  assertEquals(ISERR([]), false);
152+  assertEquals(ISERR(new NAError("error")), false);
153+  assertEquals(ISERR(new DivZeroError("error")), true);
154+  assertEquals(ISERR(new NameError("error")), true);
155+  assertEquals(ISERR(new RefError("error")), true);
156+});
157diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
158index b88f502..32510bd 100644
159--- a/tests/SheetFormulaTest.ts
160+++ b/tests/SheetFormulaTest.ts
161@@ -840,6 +840,10 @@ test("Sheet ISBLANK", function(){
162   assertFormulaEquals('=ISBLANK(N10)', true);
163 });
164 
165+test("Sheet ISERR", function(){
166+  assertFormulaEquals('=ISERR(10)', false);
167+});
168+
169 test("Sheet *", function(){
170   assertFormulaEquals('= 10 * 10', 100);
171   assertFormulaEquals('= 10 * 0', 0);