aboutsummaryrefslogtreecommitdiff
path: root/lib/types.js
diff options
context:
space:
mode:
authorBen Burwell <ben.burwell@trifecta.com>2016-09-14 12:30:04 -0400
committerBen Burwell <ben.burwell@trifecta.com>2016-09-14 12:30:04 -0400
commitfd5817a6bb3185314540825e3d665e94ffe188c0 (patch)
tree9b35138a18122ebfcb5cfa41ac0eadd27cb2c002 /lib/types.js
Initial commit
Diffstat (limited to 'lib/types.js')
-rw-r--r--lib/types.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/types.js b/lib/types.js
new file mode 100644
index 0000000..38e2b60
--- /dev/null
+++ b/lib/types.js
@@ -0,0 +1,22 @@
+var stringToType = function(str, type) {
+ switch (type) {
+ case 'number':
+ if (str.indexOf('.')) {
+ return parseFloat(str);
+ } else {
+ return parseInt(str, 10);
+ }
+ case 'string':
+ return str;
+ case 'boolean':
+ if (str === 'true') {
+ return true;
+ } else if (str === 'false') {
+ return false;
+ } else {
+ throw new Error('Invalid boolean value ' + str);
+ }
+ default:
+ throw new Error('type', type, 'is not defined');
+ }
+};