@tagplus/components 1.2.15 → 1.2.16

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 CHANGED
@@ -8,7 +8,7 @@
8
8
  "email": "bruno@tagplus.com.br"
9
9
  }
10
10
  ],
11
- "version": "1.2.15",
11
+ "version": "1.2.16",
12
12
  "main": "./dist/tp.common.js",
13
13
  "directories": {
14
14
  "lib": "src/lib"
@@ -33,11 +33,17 @@ function unformat (input, precision = defaults.precision) {
33
33
  * @returns
34
34
  */
35
35
  function formatMoney (input, toString = false, locale = defaults) {
36
- const negative = ('' + input).indexOf('-') >= 0 ? -1 : 1
36
+ debugger
37
+ let inputString = ('' + input)
38
+ // Impede de digitar . ou , porque o formatador já adiciona
39
+ if ((inputString.slice(-1).match(/[.,]/))) {
40
+ inputString = inputString.substring(0, inputString.length - 1)
41
+ }
42
+ const negative = inputString.indexOf('-') >= 0 ? -1 : 1
37
43
  const precision = locale.number.precision
38
44
 
39
45
  if (toString) {
40
- input = completeZeros(('' + input), precision)
46
+ input = completeZeros(inputString, locale)
41
47
  }
42
48
  const numbers = onlyNumbers(input, precision)
43
49
  const currency = numbersToCurrency(numbers, precision)
@@ -54,13 +60,15 @@ function formatMoney (input, toString = false, locale = defaults) {
54
60
  }
55
61
  }
56
62
 
57
- function completeZeros (input, precision = defaults.precision) {
58
- const i = input.indexOf('.')
63
+ function completeZeros (input, locale) {
64
+ const precision = locale?.number?.precision || defaults.precision
65
+ const decimal = locale?.number?.decimal || defaults.decimal
66
+ const i = input.indexOf(decimal)
59
67
  const qntDecimais = i ? input.length - i - 1 : 0
60
68
 
61
69
  // correção para decimal quebrado
62
70
  if (i === -1) {
63
- input = input + '.' + '0'.repeat(precision)
71
+ input = input + decimal + '0'.repeat(precision)
64
72
  } else if (i && qntDecimais < precision) {
65
73
  input = input + '0'.repeat(precision - qntDecimais)
66
74
  }