@eturnity/eturnity_reusable_components 1.1.30 → 1.1.31
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 +1 -1
- package/src/helpers/numberConverter.js +28 -28
package/package.json
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
1
|
export const stringToNumber = ({ value, numberPrecision, allowNegative }) => {
|
|
2
2
|
// This is for saving. It converts our input string to a readable number
|
|
3
3
|
let newVal = value.toString()
|
|
4
|
-
const selectedLang = localStorage.getItem(
|
|
4
|
+
const selectedLang = localStorage.getItem("lang")
|
|
5
5
|
// The first replace will replace not allowed characters with a blank
|
|
6
6
|
if (
|
|
7
|
-
selectedLang ===
|
|
8
|
-
selectedLang ===
|
|
9
|
-
selectedLang ===
|
|
10
|
-
selectedLang ===
|
|
11
|
-
selectedLang ===
|
|
7
|
+
selectedLang === "de-DE" ||
|
|
8
|
+
selectedLang === "it-CH" ||
|
|
9
|
+
selectedLang === "no-no" ||
|
|
10
|
+
selectedLang === "da-dk" ||
|
|
11
|
+
selectedLang === "de"
|
|
12
12
|
) {
|
|
13
13
|
// replace commas with a dot, and dots with blank
|
|
14
14
|
if (allowNegative) {
|
|
15
15
|
newVal = newVal
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
.replace(/[^\d-.,']/g, "")
|
|
17
|
+
.replace(/[.\s]/g, "")
|
|
18
|
+
.replace(/[,\s]/, ".")
|
|
19
19
|
} else {
|
|
20
20
|
newVal = newVal
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
.replace(/[^\d.,']/g, "")
|
|
22
|
+
.replace(/[.\s]/g, "")
|
|
23
|
+
.replace(/[,\s]/, ".")
|
|
24
24
|
}
|
|
25
|
-
} else if (selectedLang ===
|
|
25
|
+
} else if (selectedLang === "en-us") {
|
|
26
26
|
// replace commas with blank
|
|
27
27
|
if (allowNegative) {
|
|
28
|
-
newVal = newVal.replace(/[^\d-.,']/g,
|
|
28
|
+
newVal = newVal.replace(/[^\d-.,']/g, "").replace(/[,\s]/g, "")
|
|
29
29
|
} else {
|
|
30
|
-
newVal = newVal.replace(/[^\d.,']/g,
|
|
30
|
+
newVal = newVal.replace(/[^\d.,']/g, "").replace(/[,\s]/g, "")
|
|
31
31
|
}
|
|
32
32
|
} else if (
|
|
33
|
-
selectedLang ===
|
|
34
|
-
selectedLang ===
|
|
35
|
-
selectedLang ===
|
|
33
|
+
selectedLang === "de-ch" ||
|
|
34
|
+
selectedLang === "fr-ch" ||
|
|
35
|
+
selectedLang === "it-ch"
|
|
36
36
|
) {
|
|
37
37
|
// replace ' with blank
|
|
38
38
|
if (allowNegative) {
|
|
39
|
-
newVal = newVal.replace(/[^\d-.,']/g,
|
|
39
|
+
newVal = newVal.replace(/[^\d-.,']/g, "").replace(/['\s]/g, "")
|
|
40
40
|
} else {
|
|
41
|
-
newVal = newVal.replace(/[^\d.,']/g,
|
|
41
|
+
newVal = newVal.replace(/[^\d.,']/g, "").replace(/['\s]/g, "")
|
|
42
42
|
}
|
|
43
43
|
} else if (
|
|
44
|
-
selectedLang ===
|
|
45
|
-
selectedLang ===
|
|
46
|
-
selectedLang ===
|
|
44
|
+
selectedLang === "fr-fr" ||
|
|
45
|
+
selectedLang === "fr" ||
|
|
46
|
+
selectedLang === "sv-se"
|
|
47
47
|
) {
|
|
48
48
|
// replace space with blank, and commas with dot
|
|
49
49
|
if (allowNegative) {
|
|
50
|
-
newVal = newVal.replace(/[^\d-.,']/g,
|
|
50
|
+
newVal = newVal.replace(/[^\d-.,']/g, "").replace(/[,\s]/g, ".")
|
|
51
51
|
} else {
|
|
52
|
-
newVal = newVal.replace(/[^\d.,']/g,
|
|
52
|
+
newVal = newVal.replace(/[^\d.,']/g, "").replace(/[,\s]/g, ".")
|
|
53
53
|
}
|
|
54
54
|
} else {
|
|
55
55
|
// en-US as default
|
|
56
56
|
if (allowNegative) {
|
|
57
|
-
newVal = newVal.replace(/[^\d-.,']/g,
|
|
57
|
+
newVal = newVal.replace(/[^\d-.,']/g, "").replace(/[,\s]/g, "")
|
|
58
58
|
} else {
|
|
59
|
-
newVal = newVal.replace(/[^\d.,']/g,
|
|
59
|
+
newVal = newVal.replace(/[^\d.,']/g, "").replace(/[,\s]/g, "")
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
newVal = parseFloat(newVal).toFixed(numberPrecision)
|
|
63
63
|
return parseFloat(newVal)
|
|
64
|
-
}
|
|
64
|
+
}
|
|
65
65
|
|
|
66
66
|
export const numberToString = ({ value, numberPrecision }) => {
|
|
67
67
|
let selectedLang = localStorage.getItem("lang")
|