@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utils/formatter.js +13 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capillarytech/cap-ui-utils",
3
- "version": "1.4.18",
3
+ "version": "1.4.20",
4
4
  "description": "Utility functions shared accross all the modules",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -113,8 +113,18 @@ function truncateNumber(num, places) {
113
113
  return Math.trunc(num * numPower) / numPower;
114
114
  }
115
115
 
116
- function localeBasedNumberFormatting(locale, value) {
117
- const formattedValue = new Intl.NumberFormat(locale || "en-US", {
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
  };