commit
message
[TypeConverter] We're not really casting values, so much as converting them
author
Ben Vogt <[email protected]>
date
2017-05-06 01:10:45
stats
9 file(s) changed,
306 insertions(+),
291 deletions(-)
files
README.md
src/Formulas/Date.ts
src/Formulas/Engineering.ts
src/Formulas/Financial.ts
src/Formulas/Logical.ts
src/Formulas/Math.ts
src/Formulas/Statistical.ts
src/Formulas/Text.ts
src/Utilities/TypeCaster.ts
src/Utilities/TypeConverter.ts
1diff --git a/README.md b/README.md
2index a9d237f..d8f84c9 100644
3--- a/README.md
4+++ b/README.md
5@@ -14,7 +14,7 @@ Things I should do.
6 ### COUNT and COUNTA should be different.
7
8
9-### All formulas should used TypeCaster to pull parameters from `values`
10+### All formulas should used TypeConverter to pull parameters from `values`
11
12
13 ### Criteria evaluations should escape reg-ex characters
14diff --git a/src/Formulas/Date.ts b/src/Formulas/Date.ts
15index 3871b4d..b09d4ed 100644
16--- a/src/Formulas/Date.ts
17+++ b/src/Formulas/Date.ts
18@@ -4,8 +4,8 @@ import {
19 ArgsChecker
20 } from "../Utilities/ArgsChecker";
21 import {
22- TypeCaster
23-} from "../Utilities/TypeCaster";
24+ TypeConverter
25+} from "../Utilities/TypeConverter";
26 import {
27 NumError,
28 ValueError,
29@@ -23,15 +23,15 @@ import {
30 var DATE = function (...values) : number {
31 const FIRST_YEAR = 1900;
32 ArgsChecker.checkLength(values, 3);
33- var year = Math.abs(Math.floor(TypeCaster.firstValueAsNumber(values[0]))); // No negative values for year
34- var month = Math.floor(TypeCaster.firstValueAsNumber(values[1])) - 1; // Months are between 0 and 11.
35- var day = Math.floor(TypeCaster.firstValueAsNumber(values[2])) - 1; // Days are also zero-indexed.
36- var m = moment.utc(TypeCaster.ORIGIN_MOMENT)
37+ var year = Math.abs(Math.floor(TypeConverter.firstValueAsNumber(values[0]))); // No negative values for year
38+ var month = Math.floor(TypeConverter.firstValueAsNumber(values[1])) - 1; // Months are between 0 and 11.
39+ var day = Math.floor(TypeConverter.firstValueAsNumber(values[2])) - 1; // Days are also zero-indexed.
40+ var m = moment.utc(TypeConverter.ORIGIN_MOMENT)
41 .add(2, "days")
42 .add(year < FIRST_YEAR ? year : year - FIRST_YEAR, 'years') // If the value is less than 1900, assume 1900 as start index for year
43 .add(month, 'months')
44 .add(day, 'days');
45- var dateAsNumber = TypeCaster.momentToDayNumber(m);
46+ var dateAsNumber = TypeConverter.momentToDayNumber(m);
47 if (dateAsNumber < 0) {
48 throw new NumError("DATE evaluates to an out of range value " + dateAsNumber
49 + ". It should be greater than or equal to 0.");
50@@ -49,10 +49,10 @@ var DATE = function (...values) : number {
51 */
52 var DATEVALUE = function (...values) : number {
53 ArgsChecker.checkLength(values, 1);
54- var dateString = TypeCaster.firstValueAsString(values[0]);
55+ var dateString = TypeConverter.firstValueAsString(values[0]);
56 var dateAsNumber;
57 try {
58- dateAsNumber = TypeCaster.stringToDateNumber(dateString);
59+ dateAsNumber = TypeConverter.stringToDateNumber(dateString);
60 } catch (e) {
61 throw new ValueError("DATEVALUE parameter '" + dateString + "' cannot be parsed to date/time.");
62 }
63@@ -71,14 +71,14 @@ var DATEVALUE = function (...values) : number {
64 */
65 var EDATE = function (...values) : number {
66 ArgsChecker.checkLength(values, 2);
67- var startDateNumber = TypeCaster.firstValueAsDateNumber(values[0], true); // tell firstValueAsDateNumber to coerce boolean
68+ var startDateNumber = TypeConverter.firstValueAsDateNumber(values[0], true); // tell firstValueAsDateNumber to coerce boolean
69 if (startDateNumber < 0) {
70 throw new NumError("Function EDATE parameter 1 value is " + startDateNumber+ ". It should be greater than or equal to 0.");
71 }
72- var months = Math.floor(TypeCaster.firstValueAsNumber(values[1]));
73+ var months = Math.floor(TypeConverter.firstValueAsNumber(values[1]));
74 // While momentToDayNumber will return an inclusive count of days since 1900/1/1, moment.Moment.add assumes exclusive
75 // count of days.
76- return TypeCaster.momentToDayNumber(moment.utc(TypeCaster.ORIGIN_MOMENT).add(startDateNumber, "days").add(months, "months"));
77+ return TypeConverter.momentToDayNumber(moment.utc(TypeConverter.ORIGIN_MOMENT).add(startDateNumber, "days").add(months, "months"));
78 };
79
80
81@@ -93,12 +93,12 @@ var EDATE = function (...values) : number {
82 */
83 var EOMONTH = function (...values) : number {
84 ArgsChecker.checkLength(values, 2);
85- var startDateNumber = TypeCaster.firstValueAsDateNumber(values[0], true); // tell firstValueAsDateNumber to coerce boolean
86+ var startDateNumber = TypeConverter.firstValueAsDateNumber(values[0], true); // tell firstValueAsDateNumber to coerce boolean
87 if (startDateNumber < 0) {
88 throw new NumError("Function EOMONTH parameter 1 value is " + startDateNumber + ". It should be greater than or equal to 0.");
89 }
90- var months = Math.floor(TypeCaster.firstValueAsNumber(values[1]));
91- return TypeCaster.momentToDayNumber(moment.utc(TypeCaster.ORIGIN_MOMENT)
92+ var months = Math.floor(TypeConverter.firstValueAsNumber(values[1]));
93+ return TypeConverter.momentToDayNumber(moment.utc(TypeConverter.ORIGIN_MOMENT)
94 .add(startDateNumber, "days")
95 .add(months, "months")
96 .endOf("month"));
97@@ -114,11 +114,11 @@ var EOMONTH = function (...values) : number {
98 */
99 var DAY = function (...values) : number {
100 ArgsChecker.checkLength(values, 1);
101- var dateNumber = TypeCaster.firstValueAsDateNumber(values[0], true); // tell firstValueAsDateNumber to coerce boolean
102+ var dateNumber = TypeConverter.firstValueAsDateNumber(values[0], true); // tell firstValueAsDateNumber to coerce boolean
103 if (dateNumber < 0) {
104 throw new NumError("Function DAY parameter 1 value is " + dateNumber + ". It should be greater than or equal to 0.");
105 }
106- return TypeCaster.numberToMoment(dateNumber).date();
107+ return TypeConverter.numberToMoment(dateNumber).date();
108 };
109
110
111@@ -131,8 +131,8 @@ var DAY = function (...values) : number {
112 */
113 var DAYS = function (...values) : number {
114 ArgsChecker.checkLength(values, 2);
115- var end = TypeCaster.firstValueAsDateNumber(values[0], true); // tell firstValueAsDateNumber to coerce boolean
116- var start = TypeCaster.firstValueAsDateNumber(values[1], true); // tell firstValueAsDateNumber to coerce boolean
117+ var end = TypeConverter.firstValueAsDateNumber(values[0], true); // tell firstValueAsDateNumber to coerce boolean
118+ var start = TypeConverter.firstValueAsDateNumber(values[1], true); // tell firstValueAsDateNumber to coerce boolean
119 return end - start;
120 };
121
122@@ -155,11 +155,11 @@ var DAYS = function (...values) : number {
123 */
124 var DAYS360 = function (...values) : number {
125 ArgsChecker.checkLengthWithin(values, 2, 3);
126- var start = TypeCaster.numberToMoment(TypeCaster.firstValueAsDateNumber(values[0], true)); // tell firstValueAsDateNumber to coerce boolean
127- var end = TypeCaster.numberToMoment(TypeCaster.firstValueAsDateNumber(values[1], true)); // tell firstValueAsDateNumber to coerce boolean
128+ var start = TypeConverter.numberToMoment(TypeConverter.firstValueAsDateNumber(values[0], true)); // tell firstValueAsDateNumber to coerce boolean
129+ var end = TypeConverter.numberToMoment(TypeConverter.firstValueAsDateNumber(values[1], true)); // tell firstValueAsDateNumber to coerce boolean
130 var methodToUse = false;
131 if (values.length === 3) {
132- methodToUse = TypeCaster.firstValueAsBoolean(values[2]);
133+ methodToUse = TypeConverter.firstValueAsBoolean(values[2]);
134 }
135 var smd = 31;
136 var emd = 31;
137@@ -194,11 +194,11 @@ var DAYS360 = function (...values) : number {
138 */
139 var MONTH = function (...values) : number {
140 ArgsChecker.checkLength(values, 1);
141- var date = TypeCaster.firstValueAsDateNumber(values[0], true); // tell firstValueAsDateNumber to coerce boolean
142+ var date = TypeConverter.firstValueAsDateNumber(values[0], true); // tell firstValueAsDateNumber to coerce boolean
143 if (date < 0) {
144 throw new NumError("Function MONTH parameter 1 value is " + date + ". It should be greater than or equal to 0.");
145 }
146- return TypeCaster.numberToMoment(date).month() + 1;
147+ return TypeConverter.numberToMoment(date).month() + 1;
148 };
149
150
151@@ -211,11 +211,11 @@ var MONTH = function (...values) : number {
152 */
153 var YEAR = function (...values) : number {
154 ArgsChecker.checkLength(values, 1);
155- var date = TypeCaster.firstValueAsDateNumber(values[0], true); // tell firstValueAsDateNumber to coerce boolean
156+ var date = TypeConverter.firstValueAsDateNumber(values[0], true); // tell firstValueAsDateNumber to coerce boolean
157 if (date < 0) {
158 throw new NumError("Function YEAR parameter 1 value is " + date + ". It should be greater than or equal to 0.");
159 }
160- return TypeCaster.numberToMoment(date).year();
161+ return TypeConverter.numberToMoment(date).year();
162 };
163
164
165@@ -233,12 +233,12 @@ var YEAR = function (...values) : number {
166 */
167 var WEEKDAY = function (...values) : number {
168 ArgsChecker.checkLengthWithin(values, 1, 2);
169- var date = TypeCaster.firstValueAsDateNumber(values[0], true); // tell firstValueAsDateNumber to coerce boolean
170- var offsetType = values.length === 2 ? TypeCaster.firstValueAsNumber(values[1]) : 1;
171+ var date = TypeConverter.firstValueAsDateNumber(values[0], true); // tell firstValueAsDateNumber to coerce boolean
172+ var offsetType = values.length === 2 ? TypeConverter.firstValueAsNumber(values[1]) : 1;
173 if (date < 0) {
174 throw new NumError("Function WEEKDAY parameter 1 value is " + date + ". It should be greater than or equal to 0.");
175 }
176- var day = TypeCaster.numberToMoment(date).day();
177+ var day = TypeConverter.numberToMoment(date).day();
178 if (offsetType === 1) {
179 return day + 1;
180 } else if (offsetType === 2) {
181@@ -292,12 +292,12 @@ function calculateWeekNum(dm : moment.Moment, shifterArray : Array<number>) : nu
182 */
183 var WEEKNUM = function (...values) : number {
184 ArgsChecker.checkLengthWithin(values, 1, 2);
185- var date = TypeCaster.firstValueAsDateNumber(values[0], true); // tell firstValueAsDateNumber to coerce boolean
186- var shiftType = values.length === 2 ? TypeCaster.firstValueAsNumber(values[1]) : 1;
187+ var date = TypeConverter.firstValueAsDateNumber(values[0], true); // tell firstValueAsDateNumber to coerce boolean
188+ var shiftType = values.length === 2 ? TypeConverter.firstValueAsNumber(values[1]) : 1;
189 if (date < 0) {
190 throw new NumError("Function YEAR parameter 1 value is " + date + ". It should be greater than or equal to 0.");
191 }
192- var dm = TypeCaster.numberToMoment(date);
193+ var dm = TypeConverter.numberToMoment(date);
194 var week = dm.week();
195 var dayOfWeek = dm.day(); // between 1 and 7, inclusively
196 if (shiftType === 1) {
197@@ -364,12 +364,12 @@ var WEEKNUM = function (...values) : number {
198 */
199 var DATEDIF = function (...values) : number {
200 ArgsChecker.checkLength(values, 3);
201- var start = TypeCaster.firstValueAsDateNumber(values[0], true);
202- var end = TypeCaster.firstValueAsDateNumber(values[1], true);
203- var unit = TypeCaster.firstValueAsString(values[2]);
204+ var start = TypeConverter.firstValueAsDateNumber(values[0], true);
205+ var end = TypeConverter.firstValueAsDateNumber(values[1], true);
206+ var unit = TypeConverter.firstValueAsString(values[2]);
207 var unitClean = unit.toUpperCase();
208- var startMoment = TypeCaster.numberToMoment(start);
209- var endMoment = TypeCaster.numberToMoment(end);
210+ var startMoment = TypeConverter.numberToMoment(start);
211+ var endMoment = TypeConverter.numberToMoment(end);
212
213 if (start > end) {
214 throw new NumError("Function DATEDIF parameter 1 (" + start.toString() +
215@@ -433,12 +433,12 @@ var DATEDIF = function (...values) : number {
216 */
217 var YEARFRAC = function (...values) : number {
218 ArgsChecker.checkLengthWithin(values, 2, 3);
219- var start = TypeCaster.firstValueAsDateNumber(values[0], true);
220- var end = TypeCaster.firstValueAsDateNumber(values[1], true);
221- var basis = values.length === 2 ? 0 : TypeCaster.firstValueAsNumber(values[2]);
222+ var start = TypeConverter.firstValueAsDateNumber(values[0], true);
223+ var end = TypeConverter.firstValueAsDateNumber(values[1], true);
224+ var basis = values.length === 2 ? 0 : TypeConverter.firstValueAsNumber(values[2]);
225
226- var s = TypeCaster.numberToMoment(start);
227- var e = TypeCaster.numberToMoment(end);
228+ var s = TypeConverter.numberToMoment(start);
229+ var e = TypeConverter.numberToMoment(end);
230 if (e.isBefore(s)) {
231 var me = moment.utc(e);
232 e = moment.utc(s);
233@@ -528,9 +528,9 @@ var YEARFRAC = function (...values) : number {
234 */
235 var TIMEVALUE = function (...values) : number {
236 ArgsChecker.checkLength(values, 1);
237- var timeString = TypeCaster.firstValueAsString(values[0]);
238+ var timeString = TypeConverter.firstValueAsString(values[0]);
239 try {
240- return TypeCaster.stringToTimeNumber(timeString);
241+ return TypeConverter.stringToTimeNumber(timeString);
242 } catch (e) {
243 throw new ValueError("TIMEVALUE parameter '" + timeString + "' cannot be parsed to date/time.");
244 }
245@@ -547,7 +547,7 @@ const MILLISECONDS_IN_DAY = 86400000;
246 */
247 var HOUR = function (...values) : number {
248 ArgsChecker.checkLength(values, 1);
249- var time = TypeCaster.firstValueAsTimestampNumber(values[0]);
250+ var time = TypeConverter.firstValueAsTimestampNumber(values[0]);
251 if (time % 1 === 0) {
252 return 0;
253 }
254@@ -565,7 +565,7 @@ var HOUR = function (...values) : number {
255 */
256 var MINUTE = function (...values) : number {
257 ArgsChecker.checkLength(values, 1);
258- var time = TypeCaster.firstValueAsTimestampNumber(values[0]);
259+ var time = TypeConverter.firstValueAsTimestampNumber(values[0]);
260 if (time % 1 === 0) {
261 return 0;
262 }
263@@ -582,7 +582,7 @@ var MINUTE = function (...values) : number {
264 */
265 var SECOND = function (...values) : number {
266 ArgsChecker.checkLength(values, 1);
267- var time = TypeCaster.firstValueAsTimestampNumber(values[0]);
268+ var time = TypeConverter.firstValueAsTimestampNumber(values[0]);
269 if (time % 1 === 0) {
270 return 0;
271 }
272@@ -604,8 +604,8 @@ var SECOND = function (...values) : number {
273 */
274 var NETWORKDAYS = function (...values) : number {
275 ArgsChecker.checkLengthWithin(values, 2, 3);
276- var start = TypeCaster.firstValueAsDateNumber(values[0], true);
277- var end = TypeCaster.firstValueAsDateNumber(values[1], true);
278+ var start = TypeConverter.firstValueAsDateNumber(values[0], true);
279+ var end = TypeConverter.firstValueAsDateNumber(values[1], true);
280 var hasHolidays = values.length === 3;
281 var holidays = [];
282 if (hasHolidays) {
283@@ -629,7 +629,7 @@ var NETWORKDAYS = function (...values) : number {
284 start = swap;
285 }
286
287- var countMoment = moment.utc(TypeCaster.numberToMoment(start));
288+ var countMoment = moment.utc(TypeConverter.numberToMoment(start));
289 var weekendDays = [6, 0]; // Default weekend_days.
290 var days = end - start + 1;
291 var networkDays = days;
292@@ -637,7 +637,7 @@ var NETWORKDAYS = function (...values) : number {
293 while (j < days) {
294 if (weekendDays.indexOf(countMoment.day()) >= 0) {
295 networkDays--;
296- } else if (hasHolidays && holidays.indexOf(TypeCaster.momentToDayNumber(countMoment)) > -1) {
297+ } else if (hasHolidays && holidays.indexOf(TypeConverter.momentToDayNumber(countMoment)) > -1) {
298 networkDays--;
299 }
300 countMoment.add(1, 'days');
301@@ -670,11 +670,11 @@ var NETWORKDAYS = function (...values) : number {
302 */
303 var NETWORKDAYS$INTL = function (...values) : number {
304 ArgsChecker.checkLengthWithin(values, 2, 4);
305- var start = TypeCaster.firstValueAsDateNumber(values[0], true);
306- var end = TypeCaster.firstValueAsDateNumber(values[1], true);
307+ var start = TypeConverter.firstValueAsDateNumber(values[0], true);
308+ var end = TypeConverter.firstValueAsDateNumber(values[1], true);
309 var weekendDays = [];
310 if (values.length >= 3) {
311- var weekend = TypeCaster.firstValue(values[2]);
312+ var weekend = TypeConverter.firstValue(values[2]);
313 if (typeof weekend === "string") {
314 if (!/^[0-1]{6,}$/.test(weekend)) {
315 throw new NumError("Function NETWORKDAYS.INTL parameter 3 requires a number in the format '0000011'. "
316@@ -742,14 +742,14 @@ var NETWORKDAYS$INTL = function (...values) : number {
317 start = swap;
318 }
319
320- var countMoment = moment.utc(TypeCaster.numberToMoment(start));
321+ var countMoment = moment.utc(TypeConverter.numberToMoment(start));
322 var days = end - start + 1;
323 var networkDays = days;
324 var j = 0;
325 while (j < days) {
326 if (weekendDays.indexOf(countMoment.day()) >= 0) {
327 networkDays--;
328- } else if (hasHolidays && holidays.indexOf(TypeCaster.momentToDayNumber(countMoment)) > -1) {
329+ } else if (hasHolidays && holidays.indexOf(TypeConverter.momentToDayNumber(countMoment)) > -1) {
330 networkDays--;
331 }
332 countMoment.add(1, 'days');
333@@ -769,7 +769,7 @@ var NETWORKDAYS$INTL = function (...values) : number {
334 */
335 var NOW = function (...values) : number {
336 ArgsChecker.checkLength(values, 0);
337- return TypeCaster.momentToNumber(moment.utc());
338+ return TypeConverter.momentToNumber(moment.utc());
339 };
340
341 /**
342@@ -779,7 +779,7 @@ var NOW = function (...values) : number {
343 */
344 var TODAY = function (...values) : number {
345 ArgsChecker.checkLength(values, 0);
346- return TypeCaster.momentToNumber(moment.utc().startOf("day"));
347+ return TypeConverter.momentToNumber(moment.utc().startOf("day"));
348 };
349
350
351@@ -794,10 +794,10 @@ var TODAY = function (...values) : number {
352 */
353 var TIME = function (...values) : number {
354 ArgsChecker.checkLength(values, 3);
355- var hours = Math.floor(TypeCaster.firstValueAsNumber(values[0]));
356- var minutes = Math.floor(TypeCaster.firstValueAsNumber(values[1]));
357- var seconds = Math.floor(TypeCaster.firstValueAsNumber(values[2]));
358- var e = TypeCaster.unitsToTimeNumber(hours, minutes, seconds);
359+ var hours = Math.floor(TypeConverter.firstValueAsNumber(values[0]));
360+ var minutes = Math.floor(TypeConverter.firstValueAsNumber(values[1]));
361+ var seconds = Math.floor(TypeConverter.firstValueAsNumber(values[2]));
362+ var e = TypeConverter.unitsToTimeNumber(hours, minutes, seconds);
363 if (e < 0) {
364 throw new NumError("TIME evaluates to an out of range value " + e + ". It should be greater than or equal to 0.");
365 }
366@@ -819,8 +819,8 @@ var TIME = function (...values) : number {
367 */
368 var WORKDAY = function (...values) : number {
369 ArgsChecker.checkLengthWithin(values, 2, 3);
370- var start = TypeCaster.firstValueAsDateNumber(values[0], true);
371- var days = TypeCaster.firstValueAsNumber(values[1]);
372+ var start = TypeConverter.firstValueAsDateNumber(values[0], true);
373+ var days = TypeConverter.firstValueAsNumber(values[1]);
374 var hasHolidays = values.length === 3;
375 var holidays = [];
376 if (hasHolidays) {
377@@ -837,20 +837,20 @@ var WORKDAY = function (...values) : number {
378 }
379 }
380 } else {
381- holidays.push(TypeCaster.valueToNumber(values[2]));
382+ holidays.push(TypeConverter.valueToNumber(values[2]));
383 }
384 }
385
386 var weekendDays = [0, 6];
387- var countMoment = moment.utc(TypeCaster.numberToMoment(start));
388+ var countMoment = moment.utc(TypeConverter.numberToMoment(start));
389 var j = 0;
390 while (j < days) {
391 countMoment.add(1, 'days');
392- if (weekendDays.indexOf(countMoment.day()) < 0 && holidays.indexOf(TypeCaster.momentToDayNumber(countMoment)) < 0) {
393+ if (weekendDays.indexOf(countMoment.day()) < 0 && holidays.indexOf(TypeConverter.momentToDayNumber(countMoment)) < 0) {
394 j++;
395 }
396 }
397- return TypeCaster.momentToDayNumber(countMoment);
398+ return TypeConverter.momentToDayNumber(countMoment);
399 };
400
401
402@@ -871,11 +871,11 @@ var WORKDAY = function (...values) : number {
403 */
404 var WORKDAY$INTL = function (...values) : number {
405 ArgsChecker.checkLengthWithin(values, 2, 3);
406- var start = TypeCaster.firstValueAsDateNumber(values[0], true);
407- var days = TypeCaster.firstValueAsNumber(values[1]);
408+ var start = TypeConverter.firstValueAsDateNumber(values[0], true);
409+ var days = TypeConverter.firstValueAsNumber(values[1]);
410 var weekendDays = [];
411 if (values.length >= 3) {
412- var weekend = TypeCaster.firstValue(values[2]);
413+ var weekend = TypeConverter.firstValue(values[2]);
414 if (typeof weekend === "string") {
415 if (!/^[0-1]{6,}$/.test(weekend)) {
416 throw new NumError("Function WORKDAY.INTL parameter 3 requires a number in the format '0000011'. "
417@@ -936,18 +936,18 @@ var WORKDAY$INTL = function (...values) : number {
418 }
419 }
420 } else {
421- holidays.push(TypeCaster.valueToNumber(values[3]));
422+ holidays.push(TypeConverter.valueToNumber(values[3]));
423 }
424 }
425- var countMoment = moment.utc(TypeCaster.numberToMoment(start));
426+ var countMoment = moment.utc(TypeConverter.numberToMoment(start));
427 var j = 0;
428 while (j < days) {
429 countMoment.add(1, 'days');
430- if (weekendDays.indexOf(countMoment.day()) < 0 && holidays.indexOf(TypeCaster.momentToDayNumber(countMoment)) < 0) {
431+ if (weekendDays.indexOf(countMoment.day()) < 0 && holidays.indexOf(TypeConverter.momentToDayNumber(countMoment)) < 0) {
432 j++;
433 }
434 }
435- return TypeCaster.momentToDayNumber(countMoment);
436+ return TypeConverter.momentToDayNumber(countMoment);
437 };
438
439 export {
440diff --git a/src/Formulas/Engineering.ts b/src/Formulas/Engineering.ts
441index 59edbf7..d78e0fa 100644
442--- a/src/Formulas/Engineering.ts
443+++ b/src/Formulas/Engineering.ts
444@@ -2,8 +2,8 @@ import {
445 ArgsChecker
446 } from "../Utilities/ArgsChecker";
447 import {
448- TypeCaster
449-} from "../Utilities/TypeCaster";
450+ TypeConverter
451+} from "../Utilities/TypeConverter";
452 import {
453 ValueError,
454 NumError
455@@ -19,10 +19,10 @@ import {
456 */
457 var BIN2DEC = function (...values) : number {
458 ArgsChecker.checkLength(values, 1);
459- if (typeof TypeCaster.firstValue(values[0]) === "boolean") {
460+ if (typeof TypeConverter.firstValue(values[0]) === "boolean") {
461 throw new ValueError("Function BIN2DEC parameter 1 expects text values. But '" + values[0] + "' is a boolean and cannot be coerced to a text.");
462 }
463- var n = TypeCaster.firstValueAsString(values[0]);
464+ var n = TypeConverter.firstValueAsString(values[0]);
465 if (!(/^[01]{1,10}$/).test(n)) {
466 throw new NumError("Input for BIN2DEC ('" + n + "') is not a valid binary representation.");
467 }
468@@ -45,13 +45,13 @@ var BIN2DEC = function (...values) : number {
469 */
470 var BIN2HEX = function (...values) : string {
471 ArgsChecker.checkLengthWithin(values, 1, 2);
472- if (typeof TypeCaster.firstValue(values[0]) === "boolean") {
473+ if (typeof TypeConverter.firstValue(values[0]) === "boolean") {
474 throw new ValueError("Function BIN2HEX parameter 1 expects text values. But '" + values[0] + "' is a boolean and cannot be coerced to a text.");
475 }
476- var n = TypeCaster.firstValueAsString(values[0]);
477+ var n = TypeConverter.firstValueAsString(values[0]);
478 var p = 10;
479 if (values.length === 2) {
480- p = TypeCaster.firstValueAsNumber(values[1]);
481+ p = TypeConverter.firstValueAsNumber(values[1]);
482 }
483 if (!(/^[01]{1,10}$/).test(n)) {
484 throw new NumError("Input for BIN2HEX ('"+n+"') is not a valid binary representation.");
485@@ -91,13 +91,13 @@ var BIN2HEX = function (...values) : string {
486 */
487 var BIN2OCT = function (...values) : string {
488 ArgsChecker.checkLengthWithin(values, 1, 2);
489- if (typeof TypeCaster.firstValue(values[0]) === "boolean") {
490+ if (typeof TypeConverter.firstValue(values[0]) === "boolean") {
491 throw new ValueError("Function BIN2OCT parameter 1 expects text values. But '" + values[0] + "' is a boolean and cannot be coerced to a text.");
492 }
493- var n = TypeCaster.firstValueAsString(values[0]);
494+ var n = TypeConverter.firstValueAsString(values[0]);
495 var p = 10;
496 if (values.length === 2) {
497- p = TypeCaster.firstValueAsNumber(values[1]);
498+ p = TypeConverter.firstValueAsNumber(values[1]);
499 }
500 if (!(/^[01]{1,10}$/).test(n)) {
501 throw new NumError("Input for BIN2OCT ('"+n+"') is not a valid binary representation.");
502@@ -136,7 +136,7 @@ var BIN2OCT = function (...values) : string {
503 */
504 var DEC2OCT = function (...values) : string {
505 ArgsChecker.checkLengthWithin(values, 1, 2);
506- var n = TypeCaster.firstValueAsNumber(values[0]);
507+ var n = TypeConverter.firstValueAsNumber(values[0]);
508 if (n < 0) {
509 n = Math.ceil(n);
510 }
511@@ -146,7 +146,7 @@ var DEC2OCT = function (...values) : string {
512 var p = 10;
513 var placesPresent = false;
514 if (values.length === 2) {
515- p = Math.floor(TypeCaster.firstValueAsNumber(values[1]));
516+ p = Math.floor(TypeConverter.firstValueAsNumber(values[1]));
517 placesPresent = true;
518 }
519 if (n < -53687092 || n > 536870911) {
520@@ -184,7 +184,7 @@ var DEC2OCT = function (...values) : string {
521 */
522 var DEC2HEX = function (...values) : string {
523 ArgsChecker.checkLengthWithin(values, 1, 2);
524- var n = TypeCaster.firstValueAsNumber(values[0]);
525+ var n = TypeConverter.firstValueAsNumber(values[0]);
526 if (n < 0) {
527 n = Math.ceil(n);
528 }
529@@ -194,7 +194,7 @@ var DEC2HEX = function (...values) : string {
530 var p = 10;
531 var placesPresent = false;
532 if (values.length === 2) {
533- p = Math.floor(TypeCaster.firstValueAsNumber(values[1]));
534+ p = Math.floor(TypeConverter.firstValueAsNumber(values[1]));
535 placesPresent = true;
536 }
537 if (n < -549755813888 || n > 549755813887) {
538@@ -232,7 +232,7 @@ var DEC2HEX = function (...values) : string {
539 */
540 var DEC2BIN = function (...values) : string {
541 ArgsChecker.checkLengthWithin(values, 1, 2);
542- var n = TypeCaster.firstValueAsNumber(values[0]);
543+ var n = TypeConverter.firstValueAsNumber(values[0]);
544 if (n < 0) {
545 n = Math.ceil(n);
546 }
547@@ -245,7 +245,7 @@ var DEC2BIN = function (...values) : string {
548 var p = 10;
549 var placesPresent = false;
550 if (values.length === 2) {
551- p = Math.floor(TypeCaster.firstValueAsNumber(values[1]));
552+ p = Math.floor(TypeConverter.firstValueAsNumber(values[1]));
553 placesPresent = true;
554 }
555
556@@ -301,9 +301,9 @@ var DEC2BIN = function (...values) : string {
557 var DELTA = function (...values) : number {
558 ArgsChecker.checkLengthWithin(values, 1, 2);
559 if (values.length === 1) {
560- return TypeCaster.valueToNumber(values[0]) === 0 ? 1 : 0;
561+ return TypeConverter.valueToNumber(values[0]) === 0 ? 1 : 0;
562 }
563- return TypeCaster.valueToNumber(values[0]) === TypeCaster.valueToNumber(values[1]) ? 1 : 0;
564+ return TypeConverter.valueToNumber(values[0]) === TypeConverter.valueToNumber(values[1]) ? 1 : 0;
565 };
566
567 export {
568diff --git a/src/Formulas/Financial.ts b/src/Formulas/Financial.ts
569index ae252a0..ed4cc64 100644
570--- a/src/Formulas/Financial.ts
571+++ b/src/Formulas/Financial.ts
572@@ -2,9 +2,9 @@ import {
573 ArgsChecker
574 } from "../Utilities/ArgsChecker";
575 import {
576- TypeCaster,
577+ TypeConverter,
578 checkForDevideByZero
579-} from "../Utilities/TypeCaster";
580+} from "../Utilities/TypeConverter";
581 import {
582 NumError,
583 DivZeroError
584@@ -26,11 +26,11 @@ import {
585 */
586 var DDB = function (...values) : number {
587 ArgsChecker.checkLengthWithin(values, 4, 5);
588- var cost = TypeCaster.firstValueAsNumber(values[0]);
589- var salvage = TypeCaster.firstValueAsNumber(values[1]);
590- var life = TypeCaster.firstValueAsNumber(values[2]);
591- var period = TypeCaster.firstValueAsNumber(values[3]);
592- var factor = values.length === 5 ? TypeCaster.firstValueAsNumber(values[4]) : 2;
593+ var cost = TypeConverter.firstValueAsNumber(values[0]);
594+ var salvage = TypeConverter.firstValueAsNumber(values[1]);
595+ var life = TypeConverter.firstValueAsNumber(values[2]);
596+ var period = TypeConverter.firstValueAsNumber(values[3]);
597+ var factor = values.length === 5 ? TypeConverter.firstValueAsNumber(values[4]) : 2;
598
599 if (cost < 0) {
600 throw new NumError("Function DDB parameter 1 value is "
601@@ -78,11 +78,11 @@ var DDB = function (...values) : number {
602 */
603 var DB = function (...values) : number {
604 ArgsChecker.checkLengthWithin(values, 4, 5);
605- var cost = TypeCaster.firstValueAsNumber(values[0]);
606- var salvage = TypeCaster.firstValueAsNumber(values[1]);
607- var life = TypeCaster.firstValueAsNumber(values[2]);
608- var period = TypeCaster.firstValueAsNumber(values[3]);
609- var month = values.length === 5 ? Math.floor(TypeCaster.firstValueAsNumber(values[4])) : 12;
610+ var cost = TypeConverter.firstValueAsNumber(values[0]);
611+ var salvage = TypeConverter.firstValueAsNumber(values[1]);
612+ var life = TypeConverter.firstValueAsNumber(values[2]);
613+ var period = TypeConverter.firstValueAsNumber(values[3]);
614+ var month = values.length === 5 ? Math.floor(TypeConverter.firstValueAsNumber(values[4])) : 12;
615 if (cost < 0) {
616 throw new NumError("Function DB parameter 1 value is "
617 + cost + ". It should be greater than or equal to 0.");
618@@ -141,8 +141,8 @@ var DB = function (...values) : number {
619 */
620 var DOLLAR = function (...values) : number {
621 ArgsChecker.checkLengthWithin(values, 1, 2);
622- var v = TypeCaster.firstValueAsNumber(values[0]);
623- var places = values.length === 2 ? TypeCaster.firstValueAsNumber(values[1]) : 2;
624+ var v = TypeConverter.firstValueAsNumber(values[0]);
625+ var places = values.length === 2 ? TypeConverter.firstValueAsNumber(values[1]) : 2;
626 var sign = (v > 0) ? 1 : -1;
627 var divisor = sign * (Math.floor(Math.abs(v) * Math.pow(10, places)));
628 var pow = Math.pow(10, places);
629@@ -162,8 +162,8 @@ var DOLLAR = function (...values) : number {
630 */
631 var DOLLARDE = function (...values) : number {
632 ArgsChecker.checkLength(values, 2);
633- var dollar = TypeCaster.firstValueAsNumber(values[0]);
634- var fraction = Math.floor(TypeCaster.firstValueAsNumber(values[1]));
635+ var dollar = TypeConverter.firstValueAsNumber(values[0]);
636+ var fraction = Math.floor(TypeConverter.firstValueAsNumber(values[1]));
637 if (fraction === 0) {
638 throw new DivZeroError("Function DOLLARDE parameter 2 cannot be zero.");
639 }
640@@ -187,8 +187,8 @@ var DOLLARDE = function (...values) : number {
641 */
642 var DOLLARFR = function (...values) : number {
643 ArgsChecker.checkLength(values, 2);
644- var dollar = TypeCaster.firstValueAsNumber(values[0]);
645- var unit = Math.floor(TypeCaster.firstValueAsNumber(values[1]));
646+ var dollar = TypeConverter.firstValueAsNumber(values[0]);
647+ var unit = Math.floor(TypeConverter.firstValueAsNumber(values[1]));
648 if (unit === 0) {
649 throw new DivZeroError("Function DOLLARFR parameter 2 cannot be zero.");
650 }
651@@ -207,8 +207,8 @@ var DOLLARFR = function (...values) : number {
652 */
653 var EFFECT = function (...values) : number {
654 ArgsChecker.checkLength(values, 2);
655- var rate = TypeCaster.firstValueAsNumber(values[0]);
656- var periods = TypeCaster.firstValueAsNumber(values[1]);
657+ var rate = TypeConverter.firstValueAsNumber(values[0]);
658+ var periods = TypeConverter.firstValueAsNumber(values[1]);
659 if (rate <= 0) {
660 throw new NumError("Function EFFECT parameter 1 value is " + rate + ". It should be greater than to 0");
661 }
662@@ -267,21 +267,21 @@ function fv(rate, periods, payment, value, type) {
663 */
664 var CUMPRINC = function (...values) : number {
665 ArgsChecker.checkLength(values, 6);
666- var rate = TypeCaster.firstValueAsNumber(values[0]);
667- var periods = TypeCaster.firstValueAsNumber(values[1]);
668- var value = TypeCaster.firstValueAsNumber(values[2]);
669- var start = TypeCaster.firstValueAsNumber(values[3]);
670+ var rate = TypeConverter.firstValueAsNumber(values[0]);
671+ var periods = TypeConverter.firstValueAsNumber(values[1]);
672+ var value = TypeConverter.firstValueAsNumber(values[2]);
673+ var start = TypeConverter.firstValueAsNumber(values[3]);
674 if (start < 1) {
675 throw new NumError("Function CUMPRINC parameter 4 value is " + start + ". It should be greater than or equal to 1.");
676 }
677- var end = TypeCaster.firstValueAsNumber(values[4]);
678+ var end = TypeConverter.firstValueAsNumber(values[4]);
679 if (end < 1) {
680 throw new NumError("Function CUMPRINC parameter 5 value is " + end + ". It should be greater than or equal to 1.");
681 }
682 if (end < start) {
683 throw new NumError("Function CUMPRINC parameter 5 value is " + end + ". It should be greater than or equal to " + start + ".");
684 }
685- var type = TypeCaster.firstValueAsBoolean(values[5]);
686+ var type = TypeConverter.firstValueAsBoolean(values[5]);
687
688 var payment = pmt(rate, periods, value, 0, type);
689 var principal = 0;
690@@ -319,21 +319,21 @@ var CUMPRINC = function (...values) : number {
691 */
692 var CUMIPMT = function (...values) : number {
693 ArgsChecker.checkLength(values, 6);
694- var rate = TypeCaster.firstValueAsNumber(values[0]);
695- var periods = TypeCaster.firstValueAsNumber(values[1]);
696- var value = TypeCaster.firstValueAsNumber(values[2]);
697- var start = TypeCaster.firstValueAsNumber(values[3]);
698+ var rate = TypeConverter.firstValueAsNumber(values[0]);
699+ var periods = TypeConverter.firstValueAsNumber(values[1]);
700+ var value = TypeConverter.firstValueAsNumber(values[2]);
701+ var start = TypeConverter.firstValueAsNumber(values[3]);
702 if (start < 1) {
703 throw new NumError("Function CUMPRINC parameter 4 value is " + start + ". It should be greater than or equal to 1.");
704 }
705- var end = TypeCaster.firstValueAsNumber(values[4]);
706+ var end = TypeConverter.firstValueAsNumber(values[4]);
707 if (end < 1) {
708 throw new NumError("Function CUMPRINC parameter 5 value is " + end + ". It should be greater than or equal to 1.");
709 }
710 if (end < start) {
711 throw new NumError("Function CUMPRINC parameter 5 value is " + end + ". It should be greater than or equal to " + start + ".");
712 }
713- var type = TypeCaster.firstValueAsBoolean(values[5]);
714+ var type = TypeConverter.firstValueAsBoolean(values[5]);
715
716 var payment = pmt(rate, periods, value, 0, type);
717 var interest = 0;
718@@ -387,28 +387,28 @@ var CUMIPMT = function (...values) : number {
719 */
720 var ACCRINT = function (...values) {
721 ArgsChecker.checkLengthWithin(values, 6, 7);
722- var issue = TypeCaster.firstValueAsDateNumber(values[0]);
723+ var issue = TypeConverter.firstValueAsDateNumber(values[0]);
724 // "firstPayment" param is only here to check for errors for GS implementation.
725 // In MSE, there is a 7th (zero-indexed-6th) param that indicates the calculation-method to use, which indicates
726 // weather the total accrued interest starting at the first_intrest date, instead of the issue date.
727- var firstPayment = TypeCaster.firstValueAsDateNumber(values[1]);
728+ var firstPayment = TypeConverter.firstValueAsDateNumber(values[1]);
729 if (firstPayment < 0) {
730 throw new NumError("Function ACCRINT parameter 2 value is " + firstPayment
731 + ". It should be greater than 0.");
732 }
733- var settlement = TypeCaster.firstValueAsDateNumber(values[2]);
734+ var settlement = TypeConverter.firstValueAsDateNumber(values[2]);
735 if (issue > settlement) {
736 throw new NumError("Function ACCRINT parameter 1 (" + issue.toString()
737 + ") should be on or before Function ACCRINT parameter 3 (" + settlement.toString() + ").")
738 }
739- var rate = TypeCaster.firstValueAsNumber(values[3]);
740- var redemption = TypeCaster.firstValueAsNumber(values[4]);// "par"
741+ var rate = TypeConverter.firstValueAsNumber(values[3]);
742+ var redemption = TypeConverter.firstValueAsNumber(values[4]);// "par"
743 // The frequency parameter also does not affect the resulting value of the formula in the GS implementation.
744 // In MSE, frequency is used to calculate a more accurate value, by breaking apart the year, and computing interest
745 // on an on-going basis. In this implementation, we use YEARFRAC to get a numerical value that encompasses the
746 // functionality of "frequency".
747- var frequency = TypeCaster.firstValueAsNumber(values[5]);
748- var dayCountConvention = values.length === 7 ? TypeCaster.firstValueAsNumber(values[6]) : 1;// "basis"
749+ var frequency = TypeConverter.firstValueAsNumber(values[5]);
750+ var dayCountConvention = values.length === 7 ? TypeConverter.firstValueAsNumber(values[6]) : 1;// "basis"
751 var factor = YEARFRAC(issue, settlement, dayCountConvention);
752 return redemption * rate * factor;
753 };
754diff --git a/src/Formulas/Logical.ts b/src/Formulas/Logical.ts
755index 313a852..8381d5a 100644
756--- a/src/Formulas/Logical.ts
757+++ b/src/Formulas/Logical.ts
758@@ -2,8 +2,8 @@ import {
759 ArgsChecker
760 } from "../Utilities/ArgsChecker";
761 import {
762- TypeCaster
763-} from "../Utilities/TypeCaster";
764+ TypeConverter
765+} from "../Utilities/TypeConverter";
766 import {
767 ValueError,
768 RefError
769@@ -46,8 +46,8 @@ var AND = function (...values) {
770 */
771 var EXACT = function (...values) {
772 ArgsChecker.checkLength(values, 2);
773- var one = TypeCaster.firstValue(values[0]);
774- var two = TypeCaster.firstValue(values[1]);
775+ var one = TypeConverter.firstValue(values[0]);
776+ var two = TypeConverter.firstValue(values[1]);
777 return one.toString() === two.toString();
778 };
779
780@@ -117,7 +117,7 @@ var OR = function (...values) {
781 if (OR.apply(this, values[i])) {
782 return true;
783 }
784- } else if (TypeCaster.valueToBoolean(values[i])) {
785+ } else if (TypeConverter.valueToBoolean(values[i])) {
786 return true;
787 }
788 }
789@@ -144,7 +144,7 @@ var XOR = function (...values) {
790 }
791 alreadyTruthy = true;
792 }
793- } else if (TypeCaster.valueToBoolean(values[i])) {
794+ } else if (TypeConverter.valueToBoolean(values[i])) {
795 if (alreadyTruthy) {
796 return false;
797 }
798diff --git a/src/Formulas/Math.ts b/src/Formulas/Math.ts
799index dd69b4e..7080ecb 100644
800--- a/src/Formulas/Math.ts
801+++ b/src/Formulas/Math.ts
802@@ -2,8 +2,8 @@ import {
803 ArgsChecker
804 } from "../Utilities/ArgsChecker";
805 import {
806- TypeCaster
807-} from "../Utilities/TypeCaster";
808+ TypeConverter
809+} from "../Utilities/TypeConverter";
810 import {
811 Filter
812 } from "../Utilities/Filter";
813@@ -29,7 +29,7 @@ import {
814 */
815 var ABS = function (...values) {
816 ArgsChecker.checkLength(values, 1);
817- var v = TypeCaster.valueToNumber(values[0]);
818+ var v = TypeConverter.valueToNumber(values[0]);
819 return Math.abs(v);
820 };
821
822@@ -41,7 +41,7 @@ var ABS = function (...values) {
823 */
824 var ACOS = function (value?) {
825 ArgsChecker.checkLength(arguments, 1);
826- value = TypeCaster.valueToNumber(value);
827+ value = TypeConverter.valueToNumber(value);
828 if (value === -1) {
829 return Math.PI;
830 } else if (value > 1 || value < -1) {
831@@ -58,7 +58,7 @@ var ACOS = function (value?) {
832 */
833 var ACOSH = function (value?) {
834 ArgsChecker.checkLength(arguments, 1);
835- value = TypeCaster.valueToNumber(value);
836+ value = TypeConverter.valueToNumber(value);
837 if (value < 1) {
838 throw new NumError("Function ACOSH parameter 1 value is " + value + ". It should be greater than or equal to 1.");
839 }
840@@ -73,7 +73,7 @@ var ACOSH = function (value?) {
841 */
842 var ACOTH = function (value?) {
843 ArgsChecker.checkLength(arguments, 1);
844- value = TypeCaster.valueToNumber(value);
845+ value = TypeConverter.valueToNumber(value);
846 if (value <= 1 && value >= -1) {
847 throw new NumError("Function ACOTH parameter 1 value is " + value + ". Valid values cannot be between -1 and 1 inclusive.")
848 }
849@@ -88,7 +88,7 @@ var ACOTH = function (value?) {
850 */
851 var ASIN = function (value?) {
852 ArgsChecker.checkLength(arguments, 1);
853- value = TypeCaster.valueToNumber(value);
854+ value = TypeConverter.valueToNumber(value);
855 if (value === -1) {
856 return Math.PI;
857 } else if (value > 1 || value < -1) {
858@@ -105,7 +105,7 @@ var ASIN = function (value?) {
859 */
860 var ASINH = function (value?) {
861 ArgsChecker.checkLength(arguments, 1);
862- value = TypeCaster.valueToNumber(value);
863+ value = TypeConverter.valueToNumber(value);
864 return Math.log(value + Math.sqrt(value * value + 1));
865 };
866
867@@ -118,7 +118,7 @@ var ASINH = function (value?) {
868 */
869 var ATAN = function (value?) {
870 ArgsChecker.checkLength(arguments, 1);
871- value = TypeCaster.valueToNumber(value);
872+ value = TypeConverter.valueToNumber(value);
873 if (value === -1) {
874 return Math.PI;
875 } else if (value > 1 || value < -1) {
876@@ -137,8 +137,8 @@ var ATAN = function (value?) {
877 */
878 var ATAN2 = function (x, y) {
879 ArgsChecker.checkLength(arguments, 2);
880- x = TypeCaster.valueToNumber(x);
881- y = TypeCaster.valueToNumber(y);
882+ x = TypeConverter.valueToNumber(x);
883+ y = TypeConverter.valueToNumber(y);
884 if (x === 0 && y === 0) {
885 throw new DivZeroError("Evaluation of function ATAN2 caused a divide by zero error.");
886 }
887@@ -154,7 +154,7 @@ var ATAN2 = function (x, y) {
888 */
889 var ATANH = function (value?) : number {
890 ArgsChecker.checkLength(arguments, 1);
891- value = TypeCaster.valueToNumber(value);
892+ value = TypeConverter.valueToNumber(value);
893 if (value >= 1 || value <= -1) {
894 throw new NumError("Function ATANH parameter 1 value is " + value + ". Valid values are between -1 and 1 exclusive.");
895 }
896@@ -178,7 +178,7 @@ var EVEN = function (...values) : number {
897 }
898 return EVEN(values[0][0]);
899 }
900- var X = TypeCaster.valueToNumber(values[0]);
901+ var X = TypeConverter.valueToNumber(values[0]);
902 return X % 2 === 1 ? X + 1 : X;
903 };
904
905@@ -191,8 +191,8 @@ var EVEN = function (...values) : number {
906 */
907 var MOD = function (...values) : number {
908 ArgsChecker.checkLength(values, 2);
909- var oneN = TypeCaster.valueToNumber(values[0]);
910- var twoN = TypeCaster.valueToNumber(values[1]);
911+ var oneN = TypeConverter.valueToNumber(values[0]);
912+ var twoN = TypeConverter.valueToNumber(values[1]);
913 if (twoN === 0) {
914 throw new DivZeroError("Function MOD parameter 2 cannot be zero.");
915 }
916@@ -214,7 +214,7 @@ var ODD = function (...values) : number {
917 }
918 return ODD(values[0][0]);
919 }
920- var X = TypeCaster.valueToNumber(values[0]);
921+ var X = TypeConverter.valueToNumber(values[0]);
922 return X % 2 === 1 ? X : X + 1;
923 };
924
925@@ -227,8 +227,8 @@ var ODD = function (...values) : number {
926 */
927 var POWER = function (...values) : number {
928 ArgsChecker.checkLength(values, 2);
929- var n = TypeCaster.firstValueAsNumber(values[0]);
930- var p = TypeCaster.firstValueAsNumber(values[1]);
931+ var n = TypeConverter.firstValueAsNumber(values[0]);
932+ var p = TypeConverter.firstValueAsNumber(values[1]);
933 return Math.pow(n, p);
934 };
935
936@@ -248,7 +248,7 @@ var SUM = function (...values) : number {
937 if (values[i] === "") {
938 throw new ValueError("Function SUM parameter "+i+" expects number values. But '"+values[i]+"' is a text and cannot be coerced to a number.");
939 }
940- result = result + TypeCaster.valueToNumber(values[i]);
941+ result = result + TypeConverter.valueToNumber(values[i]);
942 }
943 }
944 return result;
945@@ -262,7 +262,7 @@ var SUM = function (...values) : number {
946 */
947 var SQRT = function (...values) : number {
948 ArgsChecker.checkLength(values, 1);
949- var x = TypeCaster.firstValueAsNumber(values[0]);
950+ var x = TypeConverter.firstValueAsNumber(values[0]);
951 if (x < 0) {
952 throw new ValueError("Function SQRT parameter 1 expects number values. But '" + values[0] + "' is a text and cannot be coerced to a number.");
953 }
954@@ -277,7 +277,7 @@ var SQRT = function (...values) : number {
955 */
956 var SQRTPI = function (...values) : number{
957 ArgsChecker.checkLength(values, 1);
958- var n = TypeCaster.firstValueAsNumber(values[0]);
959+ var n = TypeConverter.firstValueAsNumber(values[0]);
960 if (n < 0) {
961 throw new NumError("Function SQRTPI parameter 1 value is " + n + ". It should be greater than or equal to 0.");
962 }
963@@ -292,7 +292,7 @@ var SQRTPI = function (...values) : number{
964 */
965 var COS = function (...values) : number {
966 ArgsChecker.checkLength(values, 1);
967- var r = TypeCaster.firstValueAsNumber(values[0]);
968+ var r = TypeConverter.firstValueAsNumber(values[0]);
969 return Math.cos(r);
970 };
971
972@@ -304,7 +304,7 @@ var COS = function (...values) : number {
973 */
974 var COSH = function (...values) : number {
975 ArgsChecker.checkLength(values, 1);
976- var r = TypeCaster.firstValueAsNumber(values[0]);
977+ var r = TypeConverter.firstValueAsNumber(values[0]);
978 return Math["cosh"](r);
979 };
980
981@@ -316,7 +316,7 @@ var COSH = function (...values) : number {
982 */
983 var COT = function (...values) : number {
984 ArgsChecker.checkLength(values, 1);
985- var x = TypeCaster.firstValueAsNumber(values[0]);
986+ var x = TypeConverter.firstValueAsNumber(values[0]);
987 if (x === 0) {
988 throw new DivZeroError("Evaluation of function COT caused a divide by zero error.");
989 }
990@@ -331,7 +331,7 @@ var COT = function (...values) : number {
991 */
992 var COTH = function (...values) : number {
993 ArgsChecker.checkLength(values, 1);
994- var x = TypeCaster.firstValueAsNumber(values[0]);
995+ var x = TypeConverter.firstValueAsNumber(values[0]);
996 if (x === 0) {
997 throw new DivZeroError("Evaluation of function COTH caused a divide by zero error.");
998 }
999@@ -346,7 +346,7 @@ var COTH = function (...values) : number {
1000 */
1001 var INT = function (...values) : number {
1002 ArgsChecker.checkLength(values, 1);
1003- var x = TypeCaster.firstValueAsNumber(values[0]);
1004+ var x = TypeConverter.firstValueAsNumber(values[0]);
1005 return Math.floor(x);
1006 };
1007
1008@@ -362,7 +362,7 @@ var ISEVEN = function (...values) : boolean {
1009 if (values[0] === "") {
1010 throw new ValueError("Function ISEVEN parameter 1 expects boolean values. But '" + values[0] + "' is a text and cannot be coerced to a boolean.");
1011 }
1012- var x = TypeCaster.firstValueAsNumber(values[0]);
1013+ var x = TypeConverter.firstValueAsNumber(values[0]);
1014 return Math.floor(x) % 2 === 0;
1015 };
1016
1017@@ -378,7 +378,7 @@ var ISODD = function (...values) : boolean {
1018 if (values[0] === "") {
1019 throw new ValueError("Function ISODD parameter 1 expects boolean values. But '" + values[0] + "' is a text and cannot be coerced to a boolean.");
1020 }
1021- var x = TypeCaster.firstValueAsNumber(values[0]);
1022+ var x = TypeConverter.firstValueAsNumber(values[0]);
1023 return Math.floor(x) % 2 === 1;
1024 };
1025
1026@@ -390,7 +390,7 @@ var ISODD = function (...values) : boolean {
1027 */
1028 var SIN = function (...values) {
1029 ArgsChecker.checkLength(values, 1);
1030- var rad = TypeCaster.firstValueAsNumber(values[0]);
1031+ var rad = TypeConverter.firstValueAsNumber(values[0]);
1032 return rad === Math.PI ? 0 : Math.sin(rad);
1033 };
1034
1035@@ -402,7 +402,7 @@ var SIN = function (...values) {
1036 */
1037 var SINH = function (...values) : number {
1038 ArgsChecker.checkLength(values, 1);
1039- var rad = TypeCaster.firstValueAsNumber(values[0]);
1040+ var rad = TypeConverter.firstValueAsNumber(values[0]);
1041 return Math["sinh"](rad);
1042 };
1043
1044@@ -423,7 +423,7 @@ var PI = function () {
1045 */
1046 var LOG10 = function (...values) : number {
1047 ArgsChecker.checkLength(values, 1);
1048- var n = TypeCaster.firstValueAsNumber(values[0]);
1049+ var n = TypeConverter.firstValueAsNumber(values[0]);
1050 if (n < 1) {
1051 throw new NumError("Function LOG10 parameter 1 value is " + n + ". It should be greater than 0.");
1052 }
1053@@ -441,10 +441,10 @@ var LOG10 = function (...values) : number {
1054 */
1055 var LOG = function (...values) : number {
1056 ArgsChecker.checkAtLeastLength(values, 1);
1057- var n = TypeCaster.firstValueAsNumber(values[0]);
1058+ var n = TypeConverter.firstValueAsNumber(values[0]);
1059 var b = 10;
1060 if (values.length > 1) {
1061- b = TypeCaster.firstValueAsNumber(values[1]);
1062+ b = TypeConverter.firstValueAsNumber(values[1]);
1063 if (b < 1) {
1064 throw new NumError("Function LOG parameter 2 value is " + b + ". It should be greater than 0.");
1065 }
1066@@ -468,7 +468,7 @@ var LOG = function (...values) : number {
1067 */
1068 var LN = function (...values) : number {
1069 ArgsChecker.checkLength(values, 1);
1070- var n = TypeCaster.firstValueAsNumber(values[0]);
1071+ var n = TypeConverter.firstValueAsNumber(values[0]);
1072 if (n < 1) {
1073 throw new NumError("Function LN parameter 1 value is " + n + ". It should be greater than 0.");
1074 }
1075@@ -483,7 +483,7 @@ var LN = function (...values) : number {
1076 */
1077 var TAN = function (...values) : number {
1078 ArgsChecker.checkLength(values, 1);
1079- var rad = TypeCaster.firstValueAsNumber(values[0]);
1080+ var rad = TypeConverter.firstValueAsNumber(values[0]);
1081 return rad === Math.PI ? 0 : Math.tan(rad);
1082 };
1083
1084@@ -495,7 +495,7 @@ var TAN = function (...values) : number {
1085 */
1086 var TANH = function (...values) : number {
1087 ArgsChecker.checkLength(values, 1);
1088- var rad = TypeCaster.firstValueAsNumber(values[0]);
1089+ var rad = TypeConverter.firstValueAsNumber(values[0]);
1090 return Math["tanh"](rad);
1091 };
1092
1093@@ -508,11 +508,11 @@ var TANH = function (...values) : number {
1094 */
1095 var CEILING = function (...values) : number {
1096 ArgsChecker.checkLengthWithin(values, 1, 2);
1097- var num = TypeCaster.firstValueAsNumber(values[0]);
1098+ var num = TypeConverter.firstValueAsNumber(values[0]);
1099 if (values.length === 1) {
1100 return Math.ceil(num);
1101 }
1102- var significance = TypeCaster.firstValueAsNumber(values[1]);
1103+ var significance = TypeConverter.firstValueAsNumber(values[1]);
1104 if (significance === 0) {
1105 throw new DivZeroError("Function CEILING parameter 2 cannot be zero.");
1106 }
1107@@ -533,11 +533,11 @@ var CEILING = function (...values) : number {
1108 */
1109 var FLOOR = function (...values) : number {
1110 ArgsChecker.checkLengthWithin(values, 1, 2);
1111- var num = TypeCaster.firstValueAsNumber(values[0]);
1112+ var num = TypeConverter.firstValueAsNumber(values[0]);
1113 if (values.length === 1) {
1114 return Math.floor(num);
1115 }
1116- var significance = TypeCaster.firstValueAsNumber(values[1]);
1117+ var significance = TypeConverter.firstValueAsNumber(values[1]);
1118 if (significance === 0) {
1119 throw new DivZeroError("Function FLOOR parameter 2 cannot be zero.");
1120 }
1121@@ -567,7 +567,7 @@ var IF = function (...values) : any {
1122 } else if (values[0] === "") {
1123 return values[2];
1124 }
1125- return (TypeCaster.valueToBoolean(values[0])) ? values[1] : values[2];
1126+ return (TypeConverter.valueToBoolean(values[0])) ? values[1] : values[2];
1127 };
1128
1129
1130@@ -662,11 +662,11 @@ var COUNTIFS = function (...values) {
1131 */
1132 var ROUND = function (...values) {
1133 ArgsChecker.checkLengthWithin(values, 1, 2);
1134- var n = TypeCaster.firstValueAsNumber(values[0]);
1135+ var n = TypeConverter.firstValueAsNumber(values[0]);
1136 if (values.length === 1) {
1137 return Math.round(n);
1138 }
1139- var d = TypeCaster.firstValueAsNumber(values[1]);
1140+ var d = TypeConverter.firstValueAsNumber(values[1]);
1141 return Math.round(n * Math.pow(10, d)) / Math.pow(10, d);
1142 };
1143
1144@@ -679,11 +679,11 @@ var ROUND = function (...values) {
1145 */
1146 var ROUNDDOWN = function (...values) {
1147 ArgsChecker.checkLengthWithin(values, 1, 2);
1148- var n = TypeCaster.firstValueAsNumber(values[0]);
1149+ var n = TypeConverter.firstValueAsNumber(values[0]);
1150 if (values.length === 1) {
1151 return Math.floor(n);
1152 }
1153- var d = TypeCaster.firstValueAsNumber(values[1]);
1154+ var d = TypeConverter.firstValueAsNumber(values[1]);
1155 return Math.floor(n * Math.pow(10, d)) / Math.pow(10, d);
1156 };
1157
1158@@ -696,11 +696,11 @@ var ROUNDDOWN = function (...values) {
1159 */
1160 var ROUNDUP = function (...values) {
1161 ArgsChecker.checkLengthWithin(values, 1, 2);
1162- var n = TypeCaster.firstValueAsNumber(values[0]);
1163+ var n = TypeConverter.firstValueAsNumber(values[0]);
1164 if (values.length === 1) {
1165 return Math.ceil(n);
1166 }
1167- var d = TypeCaster.firstValueAsNumber(values[1]);
1168+ var d = TypeConverter.firstValueAsNumber(values[1]);
1169 return Math.ceil(n * Math.pow(10, d)) / Math.pow(10, d);
1170 };
1171
1172@@ -735,10 +735,10 @@ var SUMIF = function (...values) {
1173 if (sumRange && i > sumRange.length-1) {
1174 continue;
1175 }
1176- if (values.length === 2 && TypeCaster.canCoerceToNumber(x) && criteriaEvaluation(x)) {
1177- sum = sum + TypeCaster.valueToNumber(x);
1178- } else if (values.length === 3 && TypeCaster.canCoerceToNumber(sumRange[i]) && criteriaEvaluation(x)) {
1179- sum = sum + TypeCaster.valueToNumber(sumRange[i]);
1180+ if (values.length === 2 && TypeConverter.canCoerceToNumber(x) && criteriaEvaluation(x)) {
1181+ sum = sum + TypeConverter.valueToNumber(x);
1182+ } else if (values.length === 3 && TypeConverter.canCoerceToNumber(sumRange[i]) && criteriaEvaluation(x)) {
1183+ sum = sum + TypeConverter.valueToNumber(sumRange[i]);
1184 }
1185 }
1186 }
1187@@ -761,7 +761,7 @@ var SUMSQ = function (...values) {
1188 }
1189 result = result + SUMSQ.apply(this, Filter.filterOutNonNumberValues(values[i]));
1190 } else {
1191- var n = TypeCaster.valueToNumber(values[i]);
1192+ var n = TypeConverter.valueToNumber(values[i]);
1193 result = result + (n * n);
1194 }
1195 }
1196@@ -782,10 +782,10 @@ var SUMSQ = function (...values) {
1197 */
1198 var TRUNC = function (...values) : number {
1199 ArgsChecker.checkLengthWithin(values, 1, 2);
1200- var n = TypeCaster.firstValueAsNumber(values[0]);
1201+ var n = TypeConverter.firstValueAsNumber(values[0]);
1202 var digits = 0;
1203 if (values.length === 2) {
1204- digits = TypeCaster.firstValueAsNumber(values[1]);
1205+ digits = TypeConverter.firstValueAsNumber(values[1]);
1206 }
1207 var sign = (n > 0) ? 1 : -1;
1208 return sign * (Math.floor(Math.abs(n) * Math.pow(10, digits))) / Math.pow(10, digits);
1209@@ -800,7 +800,7 @@ var TRUNC = function (...values) : number {
1210 */
1211 var RADIANS = function (...values) {
1212 ArgsChecker.checkLength(values, 1);
1213- var d = TypeCaster.firstValueAsNumber(values[0]);
1214+ var d = TypeConverter.firstValueAsNumber(values[0]);
1215 return d * Math.PI / 180;
1216 };
1217
1218@@ -812,7 +812,7 @@ var RADIANS = function (...values) {
1219 */
1220 var DEGREES = function (...values) {
1221 ArgsChecker.checkLength(values, 1);
1222- var r = TypeCaster.firstValueAsNumber(values[0]);
1223+ var r = TypeConverter.firstValueAsNumber(values[0]);
1224 return r * 180 / Math.PI;
1225 };
1226
1227@@ -825,7 +825,7 @@ var DEGREES = function (...values) {
1228 */
1229 var ERFC = function (...values) {
1230 ArgsChecker.checkLength(values, 1);
1231- var v = TypeCaster.firstValueAsNumber(values[0]);
1232+ var v = TypeConverter.firstValueAsNumber(values[0]);
1233 return v === 0 ? 1 : 1 - erf(v);
1234 };
1235
1236@@ -840,8 +840,8 @@ var ERFC = function (...values) {
1237 */
1238 var ERF = function (...values) : number {
1239 ArgsChecker.checkLengthWithin(values, 1, 2);
1240- var lower = TypeCaster.firstValueAsNumber(values[0]);
1241- var upper = values.length === 2 ? TypeCaster.firstValueAsNumber(values[1]) : 0;
1242+ var lower = TypeConverter.firstValueAsNumber(values[0]);
1243+ var upper = values.length === 2 ? TypeConverter.firstValueAsNumber(values[1]) : 0;
1244 return values.length === 1 ? erf(lower) : erf(upper) - erf(lower);
1245 };
1246
1247@@ -1011,7 +1011,7 @@ var SUMPRODUCT = function (...values) : number {
1248 for (var i = 0; i < flattenedValues[0].length; i++) {
1249 var product = 1;
1250 for (var x = 0; x < flattenedValues.length; x++) {
1251- product *= TypeCaster.valueToNumberGracefully(flattenedValues[x][i]);
1252+ product *= TypeConverter.valueToNumberGracefully(flattenedValues[x][i]);
1253 }
1254 result += product;
1255 }
1256@@ -1040,8 +1040,8 @@ var COMBIN = function (...values) : number {
1257 }
1258 }
1259 ArgsChecker.checkLength(values, 2);
1260- var n = TypeCaster.firstValueAsNumber(values[0]);
1261- var c = TypeCaster.firstValueAsNumber(values[1]);
1262+ var n = TypeConverter.firstValueAsNumber(values[0]);
1263+ var c = TypeConverter.firstValueAsNumber(values[1]);
1264 if (n < c) {
1265 throw new NumError("Function COMBIN parameter 2 value is "
1266 + c + ". It should be less than or equal to value of Function COMBIN parameter 1 with " + n + ".");
1267diff --git a/src/Formulas/Statistical.ts b/src/Formulas/Statistical.ts
1268index 504f341..e743556 100644
1269--- a/src/Formulas/Statistical.ts
1270+++ b/src/Formulas/Statistical.ts
1271@@ -8,8 +8,8 @@ import {
1272 Filter
1273 } from "../Utilities/Filter";
1274 import {
1275- TypeCaster
1276-} from "../Utilities/TypeCaster";
1277+ TypeConverter
1278+} from "../Utilities/TypeConverter";
1279 import {
1280 RefError, NumError, DivZeroError, NAError
1281 } from "../Errors";
1282@@ -31,13 +31,13 @@ var DEVSQ = function (...values) : number {
1283 var result = 0;
1284 var count = 0;
1285 for (var i = 0; i < range.length; i++) {
1286- result = result + TypeCaster.valueToNumber(range[i]);
1287+ result = result + TypeConverter.valueToNumber(range[i]);
1288 count++;
1289 }
1290 var mean = result / count;
1291 var result = 0;
1292 for (var i = 0; i < range.length; i++) {
1293- result += Math.pow((TypeCaster.valueToNumber(range[i]) - mean), 2);
1294+ result += Math.pow((TypeConverter.valueToNumber(range[i]) - mean), 2);
1295 }
1296 return result;
1297 };
1298@@ -59,16 +59,16 @@ var MEDIAN = function (...values) : number {
1299 var filtered = Filter.filterOutStringValues(currentValue);
1300 sortedArray = sortedArray.concat(filtered);
1301 } else {
1302- sortedArray.push(TypeCaster.valueToNumber(currentValue));
1303+ sortedArray.push(TypeConverter.valueToNumber(currentValue));
1304 }
1305 });
1306 sortedArray = sortedArray.sort(function (a, b) {
1307- var aN = TypeCaster.valueToNumber(a);
1308- var bN = TypeCaster.valueToNumber(b);
1309+ var aN = TypeConverter.valueToNumber(a);
1310+ var bN = TypeConverter.valueToNumber(b);
1311 return aN - bN;
1312 });
1313 if (sortedArray.length === 1) {
1314- return TypeCaster.valueToNumber(sortedArray[0]);
1315+ return TypeConverter.valueToNumber(sortedArray[0]);
1316 }
1317 if (sortedArray.length === 0) {
1318 throw new NumError("MEDIAN has no valid input data.");
1319@@ -106,7 +106,7 @@ var AVERAGE = function (...values) : number {
1320 result = result + SUM.apply(this, filtered);
1321 count += filtered.length;
1322 } else {
1323- result = result + TypeCaster.valueToNumber(values[i]);
1324+ result = result + TypeConverter.valueToNumber(values[i]);
1325 count++;
1326 }
1327 }
1328@@ -133,20 +133,20 @@ var AVEDEV = function (...values) {
1329 }
1330 arrayValues.push(X);
1331 } else {
1332- nonArrayValues.push(TypeCaster.valueToNumber(X));
1333+ nonArrayValues.push(TypeConverter.valueToNumber(X));
1334 }
1335 }
1336
1337 // Remove string values from array-values, but not from non-array-values, and concat.
1338 var flatValues = Filter.filterOutStringValues(Filter.flatten(arrayValues)).map(function (value) {
1339- return TypeCaster.valueToNumber(value);
1340+ return TypeConverter.valueToNumber(value);
1341 }).concat(nonArrayValues);
1342
1343 // Calculating mean
1344 var result = 0;
1345 var count = 0;
1346 for (var i = 0; i < flatValues.length; i++) {
1347- result = result + TypeCaster.valueToNumber(flatValues[i]);
1348+ result = result + TypeConverter.valueToNumber(flatValues[i]);
1349 count++;
1350 }
1351 if (count === 0) {
1352@@ -155,7 +155,7 @@ var AVEDEV = function (...values) {
1353 var mean = result / count;
1354
1355 for (var i = 0; i < flatValues.length; i++) {
1356- flatValues[i] = ABS(TypeCaster.valueToNumber(flatValues[i]) - mean);
1357+ flatValues[i] = ABS(TypeConverter.valueToNumber(flatValues[i]) - mean);
1358 }
1359 return SUM(flatValues) / flatValues.length;
1360 };
1361@@ -179,7 +179,7 @@ var AVERAGEA = function (...values) {
1362 result = result + SUM.apply(this, filtered);
1363 count += filtered.length;
1364 } else {
1365- result = result + TypeCaster.valueToNumber(values[i]);
1366+ result = result + TypeConverter.valueToNumber(values[i]);
1367 count++;
1368 }
1369 }
1370@@ -321,9 +321,9 @@ var EXPONDIST = function (...values) : number {
1371 return x < 0 ? 0 : rate * Math.exp(-rate * x);
1372 }
1373 ArgsChecker.checkLength(values, 3);
1374- var x = TypeCaster.firstValueAsNumber(values[0]);
1375- var lambda = TypeCaster.firstValueAsNumber(values[1]);
1376- var cumulative = TypeCaster.firstValueAsBoolean(values[2]);
1377+ var x = TypeConverter.firstValueAsNumber(values[0]);
1378+ var lambda = TypeConverter.firstValueAsNumber(values[1]);
1379+ var cumulative = TypeConverter.firstValueAsBoolean(values[2]);
1380 return (cumulative) ? cdf(x, lambda) : pdf(x, lambda);
1381 };
1382
1383@@ -514,13 +514,13 @@ var FDIST$LEFTTAILED = function (...values) : number|undefined|boolean {
1384 return (x + y > 170) ? Math.exp(betaln(x, y)) : gammafn(x) * gammafn(y) / gammafn(x + y);
1385 }
1386 ArgsChecker.checkLength(values, 4);
1387- var x = TypeCaster.firstValueAsNumber(values[0]);
1388+ var x = TypeConverter.firstValueAsNumber(values[0]);
1389 if (x < 0) {
1390 throw new NumError("Function F.DIST parameter 1 value is " + x + ". It should be greater than or equal to 0.");
1391 }
1392- var d1 = TypeCaster.firstValueAsNumber(values[1]);
1393- var d2 = TypeCaster.firstValueAsNumber(values[2]);
1394- var cumulative = TypeCaster.firstValueAsBoolean(values[3]);
1395+ var d1 = TypeConverter.firstValueAsNumber(values[1]);
1396+ var d2 = TypeConverter.firstValueAsNumber(values[2]);
1397+ var cumulative = TypeConverter.firstValueAsBoolean(values[3]);
1398 return (cumulative) ? cdf(x, d1, d2) : pdf(x, d1, d2);
1399 };
1400
1401@@ -685,13 +685,13 @@ var FINV = function (...values) : number {
1402 return df2 / (df1 * (1 / ibetainv(x, df1 / 2, df2 / 2) - 1));
1403 }
1404 ArgsChecker.checkLength(values, 3);
1405- var probability = TypeCaster.firstValueAsNumber(values[0]);
1406+ var probability = TypeConverter.firstValueAsNumber(values[0]);
1407 if (probability <= 0.0 || probability > 1.0) {
1408 throw new NumError("Function FINV parameter 1 value is " + probability
1409 + ". It should be greater than or equal to 0, and less than 1.")
1410 }
1411- var d1 = TypeCaster.firstValueAsNumber(values[1]);
1412- var d2 = TypeCaster.firstValueAsNumber(values[2]);
1413+ var d1 = TypeConverter.firstValueAsNumber(values[1]);
1414+ var d2 = TypeConverter.firstValueAsNumber(values[2]);
1415 return inv(1.0 - probability, d1, d2);
1416 };
1417
1418@@ -703,7 +703,7 @@ var FINV = function (...values) : number {
1419 */
1420 var FISHER = function (...values) : number {
1421 ArgsChecker.checkLength(values, 1);
1422- var x = TypeCaster.firstValueAsNumber(values[0]);
1423+ var x = TypeConverter.firstValueAsNumber(values[0]);
1424 if (x <= -1 || x >= 1) {
1425 throw new NumError("Function FISHER parameter 1 value is " + x + ". Valid values are between -1 and 1 exclusive.");
1426 }
1427@@ -718,7 +718,7 @@ var FISHER = function (...values) : number {
1428 */
1429 var FISHERINV = function (...values) : number {
1430 ArgsChecker.checkLength(values, 1);
1431- var y = TypeCaster.firstValueAsNumber(values[0]);
1432+ var y = TypeConverter.firstValueAsNumber(values[0]);
1433 var e2y = Math.exp(2 * y);
1434 return (e2y - 1) / (e2y + 1);
1435 };
1436@@ -742,7 +742,7 @@ var MAX = function (...values) {
1437 maxSoFar = Math.max(MAX.apply(this, filtered), maxSoFar);
1438 }
1439 } else {
1440- maxSoFar = Math.max(TypeCaster.valueToNumber(values[i]), maxSoFar);
1441+ maxSoFar = Math.max(TypeConverter.valueToNumber(values[i]), maxSoFar);
1442 }
1443 }
1444 return maxSoFar;
1445@@ -778,7 +778,7 @@ var MIN = function (...values) {
1446 minSoFar = Math.min(MIN.apply(this, filtered), minSoFar);
1447 }
1448 } else {
1449- minSoFar = Math.min(TypeCaster.valueToNumber(values[i]), minSoFar);
1450+ minSoFar = Math.min(TypeConverter.valueToNumber(values[i]), minSoFar);
1451 }
1452 }
1453 return minSoFar;
1454@@ -814,7 +814,7 @@ var AVERAGEIF = function (...values) {
1455 var result = 0;
1456 var count = 0;
1457 for (var i = 0; i < range.length; i++) {
1458- var val = TypeCaster.valueToNumber(range[i]);
1459+ var val = TypeConverter.valueToNumber(range[i]);
1460 if (criteriaEvaluation(val)) {
1461 result = result + val;
1462 count++;
1463@@ -841,7 +841,7 @@ var COUNT = function (...values) : number {
1464 if (values[i].length > 0) {
1465 count += COUNT.apply(this, values[i]);
1466 }
1467- } else if (TypeCaster.canCoerceToNumber(values[i])) {
1468+ } else if (TypeConverter.canCoerceToNumber(values[i])) {
1469 count++;
1470 }
1471 }
1472diff --git a/src/Formulas/Text.ts b/src/Formulas/Text.ts
1473index 6a9704e..ca8dffb 100644
1474--- a/src/Formulas/Text.ts
1475+++ b/src/Formulas/Text.ts
1476@@ -2,8 +2,8 @@ import {
1477 ArgsChecker
1478 } from "../Utilities/ArgsChecker";
1479 import {
1480- TypeCaster
1481-} from "../Utilities/TypeCaster";
1482+ TypeConverter
1483+} from "../Utilities/TypeConverter";
1484 import {
1485 ValueError,
1486 NumError,
1487@@ -49,7 +49,7 @@ var ARABIC = function (text?) {
1488 */
1489 var CHAR = function (...values) : string {
1490 ArgsChecker.checkLength(values, 1);
1491- var n = TypeCaster.firstValueAsNumber(values[0]);
1492+ var n = TypeConverter.firstValueAsNumber(values[0]);
1493 if (n < 1 || n > 1114112) { //limit
1494 throw new NumError("Function CHAR parameter 1 value " + n + " is out of range.");
1495 }
1496@@ -64,7 +64,7 @@ var CHAR = function (...values) : string {
1497 */
1498 var CODE = function (...values) : number {
1499 ArgsChecker.checkLength(values, 1);
1500- var text = TypeCaster.firstValueAsString(values[0]);
1501+ var text = TypeConverter.firstValueAsString(values[0]);
1502 if (text === "") {
1503 throw new ValueError("Function CODE parameter 1 value should be non-empty.");
1504 }
1505@@ -83,11 +83,11 @@ var CODE = function (...values) : number {
1506 */
1507 var SPLIT = function (...values) : Array<string> {
1508 ArgsChecker.checkLengthWithin(values, 2, 3);
1509- var text = TypeCaster.firstValueAsString(values[0]);
1510- var delimiter = TypeCaster.firstValueAsString(values[1]);
1511+ var text = TypeConverter.firstValueAsString(values[0]);
1512+ var delimiter = TypeConverter.firstValueAsString(values[1]);
1513 var splitByEach = false;
1514 if (values.length === 3) {
1515- splitByEach = TypeCaster.firstValueAsBoolean(values[2]);
1516+ splitByEach = TypeConverter.firstValueAsBoolean(values[2]);
1517 }
1518 if (splitByEach) {
1519 var result = [text];
1520@@ -123,7 +123,7 @@ var CONCATENATE = function (...values) : string {
1521 }
1522 string += CONCATENATE.apply(this, arguments[i]);
1523 } else {
1524- string += TypeCaster.valueToString(values[i]);
1525+ string += TypeConverter.valueToString(values[i]);
1526 }
1527 }
1528 return string;
1529@@ -140,9 +140,9 @@ var CONCATENATE = function (...values) : string {
1530 */
1531 var CONVERT = function (...values) {
1532 ArgsChecker.checkLength(values, 3);
1533- var n = TypeCaster.firstValueAsNumber(values[0]);
1534- var fromUnit = TypeCaster.firstValueAsString(values[1]);
1535- var toUnit = TypeCaster.firstValueAsString(values[2]);
1536+ var n = TypeConverter.firstValueAsNumber(values[0]);
1537+ var fromUnit = TypeConverter.firstValueAsString(values[1]);
1538+ var toUnit = TypeConverter.firstValueAsString(values[2]);
1539
1540 // NOTE: A lot of the code for this method is from https://github.com/sutoiku/formula.js. I'm relying on them to have
1541 // gotten it right, but I'm spot checking some of their work against GS, MSE, LibreOffice, OpenOffice.
1542diff --git a/src/Utilities/TypeCaster.ts b/src/Utilities/TypeConverter.ts
1543similarity index 92%
1544rename from src/Utilities/TypeCaster.ts
1545rename to src/Utilities/TypeConverter.ts
1546index bc9e81c..f5e4229 100644
1547--- a/src/Utilities/TypeCaster.ts
1548+++ b/src/Utilities/TypeConverter.ts
1549@@ -122,9 +122,9 @@ function matchTimestampAndMutateMoment(timestampString : string, momentToMutate:
1550 }
1551
1552 /**
1553- * Static class of helpers used to cast various types to each other.
1554+ * Static class of helpers used to convert various types to each other.
1555 */
1556-class TypeCaster {
1557+class TypeConverter {
1558
1559 public static ORIGIN_MOMENT = moment.utc([1899, 11, 30]).startOf("day");
1560 private static SECONDS_IN_DAY = 86400;
1561@@ -140,7 +140,7 @@ class TypeCaster {
1562 try {
1563 m = matchTimestampAndMutateMoment(timeString, moment.utc([FIRST_YEAR]).startOf("year"));
1564 } catch (e) {
1565- m = TypeCaster.parseStringToMoment(timeString);
1566+ m = TypeConverter.parseStringToMoment(timeString);
1567 if (m === undefined || !m.isValid()) {
1568 throw new Error();
1569 }
1570@@ -330,11 +330,11 @@ class TypeCaster {
1571 */
1572 public static stringToDateNumber(dateString : string) : number {
1573 // m will be set and valid or invalid, or will remain undefined
1574- var m = TypeCaster.parseStringToMoment(dateString);
1575+ var m = TypeConverter.parseStringToMoment(dateString);
1576 if (m === undefined || !m.isValid()) {
1577 throw new ValueError("DATEVALUE parameter '" + dateString + "' cannot be parsed to date/time.");
1578 }
1579- return TypeCaster.momentToDayNumber(m.set('hours', 0).set('minutes', 0).set('seconds', 0));
1580+ return TypeConverter.momentToDayNumber(m.set('hours', 0).set('minutes', 0).set('seconds', 0));
1581 }
1582
1583 /**
1584@@ -374,7 +374,7 @@ class TypeCaster {
1585 */
1586 static valueToNumberGracefully(value: any) : number {
1587 try {
1588- return TypeCaster.valueToNumber(value);
1589+ return TypeConverter.valueToNumber(value);
1590 } catch (e) {
1591 return 0;
1592 }
1593@@ -422,10 +422,10 @@ class TypeCaster {
1594 return 0;
1595 }
1596 try {
1597- return TypeCaster.stringToTimeNumber(value)
1598+ return TypeConverter.stringToTimeNumber(value)
1599 } catch (e) {
1600- if (TypeCaster.canCoerceToNumber(value)) {
1601- return TypeCaster.valueToNumber(value);
1602+ if (TypeConverter.canCoerceToNumber(value)) {
1603+ return TypeConverter.valueToNumber(value);
1604 }
1605 throw new ValueError("___ expects number values. But '" + value + "' is a text and cannot be coerced to a number.")
1606 }
1607@@ -465,9 +465,9 @@ class TypeCaster {
1608 if (input.length === 0) {
1609 throw new RefError("Reference does not exist.");
1610 }
1611- return TypeCaster.firstValueAsNumber(input[0]);
1612+ return TypeConverter.firstValueAsNumber(input[0]);
1613 }
1614- return TypeCaster.valueToNumber(input);
1615+ return TypeConverter.valueToNumber(input);
1616 }
1617
1618 /**
1619@@ -480,9 +480,9 @@ class TypeCaster {
1620 if (input.length === 0) {
1621 throw new RefError("Reference does not exist.");
1622 }
1623- return TypeCaster.firstValueAsString(input[0]);
1624+ return TypeConverter.firstValueAsString(input[0]);
1625 }
1626- return TypeCaster.valueToString(input);
1627+ return TypeConverter.valueToString(input);
1628 }
1629
1630 static firstValue(input: any) : any {
1631@@ -490,7 +490,7 @@ class TypeCaster {
1632 if (input.length === 0) {
1633 throw new RefError("Reference does not exist.");
1634 }
1635- return TypeCaster.firstValue(input[0]);
1636+ return TypeConverter.firstValue(input[0]);
1637 }
1638 return input;
1639 }
1640@@ -505,9 +505,9 @@ class TypeCaster {
1641 if (input.length === 0) {
1642 throw new RefError("Reference does not exist.");
1643 }
1644- return TypeCaster.firstValueAsBoolean(input[0]);
1645+ return TypeConverter.firstValueAsBoolean(input[0]);
1646 }
1647- return TypeCaster.valueToBoolean(input);
1648+ return TypeConverter.valueToBoolean(input);
1649 }
1650
1651 /**
1652@@ -521,9 +521,9 @@ class TypeCaster {
1653 if (input.length === 0) {
1654 throw new RefError("Reference does not exist.");
1655 }
1656- return TypeCaster.firstValueAsDateNumber(input[0], coerceBoolean);
1657+ return TypeConverter.firstValueAsDateNumber(input[0], coerceBoolean);
1658 }
1659- return TypeCaster.valueToDateNumber(input, coerceBoolean);
1660+ return TypeConverter.valueToDateNumber(input, coerceBoolean);
1661 }
1662
1663 static firstValueAsTimestampNumber(input : any) : number {
1664@@ -531,9 +531,9 @@ class TypeCaster {
1665 if (input.length === 0) {
1666 throw new RefError("Reference does not exist.");
1667 }
1668- return TypeCaster.firstValueAsTimestampNumber(input[0]);
1669+ return TypeConverter.firstValueAsTimestampNumber(input[0]);
1670 }
1671- return TypeCaster.valueToTimestampNumber(input);
1672+ return TypeConverter.valueToTimestampNumber(input);
1673 }
1674
1675 /**
1676@@ -547,10 +547,10 @@ class TypeCaster {
1677 return value;
1678 } else if (typeof value === "string") {
1679 try {
1680- return TypeCaster.stringToDateNumber(value)
1681+ return TypeConverter.stringToDateNumber(value)
1682 } catch (e) {
1683- if (TypeCaster.canCoerceToNumber(value)) {
1684- return TypeCaster.valueToNumber(value);
1685+ if (TypeConverter.canCoerceToNumber(value)) {
1686+ return TypeConverter.valueToNumber(value);
1687 }
1688 throw new ValueError("___ expects date values. But '" + value + "' is a text and cannot be coerced to a date.")
1689 }
1690@@ -563,7 +563,7 @@ class TypeCaster {
1691 }
1692
1693 /**
1694- * Casts a moment to a date number.
1695+ * Converts a moment to a date number.
1696 * @param m to convert
1697 * @returns {number} date
1698 */
1699@@ -572,21 +572,21 @@ class TypeCaster {
1700 }
1701
1702 /**
1703- * Casts a moment to a date number, floored to the whole day date.
1704+ * Converts a moment to a date number, floored to the whole day date.
1705 * @param m to convert
1706 * @returns {number} date
1707 */
1708 static momentToDayNumber(m : moment.Moment) : number {
1709- return Math.floor(TypeCaster.momentToNumber(m));
1710+ return Math.floor(TypeConverter.momentToNumber(m));
1711 }
1712
1713 /**
1714- * Casts a number to moment.
1715+ * Converts a number to moment.
1716 * @param n to convert
1717 * @returns {Moment} date
1718 */
1719 static numberToMoment(n : number) : moment.Moment {
1720- return moment.utc(TypeCaster.ORIGIN_MOMENT).add(n, "days");
1721+ return moment.utc(TypeConverter.ORIGIN_MOMENT).add(n, "days");
1722 }
1723
1724 /**
1725@@ -616,6 +616,6 @@ var checkForDevideByZero = function(n : number) : number {
1726 };
1727
1728 export {
1729- TypeCaster,
1730+ TypeConverter,
1731 checkForDevideByZero
1732 }
1733\ No newline at end of file