@eturnity/eturnity_reusable_components 1.1.98 → 1.1.99
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/.prettierrc
ADDED
package/package.json
CHANGED
|
@@ -265,8 +265,8 @@ export default {
|
|
|
265
265
|
},
|
|
266
266
|
numberToStringEnabled: {
|
|
267
267
|
required: false,
|
|
268
|
-
default: true
|
|
269
|
-
}
|
|
268
|
+
default: true,
|
|
269
|
+
},
|
|
270
270
|
},
|
|
271
271
|
methods: {
|
|
272
272
|
onChangeHandler(event) {
|
|
@@ -294,12 +294,16 @@ export default {
|
|
|
294
294
|
} else {
|
|
295
295
|
let num = stringToNumber({
|
|
296
296
|
value: item,
|
|
297
|
-
numberPrecision:
|
|
297
|
+
numberPrecision: false,
|
|
298
298
|
})
|
|
299
299
|
return num
|
|
300
300
|
}
|
|
301
301
|
})
|
|
302
302
|
let evaluated = eval(formatted.join(""))
|
|
303
|
+
evaluated = stringToNumber({
|
|
304
|
+
value: evaluated,
|
|
305
|
+
numberPrecision: this.numberPrecision,
|
|
306
|
+
})
|
|
303
307
|
return evaluated
|
|
304
308
|
},
|
|
305
309
|
onInputBlur(e) {
|
|
@@ -309,7 +313,8 @@ export default {
|
|
|
309
313
|
this.onChangeHandler(evaluatedInput ? evaluatedInput : value)
|
|
310
314
|
if ((evaluatedInput && value.length) || this.minNumber !== null) {
|
|
311
315
|
this.textInput = numberToString({
|
|
312
|
-
value:
|
|
316
|
+
value:
|
|
317
|
+
evaluatedInput && value.length ? evaluatedInput : this.minNumber,
|
|
313
318
|
numberPrecision: this.numberPrecision,
|
|
314
319
|
})
|
|
315
320
|
}
|
|
@@ -338,19 +343,23 @@ export default {
|
|
|
338
343
|
? this.minNumber
|
|
339
344
|
: ""
|
|
340
345
|
if ((adjustedMinValue || adjustedMinValue === 0) && !this.isFocused) {
|
|
341
|
-
let input =
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
346
|
+
let input = this.numberToStringEnabled
|
|
347
|
+
? numberToString({
|
|
348
|
+
value: adjustedMinValue,
|
|
349
|
+
numberPrecision: this.numberPrecision,
|
|
350
|
+
})
|
|
351
|
+
: adjustedMinValue
|
|
345
352
|
let unit = this.showLinearUnitName ? "" : this.unitName
|
|
346
353
|
return input + " " + unit
|
|
347
354
|
} else if (!adjustedMinValue && adjustedMinValue !== 0) {
|
|
348
355
|
return ""
|
|
349
356
|
} else {
|
|
350
|
-
return
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
357
|
+
return this.numberToStringEnabled
|
|
358
|
+
? numberToString({
|
|
359
|
+
value: adjustedMinValue,
|
|
360
|
+
numberPrecision: this.numberPrecision,
|
|
361
|
+
})
|
|
362
|
+
: adjustedMinValue
|
|
354
363
|
}
|
|
355
364
|
},
|
|
356
365
|
},
|
|
@@ -1,79 +1,88 @@
|
|
|
1
|
-
export const stringToNumber = ({
|
|
1
|
+
export const stringToNumber = ({
|
|
2
|
+
value,
|
|
3
|
+
numberPrecision = false,
|
|
4
|
+
allowNegative
|
|
5
|
+
}) => {
|
|
2
6
|
// This is for saving. It converts our input string to a readable number
|
|
3
7
|
let newVal = value.toString()
|
|
4
|
-
const selectedLang = localStorage.getItem(
|
|
8
|
+
const selectedLang = localStorage.getItem('lang')
|
|
5
9
|
// The first replace will replace not allowed characters with a blank
|
|
6
10
|
if (
|
|
7
|
-
selectedLang ===
|
|
8
|
-
selectedLang ===
|
|
9
|
-
selectedLang ===
|
|
10
|
-
selectedLang ===
|
|
11
|
-
selectedLang ===
|
|
12
|
-
selectedLang ===
|
|
13
|
-
selectedLang ===
|
|
11
|
+
selectedLang === 'de-DE' ||
|
|
12
|
+
selectedLang === 'no-no' ||
|
|
13
|
+
selectedLang === 'da-dk' ||
|
|
14
|
+
selectedLang === 'de-lu' ||
|
|
15
|
+
selectedLang === 'de-be' ||
|
|
16
|
+
selectedLang === 'es-es' ||
|
|
17
|
+
selectedLang === 'de'
|
|
14
18
|
) {
|
|
15
19
|
// replace dots with blank, and commas with a dot: 1.234,56 --> 1234.56
|
|
16
20
|
if (allowNegative) {
|
|
17
21
|
newVal = newVal
|
|
18
|
-
.replace(/[^\d-.,']/g,
|
|
19
|
-
.replace(/[.\s]/g,
|
|
20
|
-
.replace(/[,\s]/,
|
|
22
|
+
.replace(/[^\d-.,']/g, '')
|
|
23
|
+
.replace(/[.\s]/g, '')
|
|
24
|
+
.replace(/[,\s]/, '.')
|
|
21
25
|
} else {
|
|
22
26
|
newVal = newVal
|
|
23
|
-
.replace(/[^\d.,']/g,
|
|
24
|
-
.replace(/[.\s]/g,
|
|
25
|
-
.replace(/[,\s]/,
|
|
27
|
+
.replace(/[^\d.,']/g, '')
|
|
28
|
+
.replace(/[.\s]/g, '')
|
|
29
|
+
.replace(/[,\s]/, '.')
|
|
26
30
|
}
|
|
27
|
-
} else if (selectedLang ===
|
|
31
|
+
} else if (selectedLang === 'en-us') {
|
|
28
32
|
// replace commas with blank: 1,234.56 --> 1234.56
|
|
29
33
|
if (allowNegative) {
|
|
30
|
-
newVal = newVal.replace(/[^\d-.,']/g,
|
|
34
|
+
newVal = newVal.replace(/[^\d-.,']/g, '').replace(/[,\s]/g, '')
|
|
31
35
|
} else {
|
|
32
|
-
newVal = newVal.replace(/[^\d.,']/g,
|
|
36
|
+
newVal = newVal.replace(/[^\d.,']/g, '').replace(/[,\s]/g, '')
|
|
33
37
|
}
|
|
34
38
|
} else if (
|
|
35
|
-
selectedLang ===
|
|
36
|
-
selectedLang ===
|
|
37
|
-
selectedLang ===
|
|
39
|
+
selectedLang === 'de-ch' ||
|
|
40
|
+
selectedLang === 'fr-ch' ||
|
|
41
|
+
selectedLang === 'it-ch'
|
|
38
42
|
) {
|
|
39
43
|
// replace ' with blank: 1'234.56 --> 1234.56
|
|
40
44
|
if (allowNegative) {
|
|
41
|
-
newVal = newVal.replace(/[^\d-.,']/g,
|
|
45
|
+
newVal = newVal.replace(/[^\d-.,']/g, '').replace(/['\s]/g, '')
|
|
42
46
|
} else {
|
|
43
|
-
newVal = newVal.replace(/[^\d.,']/g,
|
|
47
|
+
newVal = newVal.replace(/[^\d.,']/g, '').replace(/['\s]/g, '')
|
|
44
48
|
}
|
|
45
49
|
} else if (
|
|
46
|
-
selectedLang ===
|
|
47
|
-
selectedLang ===
|
|
48
|
-
selectedLang ===
|
|
49
|
-
selectedLang ===
|
|
50
|
-
selectedLang ===
|
|
51
|
-
selectedLang ===
|
|
50
|
+
selectedLang === 'fr-fr' ||
|
|
51
|
+
selectedLang === 'fr-be' ||
|
|
52
|
+
selectedLang === 'fr-lu' ||
|
|
53
|
+
selectedLang === 'sv-se' ||
|
|
54
|
+
selectedLang === 'pt-pt' ||
|
|
55
|
+
selectedLang === 'fr'
|
|
52
56
|
) {
|
|
53
57
|
// replace space with blank, and commas with dot: 1 234,56 --> 1234.56
|
|
54
58
|
if (allowNegative) {
|
|
55
|
-
newVal = newVal.replace(/[^\d-.,']/g,
|
|
59
|
+
newVal = newVal.replace(/[^\d-.,']/g, '').replace(/[,\s]/g, '.')
|
|
56
60
|
} else {
|
|
57
|
-
newVal = newVal.replace(/[^\d.,']/g,
|
|
61
|
+
newVal = newVal.replace(/[^\d.,']/g, '').replace(/[,\s]/g, '.')
|
|
58
62
|
}
|
|
59
63
|
} else {
|
|
60
64
|
// en-US as default: 1,234.56 --> 1234.56
|
|
61
65
|
if (allowNegative) {
|
|
62
|
-
newVal = newVal.replace(/[^\d-.,']/g,
|
|
66
|
+
newVal = newVal.replace(/[^\d-.,']/g, '').replace(/[,\s]/g, '')
|
|
63
67
|
} else {
|
|
64
|
-
newVal = newVal.replace(/[^\d.,']/g,
|
|
68
|
+
newVal = newVal.replace(/[^\d.,']/g, '').replace(/[,\s]/g, '')
|
|
65
69
|
}
|
|
66
70
|
}
|
|
67
|
-
newVal = parseFloat(newVal)
|
|
71
|
+
newVal = parseFloat(newVal)
|
|
72
|
+
if (numberPrecision !== false) {
|
|
73
|
+
newVal = newVal.toFixed(numberPrecision)
|
|
74
|
+
}
|
|
68
75
|
return parseFloat(newVal)
|
|
69
76
|
}
|
|
70
77
|
|
|
71
78
|
export const numberToString = ({ value, numberPrecision }) => {
|
|
72
|
-
let selectedLang = localStorage.getItem(
|
|
73
|
-
? localStorage.getItem(
|
|
74
|
-
|
|
79
|
+
let selectedLang = localStorage.getItem('lang')
|
|
80
|
+
? localStorage.getItem('lang') === 'fr-lu'
|
|
81
|
+
? 'fr-fr'
|
|
82
|
+
: localStorage.getItem('lang')
|
|
83
|
+
: 'en-US'
|
|
75
84
|
return value.toLocaleString(selectedLang, {
|
|
76
85
|
minimumFractionDigits: numberPrecision,
|
|
77
|
-
maximumFractionDigits: numberPrecision
|
|
86
|
+
maximumFractionDigits: numberPrecision
|
|
78
87
|
})
|
|
79
88
|
}
|