-
Notifications
You must be signed in to change notification settings - Fork 630
/
Copy pathCurrency.js
93 lines (85 loc) · 2.35 KB
/
Currency.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* Copyright (c) 2018-present, Evgeny Nadymov
*
* This source code is licensed under the GPL v.3.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
class Currency{
constructor(){
this.list = new Map([
["AED", "د.إ"],
["AFN", "؋"],
["ARS", "$"],
["AUD", "$"],
["AZN", "₼"],
["BND", "B$"],
["BRL", "R$"],
["CAD", "$"],
["CHF", "Fr"],
["CLP", "$"],
["CNY", "¥"],
["COP", "$"],
["EGP", "E£"],
["EUR", "€"],
["GBP", "£"],
["HKD", "$"],
["IDR", "Rp"],
["ILS", "₪"],
["INR", "₹"],
["ISK", "kr"],
["JPY", "¥"],
["KRW", "₩"],
["KZT", "₸"],
["MXN", "$"],
["MYR", "RM"],
["NOK", "kr"],
["NZD", "$"],
["PHP", "₱"],
["RUB", "₽"],
["SAR", "SR"],
["SEK", "kr"],
["SGD", "$"],
["TRY", "₺"],
["TTD", "$"],
["TWD", "$"],
["TZS", "TSh"],
["UAH", "₴"],
["UGX", "USh"],
["USD", "$"],
["UYU", "$"],
["VND", "₫"],
["YER", "﷼"],
["ZAR", "R"],
["IRR", "﷼"],
["IQD", "ع.د"],
["VEF", "Bs.F."]
]);
}
get(currency){
return this.list.get(currency);
}
set(currency, symbol){
this.list.set(currency, symbol);
}
getPow(currency){
if (currency === 'CLF'){
return 4;
}
if (['BHD', 'IQD', 'JOD', 'KWD', 'LYD', 'OMR', 'TND'].includes(currency)){
return 3;
}
if (['BIF', 'BYR', 'CLP', 'CVE', 'DJF', 'GNF', 'ISK', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'UYI', 'VND', 'VUV', 'XAF', 'XOF', 'XPF'].includes(currency)){
return 0;
}
if (currency === 'MRO'){
return 1;
}
return 2;
}
getString(totalAmount, currency){
const amount = (totalAmount/Math.pow(10.0, this.getPow(currency))).toFixed(2);
return `${amount} ${this.get(currency)}`;
}
}
let currency = new Currency();
export default currency;