@capillarytech/cap-ui-utils 1.4.18 → 1.4.20
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/package.json +1 -1
- package/utils/formatter.js +13 -2
package/package.json
CHANGED
package/utils/formatter.js
CHANGED
|
@@ -113,8 +113,18 @@ function truncateNumber(num, places) {
|
|
|
113
113
|
return Math.trunc(num * numPower) / numPower;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
const
|
|
116
|
+
export const getUserLocale = (currentOrgDetails) => {
|
|
117
|
+
const { basic_details } = currentOrgDetails;
|
|
118
|
+
const { base_country_code, base_language } = basic_details || {};
|
|
119
|
+
if (base_language && base_country_code)
|
|
120
|
+
return `${base_language}-${base_country_code}`;
|
|
121
|
+
// Returning en-US as default locale case
|
|
122
|
+
return "en-US";
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
function localeBasedNumberFormatting(value, currentOrgDetails = {}) {
|
|
126
|
+
const userLocale = getUserLocale(currentOrgDetails);
|
|
127
|
+
const formattedValue = new Intl.NumberFormat(userLocale, {
|
|
118
128
|
maximumFractionDigits: 2,
|
|
119
129
|
}).format(value);
|
|
120
130
|
return formattedValue;
|
|
@@ -128,5 +138,6 @@ export default {
|
|
|
128
138
|
formatNumberWithSymbol,
|
|
129
139
|
camelize,
|
|
130
140
|
snakeCaseToCamelCase,
|
|
141
|
+
getUserLocale,
|
|
131
142
|
localeBasedNumberFormatting,
|
|
132
143
|
};
|