@arc-js/jon 0.0.1

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/README.md ADDED
@@ -0,0 +1,1391 @@
1
+ # @arc-js/jon
2
+
3
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
4
+ ![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-007ACC)
5
+ ![Browser](https://img.shields.io/badge/browser-compatible-green)
6
+ ![Node.js](https://img.shields.io/badge/Node.js-18+-339933)
7
+
8
+ **@arc-js/jon** est une bibliothèque TypeScript conçue pour la validation et la gestion des schémas de données. Elle offre une solution robuste pour valider les types de données, gérer les erreurs, et supporter une variété de types de données complexes.
9
+
10
+ ## ✨ Fonctionnalités Principales
11
+
12
+ ### 📝 Validation de Schéma
13
+ - **Types de données variés** : String, Number, Boolean, Date, Enum, Array, Object, File, etc.
14
+ - **Gestion intelligente des erreurs** : Messages d'erreur personnalisables et support multi-langue.
15
+ - **Validation flexible** : Règles de validation personnalisées pour chaque type de données.
16
+
17
+ ### 🌐 Intégration Facile
18
+ - **Utilisation simple** : Intégration facile avec les applications web et Node.js.
19
+ - **Support des navigateurs** : Compatible avec les navigateurs modernes.
20
+
21
+ ## 📦 Installation
22
+
23
+ ### Via npm/yarn/pnpm
24
+
25
+ ```bash
26
+ npm install @arc-js/jon
27
+ # ou
28
+ yarn add @arc-js/jon
29
+ # ou
30
+ pnpm add @arc-js/jon
31
+ ```
32
+
33
+ ### Importation directe (CDN)
34
+
35
+ ```html
36
+ <script src="@arc-js/jon/jon.all.js"></script>
37
+ ```
38
+
39
+ ## 🚀 Utilisation
40
+
41
+ ### Importation des Schémas
42
+
43
+ ```typescript
44
+ import {
45
+ StringSchema,
46
+ NumberSchema,
47
+ BooleanSchema,
48
+ DateSchema,
49
+ EnumSchema,
50
+ NotEnumSchema,
51
+ ArraySchema,
52
+ ObjectSchema,
53
+ FileSchema
54
+ } from '@arc-js/jon';
55
+ ```
56
+
57
+ ### Exemples de Validation
58
+
59
+ #### Validation de String
60
+
61
+ ```typescript
62
+ const stringSchema = new StringSchema({ minLength: 5, maxLength: 10 });
63
+ const result = stringSchema.validate("Bonjour");
64
+ console.log(result.valid); // true ou false
65
+ ```
66
+
67
+ #### Validation de Number
68
+
69
+ ```typescript
70
+ const numberSchema = new NumberSchema({ min: 0, max: 100 });
71
+ const result = numberSchema.validate(50);
72
+ console.log(result.valid); // true ou false
73
+ ```
74
+
75
+ #### Validation de Boolean
76
+
77
+ ```typescript
78
+ const booleanSchema = new BooleanSchema();
79
+ const result = booleanSchema.validate(true);
80
+ console.log(result.valid); // true ou false
81
+ ```
82
+
83
+ #### Validation de Date
84
+
85
+ ```typescript
86
+ const dateSchema = new DateSchema();
87
+ const result = dateSchema.validate(new Date());
88
+ console.log(result.valid); // true ou false
89
+ ```
90
+
91
+ #### Validation de Enum
92
+
93
+ ```typescript
94
+ const enumSchema = new EnumSchema(["valeur1", "valeur2", "valeur3"]);
95
+ const result = enumSchema.validate("valeur1");
96
+ console.log(result.valid); // true ou false
97
+ ```
98
+
99
+ #### Validation de Array
100
+
101
+ ```typescript
102
+ const arraySchema = new ArraySchema({ minItems: 1, maxItems: 5 });
103
+ const result = arraySchema.validate([1, 2, 3]);
104
+ console.log(result.valid); // true ou false
105
+ ```
106
+
107
+ #### Validation de Object
108
+
109
+ ```typescript
110
+ const objectSchema = new ObjectSchema({
111
+ name: new StringSchema({ minLength: 2 }),
112
+ age: new NumberSchema({ min: 0 })
113
+ });
114
+ const result = objectSchema.validate({ name: "Alice", age: 30 });
115
+ console.log(result.valid); // true ou false
116
+ ```
117
+
118
+ #### Validation de File
119
+
120
+ ```typescript
121
+ const fileSchema = new FileSchema({ allowedExtensions: ["pdf", "docx"] });
122
+ const result = fileSchema.validate(new File(["contenu"], "fichier.pdf"));
123
+ console.log(result.valid); // true ou false
124
+ ```
125
+
126
+ ## Structure du Projet
127
+
128
+ ```
129
+ @arc-js/jon/
130
+ ├── jon.all.js
131
+ ├── jon.all.min.js
132
+ ├── index.d.ts
133
+ ├── index.js
134
+ ├── index.min.d.ts
135
+ ├── index.min.js
136
+ ├── package.json
137
+ ├── tsconfig.json
138
+ └── README.md
139
+ ```
140
+
141
+ ## 📜 Licence
142
+
143
+ Ce projet est sous licence MIT. Voir le fichier [LICENSE](LICENSE) pour plus de détails.
144
+
145
+ ## 📄 Démonstrations
146
+
147
+ ### 🔤 String (Chaîne de caractères)
148
+
149
+ ```typescript
150
+ // Vérification du type string
151
+ const value = "billy chaud";
152
+ const schema = (new JON.String(lang)).label('string1');
153
+ schema.validate(value);
154
+
155
+ // Vérification du type string - Echec
156
+ const value = [];
157
+ const schema = (new JON.String(lang)).label('string1');
158
+ schema.validate(value);
159
+
160
+ // Vérification du type string
161
+ const value = "billy chaud";
162
+ const schema = (new JON.String(lang)).label('string1').min(5).max(10);
163
+ schema.validate(value);
164
+
165
+ // Vérification du type string
166
+ const value = "billy chaud";
167
+ const schema = (new JON.String(lang)).label('string1').label('string1').less(5).greater(10);
168
+ schema.validate(value);
169
+
170
+ // Vérification du type string
171
+ const value = "billy";
172
+ const schema = (new JON.String(lang)).label('string1').length(5);
173
+ schema.validate(value);
174
+
175
+ // Regex Vérification du type string
176
+ const value = "bonjour billy chaud";
177
+ const schema = (new JON.String(lang)).label('string1').regexp("^bonjour");
178
+ schema.validate(value);
179
+
180
+ // Regex Vérification du type string - Echec
181
+ const value = "bonjour billy chaud";
182
+ const schema = (new JON.String(lang)).label('string1').regexp("^Bonjour");
183
+ schema.validate(value);
184
+
185
+ // Alphanumerique Vérification du type string
186
+ const value = "bonjour billy";
187
+ const schema = (new JON.String(lang)).label('string1').alphanum();
188
+ schema.validate(value);
189
+
190
+ // Alphanumerique Vérification du type string - echec
191
+ const value = "bonjour billy chaud@";
192
+ const schema = (new JON.String(lang)).label('string1').alphanum();
193
+ schema.validate(value);
194
+
195
+ // Minuscule || Vérification du type string
196
+ const value = "bonjour Moniseur BILONG Célestin, comment allez-vous?";
197
+ const schema = (new JON.String(lang)).label('string1').lowercase();
198
+ schema.validate(value);
199
+
200
+ // Majuscule || Vérification du type string
201
+ const value = "bonjour Moniseur BILONG Célestin, comment allez-vous?";
202
+ const schema = (new JON.String(lang)).label('string1').uppercase();
203
+ schema.validate(value);
204
+
205
+ // La première lettre de chaque mot en majuscule || Vérification du type string
206
+ const value = "bonjour Moniseur BILONG Célestin, comment allez-vous?";
207
+ const schema = (new JON.String(lang)).label('string1').capitalize();
208
+ schema.validate(value);
209
+
210
+ // La première lettre de la phrase en majuscule || Vérification du type string
211
+ const value = "bonjour Moniseur BILONG Célestin, comment allez-vous?";
212
+ const schema = (new JON.String(lang)).label('string1').ucFirst();
213
+ schema.validate(value);
214
+
215
+ // Verification de carte de credit
216
+ const value = '378282246310005';
217
+ const schema = (new JON.String(lang)).label('string1').creditCard();
218
+ schema.validate(value);
219
+
220
+ // Verification de carte de credit - Echec
221
+ const value = 'lorpem ipsum';
222
+ const schema = (new JON.String(lang)).label('string1').creditCard();
223
+ schema.validate(value);
224
+
225
+ // American Card | Verification de carte de credit
226
+ const value = '378734493671000';
227
+ const schema = (new JON.String(lang)).label('string1').creditCard(
228
+ [ 'american-express' ]
229
+ );
230
+ schema.validate(value);
231
+
232
+ // Discover | Verification de carte de credit
233
+ const value = '6011000990139424';
234
+ const schema = (new JON.String(lang)).label('string1').creditCard(
235
+ [ 'discover' ]
236
+ );
237
+ schema.validate(value);
238
+
239
+ // Diners Club | Verification de carte de credit
240
+ const value = '38520000023237';
241
+ const schema = (new JON.String(lang)).label('string1').creditCard(
242
+ [ 'diners-club' ]
243
+ );
244
+ schema.validate(value);
245
+
246
+ // JCB | Verification de carte de credit
247
+ const value = '3530111333300000';
248
+ const schema = (new JON.String(lang)).label('string1').creditCard(
249
+ [ 'jcb' ]
250
+ );
251
+ schema.validate(value);
252
+
253
+ // Visa | Verification de carte de credit
254
+ const value = '3530111333300000';
255
+ const schema = (new JON.String(lang)).label('string1').creditCard(
256
+ [ 'jcb' ]
257
+ );
258
+ schema.validate(value);
259
+
260
+ // MasterCard | Verification de carte de credit
261
+ const value = '5555555555554444';
262
+ const schema = (new JON.String(lang)).label('string1').creditCard(
263
+ [ 'master-card' ]
264
+ );
265
+ schema.validate(value);
266
+
267
+ // Visa | Verification de carte de credit
268
+ const value = '4111111111111111';
269
+ const schema = (new JON.String(lang)).label('string1').creditCard(
270
+ [ 'visa' ]
271
+ );
272
+ schema.validate(value);
273
+
274
+ // UBA Card (Visa && Master-card) | Verification de carte de credit
275
+ const value = '4012888888881881';
276
+ const schema = (new JON.String(lang)).label('string1').creditCard(
277
+ [ 'visa', 'master-card' ]
278
+ );
279
+ schema.validate(value);
280
+
281
+ // Data URI | Verification de Data URI
282
+ const value = 'data:image/gif;base64,R0lGODdhAQABAPAAAP8AAAAAACwAAAAAAQABAAACAkQBADs';
283
+ const schema = (new JON.String(lang)).label('string1').dataUri();
284
+ schema.validate(value);
285
+
286
+ // Data URI | Verification de Data URI - Echec
287
+ const value = '4012888888881881';
288
+ const schema = (new JON.String(lang)).label('string1').dataUri();
289
+ schema.validate(value);
290
+
291
+ // Domain | Verification de Domain
292
+ const value = "example.domain.com";
293
+ const schema = (new JON.String(lang)).label('string1').domain();
294
+ schema.validate(value);
295
+
296
+ // Domain | Verification de Domain - Echec
297
+ const value = '4012888888881881';
298
+ const schema = (new JON.String(lang)).label('string1').domain();
299
+ schema.validate(value);
300
+
301
+ // Url | Verification de Url
302
+ const value = "255.255.255.255";
303
+ const schema = (new JON.String(lang)).label('string1').url();
304
+ schema.validate(value);
305
+
306
+ // Url | Verification de Url
307
+ const value = '4012888888881881';
308
+ const schema = (new JON.String(lang)).label('string1').url();
309
+ schema.validate(value);
310
+
311
+ // Nom d'hôte | Verification de Nom d'hôte
312
+ const value = "255.255.255.255";
313
+ const schema = (new JON.String(lang)).label('string1').hostname();
314
+ schema.validate(value);
315
+
316
+ // Nom d'hôte | Verification de Nom d'hôte
317
+ const value = '4012888888881881';
318
+ const schema = (new JON.String(lang)).label('string1').hostname();
319
+ schema.validate(value);
320
+
321
+ // Adresse IP | Verification de Adresse IP
322
+ const value = '912.456.123.123';
323
+ const schema = (new JON.String(lang)).label('string1').IPAddress();
324
+ schema.validate(value);
325
+
326
+ // Adresse IP | Verification de Adresse IP
327
+ const value = "lorem ipsum";
328
+ const schema = (new JON.String(lang)).label('string1').IPAddress();
329
+ schema.validate(value);
330
+
331
+ // IPV4 | Verification de Adresse IP
332
+ const value = "192.168.1.1";
333
+ const schema = (new JON.String(lang)).label('string1').IPAddress(['ipv4']);
334
+ schema.validate(value);
335
+
336
+ // IPV6 | Verification de Adresse IP
337
+ const value = "21DA:D3:0:2F3B:2AA:FF:FE28:9C5A";
338
+ const schema = (new JON.String(lang)).label('string1').IPAddress(['ipv6']);
339
+ schema.validate(value);
340
+
341
+ // Email | Verification de Email
342
+ const value = 'bilongntouba.celestin@gmail.com';
343
+ const schema = (new JON.String(lang)).label('string1').email();
344
+ schema.validate(value);
345
+
346
+ // Email | Verification de Email
347
+ const value = "lorem ipsum";
348
+ const schema = (new JON.String(lang)).label('string1').email();
349
+ schema.validate(value);
350
+
351
+ // UUID | Verification de UUID
352
+ const value = '0D8B604A-59C7-4F44-A385-2FA6DE4CFA0C';
353
+ const schema = (new JON.String(lang)).label('string1').guid();
354
+ schema.validate(value);
355
+
356
+ // UUID | Verification de UUID - Echec
357
+ const value = "lorem ipsum";
358
+ const schema = (new JON.String(lang)).label('string1').guid();
359
+ schema.validate(value);
360
+
361
+ // UUID V1 | Verification de UUID
362
+ const value = '12345678-1234-1678-9234-567812345678';
363
+ const schema = (new JON.String(lang)).label('string1').guid(['v1']);
364
+ schema.validate(value);
365
+
366
+ // UUID V2 | Verification de UUID
367
+ const value = '12345678-1234-2678-8234-567812345678';
368
+ const schema = (new JON.String(lang)).label('string1').guid(['v2']);
369
+ schema.validate(value);
370
+
371
+ // UUID V3 | Verification de UUID
372
+ const value = '12345678-1234-3678-8234-567812345678';
373
+ const schema = (new JON.String(lang)).label('string1').guid(['v3']);
374
+ schema.validate(value);
375
+
376
+ // UUID V4 | Verification de UUID
377
+ const value = '12345678-1234-4678-8234-567812345678';
378
+ const schema = (new JON.String(lang)).label('string1').guid(['v4']);
379
+ schema.validate(value);
380
+
381
+ // UUID V5 | Verification de UUID
382
+ const value = '12345678-1234-5678-8234-567812345678';
383
+ const schema = (new JON.String(lang)).label('string1').guid(['v5']);
384
+ schema.validate(value);
385
+
386
+ // Hexadecimal | Verification de Hexadecimal
387
+ const value = '1A2B3C4D5E6F7890';
388
+ const schema = (new JON.String(lang)).label('string1').hexa();
389
+ schema.validate(value);
390
+
391
+ // Hexadecimal | Verification de Hexadecimal - Echec
392
+ const value = "hello123";
393
+ const schema = (new JON.String(lang)).label('string1').hexa();
394
+ schema.validate(value);
395
+
396
+ // Hexadecimal | Verification de Hexadecimal
397
+ const value = '1A2B3C4D5E6F7890';
398
+ const schema = (new JON.String(lang)).label('string1').hexa();
399
+ schema.validate(value);
400
+
401
+ // Hexadecimal | Verification de Hexadecimal - Echec
402
+ const value = "hello123";
403
+ const schema = (new JON.String(lang)).label('string1').hexa();
404
+ schema.validate(value);
405
+
406
+ // Binaire | Verification de Binaire
407
+ const value = '010100';
408
+ const schema = (new JON.String(lang)).label('string1').binary();
409
+ schema.validate(value);
410
+
411
+ // Binaire | Verification de Binaire - Echec
412
+ const value = "hello123";
413
+ const schema = (new JON.String(lang)).label('string1').binary();
414
+ schema.validate(value);
415
+
416
+ // Date | Verification de Date
417
+ const value = '2021/03/30 - 05:01:20';
418
+ const schema = (new JON.String(lang)).label('string1').date('%Y/%m/%d - %H:%M:%S');
419
+ schema.validate(value);
420
+
421
+ // Date | Verification de Date - Echec
422
+ const value = "hello123";
423
+ const schema = (new JON.String(lang)).label('string1').date('%Y/%m/%d - %H:%M:%S');
424
+ schema.validate(value);
425
+
426
+ // Identifiant | Verification de Identifiant
427
+ const value = 'celest';
428
+ const schema = (new JON.String(lang)).label('string1').identifier();
429
+ schema.validate(value);
430
+
431
+ // Identifiant | Verification de Identifiant - Echec
432
+ const value = "hello 123";
433
+ const schema = (new JON.String(lang)).label('string1').identifier();
434
+ schema.validate(value);
435
+
436
+ // Erreur par defaut | Verification de Erreur par defaut
437
+ const value = 'hello 123';
438
+ const schema = (new JON.String(lang)).label('default-error').identifier().defaultError("[CUSTOM] Rassurer vous d'entrer un identifiant");
439
+ schema.validate(value);
440
+
441
+ // Ajouter un ecouteur en cas d'erreur | Verification d'une chaîne de caractère
442
+ function mapError(
443
+ res,
444
+ error,
445
+ ruleName = undefined,
446
+ label = undefined,
447
+ lang = 'fr'
448
+ ) {
449
+ console.log("\n>----------------------");
450
+ console.log("[CUSTOM] -- JON - mapError | error:: ", error);
451
+ console.log("[CUSTOM] -- JON - mapError | ruleName:: ", ruleName);
452
+ console.log("[CUSTOM] -- JON - mapError | label:: ", label);
453
+ console.log("[CUSTOM] -- JON - mapError | lang:: ", lang);
454
+ console.log("\n");
455
+ console.log("[CUSTOM] -- JON - mapError | error:: ", error);
456
+ console.log("[CUSTOM] -- JON - mapError | res:: ", res);
457
+ console.log("-------------------------<");
458
+ return res;
459
+ }
460
+ const value = '456 hello 123';
461
+ const schema = (new JON.String(lang)).label('error-listener').identifier().initMapError(mapError);
462
+ schema.validate(value);
463
+
464
+ ```
465
+
466
+ ### 🔢 Number (Nombre)
467
+
468
+ ```typescript
469
+ // Vérification du type number
470
+ const value = 17;
471
+ const schema = (new JON.Number(lang)).required().default(10).label('entier1');
472
+ schema.validate(value);
473
+
474
+ // Vérification du type number - Echec
475
+ const value = false;
476
+ const schema = (new JON.Number(lang)).required().default(10).label('entier1');
477
+ schema.validate(value);
478
+
479
+ // Minimum | Vérification du type number
480
+ const value = 20;
481
+ const schema = (new JON.Number(lang)).min(5).required().label('entier1');
482
+ schema.validate(value);
483
+
484
+ // Minimum | Vérification du type number - Echec
485
+ const value = 4;
486
+ const schema = (new JON.Number(lang)).min(5).required().label('entier1');
487
+ schema.validate(value);
488
+
489
+ // Maximum | Vérification du type number
490
+ const value = 45;
491
+ const schema = (new JON.Number(lang)).max(50).required().label('entier1');
492
+ schema.validate(value);
493
+
494
+ // Maximum | Vérification du type number - Echec
495
+ const value = 100;
496
+ const schema = (new JON.Number(lang)).max(50).required().label('entier1');
497
+ schema.validate(value);
498
+
499
+ // Strictement inferieur | Vérification du type number
500
+ const value = 6;
501
+ const schema = (new JON.Number(lang)).less(5).required().label('entier1');
502
+ schema.validate(value);
503
+
504
+ // Strictement inferieur | Vérification du type number - Echec
505
+ const value = 5;
506
+ const schema = (new JON.Number(lang)).less(5).required().label('entier1');
507
+ schema.validate(value);
508
+
509
+ // Strictement superieur | Vérification du type number
510
+ const value = 4;
511
+ const schema = (new JON.Number(lang)).greater(5).required().label('entier1');
512
+ schema.validate(value);
513
+
514
+ // Strictement superieur | Vérification du type number - Echec
515
+ const value = 5;
516
+ const schema = (new JON.Number(lang)).greater(5).required().label('entier1');
517
+ schema.validate(value);
518
+
519
+ // Negatif | Vérification du type number
520
+ const value = -20;
521
+ const schema = (new JON.Number(lang)).negative().required().label('entier1');
522
+ schema.validate(value);
523
+
524
+ // Negatif | Vérification du type number - Echec
525
+ const value = 5;
526
+ const schema = (new JON.Number(lang)).negative().required().label('entier1');
527
+ schema.validate(value);
528
+
529
+ // Positif | Vérification du type number
530
+ const value = 25;
531
+ const schema = (new JON.Number(lang)).positive().required().label('entier1');
532
+ schema.validate(value);
533
+
534
+ // Positif | Vérification du type number - Echec
535
+ const value = -5;
536
+ const schema = (new JON.Number(lang)).positive().required().label('entier1');
537
+ schema.validate(value);
538
+
539
+ // Nombre signé | Vérification du type number
540
+ const value = 20;
541
+ const schema = (new JON.Number(lang)).signed().required().label('entier1');
542
+ schema.validate(value);
543
+
544
+ // Nombre signé | Vérification du type number - Echec
545
+ const value = 0;
546
+ const schema = (new JON.Number(lang)).signed().required().label('entier1');
547
+ schema.validate(value);
548
+
549
+ // Entier | Vérification du type number
550
+ const value = 25;
551
+ const schema = (new JON.Number(lang)).integer().required().label('entier1');
552
+ schema.validate(value);
553
+
554
+ // Entier | Vérification du type number - Echec
555
+ const value = 15.6;
556
+ const schema = (new JON.Number(lang)).integer().required().label('entier1');
557
+ schema.validate(value);
558
+
559
+ // Decimal | Vérification du type number
560
+ const value = 15.6;
561
+ const schema = (new JON.Number(lang)).decimal().required().label('entier1');
562
+ schema.validate(value);
563
+
564
+ // Multiple | Vérification du type number
565
+ const value = 6;
566
+ const schema = (new JON.Number(lang)).multiple(3).label('entier1');
567
+ schema.validate(value);
568
+
569
+ // Multiple | Vérification du type number - Echec
570
+ const value = 8;
571
+ const schema = (new JON.Number(lang)).multiple(3).label('entier1');
572
+ schema.validate(value);
573
+
574
+ // Port | Vérification du type number
575
+ const value = 80;
576
+ const schema = (new JON.Number(lang)).TCPPort().label('entier1');
577
+ schema.validate(value);
578
+
579
+ // Port | Vérification du type number - Echec
580
+ const value = 74654646;
581
+ const schema = (new JON.Number(lang)).TCPPort().label('entier1');
582
+ schema.validate(value);
583
+ ```
584
+
585
+ ### ✔️ Boolean (Booléen)
586
+
587
+ ```typescript
588
+ // Vérification du type Boolean
589
+ const value = true;
590
+ const schema = (new JON.Boolean(lang)).required().label('entier1');
591
+ schema.validate(value);
592
+
593
+ // Vérification du type Boolean - Echec
594
+ const value = 5656;
595
+ const schema = (new JON.Boolean(lang)).required().label('entier1');
596
+ schema.validate(value);
597
+ ```
598
+
599
+ ### 📅 Date
600
+
601
+ ```typescript
602
+
603
+ // Vérification du type Date
604
+ const value = '2020/10/19';
605
+ const schema = (new JON.Date(lang)).required().label('date1').changeFormat('%Y/%m/%d');
606
+ schema.validate(value);
607
+
608
+ // Vérification du type Date - Echec
609
+ const value = true;
610
+ const schema = (new JON.Date(lang)).required().label('date1').changeFormat('%Y/%m/%d');
611
+ schema.validate(value);
612
+
613
+ // Inferieur ou égale à | Vérification du type Date
614
+ const value = '2020/10/19';
615
+ const schema = (new JON.Date(lang)).required().label('date1').changeFormat('%Y/%m/%d').min('2019/09/03');
616
+ schema.validate(value);
617
+
618
+ // Inferieur ou égale à | Vérification du type Date - Echec
619
+ const value = '2018/01/01';
620
+ const schema = (new JON.Date(lang)).required().label('date1').changeFormat('%Y/%m/%d').min('2019/09/03');
621
+ schema.validate(value);
622
+
623
+ // Supérieur ou égale à | Vérification du type Date
624
+ const value = '2022/10/19';
625
+ const schema = (new JON.Date(lang)).required().label('date1').changeFormat('%Y/%m/%d').max('2026/08/02');
626
+ schema.validate(value);
627
+
628
+ // Supérieur ou égale à | Vérification du type Date - Echec
629
+ const value = '2030/01/01';
630
+ const schema = (new JON.Date(lang)).required().label('date1').changeFormat('%Y/%m/%d').max('2026/08/02');
631
+ schema.validate(value);
632
+
633
+ // Inferieur à | Vérification du type Date
634
+ const value = '2020/10/19';
635
+ const schema = (new JON.Date(lang)).required().label('date1').changeFormat('%Y/%m/%d').less('2019/09/03');
636
+ schema.validate(value);
637
+
638
+ // Inferieur à | Vérification du type Date - Echec
639
+ const value = '2018/01/01';
640
+ const schema = (new JON.Date(lang)).required().label('date1').changeFormat('%Y/%m/%d').less('2018/01/01');
641
+ schema.validate(value);
642
+
643
+ // Supérieur à | Vérification du type Date
644
+ const value = '2022/10/19';
645
+ const schema = (new JON.Date(lang)).required().label('date1').changeFormat('%Y/%m/%d').greater('2026/08/02');
646
+ schema.validate(value);
647
+
648
+ // Supérieur à | Vérification du type Date - Echec
649
+ const value = '2030/01/01';
650
+ const schema = (new JON.Date(lang)).required().label('date1').changeFormat('%Y/%m/%d').greater('2030/01/01');
651
+ schema.validate(value);
652
+
653
+ // Egale à | Vérification du type Date
654
+ const value = '2022/10/19';
655
+ const schema = (new JON.Date(lang)).required().label('date1').changeFormat('%Y/%m/%d').equalTo('2022/10/19');
656
+ schema.validate(value);
657
+
658
+ // Egale à | Vérification du type Date - Echec
659
+ const value = '2030/01/01';
660
+ const schema = (new JON.Date(lang)).required().label('date1').changeFormat('%Y/%m/%d').equalTo('2035/01/01');
661
+ schema.validate(value);
662
+ ```
663
+
664
+ ### 📊 Array (Tableau)
665
+
666
+ ```typescript
667
+ // Vérification du type array
668
+ const value = [ 'lorem', 'ipsum', 'dolor' ];
669
+ const schema = (new JON.Array(lang)).label('array1');
670
+ schema.validate(value);
671
+
672
+ // Vérification du type array - Echec
673
+ const value = 'lorem';
674
+ const schema = (new JON.Array(lang)).label('array1');
675
+ schema.validate(value);
676
+
677
+ // Contient un ou plusieurs types predefinis | Vérification du type array
678
+ const value = [ true, 42, false, 3.14 ];
679
+ const schema = (new JON.Array(lang)).label('array1').types(
680
+ new JON.Boolean(lang).required(),
681
+ new JON.Number(lang).required(),
682
+ );
683
+ schema.validate(value);
684
+
685
+ // Contient un ou plusieurs types predefinis | Vérification du type array - Echec
686
+ const value = [ 'tt', 'lorem' ];
687
+ const schema = (new JON.Array(lang)).label('array1').types(
688
+ new JON.Boolean(lang).required(),
689
+ new JON.Number(lang).required(),
690
+ );
691
+ schema.validate(value);
692
+
693
+ // Contient au minimum n valeur(s) | Vérification du type array
694
+ const value = [
695
+ "Doe",
696
+ "Smith",
697
+ "Johnson"
698
+ ];
699
+ const schema = (new JON.Array(lang)).min(2).label('array1').required();
700
+ schema.validate(value);
701
+
702
+ // Contient au minimum n valeur(s) | Vérification du type array - Echec
703
+ const value = [
704
+ "Doe"
705
+ ];
706
+ const schema = (new JON.Array(lang)).min(2).label('array1').required();
707
+ schema.validate(value);
708
+
709
+ // Contient au maximum n valeur(s) | Vérification du type array
710
+ const value = [
711
+ "John",
712
+ 30,
713
+ true,
714
+ {
715
+ street: "123 Main St",
716
+ city: "Anytown",
717
+ zip: "12345"
718
+ }
719
+ ];
720
+ const schema = (new JON.Array(lang)).max(5).label('array1').required();
721
+ schema.validate(value);
722
+
723
+ // Contient au minimum n valeur(s) | Vérification du type array - Echec
724
+ const value = [
725
+ "John",
726
+ 30,
727
+ true,
728
+ {
729
+ street: "123 Main St",
730
+ city: "Anytown",
731
+ zip: "12345"
732
+ },
733
+ 'extra value',
734
+ 999
735
+ ];
736
+ const schema = (new JON.Array(lang)).max(5).label('array1').required();
737
+ schema.validate(value);
738
+
739
+ // Contient au minimum n valeur(s) (n non inclus) | Vérification du type array
740
+ const value = [
741
+ "Doe",
742
+ "Smith",
743
+ "Johnson"
744
+ ];
745
+ const schema = (new JON.Array(lang)).greater(1).label('array1').required();
746
+ schema.validate(value);
747
+
748
+ // Contient au minimum n valeur(s) (n non inclus) | Vérification du type array - Echec
749
+ const value = [
750
+ "Doe"
751
+ ];
752
+ const schema = (new JON.Array(lang)).greater(1).label('array1').required();
753
+ schema.validate(value);
754
+
755
+ // Contient au maximum n valeur(s) (n non inclus) | Vérification du type array
756
+ const value = [
757
+ "John",
758
+ 30,
759
+ true,
760
+ {
761
+ street: "123 Main St",
762
+ city: "Anytown",
763
+ zip: "12345"
764
+ }
765
+ ];
766
+ const schema = (new JON.Array(lang)).less(5).label('array1').required();
767
+ schema.validate(value);
768
+
769
+ // Contient au maximum n valeur(s) (n non inclus) | Vérification du type array - Echec
770
+ const value = [
771
+ "John",
772
+ 30,
773
+ true,
774
+ {
775
+ street: "123 Main St",
776
+ city: "Anytown",
777
+ zip: "12345"
778
+ },
779
+ 'extra value'
780
+ ];
781
+ const schema = (new JON.Array(lang)).less(5).label('array1').required();
782
+ schema.validate(value);
783
+
784
+ // Contient exactement n valeur(s) (n non inclus) | Vérification du type array
785
+ const value = [
786
+ "John",
787
+ 30,
788
+ true,
789
+ {
790
+ street: "123 Main St",
791
+ city: "Anytown",
792
+ zip: "12345"
793
+ },
794
+ 'extra value'
795
+ ];
796
+ const schema = (new JON.Array(lang)).length(5).label('array1').required();
797
+ schema.validate(value);
798
+
799
+ // Contient exactement n valeur(s) (n non inclus) | Vérification du type array - Echec
800
+ const value = [
801
+ "John",
802
+ 30,
803
+ true,
804
+ {
805
+ street: "123 Main St",
806
+ city: "Anytown",
807
+ zip: "12345"
808
+ }
809
+ ];
810
+ const schema = (new JON.Array(lang)).length(5).label('array1').required();
811
+ schema.validate(value);
812
+ ```
813
+
814
+ ### 🏗️ Object (Objet)
815
+
816
+ ```typescript
817
+ // Vérification du type object
818
+ const value = {
819
+ key1: 'value1',
820
+ key2: 123,
821
+ key3: true
822
+ };
823
+ const schema = (new JON.Object(lang)).label('object1');
824
+ schema.validate(value);
825
+
826
+ // Vérification du type object - Echec
827
+ const value = 'lorem';
828
+ const schema = (new JON.Object(lang)).label('object1');
829
+ schema.validate(value);
830
+
831
+ // Structure definie | Vérification du type object
832
+ const value = {
833
+ name: "Doe",
834
+ prename: "John",
835
+ age: 30,
836
+ isMember: true,
837
+ address: {
838
+ street: "123 Main St",
839
+ city: "Anytown",
840
+ zip: "12345"
841
+ }
842
+ };
843
+ const schema = (new JON.Object(lang).struct({
844
+ name: (new JON.String(lang)).required().min(2).max(250),
845
+ prename: (new JON.String(lang)).min(2).max(250),
846
+ age: (new JON.Number(lang)).required(),
847
+ isMember: (new JON.Boolean(lang)).default(false),
848
+ address: new JON.Object(lang).struct({
849
+ street: (new JON.String(lang)).min(2).max(150),
850
+ city: (new JON.String(lang)).min(2).max(150),
851
+ zip: (new JON.String(lang)).min(2).max(150),
852
+ }).required(),
853
+ })).label('user').required();
854
+ schema.validate(value);
855
+
856
+ // Structure definie | Vérification du type object - Echec
857
+ const value = {
858
+ prename: "John",
859
+ age: 30,
860
+ isMember: true,
861
+ address: {
862
+ street: "123 Main St",
863
+ city: "Anytown",
864
+ zip: "12345"
865
+ }
866
+ };
867
+ const schema = (new JON.Object(lang).struct({
868
+ name: (new JON.String(lang)).required().min(2).max(250),
869
+ prename: (new JON.String(lang)).min(2).max(250),
870
+ age: (new JON.Number(lang)).required(),
871
+ isMember: (new JON.Boolean(lang)).default(false),
872
+ address: new JON.Object(lang).struct({
873
+ street: (new JON.String(lang)).min(2).max(150),
874
+ city: (new JON.String(lang)).min(2).max(150),
875
+ zip: (new JON.String(lang)).min(2).max(150),
876
+ }).required(),
877
+ })).label('user').required();
878
+ schema.validate(value);
879
+
880
+ // Structure stricte definie | Vérification du type object
881
+ const value = {
882
+ name: "Doe",
883
+ prename: "John"
884
+ };
885
+ const schema = (new JON.Object(lang).primaryStruct({
886
+ name: (new JON.String(lang)).required().min(2).max(250),
887
+ prename: (new JON.String(lang)).min(2).max(250),
888
+ })).label('user').required();
889
+ schema.validate(value);
890
+
891
+ // Structure stricte definie | Vérification du type object - Echec
892
+ const value = {
893
+ prename: "John",
894
+ };
895
+ const schema = (new JON.Object(lang).primaryStruct({
896
+ name: (new JON.String(lang)).required().min(2).max(250),
897
+ prename: (new JON.String(lang)).min(2).max(250),
898
+ })).label('user').required();
899
+ schema.validate(value);
900
+
901
+ // Types de valeurs strictes | Vérification du type object
902
+ const value = {
903
+ name: "Doe",
904
+ prename: "John",
905
+ age: 20,
906
+ isMember: true,
907
+ };
908
+ const schema = (new JON.Object(lang)).typesValues(
909
+ (new JON.Number(lang)).required(),
910
+ (new JON.String(lang)).required(),
911
+ ).label('user').required();
912
+ schema.validate(value);
913
+
914
+ // Types de valeurs strictes | Vérification du type object - Echec
915
+ const value = {
916
+ age: 20,
917
+ };
918
+ const schema = (new JON.Object(lang)).typesValues(
919
+ (new JON.Boolean(lang)).required(),
920
+ ).label('user').required();
921
+ schema.validate(value);
922
+
923
+ // Contient des clés spécifiques | Vérification du type object
924
+ const value = {
925
+ name: "Doe",
926
+ prename: "John",
927
+ age: 20,
928
+ isMember: true,
929
+ };
930
+ const schema = (new JON.Object(lang)).containsKeys(
931
+ ['name', 'prename', 'age', 'isMember',],
932
+ ).label('user').required();
933
+ schema.validate(value);
934
+
935
+ // Contient des clés spécifiques | Vérification du type object - Echec
936
+ const value = {
937
+ age: 20,
938
+ };
939
+ const schema = (new JON.Object(lang)).containsKeys(
940
+ ['name', 'prename',],
941
+ ).label('user').required();
942
+ schema.validate(value);
943
+
944
+ // Ne contient pas des clés spécifiques | Vérification du type object
945
+ const value = {
946
+ age: 20,
947
+ };
948
+ const schema = (new JON.Object(lang)).noContainsKeys(
949
+ ['name', 'prename',],
950
+ ).label('user').required();
951
+ schema.validate(value);
952
+
953
+ // Ne contient pas des clés spécifiques | Vérification du type object - Echec
954
+ const value = {
955
+ name: "Doe",
956
+ prename: "John",
957
+ age: 20,
958
+ isMember: true,
959
+ };
960
+ const schema = (new JON.Object(lang)).noContainsKeys(
961
+ ['name', 'prename', 'age', 'isMember',],
962
+ ).label('user').required();
963
+ schema.validate(value);
964
+
965
+ // [REGEX] Contient des clés spécifiques | Vérification du type object
966
+ const value = {
967
+ name: "Doe",
968
+ prename: "John",
969
+ age: 20,
970
+ isMember: true,
971
+ };
972
+ const schema = (new JON.Object(lang)).regExpContainsKeys(
973
+ /^(name|prename|age|isMember)$/,
974
+ ).label('user').required();
975
+ schema.validate(value);
976
+
977
+ // [REGEX] Contient des clés spécifiques | Vérification du type object - Echec
978
+ const value = {
979
+ age: 20,
980
+ };
981
+ const schema = (new JON.Object(lang)).regExpContainsKeys(
982
+ /^(name|prename)$/,
983
+ ).label('user').required();
984
+ schema.validate(value);
985
+
986
+ // [REGEX] Ne contient pas des clés spécifiques | Vérification du type object
987
+ const value = {
988
+ age: 20,
989
+ };
990
+ const schema = (new JON.Object(lang)).regExpNoContainsKeys(
991
+ /^(name|prename)$/,
992
+ ).label('user').required();
993
+ schema.validate(value);
994
+
995
+ // [REGEX] Ne contient pas des clés spécifiques | Vérification du type object - Echec
996
+ const value = {
997
+ name: "Doe",
998
+ prename: "John",
999
+ age: 20,
1000
+ isMember: true,
1001
+ };
1002
+ const schema = (new JON.Object(lang)).regExpNoContainsKeys(
1003
+ /^(name|prename|age|isMember)$/,
1004
+ ).label('user').required();
1005
+ schema.validate(value);
1006
+
1007
+ // Contient au minimum n attribut(s) | Vérification du type object
1008
+ const value = {
1009
+ name: "Doe",
1010
+ prename: "John",
1011
+ };
1012
+ const schema = (new JON.Object(lang)).min(2).label('user').required();
1013
+ schema.validate(value);
1014
+
1015
+ // Contient au minimum n attribut(s) | Vérification du type object - Echec
1016
+ const value = {
1017
+ name: "Doe",
1018
+ };
1019
+ const schema = (new JON.Object(lang)).min(2).label('user').required();
1020
+ schema.validate(value);
1021
+
1022
+ // Contient au maximum n attribut(s) | Vérification du type object
1023
+ const value = {
1024
+ prename: "John",
1025
+ age: 30,
1026
+ isMember: true,
1027
+ address: {
1028
+ street: "123 Main St",
1029
+ city: "Anytown",
1030
+ zip: "12345"
1031
+ }
1032
+ };
1033
+ const schema = (new JON.Object(lang)).max(5).label('user').required();
1034
+ schema.validate(value);
1035
+
1036
+ // Contient au minimum n attribut(s) | Vérification du type object - Echec
1037
+ const value = {
1038
+ prename: "John",
1039
+ age: 30,
1040
+ isMember: true,
1041
+ address: {
1042
+ street: "123 Main St",
1043
+ city: "Anytown",
1044
+ zip: "12345"
1045
+ }
1046
+ };
1047
+ const schema = (new JON.Object(lang)).max(5).label('user').required();
1048
+ schema.validate(value);
1049
+
1050
+ // Contient au minimum n attribut(s) (n non inclus) | Vérification du type object
1051
+ const value = {
1052
+ name: "Doe",
1053
+ prename: "John",
1054
+ };
1055
+ const schema = (new JON.Object(lang)).greater(1).label('user').required();
1056
+ schema.validate(value);
1057
+
1058
+ // Contient au minimum n attribut(s) (n non inclus) | Vérification du type object - Echec
1059
+ const value = {
1060
+ name: "Doe",
1061
+ };
1062
+ const schema = (new JON.Object(lang)).greater(1).label('user').required();
1063
+ schema.validate(value);
1064
+
1065
+ // Contient au maximum n attribut(s) (n non inclus) | Vérification du type object
1066
+ const value = {
1067
+ prename: "John",
1068
+ age: 30,
1069
+ isMember: true,
1070
+ address: {
1071
+ street: "123 Main St",
1072
+ city: "Anytown",
1073
+ zip: "12345"
1074
+ }
1075
+ };
1076
+ const schema = (new JON.Object(lang)).less(5).label('user').required();
1077
+ schema.validate(value);
1078
+
1079
+ // Contient au maximum n attribut(s) (n non inclus) | Vérification du type object - Echec
1080
+ const value = {
1081
+ prename: "John",
1082
+ age: 30,
1083
+ isMember: true,
1084
+ address: {
1085
+ street: "123 Main St",
1086
+ city: "Anytown",
1087
+ zip: "12345"
1088
+ },
1089
+ sex: 'M'
1090
+ };
1091
+ const schema = (new JON.Object(lang)).less(5).label('user').required();
1092
+ schema.validate(value);
1093
+
1094
+ // Contient exactement n attribut(s) (n non inclus) | Vérification du type object
1095
+ const value = {
1096
+ prename: "John",
1097
+ age: 30,
1098
+ isMember: true,
1099
+ address: {
1100
+ street: "123 Main St",
1101
+ city: "Anytown",
1102
+ zip: "12345"
1103
+ },
1104
+ sex: 'M',
1105
+ };
1106
+ const schema = (new JON.Object(lang)).length(5).label('user').required();
1107
+ schema.validate(value);
1108
+
1109
+ // Contient exactement n attribut(s) (n non inclus) | Vérification du type object - Echec
1110
+ const value = {
1111
+ prename: "John",
1112
+ age: 30,
1113
+ isMember: true,
1114
+ address: {
1115
+ street: "123 Main St",
1116
+ city: "Anytown",
1117
+ zip: "12345"
1118
+ },
1119
+ };
1120
+ const schema = (new JON.Object(lang)).length(5).label('user').required();
1121
+ schema.validate(value);
1122
+ ```
1123
+
1124
+ ### 📁 File (Fichier)
1125
+
1126
+ ```typescript
1127
+ // Vérification du type File (Base64)
1128
+ const value = 'data:application/javascript;base64,KGFsZXJ0KCdoZWxsbycpKTs=';
1129
+ const schema = (new JON.File(lang)).required().label('file1');
1130
+ schema.validate(value);
1131
+
1132
+ // Vérification du type File - Echec
1133
+ const value = 5656;
1134
+ const schema = (new JON.File(lang)).required().label('file1');
1135
+ schema.validate(value);
1136
+
1137
+ // Vérification du type File
1138
+ const value = 'data:application/javascript;base64,KGFsZXJ0KCdoZWxsbycpKTs=';
1139
+ const schema = (new JON.File(lang)).label('file1').min(5).max(17);
1140
+ schema.validate(value);
1141
+
1142
+ // Vérification du type File
1143
+ const value = 'data:application/javascript;base64,KGFsZXJ0KCdoZWxsbycpKTs=';
1144
+ const schema = (new JON.File(lang)).label('file1').label('file1').less(5).greater(20);
1145
+ schema.validate(value);
1146
+
1147
+ // Vérification du type File
1148
+ const value = 'data:application/javascript;base64,KGFsZXJ0KCdoZWxsbycpKTs=';
1149
+ const schema = (new JON.File(lang)).label('file1').length(17);
1150
+ schema.validate(value);
1151
+ ```
1152
+
1153
+ ### 🎯 Enum (Énumération)
1154
+
1155
+ ```typescript
1156
+ // Vérification du type Enum
1157
+ const value = 'orange';
1158
+ const schema = (new JON.Enum(lang)).required().label('enum1').choices('banane', 'orange', 'pomme', 'mangue');
1159
+ schema.validate(value);
1160
+
1161
+ // Vérification du type Enum - Echec
1162
+ const value = 'macabo';
1163
+ const schema = (new JON.Enum(lang)).required().label('enum1').choices('banane', 'orange', 'pomme');
1164
+ schema.validate(value);
1165
+ ```
1166
+
1167
+ ### 🚫 NotEnum (Exclusion)
1168
+
1169
+ ```typescript
1170
+ // Vérification du type NotEnum
1171
+ const value = 'macabo';
1172
+ const schema = (new JON.NotEnum(lang)).required().label('enum1').choices('banane', 'orange', 'pomme');
1173
+ schema.validate(value);
1174
+
1175
+ // Vérification du type NotEnum - Echec
1176
+ const value = 'orange';
1177
+ const schema = (new JON.NotEnum(lang)).required().label('enum1').choices('banane', 'orange', 'pomme', 'mangue');
1178
+ schema.validate(value);
1179
+ ```
1180
+
1181
+ ### 🔄 ChosenType (Choix de type)
1182
+
1183
+ ```typescript
1184
+
1185
+ // Vérification du type chosenType
1186
+ const value = 123;
1187
+ const schema = (new JON.ChosenType(lang)).label('chosen-type-1').choices(
1188
+ new JON.Boolean(lang).required(),
1189
+ new JON.Number(lang).required(),
1190
+ );
1191
+ schema.validate(value);
1192
+
1193
+ // Vérification du type chosenType - Echec
1194
+ const value = 'lorem';
1195
+ const schema = (new JON.ChosenType(lang)).label('chosen-type-1').choices(
1196
+ new JON.Boolean(lang).required(),
1197
+ new JON.Number(lang).required(),
1198
+ );
1199
+ schema.validate(value);
1200
+ ```
1201
+
1202
+ ### ✨ AnyType (Type personnalisé)
1203
+
1204
+ ```typescript
1205
+ // classes
1206
+ class OperationFlexible {
1207
+ nombres = [];
1208
+ constructor(...nombres) {
1209
+ this.nombres = nombres;
1210
+ }
1211
+
1212
+ setNombres(...nombres) {
1213
+ this.nombres = nombres;
1214
+ }
1215
+ getNombres() {
1216
+ return (
1217
+ (
1218
+ typeof this.nombres === 'object' &&
1219
+ Array.isArray(this.nombres)
1220
+ ) ? this.nombres : []
1221
+ );
1222
+ }
1223
+
1224
+ addition() {
1225
+ return this.nombres.reduce((acc, val) => acc + val, 0);
1226
+ }
1227
+
1228
+ soustraction(a) {
1229
+ return this.nombres.reduce((acc, val) => acc - val, a);
1230
+ }
1231
+
1232
+ multiplication() {
1233
+ return this.nombres.reduce((acc, val) => acc * val, 1);
1234
+ }
1235
+
1236
+ division(a, b = 1) {
1237
+ if (b === 0) {
1238
+ throw new Error("Division par zéro impossible");
1239
+ }
1240
+ return a / b;
1241
+ }
1242
+
1243
+ puissance(base, exposant = 1) {
1244
+ return Math.pow(base, exposant);
1245
+ }
1246
+ }
1247
+ class OperationSecurisee {
1248
+ constructor() {
1249
+ this.operations = {
1250
+ '+': (a, b) => a + b,
1251
+ '-': (a, b) => a - b,
1252
+ '*': (a, b) => a * b,
1253
+ '/': (a, b) => {
1254
+ if (b === 0) throw new Error("Division par zéro");
1255
+ return a / b;
1256
+ },
1257
+ '%': (a, b) => a % b
1258
+ };
1259
+ }
1260
+
1261
+ executer(operateur, a, b = this.getValeurParDefaut(operateur)) {
1262
+ this.validerParametres(operateur, a, b);
1263
+
1264
+ const operation = this.operations[operateur];
1265
+ if (!operation) {
1266
+ throw new Error(`Opérateur '${operateur}' non supporté`);
1267
+ }
1268
+
1269
+ return operation(a, b);
1270
+ }
1271
+
1272
+ getValeurParDefaut(operateur) {
1273
+ const defauts = {
1274
+ '+': 0,
1275
+ '-': 0,
1276
+ '*': 1,
1277
+ '/': 1,
1278
+ '%': 1
1279
+ };
1280
+ return defauts[operateur] || 0;
1281
+ }
1282
+
1283
+ validerParametres(operateur, a, b) {
1284
+ if (typeof a !== 'number' || typeof b !== 'number') {
1285
+ throw new Error("Les paramètres doivent être des nombres");
1286
+ }
1287
+
1288
+ if (operateur === '/' && b === 0) {
1289
+ throw new Error("Division par zéro impossible");
1290
+ }
1291
+ }
1292
+ }
1293
+
1294
+ // Definir une contrainte spécifique | Vérification du type anyType
1295
+ const value = new OperationFlexible(10, 5, 2);
1296
+ const schema = (new JON.AnyType(lang)).label('any-type-1').applyApp(
1297
+ (data) => data instanceof OperationFlexible,
1298
+ (data) => data,
1299
+ ((label) => ({
1300
+ 'fr': `L'attribut "${label}" n'est pas de type "OperationFlexible"`,
1301
+ 'en': `The "${label}" attribute is not of type "OperationFlexible"`,
1302
+ })),
1303
+ );
1304
+ schema.validate(value);
1305
+
1306
+ // Definir une contrainte spécifique | Vérification du type anyType - Echec
1307
+ const value = new OperationSecurisee();
1308
+ const schema = (new JON.AnyType(lang)).label('any-type-1').applyApp(
1309
+ (data) => data instanceof OperationFlexible,
1310
+ (data) => data,
1311
+ ((label) => ({
1312
+ 'fr': `L'attribut "${label}" n'est pas de type "OperationFlexible"`,
1313
+ 'en': `The "${label}" attribute is not of type "OperationFlexible"`,
1314
+ })),
1315
+ );
1316
+ schema.validate(value);
1317
+
1318
+ // Mapper l'erreur avant l'affichage | Vérification du type anyType - Echec
1319
+ function defaultMapError(
1320
+ res,
1321
+ error,
1322
+ ruleName = undefined,
1323
+ label = undefined,
1324
+ lang = 'fr'
1325
+ ) {
1326
+ console.log("\n>----------------------");
1327
+ console.log("[CUSTOM] -- JON - defaultMapError | error:: ", error);
1328
+ console.log("[CUSTOM] -- JON - defaultMapError | ruleName:: ", ruleName);
1329
+ console.log("[CUSTOM] -- JON - defaultMapError | label:: ", label);
1330
+ console.log("[CUSTOM] -- JON - defaultMapError | lang:: ", lang);
1331
+ console.log("\n");
1332
+ console.log("[CUSTOM] -- JON - defaultMapError | error:: ", error);
1333
+ console.log("[CUSTOM] -- JON - defaultMapError | res:: ", res);
1334
+ console.log("-------------------------<");
1335
+ return res;
1336
+ }
1337
+ const value = new OperationSecurisee();
1338
+ const schema = (new JON.AnyType(lang)).label('any-type-1').applyApp(
1339
+ (data) => data instanceof OperationFlexible,
1340
+ (data) => data,
1341
+ ((label) => ({
1342
+ 'fr': `L'attribut "${label}" n'est pas de type "OperationFlexible"`,
1343
+ 'en': `The "${label}" attribute is not of type "OperationFlexible"`,
1344
+ })),
1345
+ ).initMapError(defaultMapError);
1346
+ schema.validate(value);
1347
+
1348
+ // Appliquer un mapping après succès de validation | Vérification du type anyType
1349
+ const value = new OperationFlexible(10, 5, 2);
1350
+ const schema = (new JON.AnyType(lang)).label('any-type-1').applyApp(
1351
+ (data) => data instanceof OperationFlexible,
1352
+ (data) => data,
1353
+ ((label) => ({
1354
+ 'fr': `L'attribut "${label}" n'est pas de type "OperationFlexible"`,
1355
+ 'en': `The "${label}" attribute is not of type "OperationFlexible"`,
1356
+ })),
1357
+ ).applyMapping((value) => value.multiplication());
1358
+ schema.validate(value);
1359
+
1360
+ // Appliquer un mapping avant validation | Vérification du type anyType
1361
+ const value = new OperationFlexible(10, 5, 2);
1362
+ const schema = (new JON.AnyType(lang)).label('any-type-1').applyApp(
1363
+ (data) => data instanceof OperationFlexible,
1364
+ (data) => data,
1365
+ ((label) => ({
1366
+ 'fr': `L'attribut "${label}" n'est pas de type "OperationFlexible"`,
1367
+ 'en': `The "${label}" attribute is not of type "OperationFlexible"`,
1368
+ })),
1369
+ ).applyPreMapping((value) => {
1370
+ value.setNombres(...value.getNombres().map(n => n * 2));
1371
+ return value;
1372
+ }).applyMapping((value) => value.addition());
1373
+ schema.validate(value);
1374
+ ```
1375
+
1376
+ ## 📄 Licence
1377
+
1378
+ MIT License - Voir le fichier [LICENSE](LICENSE) pour plus de détails.
1379
+
1380
+ ## 🐛 Signaler un Bug
1381
+
1382
+ Envoyez nous un mail à l'adresse `contact.inicode@gmail.com` pour :
1383
+ - Signaler un bug
1384
+ - Proposer une amélioration
1385
+ - Poser une question
1386
+
1387
+ ---
1388
+
1389
+ **@arc-js/jon** - Puissant validateur de données
1390
+
1391
+ *Développé par l'équipe INICODE*