@streamscloud/kit 0.15.1 → 0.16.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.
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Utils } from './utils';
|
|
2
|
+
// `amountMinor` is an integer in the currency's smallest unit (e.g. cents) — the canonical money
|
|
3
|
+
// representation. It is converted to a major amount here via the currency's minor-unit exponent.
|
|
2
4
|
export const toPriceRepresentation = (data) => {
|
|
3
|
-
const {
|
|
5
|
+
const { amountMinor, currency, options } = data;
|
|
4
6
|
const { currencyMode = 'symbol', missingFractionMode = 'zeros-or-placeholder', locale = 'nb-NO' } = options ?? {};
|
|
5
7
|
const cfg = currencyDefaults[currency];
|
|
8
|
+
const amount = amountMinor / 10 ** cfg.minorUnit;
|
|
6
9
|
// Helper to attach currency per mode
|
|
7
10
|
const decorateWithCurrency = (value) => {
|
|
8
11
|
switch (currencyMode) {
|
|
@@ -51,9 +54,9 @@ export const toPriceRepresentation = (data) => {
|
|
|
51
54
|
}
|
|
52
55
|
};
|
|
53
56
|
const currencyDefaults = {
|
|
54
|
-
['NOK']: { symbol: 'kr', code: 'NOK', missingFractionPlaceholder: '-' },
|
|
55
|
-
['USD']: { symbol: '$', code: 'USD' },
|
|
56
|
-
['EUR']: { symbol: '€', code: 'EUR' }
|
|
57
|
+
['NOK']: { symbol: 'kr', code: 'NOK', minorUnit: 2, missingFractionPlaceholder: '-' },
|
|
58
|
+
['USD']: { symbol: '$', code: 'USD', minorUnit: 2 },
|
|
59
|
+
['EUR']: { symbol: '€', code: 'EUR', minorUnit: 2 }
|
|
57
60
|
};
|
|
58
61
|
const getDecimalSeparator = (locale) => {
|
|
59
62
|
const nf = new Intl.NumberFormat(locale);
|