@colisweb/rescript-toolkit 2.46.3 → 2.46.6
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
|
@@ -228,11 +228,15 @@ module UnitMeasure = {
|
|
|
228
228
|
| Some([_match, None, _unit]) => Decco.error(`${errorPrefix} unhandled no value`, jsonString)
|
|
229
229
|
| Some([Some(_match), Some(value), Some(unit)]) => {
|
|
230
230
|
let value = value->Js.Float.fromString
|
|
231
|
-
switch unit
|
|
231
|
+
switch unit
|
|
232
|
+
->Js.String2.replaceByRe(%re("/\s/"), "")
|
|
233
|
+
->Js.Json.string
|
|
234
|
+
->Config.unitEnum_decode {
|
|
232
235
|
| Ok(unit) => Config.wrapValue(unit, value)->Ok
|
|
233
236
|
| Error(_) => Decco.error(`${errorPrefix} unhandled unit '${unit}'`, jsonString)
|
|
234
237
|
}
|
|
235
238
|
}
|
|
239
|
+
|
|
236
240
|
| Some(_) => Decco.error(`${errorPrefix} regex capture group error`, jsonString)
|
|
237
241
|
}
|
|
238
242
|
}
|
|
@@ -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_(strictPositiveIntReex, _)
|
|
6
8
|
let isPositiveIntOrFloat = Js.Re.test_(positiveIntOrFloatRegex, _)
|
|
7
9
|
}
|
|
@@ -24,8 +24,8 @@ module Unit = (Config: UnitConfig) => {
|
|
|
24
24
|
@decco
|
|
25
25
|
type unitEnum = @decco.codec(codec) Config.unitEnum
|
|
26
26
|
|
|
27
|
-
let unitEnumToString =
|
|
28
|
-
let unitEnumFromString =
|
|
27
|
+
let unitEnumToString = Config.unitEnumToJs
|
|
28
|
+
let unitEnumFromString = Config.unitEnumFromJs
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
module Weight = {
|