@colisweb/rescript-toolkit 2.46.4 → 2.46.7

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colisweb/rescript-toolkit",
3
- "version": "2.46.4",
3
+ "version": "2.46.7",
4
4
  "scripts": {
5
5
  "clean": "rescript clean",
6
6
  "build": "rescript build -with-deps",
@@ -229,7 +229,7 @@ module UnitMeasure = {
229
229
  | Some([Some(_match), Some(value), Some(unit)]) => {
230
230
  let value = value->Js.Float.fromString
231
231
  switch unit
232
- ->Js.String2.replaceByRe(%re("/\s/"), "")
232
+ ->Js.String2.replaceByRe(%re("/\s/g"), "")
233
233
  ->Js.Json.string
234
234
  ->Config.unitEnum_decode {
235
235
  | Ok(unit) => Config.wrapValue(unit, value)->Ok
@@ -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
  }