-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes.js
More file actions
38 lines (32 loc) · 810 Bytes
/
Copy pathtypes.js
File metadata and controls
38 lines (32 loc) · 810 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
const TYPES = {
NUMBER: "number",
STRING: "string",
BOOL: "bool",
DATE: "date",
convert: function(data, type){
if(type == this.NUMBER){
return parseFloat(data);
}
if(type == this.STRING){
if(typeof data === "undefined"){
return undefined;
}
if(data === null){
return null;
}
return (new String(data)).toString();
}
if(type == this.BOOL){
return !!data;
}
if(type == this.DATE){
if(typeof data === "undefined"){
return undefined;
}
if(data === null) return null;
return new Date(data);
}
return data;
}
}
module.exports = TYPES;