spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[N] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-07-07 03:49:24
stats
8 file(s) changed, 56 insertions(+), 7 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 1139362..39503f2 100644
  3--- a/DOCS.md
  4+++ b/DOCS.md
  5@@ -603,6 +603,15 @@
  6 @returns {boolean} 
  7 @constructor
  8 ```
  9+
 10+### N 
 11+
 12+```
 13+  Returns the value as a number. 
 14+@param value - value to return. 
 15+@returns {number} 
 16+@constructor
 17+```
 18 ## Logical
 19 
 20 
 21diff --git a/TODO.md b/TODO.md
 22index b56d220..472237c 100644
 23--- a/TODO.md
 24+++ b/TODO.md
 25@@ -32,7 +32,6 @@ For example 64 tbs to a qt.
 26 * ISFORMULA - Requires changes to parser.js
 27 * ISNA - Requires changes to parser.js
 28 * ISREF - Requires changes to parser.js
 29-* N
 30 * TYPE - Requires changes to parser.js
 31 * CELL - Requires changes to parser.js
 32 * IFERROR - Requires changes to parser.js
 33diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
 34index ab72a64..8511065 100644
 35--- a/dist/Formulas/AllFormulas.js
 36+++ b/dist/Formulas/AllFormulas.js
 37@@ -85,6 +85,7 @@ exports.ISNUMBER = Info_1.ISNUMBER;
 38 exports.ISNONTEXT = Info_1.ISNONTEXT;
 39 exports.ISEMAIL = Info_1.ISEMAIL;
 40 exports.ISURL = Info_1.ISURL;
 41+exports.N = Info_1.N;
 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 148fe8e..588740f 100644
 47--- a/dist/Formulas/Info.js
 48+++ b/dist/Formulas/Info.js
 49@@ -109,3 +109,14 @@ var ISURL = function (value) {
 50     return true;
 51 };
 52 exports.ISURL = ISURL;
 53+/**
 54+ * Returns the value as a number.
 55+ * @param value - value to return.
 56+ * @returns {number}
 57+ * @constructor
 58+ */
 59+var N = function (value) {
 60+    ArgsChecker_1.ArgsChecker.checkLength(arguments, 1, "N");
 61+    return TypeConverter_1.TypeConverter.firstValueAsNumber(value);
 62+};
 63+exports.N = N;
 64diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
 65index 4a864ce..ebe2932 100644
 66--- a/src/Formulas/AllFormulas.ts
 67+++ b/src/Formulas/AllFormulas.ts
 68@@ -84,7 +84,8 @@ import {
 69   ISNUMBER,
 70   ISNONTEXT,
 71   ISEMAIL,
 72-  ISURL
 73+  ISURL,
 74+  N
 75 } from "./Info";
 76 import {
 77   CHOOSE
 78@@ -414,5 +415,6 @@ export {
 79   NEGBINOMDIST,
 80   GEOMEAN,
 81   HARMEAN,
 82-  CONFIDENCE
 83+  CONFIDENCE,
 84+  N
 85 }
 86\ No newline at end of file
 87diff --git a/src/Formulas/Info.ts b/src/Formulas/Info.ts
 88index 706efb6..0b198b5 100644
 89--- a/src/Formulas/Info.ts
 90+++ b/src/Formulas/Info.ts
 91@@ -120,6 +120,17 @@ var ISURL = function (value) {
 92   return true;
 93 };
 94 
 95+/**
 96+ * Returns the value as a number.
 97+ * @param value - value to return.
 98+ * @returns {number}
 99+ * @constructor
100+ */
101+var N = function (value) {
102+  ArgsChecker.checkLength(arguments, 1, "N");
103+  return TypeConverter.firstValueAsNumber(value);
104+};
105+
106 
107 export {
108   NA,
109@@ -128,5 +139,6 @@ export {
110   ISNUMBER,
111   ISNONTEXT,
112   ISEMAIL,
113-  ISURL
114+  ISURL,
115+  N
116 }
117\ No newline at end of file
118diff --git a/tests/Formulas/InfoTest.ts b/tests/Formulas/InfoTest.ts
119index 4b67de7..a1a6507 100644
120--- a/tests/Formulas/InfoTest.ts
121+++ b/tests/Formulas/InfoTest.ts
122@@ -5,7 +5,8 @@ import {
123   ISNUMBER,
124   ISNONTEXT,
125   ISEMAIL,
126-  ISURL
127+  ISURL,
128+  N
129 } from "../../src/Formulas/Info";
130 import * as ERRORS from "../../src/Errors";
131 import {
132@@ -95,3 +96,14 @@ test("ISURL", function(){
133     ISURL.apply(this, []);
134   }, ERRORS.NA_ERROR);
135 });
136+
137+test("N", function(){
138+  assertEquals(N("10"), 10);
139+  assertEquals(N(10), 10);
140+  assertEquals(N(true), 1);
141+  assertEquals(N(false), 0);
142+  assertEquals(N(["10", "str"]), 10);
143+  catchAndAssertEquals(function() {
144+    NA.apply(this, []);
145+  }, ERRORS.NA_ERROR);
146+});
147diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
148index 512052d..636d9d5 100644
149--- a/tests/SheetFormulaTest.ts
150+++ b/tests/SheetFormulaTest.ts
151@@ -805,10 +805,14 @@ test("Sheet HARMEAN", function(){
152   assertFormulaEquals('=HARMEAN(10, 4, 6, 3, 6, 7, 1, 1)', 2.532027128862095);
153 });
154 
155-test("Sheet HARMEAN", function(){
156+test("Sheet CONFIDENCE", function(){
157   assertFormulaEquals('=CONFIDENCE(0.04, 6.48, 25)', 2.6616585881788426);
158 });
159 
160+test("Sheet N", function(){
161+  assertFormulaEquals('=N("10")', 10);
162+});
163+
164 test("Sheet *", function(){
165   assertFormulaEquals('= 10 * 10', 100);
166   assertFormulaEquals('= 10 * 0', 0);