commit
message
[Helpers] removing in favor of TypeConverter
author
Ben Vogt <[email protected]>
date
2017-05-11 01:56:56
stats
3 file(s) changed,
6 insertions(+),
51 deletions(-)
files
src/Helpers.ts
src/Sheet.ts
tests/Formulas/HelperTest.ts
1diff --git a/src/Helpers.ts b/src/Helpers.ts
2deleted file mode 100644
3index 6a4b18f..0000000
4--- a/src/Helpers.ts
5+++ /dev/null
6@@ -1,27 +0,0 @@
7-var Helpers = {
8- number: function (num) {
9- var reg = new RegExp('(^[-+]?([0-9]+)(\.[0-9]+)?)$');
10- switch (typeof num) {
11- case 'number':
12- return num;
13- case 'string':
14- var t = num.trim();
15- if (!isNaN(t)) {
16- if (reg.test(t.trim())) {
17- if (t.indexOf('.') > -1) {
18- return parseFloat(t);
19- } else {
20- return parseInt(t, 10);
21- }
22- } else {
23- return 0;
24- }
25- }
26- }
27- return num;
28- }
29-};
30-
31-export {
32- Helpers
33-}
34\ No newline at end of file
35diff --git a/src/Sheet.ts b/src/Sheet.ts
36index 8a42060..3194839 100644
37--- a/src/Sheet.ts
38+++ b/src/Sheet.ts
39@@ -1,9 +1,9 @@
40 /// <reference path="parser.d.ts"/>
41 import { Parser } from "./Parser";
42 import { Cell } from "./Cell"
43-import {DivZeroError, RefError, NameError} from "./Errors"
44-import { Helpers } from "./Helpers";
45+import { DivZeroError, RefError, NameError } from "./Errors"
46 import { Formulas } from "./Formulas";
47+import { TypeConverter } from "./Utilities/TypeConverter";
48
49
50 /**
51@@ -335,7 +335,10 @@ var Sheet = (function () {
52 };
53
54 var helper = {
55- number: Helpers.number,
56+ /**
57+ * Is the value a number or can the value be interpreted as a number
58+ */
59+ number: TypeConverter.valueToNumber,
60
61 string: function (str) {
62 return str.substring(1, str.length - 1);
63diff --git a/tests/Formulas/HelperTest.ts b/tests/Formulas/HelperTest.ts
64deleted file mode 100644
65index e33b84a..0000000
66--- a/tests/Formulas/HelperTest.ts
67+++ /dev/null
68@@ -1,21 +0,0 @@
69-import {
70- Helpers
71-} from "../../src/Helpers";
72-import {
73- assertEquals,
74- test
75-} from "../utils/Asserts"
76-
77-test("Helpers.number", function(){
78- assertEquals(-1, Helpers.number("-1"));
79- assertEquals(1, Helpers.number("+1"));
80- assertEquals(1.8239817293871983e+28, Helpers.number("18239817293871982379817157562"));
81- assertEquals(1.8239817293871983e+28, Helpers.number("+18239817293871982379817157562"));
82- assertEquals(-1.8239817293871983e+28, Helpers.number("-18239817293871982379817157562"));
83- assertEquals(0, Helpers.number("10."));
84- assertEquals(111, Helpers.number("000111"));
85- assertEquals("10 + 10", Helpers.number("10 + 10"));
86- assertEquals("10/10", Helpers.number("10/10"));
87- assertEquals("10*10", Helpers.number("10*10"));
88- assertEquals(10.18239817293872, Helpers.number("10.18239817293871982379817157562"));
89-});