intelicoreact 1.2.51 → 1.2.52

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.
@@ -9,18 +9,19 @@ exports.default = void 0;
9
9
 
10
10
  var _react = _interopRequireDefault(require("react"));
11
11
 
12
+ var _fieldValueFormatters = require("../../../Functions/fieldValueFormatters");
13
+
12
14
  var Price = function Price(_ref) {
13
15
  var value = _ref.value,
14
- _ref$unit = _ref.unit,
15
- unit = _ref$unit === void 0 ? '$' : _ref$unit,
16
- unitAfter = _ref.unitAfter,
16
+ currencyCode = _ref.currencyCode,
17
+ isSymbolAfter = _ref.isSymbolAfter,
17
18
  className = _ref.className;
18
- if (value === undefined || value === null) return null;
19
- var formatted = Number(value === null || value === void 0 ? void 0 : value.toString().replace(/[+*?$^(,)]/g, '')).toLocaleString('en-US');
19
+ if (value === undefined || value === null) return null; // const formatted = Number(value?.toString().replace(/[+*?$^(,)]/g, '')).toLocaleString('en-US');
20
+
20
21
  return /*#__PURE__*/_react.default.createElement("div", {
21
22
  "data-testid": 'test-price',
22
23
  className: "price ".concat(className)
23
- }, !unitAfter && unit, formatted, unitAfter && unit);
24
+ }, (0, _fieldValueFormatters.formatToPriceWithCurrency)(value, currencyCode, isSymbolAfter ? 'after' : 'before'));
24
25
  };
25
26
 
26
27
  var _default = Price;
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.formatToReplaceAllWhiteSpace = formatToReplaceAllWhiteSpace;
7
- exports.formatToHideValuePartially = exports.filterNumeric = exports.filterFloat = exports.formatToHex = exports.formatToLimitLength = exports.formatNumberValueToMask = exports.formatToCutOffDotAtTheEnd = exports.formatToOnlyASCIICodeText = exports.formatToPriceWithUSD = exports.formatToTwoDigitAfterDot = exports.formatToDollarSign = exports.formatToAddBitDepthPoints = exports.formatToRemoveComa = exports.formatOnlyNumbers = exports.intlNumbersFormatter = exports.getSafelyValue = void 0;
7
+ exports.formatToHideValuePartially = exports.filterNumeric = exports.filterFloat = exports.formatToHex = exports.formatToLimitLength = exports.formatNumberValueToMask = exports.formatToCutOffDotAtTheEnd = exports.formatToOnlyASCIICodeText = exports.formatToPriceWithCurrency = exports.formatToPriceWithUSD = exports.formatToTwoDigitAfterDot = exports.formatToDollarSign = exports.formatToAddBitDepthPoints = exports.formatToRemoveComa = exports.formatOnlyNumbers = exports.intlNumbersFormatter = exports.getSafelyValue = void 0;
8
8
 
9
9
  // The first word "format" in the function name means a
10
10
  //logic in which the function transforms the incoming value in any case.
@@ -79,10 +79,23 @@ var intlNumbersFormatter = function intlNumbersFormatter(inputValue) {
79
79
 
80
80
  var quantity = fractionDigits.quantity,
81
81
  _fractionDigits$isRen = fractionDigits.isRenderAlways,
82
- isRenderAlways = _fractionDigits$isRen === void 0 ? false : _fractionDigits$isRen;
82
+ isRenderAlways = _fractionDigits$isRen === void 0 ? false : _fractionDigits$isRen,
83
+ inputMinimumFractionDigits = fractionDigits.minimumFractionDigits,
84
+ inputMaximumFractionDigits = fractionDigits.maximumFractionDigits,
85
+ conditionallyMinimumFractionDigits = fractionDigits.conditionallyMinimumFractionDigits;
83
86
  var dotIndex = inputValue === null || inputValue === void 0 ? void 0 : inputValue.indexOf('.');
84
87
  var afterDot = dotIndex !== -1 ? inputValue.slice(dotIndex + 1) : '';
85
- var minimumFractionDigits = afterDot && lastSym !== '.' ? inputValue.slice(dotIndex).length - 1 : isRenderAlways ? quantity : 0;
88
+
89
+ var minimumFractionDigits = function () {
90
+ if (typeof inputMinimumFractionDigits === 'number') return inputMinimumFractionDigits;
91
+
92
+ if (typeof conditionallyMinimumFractionDigits === 'number') {
93
+ return afterDot && lastSym !== '.' ? conditionallyMinimumFractionDigits : 0;
94
+ }
95
+
96
+ return afterDot && lastSym !== '.' ? inputValue.slice(dotIndex).length - 1 : isRenderAlways ? quantity : 0;
97
+ }();
98
+
86
99
  var priceSettings = {
87
100
  useGrouping: useGrouping,
88
101
  //группировка разрядов
@@ -94,8 +107,8 @@ var intlNumbersFormatter = function intlNumbersFormatter(inputValue) {
94
107
  //валюта в виде символа
95
108
  //минимально не надо отображать центы, если их нет, иначе всегда будет .00
96
109
  minimumFractionDigits: minimumFractionDigits,
97
- maximumFractionDigits: quantity //максимально отображать 2 цифры после запятой, если центы всё же есть
98
-
110
+ //максимально отображать 2 цифры после запятой, если центы всё же есть
111
+ maximumFractionDigits: inputMaximumFractionDigits !== null && inputMaximumFractionDigits !== void 0 ? inputMaximumFractionDigits : quantity
99
112
  };
100
113
  var output;
101
114
 
@@ -165,14 +178,33 @@ var formatToPriceWithUSD = function formatToPriceWithUSD(value) {
165
178
  currencyType: 'USD'
166
179
  },
167
180
  fractionDigits: {
168
- quantity: 2
181
+ quantity: 2,
182
+ conditionallyMinimumFractionDigits: 2
169
183
  }
170
184
  });
171
- }; // eslint-disable-next-line no-control-regex
185
+ }; //! symbolPosition временно не реализовано
172
186
 
173
187
 
174
188
  exports.formatToPriceWithUSD = formatToPriceWithUSD;
175
189
 
190
+ var formatToPriceWithCurrency = function formatToPriceWithCurrency(value, currencyCode) {
191
+ var symbolPosition = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'before';
192
+ if (isNaN(Number(value))) return value;
193
+ return intlNumbersFormatter(getSafelyValue(value), {
194
+ withSymbol: 'currency',
195
+ currency: {
196
+ currencyType: currencyCode
197
+ },
198
+ fractionDigits: {
199
+ quantity: 2,
200
+ conditionallyMinimumFractionDigits: 2
201
+ }
202
+ });
203
+ }; // eslint-disable-next-line no-control-regex
204
+
205
+
206
+ exports.formatToPriceWithCurrency = formatToPriceWithCurrency;
207
+
176
208
  var formatToOnlyASCIICodeText = function formatToOnlyASCIICodeText(text) {
177
209
  return getSafelyValue(text).replace(/[^\x00-\x7F]+/g, '');
178
210
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intelicoreact",
3
- "version": "1.2.51",
3
+ "version": "1.2.52",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [