@dilicorp/ui 1.3.20 → 1.3.21

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.
@@ -5,7 +5,7 @@ export const InputCurrency = ({ attrs, handleChange, currency, name }) => {
5
5
  const { maxLength = 20 } = attrs;
6
6
  const handleChangeCurrency = (event) => {
7
7
  const { value } = event.currentTarget;
8
- const sanitize = numberHelper.currencySanitize(value);
8
+ const sanitize = numberHelper.currencySanitize(value, currency.locale, currency.format);
9
9
  handleChange({
10
10
  currentTarget: {
11
11
  name,
@@ -2,7 +2,7 @@ declare class NumberHelper {
2
2
  float2Int(float: number): number;
3
3
  sanitize(string: string): string;
4
4
  currency(value?: number, locale?: string, format?: string): string;
5
- currencySanitize(value: string): string | null;
5
+ currencySanitize(value: string, locale?: string, format?: string): string | null;
6
6
  percentageSanitize(value: string, decimals?: number): string | null;
7
7
  }
8
8
  declare const _default: NumberHelper;
@@ -11,14 +11,17 @@ class NumberHelper {
11
11
  style: 'currency'
12
12
  }).format(value);
13
13
  }
14
- currencySanitize(value) {
14
+ currencySanitize(value, locale = 'pt-br', format = 'BRL') {
15
+ const fractionDigits = new Intl.NumberFormat(locale, { currency: format, style: 'currency' }).resolvedOptions().minimumFractionDigits;
15
16
  const sanitize = (Number(this.sanitize(value))).toString();
16
- const integer = sanitize.slice(0, -2);
17
- const decimal = sanitize.slice(-2);
18
17
  if (value.replace(/\D/g, '') === '00' || sanitize === '')
19
18
  return null;
20
- if (decimal.length === 1)
21
- return `${integer}.0${decimal}`;
19
+ if (fractionDigits === 0)
20
+ return sanitize;
21
+ const integer = sanitize.slice(0, -fractionDigits);
22
+ const decimal = sanitize.slice(-fractionDigits);
23
+ if (decimal.length < fractionDigits)
24
+ return `${integer}.${'0'.repeat(fractionDigits - decimal.length)}${decimal}`;
22
25
  return `${integer}.${decimal}`;
23
26
  }
24
27
  percentageSanitize(value, decimals = 2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dilicorp/ui",
3
- "version": "1.3.20",
3
+ "version": "1.3.21",
4
4
  "description": "A simple UI design for Dilicorp",
5
5
  "repository": {
6
6
  "type": "git",