@colisweb/rescript-toolkit 5.13.1 → 5.15.0
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/form/ReSchema.res +44 -9
- package/src/form/ReSchemaI18n.res +2 -0
- package/src/form/Reform.res +1 -0
package/package.json
CHANGED
package/src/form/ReSchema.res
CHANGED
|
@@ -28,7 +28,16 @@ module Make = (Lenses: Lenses) => {
|
|
|
28
28
|
type rec t =
|
|
29
29
|
| Email({field: Lenses.field<string>, error: option<string>}): t
|
|
30
30
|
| Phone({field: Lenses.field<string>, error: option<string>}): t
|
|
31
|
-
| Password({
|
|
31
|
+
| Password({
|
|
32
|
+
field: Lenses.field<string>,
|
|
33
|
+
login?: Lenses.state => string,
|
|
34
|
+
error: option<string>,
|
|
35
|
+
}): t
|
|
36
|
+
| OptionalPassword({
|
|
37
|
+
field: Lenses.field<string>,
|
|
38
|
+
login?: Lenses.state => string,
|
|
39
|
+
error: option<string>,
|
|
40
|
+
}): t
|
|
32
41
|
| NoValidation({field: Lenses.field<'a>}): t
|
|
33
42
|
| StringNonEmpty({field: Lenses.field<string>, error: option<string>}): t
|
|
34
43
|
| StringRegExp({field: Lenses.field<string>, matches: string, error: option<string>}): t
|
|
@@ -84,7 +93,8 @@ module Make = (Lenses: Lenses) => {
|
|
|
84
93
|
|
|
85
94
|
let email = (~error=?, field) => [Email({field, error})]
|
|
86
95
|
let phone = (~error=?, field) => [Phone({field, error})]
|
|
87
|
-
let password = (~error=?, field) => [Password({field, error})]
|
|
96
|
+
let password = (~error=?, ~login=?, field) => [Password({field, ?login, error})]
|
|
97
|
+
let optionalPassword = (~error=?, field) => [OptionalPassword({field, error})]
|
|
88
98
|
|
|
89
99
|
let nonEmpty = (~error=?, field) => [StringNonEmpty({field, error})]
|
|
90
100
|
|
|
@@ -218,15 +228,38 @@ module Make = (Lenses: Lenses) => {
|
|
|
218
228
|
}
|
|
219
229
|
},
|
|
220
230
|
)
|
|
221
|
-
| Validation.Password(
|
|
222
|
-
let value = Lenses.get(values, field)
|
|
231
|
+
| Validation.Password(fields) => {
|
|
232
|
+
let value = Lenses.get(values, fields.field)
|
|
223
233
|
|
|
224
234
|
(
|
|
225
|
-
Field(field),
|
|
226
|
-
switch value {
|
|
227
|
-
| "" => Error(i18n.stringNonEmpty(~value=""))
|
|
228
|
-
| password
|
|
229
|
-
|
|
235
|
+
Field(fields.field),
|
|
236
|
+
switch (value, fields.login->Option.map(fn => fn(values))) {
|
|
237
|
+
| ("", _) => Error(i18n.stringNonEmpty(~value=""))
|
|
238
|
+
| (password, _)
|
|
239
|
+
if !Js.Re.test_(%re("/(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{10,}/"), password) =>
|
|
240
|
+
Error(fields.error->Option.getWithDefault(i18n.passwordTooShort))
|
|
241
|
+
| (p, Some(login))
|
|
242
|
+
if p->Js.String2.toLowerCase->Js.String2.includes(login->Js.String2.toLowerCase) =>
|
|
243
|
+
Error(i18n.passwordCantContainLogin)
|
|
244
|
+
|
|
245
|
+
| _ => Valid
|
|
246
|
+
},
|
|
247
|
+
)
|
|
248
|
+
}
|
|
249
|
+
| Validation.OptionalPassword(fields) => {
|
|
250
|
+
let value = Lenses.get(values, fields.field)
|
|
251
|
+
|
|
252
|
+
(
|
|
253
|
+
Field(fields.field),
|
|
254
|
+
switch (value, fields.login->Option.map(fn => fn(values))) {
|
|
255
|
+
| ("", _) => Error(i18n.stringNonEmpty(~value=""))
|
|
256
|
+
| (password, _)
|
|
257
|
+
if !Js.Re.test_(%re("/(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{10,}/"), password) =>
|
|
258
|
+
Error(fields.error->Option.getWithDefault(i18n.passwordTooShort))
|
|
259
|
+
| (p, Some(login))
|
|
260
|
+
if p->Js.String2.toLowerCase->Js.String2.includes(login->Js.String2.toLowerCase) =>
|
|
261
|
+
Error(i18n.passwordCantContainLogin)
|
|
262
|
+
|
|
230
263
|
| _ => Valid
|
|
231
264
|
},
|
|
232
265
|
)
|
|
@@ -330,6 +363,7 @@ module Make = (Lenses: Lenses) => {
|
|
|
330
363
|
| Validation.FloatMax({field}) => Field(field) == fieldName
|
|
331
364
|
| Validation.Email({field}) => Field(field) == fieldName
|
|
332
365
|
| Validation.Password({field}) => Field(field) == fieldName
|
|
366
|
+
| Validation.OptionalPassword({field}) => Field(field) == fieldName
|
|
333
367
|
| Validation.NoValidation({field}) => Field(field) == fieldName
|
|
334
368
|
| Validation.StringNonEmpty({field}) => Field(field) == fieldName
|
|
335
369
|
| Validation.StringRegExp({field}) => Field(field) == fieldName
|
|
@@ -351,6 +385,7 @@ module Make = (Lenses: Lenses) => {
|
|
|
351
385
|
| Validation.Phone({field}) => Field(field) == fieldName
|
|
352
386
|
| Validation.True({field}) => Field(field) == fieldName
|
|
353
387
|
| Validation.Password({field}) => Field(field) == fieldName
|
|
388
|
+
| Validation.OptionalPassword({field}) => Field(field) == fieldName
|
|
354
389
|
| Validation.IntMin({field}) => Field(field) == fieldName
|
|
355
390
|
| Validation.IntMax({field}) => Field(field) == fieldName
|
|
356
391
|
| Validation.FloatMin({field}) => Field(field) == fieldName
|
|
@@ -12,6 +12,7 @@ type t = {
|
|
|
12
12
|
stringMax: (~value: string, ~max: int) => string,
|
|
13
13
|
phone: string,
|
|
14
14
|
passwordTooShort: string,
|
|
15
|
+
passwordCantContainLogin: string,
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
let default = {
|
|
@@ -35,4 +36,5 @@ let default = {
|
|
|
35
36
|
`Le champ doit avoir au maximum ${max->Int.toString} caractères.`,
|
|
36
37
|
phone: "Format du numéro invalide. Ex : +33612345678",
|
|
37
38
|
passwordTooShort: "Le mot de passe doit contenir au moins 10 caractères, avoir au moins 1 minuscule, 1 majuscule et un chiffre.",
|
|
39
|
+
passwordCantContainLogin: "Le mot de passe ne peut pas contenir l'identifiant.",
|
|
38
40
|
}
|
package/src/form/Reform.res
CHANGED
|
@@ -113,6 +113,7 @@ module Make = (Config: Config) => {
|
|
|
113
113
|
| Validation.Email({field}) => (Field(field), Pristine)
|
|
114
114
|
| Validation.Phone({field}) => (Field(field), Pristine)
|
|
115
115
|
| Validation.Password({field}) => (Field(field), Pristine)
|
|
116
|
+
| Validation.OptionalPassword({field}) => (Field(field), Pristine)
|
|
116
117
|
| Validation.NoValidation({field}) => (Field(field), Pristine)
|
|
117
118
|
| Validation.StringNonEmpty({field}) => (Field(field), Pristine)
|
|
118
119
|
| Validation.StringRegExp({field}) => (Field(field), Pristine)
|