@designcrowd/fe-shared-lib 1.2.11-ml-currency-2 → 1.2.11-ml-currency-3

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/Dockerfile CHANGED
@@ -29,7 +29,7 @@ COPY .npmignore ./
29
29
  RUN npm run bundle-translation
30
30
 
31
31
  RUN mkdir artifacts
32
- RUN npm publish --otp=143980 || (touch artifacts/npm_publish_failed && exit 1)
32
+ RUN npm publish --otp=777231 || (touch artifacts/npm_publish_failed && exit 1)
33
33
  RUN cp package.json artifacts/
34
34
 
35
35
  ENTRYPOINT ["/bin/echo", "Nothing to do."]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@designcrowd/fe-shared-lib",
3
- "version": "1.2.11-ml-currency-2",
3
+ "version": "1.2.11-ml-currency-3",
4
4
  "scripts": {
5
5
  "start": "run-p storybook watch:translation",
6
6
  "build": "npm run build:css --production",
@@ -1,5 +1,8 @@
1
1
  import Price from './Price.vue';
2
2
  import { currencies, locales } from './Price.fixtures';
3
+ import {setSharedLibLocaleAsync} from "../../../useSharedLibTranslate";
4
+
5
+ await setSharedLibLocaleAsync();
3
6
 
4
7
  // noinspection JSUnusedGlobalSymbols
5
8
  export default {
@@ -6,8 +6,7 @@
6
6
  </template>
7
7
  <script>
8
8
 
9
- import i18next from "i18next";
10
- import {setSharedLibLocaleAsync} from "../../../useSharedLibTranslate";
9
+ import {formatCurrency} from "../../../useSharedLibTranslate";
11
10
 
12
11
  export default {
13
12
  props: {
@@ -57,9 +56,6 @@ export default {
57
56
  default: false,
58
57
  },
59
58
  },
60
- setup() {
61
- setSharedLibLocaleAsync();
62
- },
63
59
  computed: {
64
60
  amountFormatted() {
65
61
  if (this.isDomainCredit) {
@@ -72,16 +68,13 @@ export default {
72
68
 
73
69
  if (this.locale != null)
74
70
  {
75
- let amount = i18next.t('{{val, currency}}', {
76
- ns: 'fe-shared-lib',
77
- val: this.amount,
78
- currency: this.currency.iso4127Code,
79
- locale: this.locale,
80
- maximumFractionDigits: this.fraction,
81
- useGrouping: false,
82
- });
83
-
84
- return this.standardiseAmount(amount);
71
+ return formatCurrency(
72
+ this.amount,
73
+ this.locale,
74
+ this.currency,
75
+ this.fraction,
76
+ this.showAbbreviatiom
77
+ );
85
78
  }
86
79
 
87
80
  const parsedAmount = Number.parseFloat(this.amount);
@@ -128,33 +121,5 @@ export default {
128
121
  return this.wrapInParentheses ? ')' : '';
129
122
  },
130
123
  },
131
- methods: {
132
- standardiseAmount(amount) {
133
- // i18next always uses iso code for ZAR, prefer symbol over iso code
134
- if (amount.includes(this.currency.iso4127Code)) {
135
- return amount.replace(this.currency.iso4127Code, this.currency.symbol);
136
- }
137
-
138
- // show abbreviation locale logic
139
- // note: showAbbreviaton is only passed as true for symbol = "$"
140
- if (this.currency.symbol != '$') {
141
- return amount
142
- }
143
-
144
- // AUD edge case for en_US
145
- if (this.currency.iso4127Code == 'AUD') {
146
- amount = amount.replace('A$', this.currency.symbol);
147
- }
148
-
149
- if (this.showAbbreviation && !amount.includes(this.currency.abbreviation)) {
150
- return `${this.currency?.abbreviation}${amount}`
151
-
152
- } else if (!this.showAbbreviation && amount.includes(this.currency.abbreviation)) {
153
- return amount.replace(this.currency.abbreviation, '');
154
- }
155
-
156
- return amount;
157
- }
158
- },
159
124
  };
160
125
  </script>
@@ -59,6 +59,42 @@ const getCurrentLocale = () => {
59
59
  return i18next.language || 'en-US';
60
60
  };
61
61
 
62
+ const formatCurrency = (amount, locale, currency, fraction = 0, showAbbreviation = false) => {
63
+ let localeAmount = i18next.t('{{val, currency}}', {
64
+ ns: 'fe-shared-lib',
65
+ val: amount,
66
+ currency: currency.iso4127Code,
67
+ locale: locale,
68
+ maximumFractionDigits: fraction,
69
+ useGrouping: false,
70
+ });
71
+
72
+ // i18next always uses iso code for ZAR, prefer symbol over iso code
73
+ if (localeAmount.includes(currency.iso4127Code)) {
74
+ return localeAmount.replace(currency.iso4127Code, currency.symbol);
75
+ }
76
+
77
+ // show abbreviation locale logic
78
+ // note: showAbbreviaton is only passed as true for symbol = "$"
79
+ if (currency.symbol != '$') {
80
+ return localeAmount;
81
+ }
82
+
83
+ // AUD edge case for en_US
84
+ if (currency.iso4127Code == 'AUD') {
85
+ localeAmount = localeAmount.replace('A$', currency.symbol);
86
+ }
87
+
88
+ if (showAbbreviation && !localeAmount.includes(currency.abbreviation)) {
89
+ return `${currency?.abbreviation}${localeAmount}`;
90
+
91
+ } else if (!showAbbreviation && localeAmount.includes(currency.abbreviation)) {
92
+ return localeAmount.replace(currency.abbreviation, '');
93
+ }
94
+
95
+ return localeAmount;
96
+ }
97
+
62
98
  export {
63
99
  setSharedLibLocaleAsync,
64
100
  getCurrentLocale,
@@ -70,5 +106,6 @@ export {
70
106
  sellDomainNameModalApplicationTr,
71
107
  sellDomainNameListModalTr,
72
108
  sellDomainNameListTr,
109
+ formatCurrency,
73
110
  };
74
111