-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathval.js
More file actions
48 lines (43 loc) · 783 Bytes
/
val.js
File metadata and controls
48 lines (43 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"use strict";
var conversions = [ {
match: /^\d+$/,
transform: function( str ) {
return parseInt( str, 10 );
}
}, {
match: /^\d+\.\d+$/,
transform: function( str ) {
return parseFloat( str, 10 );
}
}, {
match: /^true$/i,
transform: function() {
return true;
}
}, {
match: /^false$/i,
transform: function() {
return false;
}
}, {
match: /^(null|NULL)$/,
transform: function() {
return null;
}
}, {
match: /^\[.*?\]$/,
transform: function( str ) {
return str.substring( 1, str.length - 1 ).split( ',' );
}
} ];
module.exports = function( str ) {
var value = str;
conversions.some( function( conversion ) {
if ( conversion.match.test( str ) ) {
value = conversion.transform( str );
return true;
}
return false;
} );
return value;
};