-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_formatter.js
More file actions
executable file
·55 lines (52 loc) · 1.92 KB
/
Copy pathdata_formatter.js
File metadata and controls
executable file
·55 lines (52 loc) · 1.92 KB
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
49
50
51
52
53
54
55
import moment from 'moment';
import { MAX_NUMBER, CURRENCY_SYMBOL } from './../consts';
module.exports = {
getFormattedDepreciation: function (number) {
var currencyValue = (number).format(2);
return CURRENCY_SYMBOL + currencyValue.replace('.00', '') + '/yr';
},
getFormattedInstallment: function (number) {
var currencyValue = (number).format(2);
return CURRENCY_SYMBOL + currencyValue.replace('.00', '') + '/mth';
},
getFormattedCurrencyValue: function (number) {
var currencyValue = (number).format(2);
return CURRENCY_SYMBOL + currencyValue.replace('.00', '');
},
getFormattedMileage: function (number) {
return (number).format(0) + ' km';
},
getFormattedEngineCC: function (number) {
return number + 'cc';
},
getFormattedDate: function (timestamp) {
return moment.unix(timestamp).format("d MMM YYYY");
},
getFormattedShortMonth: function (number) {
return moment(number, 'M').format("MMM");
},
// getFormattedNumberOfYears: function (number) {
// if (number === 0) {
// return 'Fresh Graduate';
// } else if (number === MAX_NUMBER) {
// return 'More than 15 years';
// }
// return number>1 ? number + ' years' : number + ' year';
// },
formatDate: function (date, format) {
return moment(date).format(format);
},
shorthenThousandNumber: function (number) {
return number > 999 ? (number/1000).toFixed(0) + 'K' : number
}
};
Number.prototype.format = function(c, d, t) {
var n = this,
c = isNaN(c = Math.abs(c)) ? 2 : c,
d = d == undefined ? "." : d,
t = t == undefined ? "," : t,
s = n < 0 ? "-" : "",
i = String(parseInt(n = Math.abs(Number(n) || 0).toFixed(c))),
j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};