@colisweb/rescript-toolkit 5.14.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colisweb/rescript-toolkit",
3
- "version": "5.14.0",
3
+ "version": "5.15.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "clean": "rescript clean",
@@ -28,8 +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({field: Lenses.field<string>, error: option<string>}): t
32
- | OptionalPassword({field: Lenses.field<string>, error: option<string>}): t
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
33
41
  | NoValidation({field: Lenses.field<'a>}): t
34
42
  | StringNonEmpty({field: Lenses.field<string>, error: option<string>}): t
35
43
  | StringRegExp({field: Lenses.field<string>, matches: string, error: option<string>}): t
@@ -85,7 +93,7 @@ module Make = (Lenses: Lenses) => {
85
93
 
86
94
  let email = (~error=?, field) => [Email({field, error})]
87
95
  let phone = (~error=?, field) => [Phone({field, error})]
88
- let password = (~error=?, field) => [Password({field, error})]
96
+ let password = (~error=?, ~login=?, field) => [Password({field, ?login, error})]
89
97
  let optionalPassword = (~error=?, field) => [OptionalPassword({field, error})]
90
98
 
91
99
  let nonEmpty = (~error=?, field) => [StringNonEmpty({field, error})]
@@ -220,28 +228,38 @@ module Make = (Lenses: Lenses) => {
220
228
  }
221
229
  },
222
230
  )
223
- | Validation.Password({field, error}) => {
224
- let value = Lenses.get(values, field)
231
+ | Validation.Password(fields) => {
232
+ let value = Lenses.get(values, fields.field)
225
233
 
226
234
  (
227
- Field(field),
228
- switch value {
229
- | "" => Error(i18n.stringNonEmpty(~value=""))
230
- | password if !Js.Re.test_(%re("/(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{10,}/"), password) =>
231
- Error(error->Option.getWithDefault(i18n.passwordTooShort))
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
+
232
245
  | _ => Valid
233
246
  },
234
247
  )
235
248
  }
236
- | Validation.OptionalPassword({field, error}) => {
237
- let value = Lenses.get(values, field)
249
+ | Validation.OptionalPassword(fields) => {
250
+ let value = Lenses.get(values, fields.field)
238
251
 
239
252
  (
240
- Field(field),
241
- switch value {
242
- | "" => Valid
243
- | password if !Js.Re.test_(%re("/(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{10,}/"), password) =>
244
- Error(error->Option.getWithDefault(i18n.passwordTooShort))
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
+
245
263
  | _ => Valid
246
264
  },
247
265
  )
@@ -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
  }