@transferwise/formatting 2.10.0 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -92
- package/dist/formatting.d.ts +5 -5
- package/dist/formatting.js +1 -1
- package/dist/formatting.js.map +1 -1
- package/dist/formatting.modern.js +1 -1
- package/dist/formatting.modern.js.map +1 -1
- package/dist/formatting.module.js +1 -1
- package/dist/formatting.module.js.map +1 -1
- package/dist/formatting.umd.js +1 -1
- package/dist/formatting.umd.js.map +1 -1
- package/dist/number/number.d.ts +1 -0
- package/dist/percentage/percentage.d.ts +1 -1
- package/dist/rate/formatRate.d.ts +9 -3
- package/dist/rate/getDisplayRate.d.ts +27 -0
- package/dist/rate/getRateInAllFormats.d.ts +3 -0
- package/dist/rate/index.d.ts +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -15,7 +15,14 @@ console.log(formatNumber(number, 'en-GB' /* Optional, defaults to en-GB */));
|
|
|
15
15
|
// --> '123,456'
|
|
16
16
|
console.log(formatNumber(number, 'es-ES', 0 /* Optional precision, defaults to 0 */));
|
|
17
17
|
// --> '123.456'
|
|
18
|
-
console.log(
|
|
18
|
+
console.log(
|
|
19
|
+
formatNumber(
|
|
20
|
+
number,
|
|
21
|
+
'hu-HU',
|
|
22
|
+
0,
|
|
23
|
+
'FractionDigits' /* Optional precision type (FractionDigits or SignificantDigits), defaults to 'FractionDigits' */,
|
|
24
|
+
),
|
|
25
|
+
);
|
|
19
26
|
// --> '123 456'
|
|
20
27
|
```
|
|
21
28
|
|
|
@@ -28,7 +35,9 @@ const number = 123456;
|
|
|
28
35
|
|
|
29
36
|
console.log(formatNumberToSignificantDigits(number, 'en-GB' /* Optional, defaults to en-GB */));
|
|
30
37
|
// --> '123,456'
|
|
31
|
-
console.log(
|
|
38
|
+
console.log(
|
|
39
|
+
formatNumberToSignificantDigits(number, 'es-ES', 8 /* Optional precision, defaults to 6 */),
|
|
40
|
+
);
|
|
32
41
|
// --> '123.456,00'
|
|
33
42
|
console.log(formatNumberToSignificantDigits(number, 'hu-HU', 8));
|
|
34
43
|
// --> '123 456,00'
|
|
@@ -54,89 +63,35 @@ console.log(formatMoney(1234.56, 'EUR', 'en-GB' /* Optional, defaults to en-GB *
|
|
|
54
63
|
|
|
55
64
|
### Rate formatting
|
|
56
65
|
|
|
57
|
-
####
|
|
58
|
-
```js
|
|
59
|
-
formatRate(0.08682346801) === "0.0868235"
|
|
60
|
-
formatRate(0.08682346801, {significantFigures: 8}) === "0.086823468"
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
Limits a rate to a certain amount of precision for display (6 significant figures by default). It will always return a numberstring (string that's parseable as a number).
|
|
64
|
-
|
|
65
|
-
This is a dumb, low-level formatter for just the rate number value, and it's kept around mostly for older implementations. For typical rate display purposes, you may instead wish to make use of `getRateInAllFormats`, because it can suggest showing the rate inverted and/or multiplied if it makes sense for that currency pair.
|
|
66
|
-
|
|
67
|
-
At the moment the only configurable option is `significantFigures`, you can set it if you don't like the default of 6 significant figures.
|
|
66
|
+
#### getDisplayRate(rate, sourceCurrency, targetCurrency, locale)
|
|
68
67
|
|
|
69
|
-
|
|
68
|
+
Use this function when you need to display rates to customers. It will round rates to the correct number of decimal places and will invert rates that are best displayed in the other direction.
|
|
69
|
+
For example if a rate is very low we invert the rate so that it's easier for customers to understand.
|
|
70
70
|
|
|
71
|
-
```
|
|
72
|
-
const
|
|
71
|
+
```ts
|
|
72
|
+
const display = getDisplayRate({
|
|
73
|
+
rate: 1.2345,
|
|
74
|
+
sourceCurrency: 'BRL',
|
|
75
|
+
targetCurrency: 'EUR',
|
|
76
|
+
locale: 'de',
|
|
77
|
+
});
|
|
78
|
+
```
|
|
73
79
|
|
|
74
|
-
|
|
80
|
+
In most cases you should use `display.equation` to get a string such as `1 EUR = 4.5678 BRL`.
|
|
75
81
|
|
|
76
|
-
|
|
77
|
-
rateFormats.formats[suggested.format].output // "1 USD = 434.783 BRL"
|
|
78
|
-
// or simply...
|
|
79
|
-
rateFormats.suggested.output // "1 USD = 434.783 BRL"
|
|
82
|
+
In calculators you may wish to show the rate directly using `display.decimal`. You must have some UI component to specify if the rate has been inverted or not, based on `display.inverted`; for example a multiply/divide icon.
|
|
80
83
|
|
|
81
|
-
|
|
82
|
-
rateFormats.formats.equation.output // "1 USD = 434.783 BRL"
|
|
83
|
-
// If you always want the source-to-target number format (identical to formatNumberToSignificantDigits(rate, locale, significantFigures))...
|
|
84
|
-
rateFormats.formats.decimal.output // "0.00230000"
|
|
85
|
-
```
|
|
84
|
+
In a rate graph first call `getDisplayRate` to determine if the rates should be displayed inverted or not. Then call either `formatRate(rate, locale)` or `formatRate(1 / rate, locale)` on each data point in the graph.
|
|
86
85
|
|
|
87
|
-
|
|
86
|
+
#### formatRate(rate, locale)
|
|
88
87
|
|
|
89
88
|
```js
|
|
90
|
-
|
|
91
|
-
"suggested": {
|
|
92
|
-
"format": "equation", // either `equation` or `decimal`
|
|
93
|
-
"output": "1 USD = 434.783 BRL",
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
"formats": {
|
|
97
|
-
"decimal": {
|
|
98
|
-
"output": "0.00230000", // Equivalent to the output of formatNumberToSignificantDigits(rate, locale, significantFigures)
|
|
99
|
-
"significantFigures": 6,
|
|
100
|
-
},
|
|
101
|
-
"equation": {
|
|
102
|
-
"output": "1 USD = 434.783 BRL",
|
|
103
|
-
"reference": "target", // a.k.a. which currency is the left-hand side.
|
|
104
|
-
"referenceMultiplier": 1 // a.k.a. left-hand anchor value.
|
|
105
|
-
"calculationInDecimal": "434.783", // a.k.a. right-hand value.
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
89
|
+
formatRate(0.08682346801, 'de') === '0,0868';
|
|
109
90
|
```
|
|
110
91
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
Option | Default | Allowed | Description
|
|
114
|
-
-- | -- | -- | --
|
|
115
|
-
`reference` | 'auto' | one of 'auto', 'source', or 'target' | Control which currency appears on the left-hand side as the reference. If 'auto' (the default), it will rely on currency norms [configured here](./src/rate/config.js).
|
|
116
|
-
`referenceMultiplier` | Depends on currency, but usually 1 | Any number, but typically 1, 10, 100, 1000, etc. | Controls the amount of the left-hand reference currency. Currency norms for the default are [configured here](./src/rate/config.js).
|
|
117
|
-
`significantFigures` | 6 | Any positive integer | Controls the displayed precision of calculated values.
|
|
118
|
-
|
|
119
|
-
Thus, depending on your needs, it's possible to get your rate in any of these formats:
|
|
92
|
+
Limits a rate to a certain amount of precision for display (4 decimal places).
|
|
120
93
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
- `"1 VND = 0.0000332345 GBP"` (equation)
|
|
124
|
-
- `"100,000 VND = 3.32345 GBP"` (multiplied equation)
|
|
125
|
-
- `"1 GBP = 30,382.67 VND"` (target-reference a.k.a. inverted equation)
|
|
126
|
-
- `"100 HUF = 8,080.73 VND"` (inverted and multiplied equation)
|
|
127
|
-
- `"0.0000332345"` (decimal)
|
|
128
|
-
- `"30,382.67"` (inverted decimal)
|
|
129
|
-
|
|
130
|
-
All outputted strings are localized using the provided `locale` (defaults to `en-GB`).
|
|
131
|
-
|
|
132
|
-
_**When does `getRateInAllFormats` suggest a decimal format, and when does it suggest an equation format?**_
|
|
133
|
-
|
|
134
|
-
To avoid changing the behaviour of many existing currency pairs, `getRateInAllFormats` will suggest the decimal format (which is what we've historically shown) when:
|
|
135
|
-
|
|
136
|
-
1. the resulting `reference` is `'source'` (whether calculated by currency norms, or explicitly overriden by the user), and
|
|
137
|
-
2. the resulting `referenceMultiplier` is 1 (whether calculated by currency norms, or explicitly overriden by the user)
|
|
138
|
-
|
|
139
|
-
These 2 conditions will typically be true for "strong" source currencies like GBP, EUR, USD, AUD, SGD, etc. If at least 1 of these conditions are not true, then it will suggest the equation format.
|
|
94
|
+
This is a dumb, low-level formatter for just the rate number value, and it's only for specific rate implementations. For typical rate display purposes, you should use `getDisplayRate`.
|
|
140
95
|
|
|
141
96
|
### Percentage formatting
|
|
142
97
|
|
|
@@ -145,9 +100,9 @@ import { formatPercentage } from '@transferwise/formatting';
|
|
|
145
100
|
|
|
146
101
|
console.log(formatPercentage(0.23456789));
|
|
147
102
|
// --> '23.46%'
|
|
148
|
-
console.log(formatPercentage(0.
|
|
103
|
+
console.log(formatPercentage(0.234));
|
|
149
104
|
// --> '23.4%'
|
|
150
|
-
console.log(formatPercentage(0.
|
|
105
|
+
console.log(formatPercentage(0.23));
|
|
151
106
|
// --> '23%'
|
|
152
107
|
```
|
|
153
108
|
|
|
@@ -165,7 +120,9 @@ console.log(formatDate(date, 'en-GB', { weekday: 'short' }));
|
|
|
165
120
|
console.log(formatDate(date, 'en-GB', { month: 'long', year: 'numeric' }));
|
|
166
121
|
// --> 'December 2018'
|
|
167
122
|
```
|
|
123
|
+
|
|
168
124
|
For third parameter pass in the same [options](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat#Parameters) as for `Intl.DateTimeFormat` and for best performance use the same object (pass in reference), for example:
|
|
125
|
+
|
|
169
126
|
```javascript
|
|
170
127
|
const options = { weekday: 'short' };
|
|
171
128
|
formatDate(new Date(), 'en-GB', options);
|
|
@@ -173,8 +130,9 @@ formatDate(new Date(), 'en-GB', options);
|
|
|
173
130
|
```
|
|
174
131
|
|
|
175
132
|
### Relative Date formatting
|
|
133
|
+
|
|
176
134
|
Formats future dates using a relative description of time, e.g. 'in seconds'.
|
|
177
|
-
A relative description will be used as long as the instant of time being formatted is on the same calendar date as today in the clients timezone and the time is within 12 hours (inclusive).
|
|
135
|
+
A relative description will be used as long as the instant of time being formatted is on the same calendar date as today in the clients timezone and the time is within 12 hours (inclusive).
|
|
178
136
|
|
|
179
137
|
```javascript
|
|
180
138
|
import { formatRelativeDate } from '@transferwise/formatting';
|
|
@@ -182,21 +140,21 @@ import { formatRelativeDate } from '@transferwise/formatting';
|
|
|
182
140
|
console.log(formatRelativeDate(new Date(Date.now() + 1000))); // --> 'in seconds'
|
|
183
141
|
```
|
|
184
142
|
|
|
185
|
-
| Same Calendar Date | Time Range (inclusive) | Sample Output
|
|
186
|
-
|
|
187
|
-
| Yes | In the past | ''
|
|
188
|
-
| Yes | 00:00:00.000 -> 00:00:59.000 | 'in seconds'
|
|
189
|
-
| Yes | 00:00:59.001 -> 00:01:00.000 | 'in 1 minute'
|
|
190
|
-
| Yes | 00:01:00.001 -> 00:02:00.000 | 'in 2 minutes'
|
|
191
|
-
| Yes | 00:02:00.001 -> 00:58:00.000 | 'in x minutes' (3-58)
|
|
192
|
-
| Yes | 00:58:00.001 -> 00:59:00.000 | 'in 59 minutes'
|
|
193
|
-
| Yes | 00:59:00.001 -> 01:00:00.000 | 'in 1 hour'
|
|
194
|
-
| Yes | 01:00:00.001 -> 02:00:00.000 | 'in 2 hours'
|
|
195
|
-
| Yes | 02:00:00.001 -> 10:00:00.000 | 'in x hours' (3-10)
|
|
196
|
-
| Yes | 10:00:00.001 -> 11:00:00.000 | 'in 11 hours'
|
|
197
|
-
| Yes | 11:00:00.001 -> 12:00:00.000 | 'in 12 hours'
|
|
198
|
-
| Yes | 12:00:00.001 -> End of calendar date | 'by Aug 23'
|
|
199
|
-
| No | Any | 'by Aug 23'
|
|
143
|
+
| Same Calendar Date | Time Range (inclusive) | Sample Output |
|
|
144
|
+
| ------------------ | ------------------------------------ | --------------------- |
|
|
145
|
+
| Yes | In the past | '' |
|
|
146
|
+
| Yes | 00:00:00.000 -> 00:00:59.000 | 'in seconds' |
|
|
147
|
+
| Yes | 00:00:59.001 -> 00:01:00.000 | 'in 1 minute' |
|
|
148
|
+
| Yes | 00:01:00.001 -> 00:02:00.000 | 'in 2 minutes' |
|
|
149
|
+
| Yes | 00:02:00.001 -> 00:58:00.000 | 'in x minutes' (3-58) |
|
|
150
|
+
| Yes | 00:58:00.001 -> 00:59:00.000 | 'in 59 minutes' |
|
|
151
|
+
| Yes | 00:59:00.001 -> 01:00:00.000 | 'in 1 hour' |
|
|
152
|
+
| Yes | 01:00:00.001 -> 02:00:00.000 | 'in 2 hours' |
|
|
153
|
+
| Yes | 02:00:00.001 -> 10:00:00.000 | 'in x hours' (3-10) |
|
|
154
|
+
| Yes | 10:00:00.001 -> 11:00:00.000 | 'in 11 hours' |
|
|
155
|
+
| Yes | 11:00:00.001 -> 12:00:00.000 | 'in 12 hours' |
|
|
156
|
+
| Yes | 12:00:00.001 -> End of calendar date | 'by Aug 23' |
|
|
157
|
+
| No | Any | 'by Aug 23' |
|
|
200
158
|
|
|
201
159
|
## Developing
|
|
202
160
|
|
package/dist/formatting.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
1
|
+
export { formatAmount, formatMoney } from './currency';
|
|
2
|
+
export { formatRate, getRateInAllFormats, getDisplayRate } from './rate';
|
|
3
|
+
export { formatPercentage } from './percentage';
|
|
4
|
+
export { formatRelativeDate, formatDate } from './date';
|
|
5
|
+
export { formatNumberToSignificantDigits, formatNumber } from './number';
|
package/dist/formatting.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e,t={TYPE:"SignificantDigits",MIN_PRECISION:1,MAX_PRECISION:21},r={TYPE:"FractionDigits",MIN_PRECISION:0,MAX_PRECISION:20},n={};function i(e,t){var r=t?""+e+Object.entries(t):e;return n[r]||(n[r]=t?new Intl.NumberFormat(e,t):new Intl.NumberFormat(e)),n[r]}function a(e,r,n){return void 0===r&&(r="en-GB"),void 0===n&&(n=6),o(e,r,n,t.TYPE)}function o(n,a,o,u){if(void 0===a&&(a="en-GB"),void 0===u&&(u="FractionDigits"),!n&&0!==n)return"";"string"==typeof n&&Number(n)&&(n=Number(n));var m=u===t.TYPE?t:r,s=null!=o&&"number"==typeof o&&o>=m.MIN_PRECISION&&o<=m.MAX_PRECISION,f=function(e){try{var t=e.replace(/_/,"-");return Intl.NumberFormat(t),t}catch(e){return"en-GB"}}(a);return function(t){return void 0===e&&(e="object"==typeof Intl&&void 0!==Intl&&"function"==typeof Intl.NumberFormat&&Intl.NumberFormat&&"function"==typeof Intl.NumberFormat.supportedLocalesOf&&Intl.NumberFormat.supportedLocalesOf&&1===Intl.NumberFormat.supportedLocalesOf(t).length),e}(f)?(s?i(f,function(e,t){var r;return(r={})["minimum"+t]=e,r["maximum"+t]=e,r}(o,u)):i(f)).format(n):s?function(e,r,n){return n===t.TYPE?e.toPrecision(r):e.toFixed(r)}(n,o,u):""+n}var u={BIF:0,BYR:0,CLP:0,DJF:0,GNF:0,JPY:0,KMF:0,KRW:0,MGA:0,PYG:0,RWF:0,VND:0,VUV:0,XAF:0,XOF:0,XPF:0,HUF:0,UGX:0,KES:0,BHD:3,JOD:3,KWD:3,OMR:3,TND:3};function m(e,t,r,n){return void 0===r&&(r="en-GB"),void 0===n&&(n={alwaysShowDecimals:!1}),o(e,r,function(e,t,r){return function(e){return e%1==0}(e)&&!r?0:function(e){void 0===e&&(e="");var t=e.toUpperCase();return Object.prototype.hasOwnProperty.call(u,t)?u[t]:2}(t)}(e,t,n.alwaysShowDecimals))}function s(e,t,r){var n=e.lhsCurrency,i=e.rhsValue,o=e.rhsCurrency,u=(void 0===t?{}:t).significantFigures,s=void 0===u?6:u;return void 0===r&&(r="en-GB"),m(e.lhsValue,n,r)+" "+n+" = "+a(i,r,s)+" "+o}var f,l={BRL:{hasInversionEnabled:!0},INR:{hasInversionEnabled:!0},JPY:{hasInversionEnabled:!0},IDR:{hasInversionEnabled:!0},HUF:{hasInversionEnabled:!0},RON:{hasInversionEnabled:!0},THB:{hasInversionEnabled:!0}};function v(e,t){return e||(l[t]||{}).multiplierForEquation||1}var c={},d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function p(e,t,r){return void 0===t&&(t="en-GB"),void 0===f&&(f=function(){try{var e=new Date(2018,11,1);return"01/12/2018"===new Intl.DateTimeFormat("en-GB").format(e)}catch(e){return!1}}()),f?new Intl.DateTimeFormat(function(e){return function(e){return void 0===c[e]&&(c[e]=function(e){try{return Intl.DateTimeFormat.supportedLocalesOf([e]).length>0}catch(e){return!1}}(e)),c[e]}(e)?e:"en-GB"}(t),r).format(e):function e(t,r){void 0===r&&(r={});var n="UTC"===r.timeZone,i=[];if(r.day&&i.push(n?t.getUTCDate():t.getDate()),r.month){var a=function(e,t,r){return"short"===e.month?h[t?r.getUTCMonth():r.getMonth()]:(t?r.getUTCMonth():r.getMonth())+1}(r,n,t);!function(e){return"short"===e.month}(r)?i.push(a):i.unshift(a)}r.year&&i.push(t.getUTCFullYear());var o=function(e){return"short"===e.month?" ":"/"}(r),u=i.join(o);if(r.weekday){var m=d[n?t.getUTCDay():t.getDay()];u=u?m+", "+u:m}return u||e(t,{timeZone:r.timeZone,day:"true",month:"true",year:"true"})}(e,r)}var y,g={cs:{"relative-format-in-seconds":"během pár vteřin","relative-format-in-minutes":"v {minutes} minutách","relative-format-in-hours":"v {hours} hodinách","relative-format-in-minute":"během 1 minuty","relative-format-in-hour":"během 1 hodiny","relative-format-by":"do {formattedDate}"},de:{"relative-format-in-seconds":"binnen Sekunden","relative-format-in-minutes":"in {minutes} Minuten","relative-format-in-hours":"in {hours} Stunden","relative-format-in-minute":"in einer Minute","relative-format-in-hour":"in einer Stunde","relative-format-by":"bis {formattedDate}"},en:{"relative-format-in-seconds":"in seconds","relative-format-in-minutes":"in {minutes} minutes","relative-format-in-hours":"in {hours} hours","relative-format-in-minute":"in 1 minute","relative-format-in-hour":"in 1 hour","relative-format-by":"by {formattedDate}"},es:{"relative-format-in-seconds":"en segundos","relative-format-in-minutes":"en {minutes} minutos","relative-format-in-hours":"en {hours} horas","relative-format-in-minute":"en 1 minuto","relative-format-in-hour":"en 1 hora","relative-format-by":"el {formattedDate}"},fr:{"relative-format-in-seconds":"en quelques secondes","relative-format-in-minutes":"dans {minutes} minutes","relative-format-in-hours":"dans {hours} heures","relative-format-in-minute":"dans 1 minute","relative-format-in-hour":"dans 1 heure","relative-format-by":"d'ici le {formattedDate}"},hu:{"relative-format-in-seconds":"másodpercek alatt","relative-format-in-minutes":"{minutes} percen belül","relative-format-in-hours":"{hours} órán belül","relative-format-in-minute":"1 percen belül","relative-format-in-hour":"1 órán belül","relative-format-by":"eddig: {formattedDate}"},id:{"relative-format-in-seconds":"dalam detik","relative-format-in-minutes":"dalam {minutes} menit","relative-format-in-hours":"dalam {hours} jam","relative-format-in-minute":"dalam 1 menit","relative-format-in-hour":"dalam 1 jam","relative-format-by":"sebelum {formattedDate}"},it:{"relative-format-in-seconds":"tra qualche secondo","relative-format-in-minutes":"tra {minutes} minuti","relative-format-in-hours":"tra {hours} ore","relative-format-in-minute":"in 1 minuto","relative-format-in-hour":"in 1 ora","relative-format-by":"entro {formattedDate}"},ja:{"relative-format-in-seconds":"数秒","relative-format-in-minutes":"{minutes}分以内","relative-format-in-hours":"{hours}時間以内","relative-format-in-minute":"1分以内","relative-format-in-hour":"1時間以内","relative-format-by":"{formattedDate}まで"},pl:{"relative-format-in-seconds":"w ciągu kilku sekund","relative-format-in-minutes":"w ciągu {minutes} minut","relative-format-in-hours":"w ciągu {hours} godzin","relative-format-in-minute":"w ciągu 1 minuty","relative-format-in-hour":"w ciągu 1 godziny","relative-format-by":"do {formattedDate}"},pt:{"relative-format-in-seconds":"em segundos","relative-format-in-minutes":"em {minutes} minutos","relative-format-in-hours":"em {hours} horas","relative-format-in-minute":"em 1 minuto","relative-format-in-hour":"em 1 hora","relative-format-by":"até {formattedDate}"},ro:{"relative-format-in-seconds":"în câteva secunde","relative-format-in-minutes":"în {minutes} minute","relative-format-in-hours":"în {hours} ore","relative-format-in-minute":"în 1 minut","relative-format-in-hour":"în 1 oră","relative-format-by":"până pe {formattedDate}"},ru:{"relative-format-in-seconds":"через несколько секунд","relative-format-in-minutes":"через {minutes} мин.","relative-format-in-hours":"через {hours} ч.","relative-format-in-minute":"через минуту","relative-format-in-hour":"через 1 час","relative-format-by":"к {formattedDate}"},tr:{"relative-format-in-seconds":"saniyeler içinde","relative-format-in-minutes":"{minutes} dakika içinde","relative-format-in-hours":"{hours} saat içinde","relative-format-in-minute":"1 dakika içinde","relative-format-in-hour":"1 saat içinde","relative-format-by":"{formattedDate} itibarıyla"},uk:{"relative-format-in-seconds":"через кілька секунд","relative-format-in-minutes":"через {minutes} хв","relative-format-in-hours":"через {hours} год","relative-format-in-minute":"через 1 хвилину","relative-format-in-hour":"через 1 годину","relative-format-by":"до {formattedDate}"},zh:{"relative-format-in-seconds":"數秒內","relative-format-in-minutes":"在 {minutes} 分鐘內","relative-format-in-hours":"在 {hours} 小時內","relative-format-in-minute":"在 1 分鐘內","relative-format-in-hour":"在 1 小時內","relative-format-by":"在 {formattedDate} 或之前"}};function b(e,t,r){var n;return void 0===t&&(t={}),(n=D(r,e)?g[r][e]:D("en",e)?g.en[e]:e)&&t&&Object.keys(t).forEach(function(e){n=n.replace(new RegExp("{"+e+"}","g"),t[e])}),n||e}function D(e,t){return I(g,e)&&I(g[e],t)}function I(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function w(e,t){var r,n=((r={})[y.HOUR]=36e5,r[y.MINUTE]=6e4,r[y.SECOND]=1e3,r);return Math.ceil(e/n[t])}function F(e,t,r){var n;return 1===e?b("relative-format-in-"+r,{},t):b("relative-format-in-"+r+"s",((n={})[r+"s"]=""+e,n),t)}!function(e){e.SECOND="second",e.MINUTE="minute",e.HOUR="hour"}(y||(y={})),exports.formatAmount=m,exports.formatDate=p,exports.formatMoney=function(e,t,r,n){return void 0===r&&(r="en-GB"),void 0===n&&(n={alwaysShowDecimals:!1}),m(e,t,r,n)+" "+(t||"").toUpperCase()},exports.formatNumber=o,exports.formatNumberToSignificantDigits=a,exports.formatPercentage=function(e){return parseFloat((100*e).toFixed(2))+"%"},exports.formatRate=function(e,t,r){var n=(void 0===t?{}:t).significantFigures;return void 0===r&&(r="en-GB"),a(e,r,void 0===n?6:n)},exports.formatRelativeDate=function(e,t){return void 0===t&&(t="en-GB"),e<new Date(Date.now())?"":function(e){return function(e){var t=new Date(Date.now());return e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getFullYear()===t.getFullYear()}(e)&&function(e,t){return w(e-new Date(Date.now()),y.HOUR)<=12}(e)}(e)?function(e,t){var r=e-new Date(Date.now());if(w(r,y.SECOND)<60)return function(e){return b("relative-format-in-seconds",{},e)}(t);var n=w(r,y.MINUTE);return n<60?F(n,t,y.MINUTE):F(w(r,y.HOUR),t,y.HOUR)}(e,t):function(e,t){return b("relative-format-by",{formattedDate:p(e,t,{month:"short",day:"numeric"})},t)}(e,t)},exports.getRateInAllFormats=function(e,t,r,n,i){var o=void 0===n?{}:n,u=o.reference,m=void 0===u?"auto":u,f=o.referenceMultiplier,c=o.significantFigures,d=void 0===c?6:c;void 0===i&&(i="en-GB");var h={suggested:{},formats:{}};h.formats.decimal={output:a(e,i,d),significantFigures:d};var p=function(e,t,r,n){var i=void 0===n?{}:n,a=i.reference,o=void 0===a?"auto":a,u=i.referenceMultiplier;return function(){if(!e)throw new Error("rate parameter is mandatory (got "+e+" instead).");if(!t)throw new Error("sourceCurrency parameter is mandatory (got "+t+" instead).");if(!r)throw new Error("targetCurrency parameter is mandatory (got "+r+" instead).");if(u&&"number"!=typeof u)throw new Error("referenceMultiplier must be a number (got "+typeof u+" "+u+" instead)")}(),function(e,t){if("source"===e)return!1;if("target"===e)return!0;if(["auto",void 0,null].indexOf(e)>-1)return!!(l[t]||{}).hasInversionEnabled;throw new Error("Unrecognized reference config value: "+e+" (valid values are auto, source, target).")}(o,t)?{lhsCurrency:r,lhsValue:v(u,r),rhsCurrency:t,rhsValue:v(u,r)/e}:{lhsCurrency:t,lhsValue:v(u,t),rhsCurrency:r,rhsValue:e*v(u,t)}}(e,t,r,{reference:m,referenceMultiplier:f});return h.formats.equation={output:s(p,{significantFigures:d},i),reference:p.lhsCurrency===t?"source":"target",referenceMultiplier:p.lhsValue,calculationInDecimal:a(p.rhsValue,i,d)},h.suggested=p.lhsCurrency===t&&1===p.lhsValue?{format:"decimal",output:h.formats.decimal.output}:{format:"equation",output:h.formats.equation.output},h};
|
|
1
|
+
var e;function t(t){return void 0===e&&(e="object"==typeof Intl&&void 0!==Intl&&"function"==typeof Intl.NumberFormat&&Intl.NumberFormat&&"function"==typeof Intl.NumberFormat.supportedLocalesOf&&Intl.NumberFormat.supportedLocalesOf&&1===Intl.NumberFormat.supportedLocalesOf(t).length),e}var r={TYPE:"SignificantDigits",MIN_PRECISION:1,MAX_PRECISION:21},n={TYPE:"FractionDigits",MIN_PRECISION:0,MAX_PRECISION:20},i={};function a(e,t){var r=t?""+e+Object.entries(t):e;return i[r]||(i[r]=t?new Intl.NumberFormat(e,t):new Intl.NumberFormat(e)),i[r]}function o(e){try{var t=e.replace(/_/,"-");return Intl.NumberFormat(t),t}catch(e){return"en-GB"}}function u(e,t,n){return void 0===t&&(t="en-GB"),void 0===n&&(n=6),m(e,t,n,r.TYPE)}function m(e,i,u,m){if(void 0===i&&(i="en-GB"),void 0===m&&(m="FractionDigits"),!e&&0!==e)return"";"string"==typeof e&&Number(e)&&(e=Number(e));var s=m===r.TYPE?r:n,f=null!=u&&"number"==typeof u&&u>=s.MIN_PRECISION&&u<=s.MAX_PRECISION,l=o(i);return t(l)?(f?a(l,function(e,t){var r;return(r={})["minimum"+t]=e,r["maximum"+t]=e,r}(u,m)):a(l)).format(e):f?function(e,t,n){return n===r.TYPE?e.toPrecision(t):e.toFixed(t)}(e,u,m):""+e}var s={BIF:0,BYR:0,CLP:0,DJF:0,GNF:0,JPY:0,KMF:0,KRW:0,MGA:0,PYG:0,RWF:0,VND:0,VUV:0,XAF:0,XOF:0,XPF:0,HUF:0,UGX:0,KES:0,BHD:3,JOD:3,KWD:3,OMR:3,TND:3};function f(e,t,r,n){return void 0===r&&(r="en-GB"),void 0===n&&(n={alwaysShowDecimals:!1}),m(e,r,function(e,t,r){return function(e){return e%1==0}(e)&&!r?0:function(e){void 0===e&&(e="");var t=e.toUpperCase();return Object.prototype.hasOwnProperty.call(s,t)?s[t]:2}(t)}(e,t,n.alwaysShowDecimals))}function l(e,t,r){if("string"==typeof t)return v(e,t);var n=t&&t.significantFigures;return n?u(e,r||"en-GB",n):v(e,r||"en-GB")}function v(e,r){var n=4-Math.min(2,Math.max(0,Math.floor(Math.log10(e))-1));return function(e,r,n,i){var u=o(n);return t(u)?a(u,r).format(e):i}(e,{minimumFractionDigits:0,maximumFractionDigits:n},r,e.toFixed(n))}function c(e,t,r){var n=e.lhsCurrency,i=e.rhsValue,a=e.rhsCurrency,o=(void 0===t?{}:t).significantFigures,m=void 0===o?6:o;return void 0===r&&(r="en-GB"),f(e.lhsValue,n,r)+" "+n+" = "+u(i,r,m)+" "+a}var h,d={BRL:{hasInversionEnabled:!0},INR:{hasInversionEnabled:!0},JPY:{hasInversionEnabled:!0},IDR:{hasInversionEnabled:!0},HUF:{hasInversionEnabled:!0},RON:{hasInversionEnabled:!0},THB:{hasInversionEnabled:!0}};function y(e,t){return e||(d[t]||{}).multiplierForEquation||1}var p={},g=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],b=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function D(e,t,r){return void 0===t&&(t="en-GB"),void 0===h&&(h=function(){try{var e=new Date(2018,11,1);return"01/12/2018"===new Intl.DateTimeFormat("en-GB").format(e)}catch(e){return!1}}()),h?new Intl.DateTimeFormat(function(e){return function(e){return void 0===p[e]&&(p[e]=function(e){try{return Intl.DateTimeFormat.supportedLocalesOf([e]).length>0}catch(e){return!1}}(e)),p[e]}(e)?e:"en-GB"}(t),r).format(e):function e(t,r){void 0===r&&(r={});var n="UTC"===r.timeZone,i=[];if(r.day&&i.push(n?t.getUTCDate():t.getDate()),r.month){var a=function(e,t,r){return"short"===e.month?b[t?r.getUTCMonth():r.getMonth()]:(t?r.getUTCMonth():r.getMonth())+1}(r,n,t);!function(e){return"short"===e.month}(r)?i.push(a):i.unshift(a)}r.year&&i.push(t.getUTCFullYear());var o=function(e){return"short"===e.month?" ":"/"}(r),u=i.join(o);if(r.weekday){var m=g[n?t.getUTCDay():t.getDay()];u=u?m+", "+u:m}return u||e(t,{timeZone:r.timeZone,day:"true",month:"true",year:"true"})}(e,r)}var I,F={cs:{"relative-format-in-seconds":"během pár vteřin","relative-format-in-minutes":"v {minutes} minutách","relative-format-in-hours":"v {hours} hodinách","relative-format-in-minute":"během 1 minuty","relative-format-in-hour":"během 1 hodiny","relative-format-by":"do {formattedDate}"},de:{"relative-format-in-seconds":"in Sekunden","relative-format-in-minutes":"in {minutes} Minuten","relative-format-in-hours":"in {hours} Stunden","relative-format-in-minute":"in 1 Minute","relative-format-in-hour":"in 1 Stunde","relative-format-by":"bis {formattedDate}"},en:{"relative-format-in-seconds":"in seconds","relative-format-in-minutes":"in {minutes} minutes","relative-format-in-hours":"in {hours} hours","relative-format-in-minute":"in 1 minute","relative-format-in-hour":"in 1 hour","relative-format-by":"by {formattedDate}"},es:{"relative-format-in-seconds":"en segundos","relative-format-in-minutes":"en {minutes} minutos","relative-format-in-hours":"en {hours} horas","relative-format-in-minute":"en 1 minuto","relative-format-in-hour":"en 1 hora","relative-format-by":"el {formattedDate}"},fr:{"relative-format-in-seconds":"en quelques secondes","relative-format-in-minutes":"dans {minutes} minutes","relative-format-in-hours":"dans {hours} heures","relative-format-in-minute":"dans 1 minute","relative-format-in-hour":"dans 1 heure","relative-format-by":"d'ici le {formattedDate}"},hu:{"relative-format-in-seconds":"másodpercek alatt","relative-format-in-minutes":"{minutes} percen belül","relative-format-in-hours":"{hours} órán belül","relative-format-in-minute":"1 percen belül","relative-format-in-hour":"1 órán belül","relative-format-by":"ekkor: {formattedDate}"},id:{"relative-format-in-seconds":"dalam beberapa detik","relative-format-in-minutes":"dalam {minutes} menit","relative-format-in-hours":"dalam {hours} jam","relative-format-in-minute":"dalam 1 menit","relative-format-in-hour":"dalam 1 jam","relative-format-by":"sebelum {formattedDate}"},it:{"relative-format-in-seconds":"tra qualche secondo","relative-format-in-minutes":"tra {minutes} minuti","relative-format-in-hours":"tra {hours} ore","relative-format-in-minute":"in 1 minuto","relative-format-in-hour":"in 1 ora","relative-format-by":"entro il {formattedDate}"},ja:{"relative-format-in-seconds":"数秒","relative-format-in-minutes":"{minutes}分以内","relative-format-in-hours":"{hours}時間以内","relative-format-in-minute":"1分以内","relative-format-in-hour":"1時間以内","relative-format-by":"{formattedDate} まで"},pl:{"relative-format-in-seconds":"w ciągu kilku sekund","relative-format-in-minutes":"w ciągu {minutes} minut","relative-format-in-hours":"w ciągu {hours} godzin","relative-format-in-minute":"w ciągu 1 minuty","relative-format-in-hour":"w ciągu 1 godziny","relative-format-by":"do {formattedDate}"},pt:{"relative-format-in-seconds":"em segundos","relative-format-in-minutes":"em {minutes} minutos","relative-format-in-hours":"em {hours} horas","relative-format-in-minute":"em 1 minuto","relative-format-in-hour":"em 1 hora","relative-format-by":"até {formattedDate}"},ro:{"relative-format-in-seconds":"în câteva secunde","relative-format-in-minutes":"în {minutes} minute","relative-format-in-hours":"în {hours} ore","relative-format-in-minute":"în 1 minut","relative-format-in-hour":"în 1 oră","relative-format-by":"până pe {formattedDate}"},ru:{"relative-format-in-seconds":"через несколько секунд","relative-format-in-minutes":"через {minutes} мин.","relative-format-in-hours":"через {hours} ч.","relative-format-in-minute":"через минуту","relative-format-in-hour":"через 1 час","relative-format-by":"{formattedDate}"},th:{"relative-format-in-seconds":"ในไม่กี่วินาที","relative-format-in-minutes":"ใน {minutes} นาที","relative-format-in-hours":"ใน {hours} ชั่วโมง","relative-format-in-minute":"ใน 1 นาที","relative-format-in-hour":"ใน 1 ชั่วโมง","relative-format-by":"ภายใน {formattedDate}"},tr:{"relative-format-in-seconds":"saniyeler içinde","relative-format-in-minutes":"{minutes} dakika içinde","relative-format-in-hours":"{hours} saat içinde","relative-format-in-minute":"1 dakika içinde","relative-format-in-hour":"1 saat içinde","relative-format-by":"{formattedDate} itibarıyla"},uk:{"relative-format-in-seconds":"через кілька секунд","relative-format-in-minutes":"через {minutes} хв","relative-format-in-hours":"через {hours} год","relative-format-in-minute":"через 1 хвилину","relative-format-in-hour":"через 1 годину","relative-format-by":"до {formattedDate}"},"zh-CN":{"relative-format-in-seconds":"数秒内","relative-format-in-minutes":"{minutes} 分钟内","relative-format-in-hours":"{hours} 小时内","relative-format-in-minute":"1 分钟内","relative-format-in-hour":"1 小时内","relative-format-by":"{formattedDate} 前"},"zh-HK":{"relative-format-in-seconds":"數秒內","relative-format-in-minutes":"在 {minutes} 分鐘內","relative-format-in-hours":"在 {hours} 小時內","relative-format-in-minute":"在 1 分鐘內","relative-format-in-hour":"在 1 小時內","relative-format-by":"在 {formattedDate} 或之前"}};function w(e,t,r){var n;return void 0===t&&(t={}),(n=N(r,e)?F[r][e]:N("en",e)?F.en[e]:e)&&t&&Object.keys(t).forEach(function(e){n=n.replace(new RegExp("{"+e+"}","g"),t[e])}),n||e}function N(e,t){return E(F,e)&&E(F[e],t)}function E(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function M(e,t){var r,n=((r={})[I.HOUR]=36e5,r[I.MINUTE]=6e4,r[I.SECOND]=1e3,r);return Math.ceil(e/n[t])}function C(e,t,r){var n;return 1===e?w("relative-format-in-"+r,{},t):w("relative-format-in-"+r+"s",((n={})[r+"s"]=""+e,n),t)}!function(e){e.SECOND="second",e.MINUTE="minute",e.HOUR="hour"}(I||(I={})),exports.formatAmount=f,exports.formatDate=D,exports.formatMoney=function(e,t,r,n){return void 0===r&&(r="en-GB"),void 0===n&&(n={alwaysShowDecimals:!1}),f(e,t,r,n)+" "+(t||"").toUpperCase()},exports.formatNumber=m,exports.formatNumberToSignificantDigits=u,exports.formatPercentage=function(e,t){return void 0===t&&(t="en-GB"),Intl.NumberFormat(t,{style:"percent",maximumFractionDigits:2}).format(e)},exports.formatRate=l,exports.formatRelativeDate=function(e,t){return void 0===t&&(t="en-GB"),e<new Date(Date.now())?"":function(e){return function(e){var t=new Date(Date.now());return e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getFullYear()===t.getFullYear()}(e)&&function(e,t){return M(e-new Date(Date.now()),I.HOUR)<=12}(e)}(e)?function(e,t){var r=e-new Date(Date.now());if(M(r,I.SECOND)<60)return function(e){return w("relative-format-in-seconds",{},e)}(t);var n=M(r,I.MINUTE);return n<60?C(n,t,I.MINUTE):C(M(r,I.HOUR),t,I.HOUR)}(e,t):function(e,t){return w("relative-format-by",{formattedDate:D(e,t,{month:"short",day:"numeric"})},t)}(e,t)},exports.getDisplayRate=function(e){var t=e.rate,r=e.sourceCurrency,n=e.targetCurrency,i=e.locale,a=function(e,t){return"BRL"===e&&t<=10||t<.1}(r,t),o=a?1/t:t,u="1 "+(a?n:r),m=l(o,i)+" "+(a?r:n);return{decimal:l(o,i),inverted:a,equation:u+" = "+m}},exports.getRateInAllFormats=function(e,t,r,n,i){var a=void 0===n?{}:n,o=a.reference,m=void 0===o?"auto":o,s=a.referenceMultiplier,f=a.significantFigures,l=void 0===f?6:f;void 0===i&&(i="en-GB");var v={suggested:{},formats:{}};v.formats.decimal={output:u(e,i,l),significantFigures:l};var h=function(e,t,r,n){var i=void 0===n?{}:n,a=i.reference,o=void 0===a?"auto":a,u=i.referenceMultiplier;return function(){if(!e)throw new Error("rate parameter is mandatory (got "+e+" instead).");if(!t)throw new Error("sourceCurrency parameter is mandatory (got "+t+" instead).");if(!r)throw new Error("targetCurrency parameter is mandatory (got "+r+" instead).");if(u&&"number"!=typeof u)throw new Error("referenceMultiplier must be a number (got "+typeof u+" "+u+" instead)")}(),function(e,t){if("source"===e)return!1;if("target"===e)return!0;if(["auto",void 0,null].indexOf(e)>-1)return!!(d[t]||{}).hasInversionEnabled;throw new Error("Unrecognized reference config value: "+e+" (valid values are auto, source, target).")}(o,t)?{lhsCurrency:r,lhsValue:y(u,r),rhsCurrency:t,rhsValue:y(u,r)/e}:{lhsCurrency:t,lhsValue:y(u,t),rhsCurrency:r,rhsValue:e*y(u,t)}}(e,t,r,{reference:m,referenceMultiplier:s});return v.formats.equation={output:c(h,{significantFigures:l},i),reference:h.lhsCurrency===t?"source":"target",referenceMultiplier:h.lhsValue,calculationInDecimal:u(h.rhsValue,i,l)},v.suggested=h.lhsCurrency===t&&1===h.lhsValue?{format:"decimal",output:v.formats.decimal.output}:{format:"equation",output:v.formats.equation.output},v};
|
|
2
2
|
//# sourceMappingURL=formatting.js.map
|
package/dist/formatting.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatting.js","sources":["../src/number/feature-detection/intl.ts","../src/number/number.ts","../src/defaults/index.ts","../src/currency/currency.ts","../src/rate/formatRateEquation.ts","../src/rate/config.ts","../src/date/support-detection/intl.ts","../src/rate/getRateEquation.ts","../src/date/support-detection/selectedLocale.ts","../src/date/fallback-format/fallbackFormat.ts","../src/date/date.ts","../src/date/isToday.ts","../src/date/relative-date/relativeDateFormatter.ts","../src/translations/translator.ts","../src/percentage/percentage.ts","../src/rate/formatRate.ts","../src/rate/getRateInAllFormats.ts"],"sourcesContent":["let isSupported: boolean | undefined;\n\n/**\n * Checks if Intl.NumberFormat is supported for a specific locale\n * @param {String} locale\n * @returns {Boolean}\n */\nexport function isIntlNumberFormatSupported(locale: string): boolean {\n if (isSupported === undefined) {\n isSupported =\n typeof Intl === 'object' &&\n Intl !== undefined &&\n typeof Intl.NumberFormat === 'function' &&\n Intl.NumberFormat &&\n typeof Intl.NumberFormat.supportedLocalesOf === 'function' &&\n Intl.NumberFormat.supportedLocalesOf &&\n Intl.NumberFormat.supportedLocalesOf(locale).length === 1;\n }\n return isSupported;\n}\n","import {\n DEFAULT_LOCALE,\n PRECISION,\n NUMBER_OF_RATE_SIGNIFICANT_DIGITS,\n PrecisionType,\n} from '../defaults';\nimport { isIntlNumberFormatSupported } from './feature-detection';\n\nconst { SIGNIFICANT_DIGITS, FRACTION_DIGITS } = PRECISION;\n\nconst formatters: Record<string, any> = {}; // cache, sample: { 'en-GB': formatter, 'en-GB2': formatter }\n\n/**\n * Returns a formatter for the specified locale and NumberFormatOptions\n * @param {String} locale\n * @param {Intl.NumberFormatOptions} options\n * @returns {Intl.NumberFormat}\n */\nfunction getFormatter(locale: string, options?: Intl.NumberFormatOptions): Intl.NumberFormat {\n const cacheKey = options ? `${locale}${Object.entries(options)}` : locale;\n if (!formatters[cacheKey]) {\n formatters[cacheKey] = options\n ? new Intl.NumberFormat(locale, options)\n : new Intl.NumberFormat(locale);\n }\n return formatters[cacheKey];\n}\n\n/**\n * Returns the desired options object for\n * `Number.toLocaleString` and `Intl.NumberFormat` methods\n * @param {Number} precision\n * @param {String} precisionType - `FractionDigits|SignificantDigits`\n */\nfunction getPrecisionOptions(precision: number, precisionType: PrecisionType) {\n return {\n [`minimum${precisionType}`]: precision,\n [`maximum${precisionType}`]: precision,\n };\n}\n\n/**\n * Returns the locale that was passed in if it works\n * with `toLocaleString` or otherwise falls back to `DEFAULT_LOCALE`\n * @param {String} locale\n */\nfunction getValidLocale(locale: string) {\n try {\n const noUnderscoreLocale = locale.replace(/_/, '-');\n\n Intl.NumberFormat(noUnderscoreLocale);\n return noUnderscoreLocale;\n } catch (e) {\n return DEFAULT_LOCALE;\n }\n}\n\n/**\n * Formats the number as a fallback for when `toLocaleString` method is not supported\n * by the browser. Will use `toFixed` to format `FractionDigits` precisionType and `toPrecision`\n * to format `SignificantDigits` precision type.\n * @param {Number} number\n * @param {Number} precision - this may be a value between 0 and 20 for `FractionDigits` or 1 and 21 for `SignificantDigits`\n * @param {String} precisionType - `FractionDigits|SignificantDigits`\n * @returns {String}\n */\nfunction formatNumberWithFallback(number: number, precision: number, precisionType: PrecisionType) {\n return precisionType === SIGNIFICANT_DIGITS.TYPE\n ? number.toPrecision(precision)\n : number.toFixed(precision);\n}\n\n/**\n * Formats a number to a significant number of digits with valid fallback even if the\n * `toLocaleString` method is not supported by the actual browser\n * @param {Number|String} number\n * @param {Number} significantDigits - this may be a value between 1 and 21, inclusive\n * @param {String} locale\n * @returns {String}\n */\nexport function formatNumberToSignificantDigits(\n number: number,\n locale = DEFAULT_LOCALE,\n significantDigits = NUMBER_OF_RATE_SIGNIFICANT_DIGITS,\n) {\n return formatNumber(number, locale, significantDigits, SIGNIFICANT_DIGITS.TYPE);\n}\n\n/**\n * Formats a number precisely with valid fallback even if the\n * `toLocaleString` method is not supported by the actual browser\n * @param {Number|String} number\n * @param {String} locale\n * @param {Number} precision - this may be a value between 0 and 20 for `FractionDigits` or 1 and 21 for `SignificantDigits`\n * @param {String} precisionType - `FractionDigits|SignificantDigits`\n * @returns {String}\n */\nexport function formatNumber(\n number: number,\n locale = DEFAULT_LOCALE,\n precision?: number,\n precisionType: PrecisionType = 'FractionDigits',\n): string {\n if (!number && number !== 0) {\n return '';\n }\n\n if (typeof number === 'string' && Number(number)) {\n // eslint-disable-next-line no-param-reassign\n number = Number(number);\n }\n\n const { MIN_PRECISION, MAX_PRECISION } =\n precisionType === SIGNIFICANT_DIGITS.TYPE ? SIGNIFICANT_DIGITS : FRACTION_DIGITS;\n\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed#Parameters\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat#Parameters\n const isPrecisionValid =\n precision !== undefined &&\n precision !== null &&\n typeof precision === 'number' &&\n precision >= MIN_PRECISION &&\n precision <= MAX_PRECISION;\n\n const validatedLocale = getValidLocale(locale);\n\n if (!isIntlNumberFormatSupported(validatedLocale)) {\n return isPrecisionValid\n ? formatNumberWithFallback(number, precision!, precisionType)\n : `${number}`;\n }\n\n const formatter = isPrecisionValid\n ? getFormatter(validatedLocale, getPrecisionOptions(precision!, precisionType))\n : getFormatter(validatedLocale);\n\n return formatter.format(number);\n}\n","export const DEFAULT_LOCALE = 'en-GB';\nexport const DEFAULT_PRECISION_TYPE = 'FractionDigits';\nexport const NUMBER_OF_RATE_SIGNIFICANT_DIGITS = 6;\nexport const DEFAULT_RATE_MULTIPLIER = 1;\nexport const PRECISION = {\n SIGNIFICANT_DIGITS: {\n TYPE: 'SignificantDigits' as PrecisionType,\n MIN_PRECISION: 1,\n MAX_PRECISION: 21,\n },\n FRACTION_DIGITS: {\n TYPE: 'FractionDigits' as PrecisionType,\n MIN_PRECISION: 0,\n MAX_PRECISION: 20,\n },\n};\nexport type PrecisionType = 'SignificantDigits' | 'FractionDigits';\n","import { DEFAULT_LOCALE } from '../defaults';\nimport { formatNumber } from '../number';\n\nconst currencyDecimals = {\n BIF: 0,\n BYR: 0,\n CLP: 0,\n DJF: 0,\n GNF: 0,\n JPY: 0,\n KMF: 0,\n KRW: 0,\n MGA: 0,\n PYG: 0,\n RWF: 0,\n VND: 0,\n VUV: 0,\n XAF: 0,\n XOF: 0,\n XPF: 0,\n // technically HUF does have decimals, but due to the exchange rate banks\n // do not accept decimal amounts\n HUF: 0,\n UGX: 0,\n // local banks do not consistently support the ideal 2-decimal places fractional part\n KES: 0,\n\n BHD: 3,\n JOD: 3,\n KWD: 3,\n OMR: 3,\n TND: 3,\n};\n\nconst DEFAULT_CURRENCY_DECIMALS = 2;\n\nfunction getCurrencyDecimals(currency = '') {\n const upperCaseCurrency = currency.toUpperCase();\n if (Object.prototype.hasOwnProperty.call(currencyDecimals, upperCaseCurrency)) {\n return currencyDecimals[upperCaseCurrency as keyof typeof currencyDecimals];\n }\n return DEFAULT_CURRENCY_DECIMALS;\n}\n\nfunction amountHasNoDecimals(amount: number): boolean {\n return amount % 1 === 0;\n}\n\nfunction getPrecision(amount: number, currencyCode: string, alwaysShowDecimals: boolean): number {\n if (amountHasNoDecimals(amount) && !alwaysShowDecimals) {\n return 0;\n }\n\n return getCurrencyDecimals(currencyCode);\n}\n\nexport function formatAmount(\n amount: number,\n currencyCode: string,\n locale = DEFAULT_LOCALE,\n options = { alwaysShowDecimals: false },\n): string {\n const availablePrecision = getPrecision(amount, currencyCode, options.alwaysShowDecimals);\n \n return formatNumber(amount, locale, availablePrecision);\n}\n\nexport function formatMoney(\n amount: number,\n currencyCode: string,\n locale = DEFAULT_LOCALE,\n options = { alwaysShowDecimals: false },\n) {\n return `${formatAmount(amount, currencyCode, locale, options)} ${(\n currencyCode || ''\n ).toUpperCase()}`;\n}\n","import { NUMBER_OF_RATE_SIGNIFICANT_DIGITS, DEFAULT_LOCALE } from '../defaults';\nimport { formatNumberToSignificantDigits } from '../number';\nimport { formatAmount } from '../currency';\n\nexport default function(\n {\n lhsValue,\n lhsCurrency,\n rhsValue,\n rhsCurrency,\n }: { lhsValue: number; lhsCurrency: string; rhsValue: number; rhsCurrency: string },\n { significantFigures = NUMBER_OF_RATE_SIGNIFICANT_DIGITS } = {},\n locale = DEFAULT_LOCALE,\n) {\n return `${formatAmount(\n lhsValue,\n lhsCurrency,\n locale,\n )} ${lhsCurrency} = ${formatNumberToSignificantDigits(\n rhsValue,\n locale,\n significantFigures,\n )} ${rhsCurrency}`;\n}\n","export default {\n BRL: {\n hasInversionEnabled: true,\n },\n INR: {\n hasInversionEnabled: true,\n },\n JPY: {\n hasInversionEnabled: true,\n },\n IDR: {\n hasInversionEnabled: true\n },\n HUF: {\n hasInversionEnabled: true,\n },\n RON: {\n hasInversionEnabled: true,\n },\n THB: {\n hasInversionEnabled: true,\n },\n} as Record<string, { hasInversionEnabled?: boolean; multiplierForEquation?: number }>;\n","import { DEFAULT_LOCALE } from '../../defaults';\n\nlet intlSupported: boolean | undefined; // cache\n\nexport function isIntlSupported(): boolean {\n if (intlSupported === undefined) {\n intlSupported = intlDateTimeFormatReturnsCorrectValue();\n }\n return intlSupported;\n}\n\nfunction intlDateTimeFormatReturnsCorrectValue(): boolean {\n try {\n const date = new Date(2018, 11, 1);\n const dateString = new Intl.DateTimeFormat(DEFAULT_LOCALE).format(date);\n return dateString === '01/12/2018';\n } catch (e) {\n return false;\n }\n}\n","import config from './config';\nimport { DEFAULT_RATE_MULTIPLIER } from '../defaults';\n\nexport type Reference = 'auto' | 'source' | 'target';\n\nexport default function(\n rate: number,\n sourceCurrency: string,\n targetCurrency: string,\n {\n reference = 'auto',\n referenceMultiplier,\n }: { reference?: Reference; referenceMultiplier?: number } = {},\n) {\n validateParameters();\n\n if (shouldInvertEquation(reference, sourceCurrency)) {\n return {\n // inverted.\n lhsCurrency: targetCurrency,\n lhsValue: getMultiplier(referenceMultiplier, targetCurrency),\n rhsCurrency: sourceCurrency,\n rhsValue: getMultiplier(referenceMultiplier, targetCurrency) / rate,\n };\n }\n return {\n // normal.\n lhsCurrency: sourceCurrency,\n lhsValue: getMultiplier(referenceMultiplier, sourceCurrency),\n rhsCurrency: targetCurrency,\n rhsValue: rate * getMultiplier(referenceMultiplier, sourceCurrency),\n };\n\n function validateParameters(): void {\n if (!rate) throw new Error(`rate parameter is mandatory (got ${rate} instead).`);\n if (!sourceCurrency)\n throw new Error(`sourceCurrency parameter is mandatory (got ${sourceCurrency} instead).`);\n if (!targetCurrency)\n throw new Error(`targetCurrency parameter is mandatory (got ${targetCurrency} instead).`);\n if (referenceMultiplier && typeof referenceMultiplier !== 'number') {\n throw new Error(\n `referenceMultiplier must be a number (got ${typeof referenceMultiplier} ${referenceMultiplier} instead)`,\n );\n }\n // Let shouldInvertEquation() handle `reference`.\n }\n}\n\nfunction shouldInvertEquation(referenceConfig: Reference, sourceCurrency: string): boolean {\n if (referenceConfig === 'source') return false;\n if (referenceConfig === 'target') return true;\n if (['auto', undefined, null].indexOf(referenceConfig) > -1)\n return !!(config[sourceCurrency] || {}).hasInversionEnabled;\n throw new Error(\n `Unrecognized reference config value: ${referenceConfig} (valid values are auto, source, target).`,\n );\n}\n\nfunction getMultiplier(\n referenceMultiplierOverride: number | undefined,\n lhsCurrency: string,\n): number {\n return (\n referenceMultiplierOverride ||\n (config[lhsCurrency] || {}).multiplierForEquation ||\n DEFAULT_RATE_MULTIPLIER\n );\n}\n","const supportedLocales: Record<string, boolean> = {}; // cache\n\nexport function isSelectedLocaleSupported(locale: string): boolean {\n if (supportedLocales[locale] === undefined) {\n supportedLocales[locale] = checkForLocaleSupport(locale);\n }\n return supportedLocales[locale];\n}\n\nfunction checkForLocaleSupport(locale: string): boolean {\n try {\n return Intl.DateTimeFormat.supportedLocalesOf([locale]).length > 0;\n } catch (e) {\n return false;\n }\n}\n","const WEEKDAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];\nconst SHORT_MONTHS = [\n 'Jan',\n 'Feb',\n 'Mar',\n 'Apr',\n 'May',\n 'Jun',\n 'Jul',\n 'Aug',\n 'Sep',\n 'Oct',\n 'Nov',\n 'Dec',\n];\n\nfunction getJoiningCharacter(options: Intl.DateTimeFormatOptions): string {\n return options.month === 'short' ? ' ' : '/';\n}\n\nfunction isMonthFirst(options: Intl.DateTimeFormatOptions) {\n return options.month === 'short';\n}\n\nfunction getFormattedMonth(\n options: Intl.DateTimeFormatOptions,\n isUTC: boolean,\n date: Date,\n): string | number {\n if (options.month === 'short') {\n return SHORT_MONTHS[isUTC ? date.getUTCMonth() : date.getMonth()];\n }\n return (isUTC ? date.getUTCMonth() : date.getMonth()) + 1;\n}\n\n// Sample outputs: 'Sat, 1/12/2018', '1/12/2018', '12/2018', Sat, 1'\nexport function getFallbackFormat(date: Date, options: Intl.DateTimeFormatOptions = {}): string {\n const isUTC = options.timeZone === 'UTC';\n\n const dateParts = [];\n if (options.day) dateParts.push(isUTC ? date.getUTCDate() : date.getDate());\n if (options.month) {\n const monthFormat = getFormattedMonth(options, isUTC, date);\n if (isMonthFirst(options)) {\n dateParts.unshift(monthFormat);\n } else {\n dateParts.push(monthFormat);\n }\n }\n if (options.year) dateParts.push(isUTC ? date.getUTCFullYear() : date.getUTCFullYear());\n\n const joiningCharacter = getJoiningCharacter(options);\n let fallbackDate = dateParts.join(joiningCharacter);\n\n if (options.weekday) {\n const dayName = WEEKDAYS[isUTC ? date.getUTCDay() : date.getDay()];\n fallbackDate = fallbackDate ? `${dayName}, ${fallbackDate}` : dayName;\n }\n return (\n fallbackDate ||\n getFallbackFormat(date, {\n timeZone: options.timeZone,\n day: 'true',\n month: 'true',\n year: 'true',\n })\n );\n}\n","import { isIntlSupported, isSelectedLocaleSupported } from './support-detection';\nimport { getFallbackFormat } from './fallback-format';\nimport { DEFAULT_LOCALE } from '../defaults';\n\nexport function formatDate(\n date: Date,\n locale = DEFAULT_LOCALE,\n options?: Intl.DateTimeFormatOptions,\n): string {\n return isIntlSupported()\n ? new Intl.DateTimeFormat(getSupportedLocale(locale), options).format(date)\n : getFallbackFormat(date, options);\n}\n\nfunction getSupportedLocale(locale: string) {\n return isSelectedLocaleSupported(locale) ? locale : DEFAULT_LOCALE;\n}\n","export default (date: Date): boolean => {\n const today = new Date(Date.now());\n return (\n date.getDate() === today.getDate() &&\n date.getMonth() === today.getMonth() &&\n date.getFullYear() === today.getFullYear()\n );\n};\n","import isToday from '../isToday';\nimport { formatDate } from '../date';\nimport { getTranslation } from '../../translations/translator';\nimport { DEFAULT_LOCALE } from '../../defaults';\n\nexport function formatRelativeDate(date: Date, locale = DEFAULT_LOCALE): string {\n if (date < new Date(Date.now())) {\n return '';\n }\n\n let formatted;\n if (shouldFormatRelative(date)) {\n formatted = formatRelative(date, locale);\n } else {\n formatted = formatAbsolute(date, locale);\n }\n return formatted;\n}\n\nfunction shouldFormatRelative(date: Date): boolean {\n return isToday(date) && isWithinHours(date, 12);\n}\n\nfunction isWithinHours(date: Date, boundary: number): boolean {\n const now = new Date(Date.now());\n //@ts-expect-error date maths\n const diff = date - now;\n return getDifferenceIn(diff, TimeUnit.HOUR) <= boundary;\n}\n\nfunction formatRelative(date: Date, locale: string): string {\n const now = new Date(Date.now());\n //@ts-expect-error date maths\n const diff = date - now;\n\n if (getDifferenceIn(diff, TimeUnit.SECOND) < 60) {\n return formatSeconds(locale);\n }\n\n const differenceInMinutes = getDifferenceIn(diff, TimeUnit.MINUTE);\n if (differenceInMinutes < 60) {\n return formatTimeUnit(differenceInMinutes, locale, TimeUnit.MINUTE);\n }\n\n return formatTimeUnit(getDifferenceIn(diff, TimeUnit.HOUR), locale, TimeUnit.HOUR);\n}\n\nfunction formatAbsolute(date: Date, locale: string): string {\n const params = {\n formattedDate: formatDate(date, locale, { month: 'short', day: 'numeric' }),\n };\n return getTranslation('relative-format-by', params, locale);\n}\n\nfunction getDifferenceIn(diff: number, timeUnitValue: TimeUnit): number {\n const millisecondsMap = {\n [TimeUnit.HOUR]: 3600000,\n [TimeUnit.MINUTE]: 60000,\n [TimeUnit.SECOND]: 1000,\n };\n return Math.ceil(diff / millisecondsMap[timeUnitValue]);\n}\n\nfunction formatTimeUnit(value: number, locale: string, timeUnit: string): string {\n if (value === 1) {\n return getTranslation(`relative-format-in-${timeUnit}`, {}, locale);\n }\n return getTranslation(\n `relative-format-in-${timeUnit}s`,\n { [`${timeUnit}s`]: `${value}` },\n locale,\n );\n}\n\nfunction formatSeconds(locale: string) {\n return getTranslation('relative-format-in-seconds', {}, locale);\n}\n\nenum TimeUnit {\n SECOND = 'second',\n MINUTE = 'minute',\n HOUR = 'hour',\n}\n","// eslint-disable-next-line import/no-unresolved\nimport translations from './translations.json';\n\nexport function getTranslation(\n translationKey: string,\n params: Record<string, string> = {},\n locale: string,\n): string {\n let translatedMessage: string | undefined;\n if (hasTranslation(locale, translationKey)) {\n translatedMessage = (translations as Record<string, Record<string, string>>)[locale][\n translationKey\n ];\n } else if (hasTranslation('en', translationKey)) {\n translatedMessage = (translations as Record<string, Record<string, string>>).en[translationKey];\n } else {\n translatedMessage = translationKey;\n }\n\n if (translatedMessage && params) {\n Object.keys(params).forEach(key => {\n translatedMessage = (translatedMessage as string).replace(\n new RegExp(`{${key}}`, 'g'),\n params[key],\n );\n });\n }\n\n return translatedMessage || translationKey;\n}\n\nfunction hasTranslation(locale: string, translationKey: string): boolean {\n return (\n hasOwnProperty(translations, locale) &&\n hasOwnProperty((translations as Record<string, Record<string, string>>)[locale], translationKey)\n );\n}\n\nfunction hasOwnProperty(obj: any, key: string) {\n return Object.prototype.hasOwnProperty.call(obj, key);\n}\n","export function formatPercentage(value: number) {\n return `${parseFloat((value * 100).toFixed(2))}%`;\n}\n","import { NUMBER_OF_RATE_SIGNIFICANT_DIGITS, DEFAULT_LOCALE } from '../defaults';\nimport { formatNumberToSignificantDigits } from '../number';\n\nexport default function(\n rate: number,\n { significantFigures = NUMBER_OF_RATE_SIGNIFICANT_DIGITS } = {},\n locale = DEFAULT_LOCALE,\n) {\n return formatNumberToSignificantDigits(rate, locale, significantFigures);\n}\n","import { NUMBER_OF_RATE_SIGNIFICANT_DIGITS, DEFAULT_LOCALE } from '../defaults';\nimport { formatNumberToSignificantDigits } from '../number';\nimport formatRateEquation from './formatRateEquation';\nimport getRateEquation, { Reference } from './getRateEquation';\n\nexport default function(\n rate: number,\n sourceCurrency: string,\n targetCurrency: string,\n {\n reference = 'auto',\n referenceMultiplier,\n significantFigures = NUMBER_OF_RATE_SIGNIFICANT_DIGITS,\n }: { reference?: Reference; referenceMultiplier?: number; significantFigures?: number } = {},\n locale = DEFAULT_LOCALE,\n) {\n const response = {\n suggested: {},\n formats: {} as Record<string, any>,\n };\n\n response.formats.decimal = {\n output: formatNumberToSignificantDigits(rate, locale, significantFigures),\n significantFigures,\n };\n\n const equation = getRateEquation(rate, sourceCurrency, targetCurrency, {\n reference,\n referenceMultiplier,\n });\n\n response.formats.equation = {\n output: formatRateEquation(equation, { significantFigures }, locale),\n reference: equation.lhsCurrency === sourceCurrency ? 'source' : 'target',\n referenceMultiplier: equation.lhsValue,\n calculationInDecimal: formatNumberToSignificantDigits(\n equation.rhsValue,\n locale,\n significantFigures,\n ),\n };\n\n if (equation.lhsCurrency === sourceCurrency && equation.lhsValue === 1) {\n response.suggested = {\n format: 'decimal',\n output: response.formats.decimal.output,\n };\n } else {\n response.suggested = {\n format: 'equation',\n output: response.formats.equation.output,\n };\n }\n\n return response;\n}\n"],"names":["isSupported","SIGNIFICANT_DIGITS","TYPE","MIN_PRECISION","MAX_PRECISION","FRACTION_DIGITS","formatters","getFormatter","locale","options","cacheKey","Object","entries","Intl","NumberFormat","formatNumberToSignificantDigits","number","significantDigits","formatNumber","precision","precisionType","Number","isPrecisionValid","validatedLocale","noUnderscoreLocale","replace","e","getValidLocale","undefined","supportedLocalesOf","length","isIntlNumberFormatSupported","getPrecisionOptions","format","toPrecision","toFixed","formatNumberWithFallback","currencyDecimals","BIF","BYR","CLP","DJF","GNF","JPY","KMF","KRW","MGA","PYG","RWF","VND","VUV","XAF","XOF","XPF","HUF","UGX","KES","BHD","JOD","KWD","OMR","TND","formatAmount","amount","currencyCode","alwaysShowDecimals","amountHasNoDecimals","currency","upperCaseCurrency","toUpperCase","prototype","hasOwnProperty","call","getCurrencyDecimals","getPrecision","lhsCurrency","rhsValue","rhsCurrency","significantFigures","lhsValue","intlSupported","BRL","hasInversionEnabled","INR","IDR","RON","THB","getMultiplier","referenceMultiplierOverride","config","multiplierForEquation","supportedLocales","WEEKDAYS","SHORT_MONTHS","formatDate","date","Date","DateTimeFormat","intlDateTimeFormatReturnsCorrectValue","checkForLocaleSupport","isSelectedLocaleSupported","getSupportedLocale","getFallbackFormat","isUTC","timeZone","dateParts","day","push","getUTCDate","getDate","month","monthFormat","getUTCMonth","getMonth","getFormattedMonth","isMonthFirst","unshift","year","getUTCFullYear","joiningCharacter","getJoiningCharacter","fallbackDate","join","weekday","dayName","getUTCDay","getDay","TimeUnit","getTranslation","translationKey","params","translatedMessage","hasTranslation","translations","en","keys","forEach","key","RegExp","obj","getDifferenceIn","diff","timeUnitValue","millisecondsMap","HOUR","MINUTE","SECOND","Math","ceil","formatTimeUnit","value","timeUnit","parseFloat","rate","now","today","getFullYear","isToday","boundary","isWithinHours","shouldFormatRelative","formatSeconds","differenceInMinutes","formatRelative","formattedDate","formatAbsolute","sourceCurrency","targetCurrency","reference","referenceMultiplier","response","suggested","formats","decimal","output","equation","Error","validateParameters","referenceConfig","indexOf","shouldInvertEquation","getRateEquation","formatRateEquation","calculationInDecimal"],"mappings":"IAAIA,ECQIC,ECHc,CAClBC,KAAM,oBACNC,cAAe,EACfC,cAAe,IDASC,ECET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EAAckF,EAAqBH,ISJrCe,CAAgB5B,EAAMa,EAAgBC,EAAgB,CACrEC,UAAAA,EACAC,oBAAAA,IA0BF,OAvBAC,EAASE,QAAQG,SAAW,CAC1BD,OAAQQ,EAAmBP,EAAU,CAAEjG,mBAAAA,GAAsBtE,GAC7DgK,UAAWO,EAASpG,cAAgB2F,EAAiB,SAAW,SAChEG,oBAAqBM,EAAShG,SAC9BwG,qBAAsBxK,EACpBgK,EAASnG,SACTpE,EACAsE,IAKF4F,EAASC,UADPI,EAASpG,cAAgB2F,GAAwC,IAAtBS,EAAShG,SACjC,CACnB9C,OAAQ,UACR6I,OAAQJ,EAASE,QAAQC,QAAQC,QAGd,CACnB7I,OAAQ,WACR6I,OAAQJ,EAASE,QAAQG,SAASD,QAI/BJ"}
|
|
1
|
+
{"version":3,"file":"formatting.js","sources":["../src/number/feature-detection/intl.ts","../src/number/number.ts","../src/defaults/index.ts","../src/currency/currency.ts","../src/rate/formatRate.ts","../src/rate/formatRateEquation.ts","../src/rate/config.ts","../src/date/support-detection/intl.ts","../src/rate/getRateEquation.ts","../src/date/support-detection/selectedLocale.ts","../src/date/fallback-format/fallbackFormat.ts","../src/date/date.ts","../src/date/isToday.ts","../src/date/relative-date/relativeDateFormatter.ts","../src/translations/translator.ts","../src/percentage/percentage.ts","../src/rate/getDisplayRate.ts","../src/rate/getRateInAllFormats.ts"],"sourcesContent":["let isSupported: boolean | undefined;\n\n/**\n * Checks if Intl.NumberFormat is supported for a specific locale\n * @param {String} locale\n * @returns {Boolean}\n */\nexport function isIntlNumberFormatSupported(locale: string): boolean {\n if (isSupported === undefined) {\n isSupported =\n typeof Intl === 'object' &&\n Intl !== undefined &&\n typeof Intl.NumberFormat === 'function' &&\n Intl.NumberFormat &&\n typeof Intl.NumberFormat.supportedLocalesOf === 'function' &&\n Intl.NumberFormat.supportedLocalesOf &&\n Intl.NumberFormat.supportedLocalesOf(locale).length === 1;\n }\n return isSupported;\n}\n","import {\n DEFAULT_LOCALE,\n PRECISION,\n NUMBER_OF_RATE_SIGNIFICANT_DIGITS,\n PrecisionType,\n} from '../defaults';\nimport { isIntlNumberFormatSupported } from './feature-detection';\n\nconst { SIGNIFICANT_DIGITS, FRACTION_DIGITS } = PRECISION;\n\nconst formatters: Record<string, any> = {}; // cache, sample: { 'en-GB': formatter, 'en-GB2': formatter }\n\n/**\n * Returns a formatter for the specified locale and NumberFormatOptions\n * @param {String} locale\n * @param {Intl.NumberFormatOptions} options\n * @returns {Intl.NumberFormat}\n */\nfunction getFormatter(locale: string, options?: Intl.NumberFormatOptions): Intl.NumberFormat {\n const cacheKey = options ? `${locale}${Object.entries(options)}` : locale;\n if (!formatters[cacheKey]) {\n formatters[cacheKey] = options\n ? new Intl.NumberFormat(locale, options)\n : new Intl.NumberFormat(locale);\n }\n return formatters[cacheKey];\n}\n\n/**\n * Returns the desired options object for\n * `Number.toLocaleString` and `Intl.NumberFormat` methods\n * @param {Number} precision\n * @param {String} precisionType - `FractionDigits|SignificantDigits`\n */\nfunction getPrecisionOptions(precision: number, precisionType: PrecisionType) {\n return {\n [`minimum${precisionType}`]: precision,\n [`maximum${precisionType}`]: precision,\n };\n}\n\n/**\n * Returns the locale that was passed in if it works\n * with `toLocaleString` or otherwise falls back to `DEFAULT_LOCALE`\n * @param {String} locale\n */\nfunction getValidLocale(locale: string) {\n try {\n const noUnderscoreLocale = locale.replace(/_/, '-');\n\n Intl.NumberFormat(noUnderscoreLocale);\n return noUnderscoreLocale;\n } catch (e) {\n return DEFAULT_LOCALE;\n }\n}\n\n/**\n * Formats the number as a fallback for when `toLocaleString` method is not supported\n * by the browser. Will use `toFixed` to format `FractionDigits` precisionType and `toPrecision`\n * to format `SignificantDigits` precision type.\n * @param {Number} number\n * @param {Number} precision - this may be a value between 0 and 20 for `FractionDigits` or 1 and 21 for `SignificantDigits`\n * @param {String} precisionType - `FractionDigits|SignificantDigits`\n * @returns {String}\n */\nfunction formatNumberWithFallback(number: number, precision: number, precisionType: PrecisionType) {\n return precisionType === SIGNIFICANT_DIGITS.TYPE\n ? number.toPrecision(precision)\n : number.toFixed(precision);\n}\n\n/**\n * Formats a number to a significant number of digits with valid fallback even if the\n * `toLocaleString` method is not supported by the actual browser\n * @param {Number|String} number\n * @param {Number} significantDigits - this may be a value between 1 and 21, inclusive\n * @param {String} locale\n * @returns {String}\n */\nexport function formatNumberToSignificantDigits(\n number: number,\n locale = DEFAULT_LOCALE,\n significantDigits = NUMBER_OF_RATE_SIGNIFICANT_DIGITS,\n) {\n return formatNumber(number, locale, significantDigits, SIGNIFICANT_DIGITS.TYPE);\n}\n\n/**\n * Formats a number precisely with valid fallback even if the\n * `toLocaleString` method is not supported by the actual browser\n * @param {Number|String} number\n * @param {String} locale\n * @param {Number} precision - this may be a value between 0 and 20 for `FractionDigits` or 1 and 21 for `SignificantDigits`\n * @param {String} precisionType - `FractionDigits|SignificantDigits`\n * @returns {String}\n */\nexport function formatNumber(\n number: number,\n locale = DEFAULT_LOCALE,\n precision?: number,\n precisionType: PrecisionType = 'FractionDigits',\n): string {\n if (!number && number !== 0) {\n return '';\n }\n\n if (typeof number === 'string' && Number(number)) {\n // eslint-disable-next-line no-param-reassign\n number = Number(number);\n }\n\n const { MIN_PRECISION, MAX_PRECISION } =\n precisionType === SIGNIFICANT_DIGITS.TYPE ? SIGNIFICANT_DIGITS : FRACTION_DIGITS;\n\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed#Parameters\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat#Parameters\n const isPrecisionValid =\n precision !== undefined &&\n precision !== null &&\n typeof precision === 'number' &&\n precision >= MIN_PRECISION &&\n precision <= MAX_PRECISION;\n\n const validatedLocale = getValidLocale(locale);\n\n if (!isIntlNumberFormatSupported(validatedLocale)) {\n return isPrecisionValid\n ? formatNumberWithFallback(number, precision!, precisionType)\n : `${number}`;\n }\n\n const formatter = isPrecisionValid\n ? getFormatter(validatedLocale, getPrecisionOptions(precision!, precisionType))\n : getFormatter(validatedLocale);\n\n return formatter.format(number);\n}\n\nexport function formatNumberWithOptions(\n value: number,\n options: Intl.NumberFormatOptions,\n locale: string,\n fallback: string,\n) {\n const validatedLocale = getValidLocale(locale);\n if (!isIntlNumberFormatSupported(validatedLocale)) {\n return fallback;\n }\n\n return getFormatter(validatedLocale, options).format(value);\n}\n","export const DEFAULT_LOCALE = 'en-GB';\nexport const DEFAULT_PRECISION_TYPE = 'FractionDigits';\nexport const NUMBER_OF_RATE_SIGNIFICANT_DIGITS = 6;\nexport const DEFAULT_RATE_MULTIPLIER = 1;\nexport const PRECISION = {\n SIGNIFICANT_DIGITS: {\n TYPE: 'SignificantDigits' as PrecisionType,\n MIN_PRECISION: 1,\n MAX_PRECISION: 21,\n },\n FRACTION_DIGITS: {\n TYPE: 'FractionDigits' as PrecisionType,\n MIN_PRECISION: 0,\n MAX_PRECISION: 20,\n },\n};\nexport type PrecisionType = 'SignificantDigits' | 'FractionDigits';\n","import { DEFAULT_LOCALE } from '../defaults';\nimport { formatNumber } from '../number';\n\nconst currencyDecimals = {\n BIF: 0,\n BYR: 0,\n CLP: 0,\n DJF: 0,\n GNF: 0,\n JPY: 0,\n KMF: 0,\n KRW: 0,\n MGA: 0,\n PYG: 0,\n RWF: 0,\n VND: 0,\n VUV: 0,\n XAF: 0,\n XOF: 0,\n XPF: 0,\n // technically HUF does have decimals, but due to the exchange rate banks\n // do not accept decimal amounts\n HUF: 0,\n UGX: 0,\n // local banks do not consistently support the ideal 2-decimal places fractional part\n KES: 0,\n\n BHD: 3,\n JOD: 3,\n KWD: 3,\n OMR: 3,\n TND: 3,\n};\n\nconst DEFAULT_CURRENCY_DECIMALS = 2;\n\nfunction getCurrencyDecimals(currency = '') {\n const upperCaseCurrency = currency.toUpperCase();\n if (Object.prototype.hasOwnProperty.call(currencyDecimals, upperCaseCurrency)) {\n return currencyDecimals[upperCaseCurrency as keyof typeof currencyDecimals];\n }\n return DEFAULT_CURRENCY_DECIMALS;\n}\n\nfunction amountHasNoDecimals(amount: number): boolean {\n return amount % 1 === 0;\n}\n\nfunction getPrecision(amount: number, currencyCode: string, alwaysShowDecimals: boolean): number {\n if (amountHasNoDecimals(amount) && !alwaysShowDecimals) {\n return 0;\n }\n\n return getCurrencyDecimals(currencyCode);\n}\n\nexport function formatAmount(\n amount: number,\n currencyCode: string,\n locale = DEFAULT_LOCALE,\n options = { alwaysShowDecimals: false },\n): string {\n const availablePrecision = getPrecision(amount, currencyCode, options.alwaysShowDecimals);\n \n return formatNumber(amount, locale, availablePrecision);\n}\n\nexport function formatMoney(\n amount: number,\n currencyCode: string,\n locale = DEFAULT_LOCALE,\n options = { alwaysShowDecimals: false },\n) {\n return `${formatAmount(amount, currencyCode, locale, options)} ${(\n currencyCode || ''\n ).toUpperCase()}`;\n}\n","import { DEFAULT_LOCALE } from '../defaults';\nimport { formatNumberWithOptions, formatNumberToSignificantDigits } from '../number';\n\nexport type FormatRateOptions = {\n significantFigures?: number;\n};\n\nfunction formatRate(rate: number, locale: string): string;\n/**\n * @deprecated Do not specify options, always specify a locale.\n */\nfunction formatRate(rate: number, options?: FormatRateOptions, locale?: string): string;\n\nfunction formatRate(\n rate: number,\n optionsOrLocale?: FormatRateOptions | string,\n locale?: string,\n): string {\n if (typeof optionsOrLocale === 'string') {\n return formatRateInternal(rate, optionsOrLocale);\n }\n\n const significantFigures = optionsOrLocale && optionsOrLocale.significantFigures;\n if (significantFigures) {\n return formatNumberToSignificantDigits(rate, locale || DEFAULT_LOCALE, significantFigures);\n }\n\n return formatRateInternal(rate, locale || DEFAULT_LOCALE);\n}\n\nfunction formatRateInternal(rate: number, locale: string) {\n // We lower the number of decimal places if the value is big, to minimun of 2\n const sizeAdjuster =\n // Upper bound 2\n Math.min(\n 2,\n // Low bound 0\n Math.max(\n 0,\n // Number of siginificant leading digits - 1\n Math.floor(Math.log10(rate)) - 1,\n ),\n );\n const maximumFractionDigits = 4 - sizeAdjuster;\n\n return formatNumberWithOptions(\n rate,\n {\n minimumFractionDigits: 0,\n maximumFractionDigits,\n },\n locale,\n rate.toFixed(maximumFractionDigits),\n );\n}\n\nexport default formatRate;\n","import { NUMBER_OF_RATE_SIGNIFICANT_DIGITS, DEFAULT_LOCALE } from '../defaults';\nimport { formatNumberToSignificantDigits } from '../number';\nimport { formatAmount } from '../currency';\n\nexport default function(\n {\n lhsValue,\n lhsCurrency,\n rhsValue,\n rhsCurrency,\n }: { lhsValue: number; lhsCurrency: string; rhsValue: number; rhsCurrency: string },\n { significantFigures = NUMBER_OF_RATE_SIGNIFICANT_DIGITS } = {},\n locale = DEFAULT_LOCALE,\n) {\n return `${formatAmount(\n lhsValue,\n lhsCurrency,\n locale,\n )} ${lhsCurrency} = ${formatNumberToSignificantDigits(\n rhsValue,\n locale,\n significantFigures,\n )} ${rhsCurrency}`;\n}\n","export default {\n BRL: {\n hasInversionEnabled: true,\n },\n INR: {\n hasInversionEnabled: true,\n },\n JPY: {\n hasInversionEnabled: true,\n },\n IDR: {\n hasInversionEnabled: true\n },\n HUF: {\n hasInversionEnabled: true,\n },\n RON: {\n hasInversionEnabled: true,\n },\n THB: {\n hasInversionEnabled: true,\n },\n} as Record<string, { hasInversionEnabled?: boolean; multiplierForEquation?: number }>;\n","import { DEFAULT_LOCALE } from '../../defaults';\n\nlet intlSupported: boolean | undefined; // cache\n\nexport function isIntlSupported(): boolean {\n if (intlSupported === undefined) {\n intlSupported = intlDateTimeFormatReturnsCorrectValue();\n }\n return intlSupported;\n}\n\nfunction intlDateTimeFormatReturnsCorrectValue(): boolean {\n try {\n const date = new Date(2018, 11, 1);\n const dateString = new Intl.DateTimeFormat(DEFAULT_LOCALE).format(date);\n return dateString === '01/12/2018';\n } catch (e) {\n return false;\n }\n}\n","import config from './config';\nimport { DEFAULT_RATE_MULTIPLIER } from '../defaults';\n\nexport type Reference = 'auto' | 'source' | 'target';\n\nexport default function(\n rate: number,\n sourceCurrency: string,\n targetCurrency: string,\n {\n reference = 'auto',\n referenceMultiplier,\n }: { reference?: Reference; referenceMultiplier?: number } = {},\n) {\n validateParameters();\n\n if (shouldInvertEquation(reference, sourceCurrency)) {\n return {\n // inverted.\n lhsCurrency: targetCurrency,\n lhsValue: getMultiplier(referenceMultiplier, targetCurrency),\n rhsCurrency: sourceCurrency,\n rhsValue: getMultiplier(referenceMultiplier, targetCurrency) / rate,\n };\n }\n return {\n // normal.\n lhsCurrency: sourceCurrency,\n lhsValue: getMultiplier(referenceMultiplier, sourceCurrency),\n rhsCurrency: targetCurrency,\n rhsValue: rate * getMultiplier(referenceMultiplier, sourceCurrency),\n };\n\n function validateParameters(): void {\n if (!rate) throw new Error(`rate parameter is mandatory (got ${rate} instead).`);\n if (!sourceCurrency)\n throw new Error(`sourceCurrency parameter is mandatory (got ${sourceCurrency} instead).`);\n if (!targetCurrency)\n throw new Error(`targetCurrency parameter is mandatory (got ${targetCurrency} instead).`);\n if (referenceMultiplier && typeof referenceMultiplier !== 'number') {\n throw new Error(\n `referenceMultiplier must be a number (got ${typeof referenceMultiplier} ${referenceMultiplier} instead)`,\n );\n }\n // Let shouldInvertEquation() handle `reference`.\n }\n}\n\nfunction shouldInvertEquation(referenceConfig: Reference, sourceCurrency: string): boolean {\n if (referenceConfig === 'source') return false;\n if (referenceConfig === 'target') return true;\n if (['auto', undefined, null].indexOf(referenceConfig) > -1)\n return !!(config[sourceCurrency] || {}).hasInversionEnabled;\n throw new Error(\n `Unrecognized reference config value: ${referenceConfig} (valid values are auto, source, target).`,\n );\n}\n\nfunction getMultiplier(\n referenceMultiplierOverride: number | undefined,\n lhsCurrency: string,\n): number {\n return (\n referenceMultiplierOverride ||\n (config[lhsCurrency] || {}).multiplierForEquation ||\n DEFAULT_RATE_MULTIPLIER\n );\n}\n","const supportedLocales: Record<string, boolean> = {}; // cache\n\nexport function isSelectedLocaleSupported(locale: string): boolean {\n if (supportedLocales[locale] === undefined) {\n supportedLocales[locale] = checkForLocaleSupport(locale);\n }\n return supportedLocales[locale];\n}\n\nfunction checkForLocaleSupport(locale: string): boolean {\n try {\n return Intl.DateTimeFormat.supportedLocalesOf([locale]).length > 0;\n } catch (e) {\n return false;\n }\n}\n","const WEEKDAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];\nconst SHORT_MONTHS = [\n 'Jan',\n 'Feb',\n 'Mar',\n 'Apr',\n 'May',\n 'Jun',\n 'Jul',\n 'Aug',\n 'Sep',\n 'Oct',\n 'Nov',\n 'Dec',\n];\n\nfunction getJoiningCharacter(options: Intl.DateTimeFormatOptions): string {\n return options.month === 'short' ? ' ' : '/';\n}\n\nfunction isMonthFirst(options: Intl.DateTimeFormatOptions) {\n return options.month === 'short';\n}\n\nfunction getFormattedMonth(\n options: Intl.DateTimeFormatOptions,\n isUTC: boolean,\n date: Date,\n): string | number {\n if (options.month === 'short') {\n return SHORT_MONTHS[isUTC ? date.getUTCMonth() : date.getMonth()];\n }\n return (isUTC ? date.getUTCMonth() : date.getMonth()) + 1;\n}\n\n// Sample outputs: 'Sat, 1/12/2018', '1/12/2018', '12/2018', Sat, 1'\nexport function getFallbackFormat(date: Date, options: Intl.DateTimeFormatOptions = {}): string {\n const isUTC = options.timeZone === 'UTC';\n\n const dateParts = [];\n if (options.day) dateParts.push(isUTC ? date.getUTCDate() : date.getDate());\n if (options.month) {\n const monthFormat = getFormattedMonth(options, isUTC, date);\n if (isMonthFirst(options)) {\n dateParts.unshift(monthFormat);\n } else {\n dateParts.push(monthFormat);\n }\n }\n if (options.year) dateParts.push(isUTC ? date.getUTCFullYear() : date.getUTCFullYear());\n\n const joiningCharacter = getJoiningCharacter(options);\n let fallbackDate = dateParts.join(joiningCharacter);\n\n if (options.weekday) {\n const dayName = WEEKDAYS[isUTC ? date.getUTCDay() : date.getDay()];\n fallbackDate = fallbackDate ? `${dayName}, ${fallbackDate}` : dayName;\n }\n return (\n fallbackDate ||\n getFallbackFormat(date, {\n timeZone: options.timeZone,\n day: 'true',\n month: 'true',\n year: 'true',\n })\n );\n}\n","import { isIntlSupported, isSelectedLocaleSupported } from './support-detection';\nimport { getFallbackFormat } from './fallback-format';\nimport { DEFAULT_LOCALE } from '../defaults';\n\nexport function formatDate(\n date: Date,\n locale = DEFAULT_LOCALE,\n options?: Intl.DateTimeFormatOptions,\n): string {\n return isIntlSupported()\n ? new Intl.DateTimeFormat(getSupportedLocale(locale), options).format(date)\n : getFallbackFormat(date, options);\n}\n\nfunction getSupportedLocale(locale: string) {\n return isSelectedLocaleSupported(locale) ? locale : DEFAULT_LOCALE;\n}\n","export default (date: Date): boolean => {\n const today = new Date(Date.now());\n return (\n date.getDate() === today.getDate() &&\n date.getMonth() === today.getMonth() &&\n date.getFullYear() === today.getFullYear()\n );\n};\n","import isToday from '../isToday';\nimport { formatDate } from '../date';\nimport { getTranslation } from '../../translations/translator';\nimport { DEFAULT_LOCALE } from '../../defaults';\n\nexport function formatRelativeDate(date: Date, locale = DEFAULT_LOCALE): string {\n if (date < new Date(Date.now())) {\n return '';\n }\n\n let formatted;\n if (shouldFormatRelative(date)) {\n formatted = formatRelative(date, locale);\n } else {\n formatted = formatAbsolute(date, locale);\n }\n return formatted;\n}\n\nfunction shouldFormatRelative(date: Date): boolean {\n return isToday(date) && isWithinHours(date, 12);\n}\n\nfunction isWithinHours(date: Date, boundary: number): boolean {\n const now = new Date(Date.now());\n //@ts-expect-error date maths\n const diff = date - now;\n return getDifferenceIn(diff, TimeUnit.HOUR) <= boundary;\n}\n\nfunction formatRelative(date: Date, locale: string): string {\n const now = new Date(Date.now());\n //@ts-expect-error date maths\n const diff = date - now;\n\n if (getDifferenceIn(diff, TimeUnit.SECOND) < 60) {\n return formatSeconds(locale);\n }\n\n const differenceInMinutes = getDifferenceIn(diff, TimeUnit.MINUTE);\n if (differenceInMinutes < 60) {\n return formatTimeUnit(differenceInMinutes, locale, TimeUnit.MINUTE);\n }\n\n return formatTimeUnit(getDifferenceIn(diff, TimeUnit.HOUR), locale, TimeUnit.HOUR);\n}\n\nfunction formatAbsolute(date: Date, locale: string): string {\n const params = {\n formattedDate: formatDate(date, locale, { month: 'short', day: 'numeric' }),\n };\n return getTranslation('relative-format-by', params, locale);\n}\n\nfunction getDifferenceIn(diff: number, timeUnitValue: TimeUnit): number {\n const millisecondsMap = {\n [TimeUnit.HOUR]: 3600000,\n [TimeUnit.MINUTE]: 60000,\n [TimeUnit.SECOND]: 1000,\n };\n return Math.ceil(diff / millisecondsMap[timeUnitValue]);\n}\n\nfunction formatTimeUnit(value: number, locale: string, timeUnit: string): string {\n if (value === 1) {\n return getTranslation(`relative-format-in-${timeUnit}`, {}, locale);\n }\n return getTranslation(\n `relative-format-in-${timeUnit}s`,\n { [`${timeUnit}s`]: `${value}` },\n locale,\n );\n}\n\nfunction formatSeconds(locale: string) {\n return getTranslation('relative-format-in-seconds', {}, locale);\n}\n\nenum TimeUnit {\n SECOND = 'second',\n MINUTE = 'minute',\n HOUR = 'hour',\n}\n","// eslint-disable-next-line import/no-unresolved\nimport translations from './translations.json';\n\nexport function getTranslation(\n translationKey: string,\n params: Record<string, string> = {},\n locale: string,\n): string {\n let translatedMessage: string | undefined;\n if (hasTranslation(locale, translationKey)) {\n translatedMessage = (translations as Record<string, Record<string, string>>)[locale][\n translationKey\n ];\n } else if (hasTranslation('en', translationKey)) {\n translatedMessage = (translations as Record<string, Record<string, string>>).en[translationKey];\n } else {\n translatedMessage = translationKey;\n }\n\n if (translatedMessage && params) {\n Object.keys(params).forEach(key => {\n translatedMessage = (translatedMessage as string).replace(\n new RegExp(`{${key}}`, 'g'),\n params[key],\n );\n });\n }\n\n return translatedMessage || translationKey;\n}\n\nfunction hasTranslation(locale: string, translationKey: string): boolean {\n return (\n hasOwnProperty(translations, locale) &&\n hasOwnProperty((translations as Record<string, Record<string, string>>)[locale], translationKey)\n );\n}\n\nfunction hasOwnProperty(obj: any, key: string) {\n return Object.prototype.hasOwnProperty.call(obj, key);\n}\n","export const formatPercentage= (percentage: number, locale = 'en-GB'): string =>\n Intl.NumberFormat(locale, {\n style: 'percent',\n maximumFractionDigits: 2,\n }).format(percentage);\n\n\n","import formatRate from './formatRate';\n\nexport type DisplayRate = {\n /**\n * Numerical rate to 4 decimal places. Only use when there is another indicator on the screen\n * for if the rate is inverted or not, such as a multiply/divide icon.\n */\n decimal: string;\n /**\n * Rate equation such as `1 ABC = 0.5743 DEF`. Use this whenever you need to display a rate\n * without much context.\n */\n equation: string;\n /**\n * If the rates given are given in the opposite direction to now the function was called.\n * For example if source was BRL and target was EUR, an inverted equation of\n * `1 EUR = 5.1233 BRL` may be returned.\n */\n inverted: boolean;\n};\n\n/**\n * Returns rates for displaying to customers.\n */\nexport default function getDisplayRate({\n rate,\n sourceCurrency,\n targetCurrency,\n locale,\n}: {\n rate: number;\n sourceCurrency: string;\n targetCurrency: string;\n locale: string;\n}): DisplayRate {\n const inverted = shouldInvertEquation(sourceCurrency, rate);\n\n const rawValue = inverted ? 1 / rate : rate;\n\n const leftHandSide = `1 ${inverted ? targetCurrency : sourceCurrency}`;\n const rightHandSide = `${formatRate(rawValue, locale)} ${\n inverted ? sourceCurrency : targetCurrency\n }`;\n\n return {\n decimal: formatRate(rawValue, locale),\n inverted,\n equation: `${leftHandSide} = ${rightHandSide}`,\n };\n}\n\nfunction shouldInvertEquation(sourceCurrency: string, rate: number): boolean {\n if (sourceCurrency === 'BRL' && rate <= 10) {\n // Prefer to show BRL inverted unless the rate would be below 0.1\n return true;\n }\n\n // Prefer not to show very low rates\n return rate < 0.1;\n}\n","import { NUMBER_OF_RATE_SIGNIFICANT_DIGITS, DEFAULT_LOCALE } from '../defaults';\nimport { formatNumberToSignificantDigits } from '../number';\nimport formatRateEquation from './formatRateEquation';\nimport getRateEquation, { Reference } from './getRateEquation';\n\n/**\n * @deprecated use getDisplayRate\n */\nexport default function(\n rate: number,\n sourceCurrency: string,\n targetCurrency: string,\n {\n reference = 'auto',\n referenceMultiplier,\n significantFigures = NUMBER_OF_RATE_SIGNIFICANT_DIGITS,\n }: { reference?: Reference; referenceMultiplier?: number; significantFigures?: number } = {},\n locale = DEFAULT_LOCALE,\n) {\n const response = {\n suggested: {},\n formats: {} as Record<string, any>,\n };\n\n response.formats.decimal = {\n output: formatNumberToSignificantDigits(rate, locale, significantFigures),\n significantFigures,\n };\n\n const equation = getRateEquation(rate, sourceCurrency, targetCurrency, {\n reference,\n referenceMultiplier,\n });\n\n response.formats.equation = {\n output: formatRateEquation(equation, { significantFigures }, locale),\n reference: equation.lhsCurrency === sourceCurrency ? 'source' : 'target',\n referenceMultiplier: equation.lhsValue,\n calculationInDecimal: formatNumberToSignificantDigits(\n equation.rhsValue,\n locale,\n significantFigures,\n ),\n };\n\n if (equation.lhsCurrency === sourceCurrency && equation.lhsValue === 1) {\n response.suggested = {\n format: 'decimal',\n output: response.formats.decimal.output,\n };\n } else {\n response.suggested = {\n format: 'equation',\n output: response.formats.equation.output,\n };\n }\n\n return response;\n}\n"],"names":["isSupported","isIntlNumberFormatSupported","locale","undefined","Intl","NumberFormat","supportedLocalesOf","length","SIGNIFICANT_DIGITS","TYPE","MIN_PRECISION","MAX_PRECISION","FRACTION_DIGITS","formatters","getFormatter","options","cacheKey","Object","entries","getValidLocale","noUnderscoreLocale","replace","e","formatNumberToSignificantDigits","number","significantDigits","formatNumber","precision","precisionType","Number","isPrecisionValid","validatedLocale","getPrecisionOptions","format","toPrecision","toFixed","formatNumberWithFallback","currencyDecimals","BIF","BYR","CLP","DJF","GNF","JPY","KMF","KRW","MGA","PYG","RWF","VND","VUV","XAF","XOF","XPF","HUF","UGX","KES","BHD","JOD","KWD","OMR","TND","formatAmount","amount","currencyCode","alwaysShowDecimals","amountHasNoDecimals","currency","upperCaseCurrency","toUpperCase","prototype","hasOwnProperty","call","getCurrencyDecimals","getPrecision","formatRate","rate","optionsOrLocale","formatRateInternal","significantFigures","maximumFractionDigits","Math","min","max","floor","log10","value","fallback","formatNumberWithOptions","minimumFractionDigits","lhsCurrency","rhsValue","rhsCurrency","lhsValue","intlSupported","BRL","hasInversionEnabled","INR","IDR","RON","THB","getMultiplier","referenceMultiplierOverride","config","multiplierForEquation","supportedLocales","WEEKDAYS","SHORT_MONTHS","formatDate","date","Date","DateTimeFormat","intlDateTimeFormatReturnsCorrectValue","checkForLocaleSupport","isSelectedLocaleSupported","getSupportedLocale","getFallbackFormat","isUTC","timeZone","dateParts","day","push","getUTCDate","getDate","month","monthFormat","getUTCMonth","getMonth","getFormattedMonth","isMonthFirst","unshift","year","getUTCFullYear","joiningCharacter","getJoiningCharacter","fallbackDate","join","weekday","dayName","getUTCDay","getDay","TimeUnit","getTranslation","translationKey","params","translatedMessage","hasTranslation","translations","en","keys","forEach","key","RegExp","obj","getDifferenceIn","diff","timeUnitValue","millisecondsMap","HOUR","MINUTE","SECOND","ceil","formatTimeUnit","timeUnit","percentage","style","now","today","getFullYear","isToday","boundary","isWithinHours","shouldFormatRelative","formatSeconds","differenceInMinutes","formatRelative","formattedDate","formatAbsolute","sourceCurrency","targetCurrency","inverted","shouldInvertEquation","rawValue","leftHandSide","rightHandSide","decimal","equation","reference","referenceMultiplier","response","suggested","formats","output","Error","validateParameters","referenceConfig","indexOf","getRateEquation","formatRateEquation","calculationInDecimal"],"mappings":"IAAIA,EAOJ,SAAgBC,EAA4BC,GAW1C,YAVoBC,IAAhBH,IACFA,EACkB,iBAATI,WACED,IAATC,MAC6B,mBAAtBA,KAAKC,cACZD,KAAKC,cAC2C,mBAAzCD,KAAKC,aAAaC,oBACzBF,KAAKC,aAAaC,oBACsC,IAAxDF,KAAKC,aAAaC,mBAAmBJ,GAAQK,QAE1CP,MCVDQ,ECHc,CAClBC,KAAM,oBACNC,cAAe,EACfC,cAAe,IDASC,ECET,CACfH,KAAM,iBACNC,cAAe,EACfC,cAAe,IDHbE,EAAkC,GAQxC,SAASC,EAAaZ,EAAgBa,GACpC,IAAMC,EAAWD,KAAab,EAASe,OAAOC,QAAQH,GAAab,EAMnE,OALKW,EAAWG,KACdH,EAAWG,GAAYD,EACnB,IAAIX,KAAKC,aAAaH,EAAQ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ISION:0,MAX_PRECISION:20}},n={};function i(e,t){const r=t?`${e}${Object.entries(t)}`:e;return n[r]||(n[r]=t?new Intl.NumberFormat(e,t):new Intl.NumberFormat(e)),n[r]}function a(e,r="en-GB",n=6){return o(e,r,n,t.TYPE)}function o(n,a="en-GB",o,u="FractionDigits"){if(!n&&0!==n)return"";"string"==typeof n&&Number(n)&&(n=Number(n));const{MIN_PRECISION:m,MAX_PRECISION:s}=u===t.TYPE?t:r,l=null!=o&&"number"==typeof o&&o>=m&&o<=s,f=function(e){try{const t=e.replace(/_/,"-");return Intl.NumberFormat(t),t}catch(e){return"en-GB"}}(a);return function(t){return void 0===e&&(e="object"==typeof Intl&&void 0!==Intl&&"function"==typeof Intl.NumberFormat&&Intl.NumberFormat&&"function"==typeof Intl.NumberFormat.supportedLocalesOf&&Intl.NumberFormat.supportedLocalesOf&&1===Intl.NumberFormat.supportedLocalesOf(t).length),e}(f)?(l?i(f,function(e,t){return{["minimum"+t]:e,["maximum"+t]:e}}(o,u)):i(f)).format(n):l?function(e,r,n){return n===t.TYPE?e.toPrecision(r):e.toFixed(r)}(n,o,u):""+n}const u={BIF:0,BYR:0,CLP:0,DJF:0,GNF:0,JPY:0,KMF:0,KRW:0,MGA:0,PYG:0,RWF:0,VND:0,VUV:0,XAF:0,XOF:0,XPF:0,HUF:0,UGX:0,KES:0,BHD:3,JOD:3,KWD:3,OMR:3,TND:3};function m(e,t,r="en-GB",n={alwaysShowDecimals:!1}){return o(e,r,function(e,t,r){return function(e){return e%1==0}(e)&&!r?0:function(e=""){const t=e.toUpperCase();return Object.prototype.hasOwnProperty.call(u,t)?u[t]:2}(t)}(e,t,n.alwaysShowDecimals))}function s(e,t,r="en-GB",n={alwaysShowDecimals:!1}){return`${m(e,t,r,n)} ${(t||"").toUpperCase()}`}function l(e,{significantFigures:t=6}={},r="en-GB"){return a(e,r,t)}function f({lhsValue:e,lhsCurrency:t,rhsValue:r,rhsCurrency:n},{significantFigures:i=6}={},o="en-GB"){return`${m(e,t,o)} ${t} = ${a(r,o,i)} ${n}`}var c={BRL:{hasInversionEnabled:!0},INR:{hasInversionEnabled:!0},JPY:{hasInversionEnabled:!0},IDR:{hasInversionEnabled:!0},HUF:{hasInversionEnabled:!0},RON:{hasInversionEnabled:!0},THB:{hasInversionEnabled:!0}};function h(e,t){return e||(c[t]||{}).multiplierForEquation||1}function v(e,t,r,{reference:n="auto",referenceMultiplier:i,significantFigures:o=6}={},u="en-GB"){const m={suggested:{},formats:{}};m.formats.decimal={output:a(e,u,o),significantFigures:o};const s=function(e,t,r,{reference:n="auto",referenceMultiplier:i}={}){return function(){if(!e)throw new Error(`rate parameter is mandatory (got ${e} instead).`);if(!t)throw new Error(`sourceCurrency parameter is mandatory (got ${t} instead).`);if(!r)throw new Error(`targetCurrency parameter is mandatory (got ${r} instead).`);if(i&&"number"!=typeof i)throw new Error(`referenceMultiplier must be a number (got ${typeof i} ${i} instead)`)}(),function(e,t){if("source"===e)return!1;if("target"===e)return!0;if(["auto",void 0,null].indexOf(e)>-1)return!!(c[t]||{}).hasInversionEnabled;throw new Error(`Unrecognized reference config value: ${e} (valid values are auto, source, target).`)}(n,t)?{lhsCurrency:r,lhsValue:h(i,r),rhsCurrency:t,rhsValue:h(i,r)/e}:{lhsCurrency:t,lhsValue:h(i,t),rhsCurrency:r,rhsValue:e*h(i,t)}}(e,t,r,{reference:n,referenceMultiplier:i});return m.formats.equation={output:f(s,{significantFigures:o},u),reference:s.lhsCurrency===t?"source":"target",referenceMultiplier:s.lhsValue,calculationInDecimal:a(s.rhsValue,u,o)},m.suggested=s.lhsCurrency===t&&1===s.lhsValue?{format:"decimal",output:m.formats.decimal.output}:{format:"equation",output:m.formats.equation.output},m}function d(e){return parseFloat((100*e).toFixed(2))+"%"}let y;const I={},g=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],p=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function b(e,t="en-GB",r){return void 0===y&&(y=function(){try{const e=new Date(2018,11,1);return"01/12/2018"===new Intl.DateTimeFormat("en-GB").format(e)}catch(e){return!1}}()),y?new Intl.DateTimeFormat(function(e){return function(e){return void 0===I[e]&&(I[e]=function(e){try{return Intl.DateTimeFormat.supportedLocalesOf([e]).length>0}catch(e){return!1}}(e)),I[e]}(e)?e:"en-GB"}(t),r).format(e):function e(t,r={}){const n="UTC"===r.timeZone,i=[];if(r.day&&i.push(n?t.getUTCDate():t.getDate()),r.month){const e=function(e,t,r){return"short"===e.month?p[t?r.getUTCMonth():r.getMonth()]:(t?r.getUTCMonth():r.getMonth())+1}(r,n,t);!function(e){return"short"===e.month}(r)?i.push(e):i.unshift(e)}r.year&&i.push(t.getUTCFullYear());const a=function(e){return"short"===e.month?" ":"/"}(r);let o=i.join(a);if(r.weekday){const e=g[n?t.getUTCDay():t.getDay()];o=o?`${e}, ${o}`:e}return o||e(t,{timeZone:r.timeZone,day:"true",month:"true",year:"true"})}(e,r)}var D,F={cs:{"relative-format-in-seconds":"během pár vteřin","relative-format-in-minutes":"v {minutes} minutách","relative-format-in-hours":"v {hours} hodinách","relative-format-in-minute":"během 1 minuty","relative-format-in-hour":"během 1 hodiny","relative-format-by":"do {formattedDate}"},de:{"relative-format-in-seconds":"binnen Sekunden","relative-format-in-minutes":"in {minutes} Minuten","relative-format-in-hours":"in {hours} Stunden","relative-format-in-minute":"in einer Minute","relative-format-in-hour":"in einer Stunde","relative-format-by":"bis {formattedDate}"},en:{"relative-format-in-seconds":"in seconds","relative-format-in-minutes":"in {minutes} minutes","relative-format-in-hours":"in {hours} hours","relative-format-in-minute":"in 1 minute","relative-format-in-hour":"in 1 hour","relative-format-by":"by {formattedDate}"},es:{"relative-format-in-seconds":"en segundos","relative-format-in-minutes":"en {minutes} minutos","relative-format-in-hours":"en {hours} horas","relative-format-in-minute":"en 1 minuto","relative-format-in-hour":"en 1 hora","relative-format-by":"el {formattedDate}"},fr:{"relative-format-in-seconds":"en quelques secondes","relative-format-in-minutes":"dans {minutes} minutes","relative-format-in-hours":"dans {hours} heures","relative-format-in-minute":"dans 1 minute","relative-format-in-hour":"dans 1 heure","relative-format-by":"d'ici le {formattedDate}"},hu:{"relative-format-in-seconds":"másodpercek alatt","relative-format-in-minutes":"{minutes} percen belül","relative-format-in-hours":"{hours} órán belül","relative-format-in-minute":"1 percen belül","relative-format-in-hour":"1 órán belül","relative-format-by":"eddig: {formattedDate}"},id:{"relative-format-in-seconds":"dalam detik","relative-format-in-minutes":"dalam {minutes} menit","relative-format-in-hours":"dalam {hours} jam","relative-format-in-minute":"dalam 1 menit","relative-format-in-hour":"dalam 1 jam","relative-format-by":"sebelum {formattedDate}"},it:{"relative-format-in-seconds":"tra qualche secondo","relative-format-in-minutes":"tra {minutes} minuti","relative-format-in-hours":"tra {hours} ore","relative-format-in-minute":"in 1 minuto","relative-format-in-hour":"in 1 ora","relative-format-by":"entro {formattedDate}"},ja:{"relative-format-in-seconds":"数秒","relative-format-in-minutes":"{minutes}分以内","relative-format-in-hours":"{hours}時間以内","relative-format-in-minute":"1分以内","relative-format-in-hour":"1時間以内","relative-format-by":"{formattedDate}まで"},pl:{"relative-format-in-seconds":"w ciągu kilku sekund","relative-format-in-minutes":"w ciągu {minutes} minut","relative-format-in-hours":"w ciągu {hours} godzin","relative-format-in-minute":"w ciągu 1 minuty","relative-format-in-hour":"w ciągu 1 godziny","relative-format-by":"do {formattedDate}"},pt:{"relative-format-in-seconds":"em segundos","relative-format-in-minutes":"em {minutes} minutos","relative-format-in-hours":"em {hours} horas","relative-format-in-minute":"em 1 minuto","relative-format-in-hour":"em 1 hora","relative-format-by":"até {formattedDate}"},ro:{"relative-format-in-seconds":"în câteva secunde","relative-format-in-minutes":"în {minutes} minute","relative-format-in-hours":"în {hours} ore","relative-format-in-minute":"în 1 minut","relative-format-in-hour":"în 1 oră","relative-format-by":"până pe {formattedDate}"},ru:{"relative-format-in-seconds":"через несколько секунд","relative-format-in-minutes":"через {minutes} мин.","relative-format-in-hours":"через {hours} ч.","relative-format-in-minute":"через минуту","relative-format-in-hour":"через 1 час","relative-format-by":"к {formattedDate}"},tr:{"relative-format-in-seconds":"saniyeler içinde","relative-format-in-minutes":"{minutes} dakika içinde","relative-format-in-hours":"{hours} saat içinde","relative-format-in-minute":"1 dakika içinde","relative-format-in-hour":"1 saat içinde","relative-format-by":"{formattedDate} itibarıyla"},uk:{"relative-format-in-seconds":"через кілька секунд","relative-format-in-minutes":"через {minutes} хв","relative-format-in-hours":"через {hours} год","relative-format-in-minute":"через 1 хвилину","relative-format-in-hour":"через 1 годину","relative-format-by":"до {formattedDate}"},zh:{"relative-format-in-seconds":"數秒內","relative-format-in-minutes":"在 {minutes} 分鐘內","relative-format-in-hours":"在 {hours} 小時內","relative-format-in-minute":"在 1 分鐘內","relative-format-in-hour":"在 1 小時內","relative-format-by":"在 {formattedDate} 或之前"}};function w(e,t={},r){let n;return n=N(r,e)?F[r][e]:N("en",e)?F.en[e]:e,n&&t&&Object.keys(t).forEach(e=>{n=n.replace(new RegExp(`{${e}}`,"g"),t[e])}),n||e}function N(e,t){return E(F,e)&&E(F[e],t)}function E(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function C(e,t="en-GB"){if(e<new Date(Date.now()))return"";let r;return r=function(e){return(e=>{const t=new Date(Date.now());return e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getFullYear()===t.getFullYear()})(e)&&function(e,t){return O(e-new Date(Date.now()),D.HOUR)<=12}(e)}(e)?function(e,t){const r=e-new Date(Date.now());if(O(r,D.SECOND)<60)return function(e){return w("relative-format-in-seconds",{},e)}(t);const n=O(r,D.MINUTE);return n<60?M(n,t,D.MINUTE):M(O(r,D.HOUR),t,D.HOUR)}(e,t):function(e,t){return w("relative-format-by",{formattedDate:b(e,t,{month:"short",day:"numeric"})},t)}(e,t),r}function O(e,t){return Math.ceil(e/{[D.HOUR]:36e5,[D.MINUTE]:6e4,[D.SECOND]:1e3}[t])}function M(e,t,r){return 1===e?w("relative-format-in-"+r,{},t):w(`relative-format-in-${r}s`,{[r+"s"]:""+e},t)}!function(e){e.SECOND="second",e.MINUTE="minute",e.HOUR="hour"}(D||(D={}));export{m as formatAmount,b as formatDate,s as formatMoney,o as formatNumber,a as formatNumberToSignificantDigits,d as formatPercentage,l as formatRate,C as formatRelativeDate,v as getRateInAllFormats};
|
|
1
|
+
let e;function t(t){return void 0===e&&(e="object"==typeof Intl&&void 0!==Intl&&"function"==typeof Intl.NumberFormat&&Intl.NumberFormat&&"function"==typeof Intl.NumberFormat.supportedLocalesOf&&Intl.NumberFormat.supportedLocalesOf&&1===Intl.NumberFormat.supportedLocalesOf(t).length),e}const{SIGNIFICANT_DIGITS:r,FRACTION_DIGITS:n}={SIGNIFICANT_DIGITS:{TYPE:"SignificantDigits",MIN_PRECISION:1,MAX_PRECISION:21},FRACTION_DIGITS:{TYPE:"FractionDigits",MIN_PRECISION:0,MAX_PRECISION:20}},i={};function a(e,t){const r=t?`${e}${Object.entries(t)}`:e;return i[r]||(i[r]=t?new Intl.NumberFormat(e,t):new Intl.NumberFormat(e)),i[r]}function o(e){try{const t=e.replace(/_/,"-");return Intl.NumberFormat(t),t}catch(e){return"en-GB"}}function u(e,t="en-GB",n=6){return m(e,t,n,r.TYPE)}function m(e,i="en-GB",u,m="FractionDigits"){if(!e&&0!==e)return"";"string"==typeof e&&Number(e)&&(e=Number(e));const{MIN_PRECISION:s,MAX_PRECISION:l}=m===r.TYPE?r:n,f=null!=u&&"number"==typeof u&&u>=s&&u<=l,c=o(i);return t(c)?(f?a(c,function(e,t){return{["minimum"+t]:e,["maximum"+t]:e}}(u,m)):a(c)).format(e):f?function(e,t,n){return n===r.TYPE?e.toPrecision(t):e.toFixed(t)}(e,u,m):""+e}const s={BIF:0,BYR:0,CLP:0,DJF:0,GNF:0,JPY:0,KMF:0,KRW:0,MGA:0,PYG:0,RWF:0,VND:0,VUV:0,XAF:0,XOF:0,XPF:0,HUF:0,UGX:0,KES:0,BHD:3,JOD:3,KWD:3,OMR:3,TND:3};function l(e,t,r="en-GB",n={alwaysShowDecimals:!1}){return m(e,r,function(e,t,r){return function(e){return e%1==0}(e)&&!r?0:function(e=""){const t=e.toUpperCase();return Object.prototype.hasOwnProperty.call(s,t)?s[t]:2}(t)}(e,t,n.alwaysShowDecimals))}function f(e,t,r="en-GB",n={alwaysShowDecimals:!1}){return`${l(e,t,r,n)} ${(t||"").toUpperCase()}`}function c(e,t,r){if("string"==typeof t)return h(e,t);const n=t&&t.significantFigures;return n?u(e,r||"en-GB",n):h(e,r||"en-GB")}function h(e,r){const n=4-Math.min(2,Math.max(0,Math.floor(Math.log10(e))-1));return function(e,r,n,i){const u=o(n);return t(u)?a(u,r).format(e):i}(e,{minimumFractionDigits:0,maximumFractionDigits:n},r,e.toFixed(n))}function v({lhsValue:e,lhsCurrency:t,rhsValue:r,rhsCurrency:n},{significantFigures:i=6}={},a="en-GB"){return`${l(e,t,a)} ${t} = ${u(r,a,i)} ${n}`}var d={BRL:{hasInversionEnabled:!0},INR:{hasInversionEnabled:!0},JPY:{hasInversionEnabled:!0},IDR:{hasInversionEnabled:!0},HUF:{hasInversionEnabled:!0},RON:{hasInversionEnabled:!0},THB:{hasInversionEnabled:!0}};function y(e,t){return e||(d[t]||{}).multiplierForEquation||1}function g(e,t,r,{reference:n="auto",referenceMultiplier:i,significantFigures:a=6}={},o="en-GB"){const m={suggested:{},formats:{}};m.formats.decimal={output:u(e,o,a),significantFigures:a};const s=function(e,t,r,{reference:n="auto",referenceMultiplier:i}={}){return function(){if(!e)throw new Error(`rate parameter is mandatory (got ${e} instead).`);if(!t)throw new Error(`sourceCurrency parameter is mandatory (got ${t} instead).`);if(!r)throw new Error(`targetCurrency parameter is mandatory (got ${r} instead).`);if(i&&"number"!=typeof i)throw new Error(`referenceMultiplier must be a number (got ${typeof i} ${i} instead)`)}(),function(e,t){if("source"===e)return!1;if("target"===e)return!0;if(["auto",void 0,null].indexOf(e)>-1)return!!(d[t]||{}).hasInversionEnabled;throw new Error(`Unrecognized reference config value: ${e} (valid values are auto, source, target).`)}(n,t)?{lhsCurrency:r,lhsValue:y(i,r),rhsCurrency:t,rhsValue:y(i,r)/e}:{lhsCurrency:t,lhsValue:y(i,t),rhsCurrency:r,rhsValue:e*y(i,t)}}(e,t,r,{reference:n,referenceMultiplier:i});return m.formats.equation={output:v(s,{significantFigures:a},o),reference:s.lhsCurrency===t?"source":"target",referenceMultiplier:s.lhsValue,calculationInDecimal:u(s.rhsValue,o,a)},m.suggested=s.lhsCurrency===t&&1===s.lhsValue?{format:"decimal",output:m.formats.decimal.output}:{format:"equation",output:m.formats.equation.output},m}function D({rate:e,sourceCurrency:t,targetCurrency:r,locale:n}){const i=function(e,t){return"BRL"===e&&t<=10||t<.1}(t,e),a=i?1/e:e,o="1 "+(i?r:t),u=`${c(a,n)} ${i?t:r}`;return{decimal:c(a,n),inverted:i,equation:`${o} = ${u}`}}const b=(e,t="en-GB")=>Intl.NumberFormat(t,{style:"percent",maximumFractionDigits:2}).format(e);let I;const p={},F=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],N=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function w(e,t="en-GB",r){return void 0===I&&(I=function(){try{const e=new Date(2018,11,1);return"01/12/2018"===new Intl.DateTimeFormat("en-GB").format(e)}catch(e){return!1}}()),I?new Intl.DateTimeFormat(function(e){return function(e){return void 0===p[e]&&(p[e]=function(e){try{return Intl.DateTimeFormat.supportedLocalesOf([e]).length>0}catch(e){return!1}}(e)),p[e]}(e)?e:"en-GB"}(t),r).format(e):function e(t,r={}){const n="UTC"===r.timeZone,i=[];if(r.day&&i.push(n?t.getUTCDate():t.getDate()),r.month){const e=function(e,t,r){return"short"===e.month?N[t?r.getUTCMonth():r.getMonth()]:(t?r.getUTCMonth():r.getMonth())+1}(r,n,t);!function(e){return"short"===e.month}(r)?i.push(e):i.unshift(e)}r.year&&i.push(t.getUTCFullYear());const a=function(e){return"short"===e.month?" ":"/"}(r);let o=i.join(a);if(r.weekday){const e=F[n?t.getUTCDay():t.getDay()];o=o?`${e}, ${o}`:e}return o||e(t,{timeZone:r.timeZone,day:"true",month:"true",year:"true"})}(e,r)}var C,E={cs:{"relative-format-in-seconds":"během pár vteřin","relative-format-in-minutes":"v {minutes} minutách","relative-format-in-hours":"v {hours} hodinách","relative-format-in-minute":"během 1 minuty","relative-format-in-hour":"během 1 hodiny","relative-format-by":"do {formattedDate}"},de:{"relative-format-in-seconds":"in Sekunden","relative-format-in-minutes":"in {minutes} Minuten","relative-format-in-hours":"in {hours} Stunden","relative-format-in-minute":"in 1 Minute","relative-format-in-hour":"in 1 Stunde","relative-format-by":"bis {formattedDate}"},en:{"relative-format-in-seconds":"in seconds","relative-format-in-minutes":"in {minutes} minutes","relative-format-in-hours":"in {hours} hours","relative-format-in-minute":"in 1 minute","relative-format-in-hour":"in 1 hour","relative-format-by":"by {formattedDate}"},es:{"relative-format-in-seconds":"en segundos","relative-format-in-minutes":"en {minutes} minutos","relative-format-in-hours":"en {hours} horas","relative-format-in-minute":"en 1 minuto","relative-format-in-hour":"en 1 hora","relative-format-by":"el {formattedDate}"},fr:{"relative-format-in-seconds":"en quelques secondes","relative-format-in-minutes":"dans {minutes} minutes","relative-format-in-hours":"dans {hours} heures","relative-format-in-minute":"dans 1 minute","relative-format-in-hour":"dans 1 heure","relative-format-by":"d'ici le {formattedDate}"},hu:{"relative-format-in-seconds":"másodpercek alatt","relative-format-in-minutes":"{minutes} percen belül","relative-format-in-hours":"{hours} órán belül","relative-format-in-minute":"1 percen belül","relative-format-in-hour":"1 órán belül","relative-format-by":"ekkor: {formattedDate}"},id:{"relative-format-in-seconds":"dalam beberapa detik","relative-format-in-minutes":"dalam {minutes} menit","relative-format-in-hours":"dalam {hours} jam","relative-format-in-minute":"dalam 1 menit","relative-format-in-hour":"dalam 1 jam","relative-format-by":"sebelum {formattedDate}"},it:{"relative-format-in-seconds":"tra qualche secondo","relative-format-in-minutes":"tra {minutes} minuti","relative-format-in-hours":"tra {hours} ore","relative-format-in-minute":"in 1 minuto","relative-format-in-hour":"in 1 ora","relative-format-by":"entro il {formattedDate}"},ja:{"relative-format-in-seconds":"数秒","relative-format-in-minutes":"{minutes}分以内","relative-format-in-hours":"{hours}時間以内","relative-format-in-minute":"1分以内","relative-format-in-hour":"1時間以内","relative-format-by":"{formattedDate} まで"},pl:{"relative-format-in-seconds":"w ciągu kilku sekund","relative-format-in-minutes":"w ciągu {minutes} minut","relative-format-in-hours":"w ciągu {hours} godzin","relative-format-in-minute":"w ciągu 1 minuty","relative-format-in-hour":"w ciągu 1 godziny","relative-format-by":"do {formattedDate}"},pt:{"relative-format-in-seconds":"em segundos","relative-format-in-minutes":"em {minutes} minutos","relative-format-in-hours":"em {hours} horas","relative-format-in-minute":"em 1 minuto","relative-format-in-hour":"em 1 hora","relative-format-by":"até {formattedDate}"},ro:{"relative-format-in-seconds":"în câteva secunde","relative-format-in-minutes":"în {minutes} minute","relative-format-in-hours":"în {hours} ore","relative-format-in-minute":"în 1 minut","relative-format-in-hour":"în 1 oră","relative-format-by":"până pe {formattedDate}"},ru:{"relative-format-in-seconds":"через несколько секунд","relative-format-in-minutes":"через {minutes} мин.","relative-format-in-hours":"через {hours} ч.","relative-format-in-minute":"через минуту","relative-format-in-hour":"через 1 час","relative-format-by":"{formattedDate}"},th:{"relative-format-in-seconds":"ในไม่กี่วินาที","relative-format-in-minutes":"ใน {minutes} นาที","relative-format-in-hours":"ใน {hours} ชั่วโมง","relative-format-in-minute":"ใน 1 นาที","relative-format-in-hour":"ใน 1 ชั่วโมง","relative-format-by":"ภายใน {formattedDate}"},tr:{"relative-format-in-seconds":"saniyeler içinde","relative-format-in-minutes":"{minutes} dakika içinde","relative-format-in-hours":"{hours} saat içinde","relative-format-in-minute":"1 dakika içinde","relative-format-in-hour":"1 saat içinde","relative-format-by":"{formattedDate} itibarıyla"},uk:{"relative-format-in-seconds":"через кілька секунд","relative-format-in-minutes":"через {minutes} хв","relative-format-in-hours":"через {hours} год","relative-format-in-minute":"через 1 хвилину","relative-format-in-hour":"через 1 годину","relative-format-by":"до {formattedDate}"},"zh-CN":{"relative-format-in-seconds":"数秒内","relative-format-in-minutes":"{minutes} 分钟内","relative-format-in-hours":"{hours} 小时内","relative-format-in-minute":"1 分钟内","relative-format-in-hour":"1 小时内","relative-format-by":"{formattedDate} 前"},"zh-HK":{"relative-format-in-seconds":"數秒內","relative-format-in-minutes":"在 {minutes} 分鐘內","relative-format-in-hours":"在 {hours} 小時內","relative-format-in-minute":"在 1 分鐘內","relative-format-in-hour":"在 1 小時內","relative-format-by":"在 {formattedDate} 或之前"}};function M(e,t={},r){let n;return n=O(r,e)?E[r][e]:O("en",e)?E.en[e]:e,n&&t&&Object.keys(t).forEach(e=>{n=n.replace(new RegExp(`{${e}}`,"g"),t[e])}),n||e}function O(e,t){return T(E,e)&&T(E[e],t)}function T(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function S(e,t="en-GB"){if(e<new Date(Date.now()))return"";let r;return r=function(e){return(e=>{const t=new Date(Date.now());return e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getFullYear()===t.getFullYear()})(e)&&function(e,t){return G(e-new Date(Date.now()),C.HOUR)<=12}(e)}(e)?function(e,t){const r=e-new Date(Date.now());if(G(r,C.SECOND)<60)return function(e){return M("relative-format-in-seconds",{},e)}(t);const n=G(r,C.MINUTE);return n<60?R(n,t,C.MINUTE):R(G(r,C.HOUR),t,C.HOUR)}(e,t):function(e,t){return M("relative-format-by",{formattedDate:w(e,t,{month:"short",day:"numeric"})},t)}(e,t),r}function G(e,t){return Math.ceil(e/{[C.HOUR]:36e5,[C.MINUTE]:6e4,[C.SECOND]:1e3}[t])}function R(e,t,r){return 1===e?M("relative-format-in-"+r,{},t):M(`relative-format-in-${r}s`,{[r+"s"]:""+e},t)}!function(e){e.SECOND="second",e.MINUTE="minute",e.HOUR="hour"}(C||(C={}));export{l as formatAmount,w as formatDate,f as formatMoney,m as formatNumber,u as formatNumberToSignificantDigits,b as formatPercentage,c as formatRate,S as formatRelativeDate,D as getDisplayRate,g as getRateInAllFormats};
|
|
2
2
|
//# sourceMappingURL=formatting.modern.js.map
|