aboutsummaryrefslogtreecommitdiff
path: root/lib/types.js
blob: 38e2b60593a3583c43cba3a5b055d79fda36d085 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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');
	}
};