aboutsummaryrefslogtreecommitdiff
path: root/lib/types.js
diff options
context:
space:
mode:
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');
+ }
+};