1 | import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
2 | import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
3 | import _objectSpread from "@babel/runtime/helpers/objectSpread";
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | var intlFormats = {
|
22 | USD: {
|
23 | symbol: '$',
|
24 | decimal: '.',
|
25 | groupDelim: ','
|
26 | },
|
27 | GBP: {
|
28 | symbol: '£',
|
29 | decimal: '.',
|
30 | groupDelim: ','
|
31 | },
|
32 | EUR: {
|
33 | symbol: '€',
|
34 | decimal: '.',
|
35 | groupDelim: ','
|
36 | }
|
37 | };
|
38 | var IntlPatches = {
|
39 | formatToPartsPatch: function formatToPartsPatch(_ref, num) {
|
40 | var currency = _ref.currency,
|
41 | maximumFractionDigits = _ref.maximumFractionDigits,
|
42 | useGrouping = _ref.useGrouping;
|
43 |
|
44 | var format = intlFormats[currency] || _objectSpread({}, intlFormats.USD, {
|
45 | symbol: currency
|
46 | });
|
47 |
|
48 | var symbol = format.symbol,
|
49 | decimal = format.decimal,
|
50 | groupDelim = format.groupDelim;
|
51 | var parts = [{
|
52 | type: 'currency',
|
53 | value: symbol
|
54 | }];
|
55 |
|
56 | var _num$toFixed$match = num.toFixed(maximumFractionDigits).match(/\d+/g),
|
57 | _num$toFixed$match2 = _slicedToArray(_num$toFixed$match, 2),
|
58 | integer = _num$toFixed$match2[0],
|
59 | fraction = _num$toFixed$match2[1];
|
60 |
|
61 | if (useGrouping !== false) {
|
62 | var intParts = [];
|
63 | var firstGroupLength = integer.length % 3;
|
64 | var integerSlice = integer;
|
65 |
|
66 | if (firstGroupLength > 0) {
|
67 | intParts.push(JSON.stringify({
|
68 | type: 'integer',
|
69 | value: integer.slice(0, firstGroupLength)
|
70 | }));
|
71 | integerSlice = integer.slice(firstGroupLength);
|
72 | }
|
73 |
|
74 | var groups = integerSlice.match(/\d{3}/g);
|
75 |
|
76 | if (groups) {
|
77 | intParts.push.apply(intParts, _toConsumableArray(groups.map(function (intPart) {
|
78 | return JSON.stringify({
|
79 | type: 'integer',
|
80 | value: intPart
|
81 | });
|
82 | })));
|
83 | }
|
84 |
|
85 | var groupDelimJSON = ',' + JSON.stringify({
|
86 | type: 'group',
|
87 | value: groupDelim
|
88 | }) + ',';
|
89 | var intAndGroupParts = JSON.parse("[".concat(intParts.join(groupDelimJSON), "]"));
|
90 | parts.push.apply(parts, _toConsumableArray(intAndGroupParts));
|
91 | } else {
|
92 | parts.push({
|
93 | type: 'integer',
|
94 | value: integer
|
95 | });
|
96 | }
|
97 |
|
98 | return parts.concat([{
|
99 | type: 'decimal',
|
100 | value: decimal
|
101 | }, {
|
102 | type: 'fraction',
|
103 | value: fraction
|
104 | }]);
|
105 | },
|
106 | toParts: function toParts(num) {
|
107 | return this.formatToParts ? this.formatToParts(num) : IntlPatches.formatToPartsPatch(this.resolvedOptions(), num);
|
108 | }
|
109 | };
|
110 | export default IntlPatches;
|
111 |
|
\ | No newline at end of file |