-
Notifications
You must be signed in to change notification settings - Fork 2
/
formatter.js
37 lines (34 loc) · 933 Bytes
/
formatter.js
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
const formatDate = (date) => {
var mm = date.getMonth() + 1;
var dd = date.getDate();
return [
date.getFullYear(),
(mm > 9 ? '' : '0') + mm,
(dd > 9 ? '' : '0') + dd
].join('-');
};
const formatValue = (value) => {
if (typeof (value) === 'string') {
if (!value || value === null || value === undefined || value.length === 0 || value.toLowerCase() === 'null') {
return null;
}
else if (value.toLowerCase() === 'false') {
return false;
}
else if (value.toLowerCase() === 'true') {
return true;
}
else if (!isNaN(value)) {
return Number(value);
}
else if (new Date(value) !== "Invalid Date" && !isNaN(new Date(value))) {
return new Date(value);
}
return value;
}
return value;
};
module.exports = {
formatDate,
formatValue
};