@fiscozen/composables 0.1.20 → 0.1.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.
package/package.json
CHANGED
|
@@ -8,7 +8,10 @@ export const useCurrency = () => {
|
|
|
8
8
|
() => vm?.props.modelValue as unknown as number | undefined
|
|
9
9
|
)
|
|
10
10
|
|
|
11
|
-
const format = (input: number) => {
|
|
11
|
+
const format = (input: number | null) => {
|
|
12
|
+
if (input === null) {
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
12
15
|
return input.toLocaleString('it-IT', {
|
|
13
16
|
minimumFractionDigits: 2,
|
|
14
17
|
maximumFractionDigits: 2
|
|
@@ -20,7 +23,7 @@ export const useCurrency = () => {
|
|
|
20
23
|
return parseFloat(text)
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
const setValue = (val: number) => {
|
|
26
|
+
const setValue = (val: number | null) => {
|
|
24
27
|
if (Number.isNaN(val)) {
|
|
25
28
|
return
|
|
26
29
|
}
|
|
@@ -35,17 +38,25 @@ export const useCurrency = () => {
|
|
|
35
38
|
let { value } = el
|
|
36
39
|
value = value.replace(/[^0-9,.]/g, '')
|
|
37
40
|
inputRef.value.value = value
|
|
38
|
-
const
|
|
39
|
-
setValue(Number.isNaN(
|
|
41
|
+
const numberValue = (vm?.props.nullOnEmpty && value === '') ? null : parse(value)
|
|
42
|
+
setValue(Number.isNaN(numberValue) ? 0 : numberValue)
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
const onBlur = (e: FocusEvent) => {
|
|
43
46
|
if (!inputRef.value || !e.target) {
|
|
44
47
|
return
|
|
45
48
|
}
|
|
46
|
-
let
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
let rawValue = (e.target as HTMLInputElement).value.replace(/,/g, '.');
|
|
50
|
+
let number: number | null;
|
|
51
|
+
|
|
52
|
+
if (rawValue === '' && vm?.props.nullOnEmpty) {
|
|
53
|
+
number = null
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
number = parse(rawValue)
|
|
57
|
+
if (Number.isNaN(number)) {
|
|
58
|
+
number = 0
|
|
59
|
+
}
|
|
49
60
|
}
|
|
50
61
|
const text = format(number)
|
|
51
62
|
|