@colisweb/rescript-toolkit 2.46.4 → 2.46.5
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
|
@@ -19,6 +19,9 @@ module Msg = {
|
|
|
19
19
|
let required14Digits = {
|
|
20
20
|
defaultMessage: "Format requis : 14 chiffres",
|
|
21
21
|
}
|
|
22
|
+
let requiredStrictPosInt = {
|
|
23
|
+
defaultMessage: "Doit etre un entier strictement positif",
|
|
24
|
+
}
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
let toReSchemaResult = (opt: option<string>): ReSchema.fieldState =>
|
|
@@ -43,6 +46,15 @@ let requiredPosInt = (intl, value) => {
|
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
|
|
49
|
+
let requiredStrictPosInt = (intl, value) => {
|
|
50
|
+
switch value {
|
|
51
|
+
| "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
|
|
52
|
+
| value if !Toolkit__Utils_Regex.Test.isStrictPositiveInt(value) =>
|
|
53
|
+
Some(Intl.formatMessage(intl, Msg.requiredStrictPosInt))
|
|
54
|
+
| _ => None
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
46
58
|
let optionalPosInt = (intl, value) => {
|
|
47
59
|
switch value {
|
|
48
60
|
| "" => None
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
let positiveIntRegex = %re("/^[0-9]+$/")
|
|
2
|
+
let strictPositiveIntReex = %re("/^[0-9]*[1-9][0-9]*$/")
|
|
2
3
|
let positiveIntOrFloatRegex = %re("/^[0-9]+(?:\.?[0-9]+)?$/")
|
|
3
4
|
|
|
4
5
|
module Test = {
|
|
5
6
|
let isPositiveInt = Js.Re.test_(positiveIntRegex, _)
|
|
7
|
+
let isStrictPositiveInt = Js.Re.test_(positiveIntOrFloatRegex, _)
|
|
6
8
|
let isPositiveIntOrFloat = Js.Re.test_(positiveIntOrFloatRegex, _)
|
|
7
9
|
}
|