theo_lafond_react_ci_cd 0.0.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/babel.config.cjs +6 -0
- package/cypress.config.js +12 -0
- package/dist/App.css +35 -0
- package/dist/App.js +147 -0
- package/dist/assets/react.svg +1 -0
- package/dist/components/PersonForm.css +63 -0
- package/dist/components/PersonForm.js +312 -0
- package/dist/domain/module.js +33 -0
- package/dist/domain/services/personService.js +126 -0
- package/dist/domain/validator.js +143 -0
- package/dist/index.css +64 -0
- package/dist/index.js +13 -0
- package/dist/main.js +11 -0
- package/dist/pages/Home.css +57 -0
- package/dist/pages/Home.js +102 -0
- package/dist/pages/Register.css +28 -0
- package/dist/pages/Register.js +40 -0
- package/dist/utils/errorMessages.js +46 -0
- package/eslint.config.js +29 -0
- package/jest.config.cjs +9 -0
- package/jsdoc.json +8 -0
- package/package.json +50 -0
- package/public/docs/App.jsx.html +114 -0
- package/public/docs/components_PersonForm.jsx.html +282 -0
- package/public/docs/domain_module.js.html +81 -0
- package/public/docs/domain_personService.js.html +69 -0
- package/public/docs/domain_validator.js.html +190 -0
- package/public/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/public/docs/fonts/OpenSans-Bold-webfont.svg +1830 -0
- package/public/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/public/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/public/docs/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
- package/public/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/public/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/public/docs/fonts/OpenSans-Italic-webfont.svg +1830 -0
- package/public/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/public/docs/fonts/OpenSans-Light-webfont.eot +0 -0
- package/public/docs/fonts/OpenSans-Light-webfont.svg +1831 -0
- package/public/docs/fonts/OpenSans-Light-webfont.woff +0 -0
- package/public/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/public/docs/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
- package/public/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/public/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/public/docs/fonts/OpenSans-Regular-webfont.svg +1831 -0
- package/public/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/public/docs/global.html +2439 -0
- package/public/docs/module-App.html +362 -0
- package/public/docs/module-Home.html +373 -0
- package/public/docs/module-PersonForm.html +723 -0
- package/public/docs/module-Register.html +281 -0
- package/public/docs/module.js.html +81 -0
- package/public/docs/pages_Home.jsx.html +106 -0
- package/public/docs/pages_Register.jsx.html +78 -0
- package/public/docs/scripts/linenumber.js +25 -0
- package/public/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/public/docs/scripts/prettify/lang-css.js +2 -0
- package/public/docs/scripts/prettify/prettify.js +28 -0
- package/public/docs/styles/jsdoc-default.css +358 -0
- package/public/docs/styles/prettify-jsdoc.css +111 -0
- package/public/docs/styles/prettify-tomorrow.css +132 -0
- package/public/docs/utils_errorMessages.js.html +87 -0
- package/public/docs/validator.js.html +179 -0
- package/public/vite.svg +1 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/* JSDoc prettify.js theme */
|
|
2
|
+
|
|
3
|
+
/* plain text */
|
|
4
|
+
.pln {
|
|
5
|
+
color: #000000;
|
|
6
|
+
font-weight: normal;
|
|
7
|
+
font-style: normal;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/* string content */
|
|
11
|
+
.str {
|
|
12
|
+
color: #006400;
|
|
13
|
+
font-weight: normal;
|
|
14
|
+
font-style: normal;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* a keyword */
|
|
18
|
+
.kwd {
|
|
19
|
+
color: #000000;
|
|
20
|
+
font-weight: bold;
|
|
21
|
+
font-style: normal;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* a comment */
|
|
25
|
+
.com {
|
|
26
|
+
font-weight: normal;
|
|
27
|
+
font-style: italic;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* a type name */
|
|
31
|
+
.typ {
|
|
32
|
+
color: #000000;
|
|
33
|
+
font-weight: normal;
|
|
34
|
+
font-style: normal;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* a literal value */
|
|
38
|
+
.lit {
|
|
39
|
+
color: #006400;
|
|
40
|
+
font-weight: normal;
|
|
41
|
+
font-style: normal;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* punctuation */
|
|
45
|
+
.pun {
|
|
46
|
+
color: #000000;
|
|
47
|
+
font-weight: bold;
|
|
48
|
+
font-style: normal;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* lisp open bracket */
|
|
52
|
+
.opn {
|
|
53
|
+
color: #000000;
|
|
54
|
+
font-weight: bold;
|
|
55
|
+
font-style: normal;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* lisp close bracket */
|
|
59
|
+
.clo {
|
|
60
|
+
color: #000000;
|
|
61
|
+
font-weight: bold;
|
|
62
|
+
font-style: normal;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/* a markup tag name */
|
|
66
|
+
.tag {
|
|
67
|
+
color: #006400;
|
|
68
|
+
font-weight: normal;
|
|
69
|
+
font-style: normal;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/* a markup attribute name */
|
|
73
|
+
.atn {
|
|
74
|
+
color: #006400;
|
|
75
|
+
font-weight: normal;
|
|
76
|
+
font-style: normal;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* a markup attribute value */
|
|
80
|
+
.atv {
|
|
81
|
+
color: #006400;
|
|
82
|
+
font-weight: normal;
|
|
83
|
+
font-style: normal;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/* a declaration */
|
|
87
|
+
.dec {
|
|
88
|
+
color: #000000;
|
|
89
|
+
font-weight: bold;
|
|
90
|
+
font-style: normal;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* a variable name */
|
|
94
|
+
.var {
|
|
95
|
+
color: #000000;
|
|
96
|
+
font-weight: normal;
|
|
97
|
+
font-style: normal;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* a function name */
|
|
101
|
+
.fun {
|
|
102
|
+
color: #000000;
|
|
103
|
+
font-weight: bold;
|
|
104
|
+
font-style: normal;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/* Specify class=linenums on a pre to get line numbering */
|
|
108
|
+
ol.linenums {
|
|
109
|
+
margin-top: 0;
|
|
110
|
+
margin-bottom: 0;
|
|
111
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/* Tomorrow Theme */
|
|
2
|
+
/* Original theme - https://github.com/chriskempson/tomorrow-theme */
|
|
3
|
+
/* Pretty printing styles. Used with prettify.js. */
|
|
4
|
+
/* SPAN elements with the classes below are added by prettyprint. */
|
|
5
|
+
/* plain text */
|
|
6
|
+
.pln {
|
|
7
|
+
color: #4d4d4c; }
|
|
8
|
+
|
|
9
|
+
@media screen {
|
|
10
|
+
/* string content */
|
|
11
|
+
.str {
|
|
12
|
+
color: #718c00; }
|
|
13
|
+
|
|
14
|
+
/* a keyword */
|
|
15
|
+
.kwd {
|
|
16
|
+
color: #8959a8; }
|
|
17
|
+
|
|
18
|
+
/* a comment */
|
|
19
|
+
.com {
|
|
20
|
+
color: #8e908c; }
|
|
21
|
+
|
|
22
|
+
/* a type name */
|
|
23
|
+
.typ {
|
|
24
|
+
color: #4271ae; }
|
|
25
|
+
|
|
26
|
+
/* a literal value */
|
|
27
|
+
.lit {
|
|
28
|
+
color: #f5871f; }
|
|
29
|
+
|
|
30
|
+
/* punctuation */
|
|
31
|
+
.pun {
|
|
32
|
+
color: #4d4d4c; }
|
|
33
|
+
|
|
34
|
+
/* lisp open bracket */
|
|
35
|
+
.opn {
|
|
36
|
+
color: #4d4d4c; }
|
|
37
|
+
|
|
38
|
+
/* lisp close bracket */
|
|
39
|
+
.clo {
|
|
40
|
+
color: #4d4d4c; }
|
|
41
|
+
|
|
42
|
+
/* a markup tag name */
|
|
43
|
+
.tag {
|
|
44
|
+
color: #c82829; }
|
|
45
|
+
|
|
46
|
+
/* a markup attribute name */
|
|
47
|
+
.atn {
|
|
48
|
+
color: #f5871f; }
|
|
49
|
+
|
|
50
|
+
/* a markup attribute value */
|
|
51
|
+
.atv {
|
|
52
|
+
color: #3e999f; }
|
|
53
|
+
|
|
54
|
+
/* a declaration */
|
|
55
|
+
.dec {
|
|
56
|
+
color: #f5871f; }
|
|
57
|
+
|
|
58
|
+
/* a variable name */
|
|
59
|
+
.var {
|
|
60
|
+
color: #c82829; }
|
|
61
|
+
|
|
62
|
+
/* a function name */
|
|
63
|
+
.fun {
|
|
64
|
+
color: #4271ae; } }
|
|
65
|
+
/* Use higher contrast and text-weight for printable form. */
|
|
66
|
+
@media print, projection {
|
|
67
|
+
.str {
|
|
68
|
+
color: #060; }
|
|
69
|
+
|
|
70
|
+
.kwd {
|
|
71
|
+
color: #006;
|
|
72
|
+
font-weight: bold; }
|
|
73
|
+
|
|
74
|
+
.com {
|
|
75
|
+
color: #600;
|
|
76
|
+
font-style: italic; }
|
|
77
|
+
|
|
78
|
+
.typ {
|
|
79
|
+
color: #404;
|
|
80
|
+
font-weight: bold; }
|
|
81
|
+
|
|
82
|
+
.lit {
|
|
83
|
+
color: #044; }
|
|
84
|
+
|
|
85
|
+
.pun, .opn, .clo {
|
|
86
|
+
color: #440; }
|
|
87
|
+
|
|
88
|
+
.tag {
|
|
89
|
+
color: #006;
|
|
90
|
+
font-weight: bold; }
|
|
91
|
+
|
|
92
|
+
.atn {
|
|
93
|
+
color: #404; }
|
|
94
|
+
|
|
95
|
+
.atv {
|
|
96
|
+
color: #060; } }
|
|
97
|
+
/* Style */
|
|
98
|
+
/*
|
|
99
|
+
pre.prettyprint {
|
|
100
|
+
background: white;
|
|
101
|
+
font-family: Consolas, Monaco, 'Andale Mono', monospace;
|
|
102
|
+
font-size: 12px;
|
|
103
|
+
line-height: 1.5;
|
|
104
|
+
border: 1px solid #ccc;
|
|
105
|
+
padding: 10px; }
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
/* Specify class=linenums on a pre to get line numbering */
|
|
109
|
+
ol.linenums {
|
|
110
|
+
margin-top: 0;
|
|
111
|
+
margin-bottom: 0; }
|
|
112
|
+
|
|
113
|
+
/* IE indents via margin-left */
|
|
114
|
+
li.L0,
|
|
115
|
+
li.L1,
|
|
116
|
+
li.L2,
|
|
117
|
+
li.L3,
|
|
118
|
+
li.L4,
|
|
119
|
+
li.L5,
|
|
120
|
+
li.L6,
|
|
121
|
+
li.L7,
|
|
122
|
+
li.L8,
|
|
123
|
+
li.L9 {
|
|
124
|
+
/* */ }
|
|
125
|
+
|
|
126
|
+
/* Alternate shading for lines */
|
|
127
|
+
li.L1,
|
|
128
|
+
li.L3,
|
|
129
|
+
li.L5,
|
|
130
|
+
li.L7,
|
|
131
|
+
li.L9 {
|
|
132
|
+
/* */ }
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>JSDoc: Source: utils/errorMessages.js</title>
|
|
6
|
+
|
|
7
|
+
<script src="scripts/prettify/prettify.js"> </script>
|
|
8
|
+
<script src="scripts/prettify/lang-css.js"> </script>
|
|
9
|
+
<!--[if lt IE 9]>
|
|
10
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
11
|
+
<![endif]-->
|
|
12
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
13
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
14
|
+
</head>
|
|
15
|
+
|
|
16
|
+
<body>
|
|
17
|
+
|
|
18
|
+
<div id="main">
|
|
19
|
+
|
|
20
|
+
<h1 class="page-title">Source: utils/errorMessages.js</h1>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
<section>
|
|
28
|
+
<article>
|
|
29
|
+
<pre class="prettyprint source linenums"><code>/**
|
|
30
|
+
* Object containing all error messages used in the form
|
|
31
|
+
* @constant {Object.<string, string>}
|
|
32
|
+
* @property {string} INVALID_FIRST_NAME - "Le prénom n'est pas valide"
|
|
33
|
+
* @property {string} INVALID_LAST_NAME - "Le nom n'est pas valide"
|
|
34
|
+
* @property {string} INVALID_EMAIL - "L'email n'est pas valide"
|
|
35
|
+
* @property {string} EMAIL_ALREADY_EXISTS - "Cet email est déjà utilisé"
|
|
36
|
+
* @property {string} INVALID_ZIP - "Le code postal doit contenir 5 chiffres"
|
|
37
|
+
* @property {string} INVALID_CITY - "Le nom de la ville n'est pas valide"
|
|
38
|
+
* @property {string} UNDERAGE - "Vous devez avoir au moins 18 ans"
|
|
39
|
+
* @property {string} FUTURE_DATE - "La date de naissance ne peut pas être dans le futur"
|
|
40
|
+
* @property {string} INVALID_DATE - "La date de naissance est invalide",
|
|
41
|
+
* @property {string} BIRTHDATE_TOO_OLD - "La date de naissance est trop ancienne",
|
|
42
|
+
* @property {string} XSS_DETECTED - "Caractères interdits détectés"
|
|
43
|
+
*/
|
|
44
|
+
export const errorMessages = {
|
|
45
|
+
INVALID_FIRST_NAME: "Le prénom n'est pas valide",
|
|
46
|
+
INVALID_LAST_NAME: "Le nom n'est pas valide",
|
|
47
|
+
INVALID_EMAIL: "L'email n'est pas valide",
|
|
48
|
+
EMAIL_ALREADY_EXISTS: "Cet email est déjà utilisé",
|
|
49
|
+
INVALID_ZIP: "Le code postal doit contenir 5 chiffres",
|
|
50
|
+
INVALID_CITY: "Le nom de la ville n'est pas valide",
|
|
51
|
+
UNDERAGE: "Vous devez avoir au moins 18 ans",
|
|
52
|
+
FUTURE_DATE: "La date de naissance ne peut pas être dans le futur",
|
|
53
|
+
INVALID_DATE: "La date de naissance est invalide",
|
|
54
|
+
BIRTHDATE_TOO_OLD: "La date de naissance est trop ancienne",
|
|
55
|
+
XSS_DETECTED: "Caractères interdits détectés"
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Retrieves the error message corresponding to a given key
|
|
60
|
+
* @param {string} key - The error key (e.g., "INVALID_EMAIL", "UNDERAGE")
|
|
61
|
+
* @returns {string} The corresponding error message, or "Unknown error" if the key does not exist
|
|
62
|
+
*/
|
|
63
|
+
export function getErrorMessage(key) {
|
|
64
|
+
return errorMessages[key] || "Erreur inconnue";
|
|
65
|
+
}</code></pre>
|
|
66
|
+
</article>
|
|
67
|
+
</section>
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
</div>
|
|
73
|
+
|
|
74
|
+
<nav>
|
|
75
|
+
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-App.html">App</a></li><li><a href="module-Home.html">Home</a></li><li><a href="module-PersonForm.html">PersonForm</a></li><li><a href="module-Register.html">Register</a></li></ul><h3>Global</h3><ul><li><a href="global.html#addPerson">addPerson</a></li><li><a href="global.html#calculateAge">calculateAge</a></li><li><a href="global.html#errorMessages">errorMessages</a></li><li><a href="global.html#getErrorMessage">getErrorMessage</a></li><li><a href="global.html#validateAge">validateAge</a></li><li><a href="global.html#validateCity">validateCity</a></li><li><a href="global.html#validateEmail">validateEmail</a></li><li><a href="global.html#validateName">validateName</a></li><li><a href="global.html#validatePerson">validatePerson</a></li><li><a href="global.html#validateZipCode">validateZipCode</a></li></ul>
|
|
76
|
+
</nav>
|
|
77
|
+
|
|
78
|
+
<br class="clear">
|
|
79
|
+
|
|
80
|
+
<footer>
|
|
81
|
+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.5</a> on Fri Feb 20 2026 09:18:58 GMT+0100 (heure normale d’Europe centrale)
|
|
82
|
+
</footer>
|
|
83
|
+
|
|
84
|
+
<script> prettyPrint(); </script>
|
|
85
|
+
<script src="scripts/linenumber.js"> </script>
|
|
86
|
+
</body>
|
|
87
|
+
</html>
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>JSDoc: Source: validator.js</title>
|
|
6
|
+
|
|
7
|
+
<script src="scripts/prettify/prettify.js"> </script>
|
|
8
|
+
<script src="scripts/prettify/lang-css.js"> </script>
|
|
9
|
+
<!--[if lt IE 9]>
|
|
10
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
11
|
+
<![endif]-->
|
|
12
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
13
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
14
|
+
</head>
|
|
15
|
+
|
|
16
|
+
<body>
|
|
17
|
+
|
|
18
|
+
<div id="main">
|
|
19
|
+
|
|
20
|
+
<h1 class="page-title">Source: validator.js</h1>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
<section>
|
|
28
|
+
<article>
|
|
29
|
+
<pre class="prettyprint source linenums"><code>import {calculateAge} from "./module.js";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Validates all parameters for a person
|
|
33
|
+
* @param {Object} person - { birthDate, zip, identity, email }
|
|
34
|
+
* @param {Date} person.birthDate - Date of birth
|
|
35
|
+
* @param {string} person.zip - French zip code (5 digits)
|
|
36
|
+
* @param {string} person.city - City name (letters, accents, espace, hyphens)
|
|
37
|
+
* @param {string} person.firstName - First name (letters, accents, hyphens)
|
|
38
|
+
* @param {string} person.lastName - Last name (letters, accents, hyphens)
|
|
39
|
+
* @param {string} person.email - Email address
|
|
40
|
+
* @returns {true} if everything is valid
|
|
41
|
+
* @throws {Error} MISSING_PARAM, PARAM_TYPE_ERROR, UNDERAGE, INVALID_ZIP, INVALID_CITY, INVALID_FIRST_NAME, INVALID_LAST_NAME, XSS_DETECTED, INVALID_EMAIL
|
|
42
|
+
*/
|
|
43
|
+
export function validatePerson(person) {
|
|
44
|
+
if (!person || typeof person !== "object") {
|
|
45
|
+
throw new Error("MISSING_PARAM: person");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!person.birthDate) throw new Error("MISSING_PARAM: birthDate");
|
|
49
|
+
if (!person.zip) throw new Error("MISSING_PARAM: zip");
|
|
50
|
+
if (!person.city) throw new Error("MISSING_PARAM: city");
|
|
51
|
+
if (!person.firstName) throw new Error("MISSING_PARAM: firstName");
|
|
52
|
+
if (!person.lastName) throw new Error("MISSING_PARAM: lastName");
|
|
53
|
+
if (!person.email) throw new Error("MISSING_PARAM: email");
|
|
54
|
+
|
|
55
|
+
if (!(person.birthDate instanceof Date)) throw new TypeError("PARAM_TYPE_ERROR: birthDate must be a Date");
|
|
56
|
+
if (typeof person.zip !== "string") throw new TypeError("PARAM_TYPE_ERROR: zip must be a string");
|
|
57
|
+
if (typeof person.city !== "string") throw new TypeError("PARAM_TYPE_ERROR: city must be a string");
|
|
58
|
+
if (typeof person.firstName !== "string") throw new TypeError("PARAM_TYPE_ERROR: firstName must be a string");
|
|
59
|
+
if (typeof person.lastName !== "string") throw new TypeError("PARAM_TYPE_ERROR: lastName must be a string");
|
|
60
|
+
if (typeof person.email !== "string") throw new TypeError("PARAM_TYPE_ERROR: email must be a string");
|
|
61
|
+
|
|
62
|
+
validateAge(person.birthDate);
|
|
63
|
+
validateZipCode(person.zip);
|
|
64
|
+
validateCity(person.city)
|
|
65
|
+
validateName(person.firstName);
|
|
66
|
+
validateName(person.lastName);
|
|
67
|
+
validateEmail(person.email);
|
|
68
|
+
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Validates a person's age based on birth date.
|
|
74
|
+
* Rejects if under 18 years old.
|
|
75
|
+
* @param {Date} birthDate - Date of birth
|
|
76
|
+
* @returns {boolean} Returns true if age is 18 or older
|
|
77
|
+
* @throws {Error} UNDERAGE if age < 18
|
|
78
|
+
* @throws {TypeError} INVALID_DATE if birthDate is not a valid Date
|
|
79
|
+
* @throws {Error} FUTURE_DATE if birthDate is in the future
|
|
80
|
+
*/
|
|
81
|
+
export function validateAge(birthDate) {
|
|
82
|
+
if (!(birthDate instanceof Date) || Number.isNaN(birthDate.getTime())) {
|
|
83
|
+
throw new TypeError("INVALID_DATE");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const now = new Date();
|
|
87
|
+
if (birthDate > now) throw new Error("FUTURE_DATE");
|
|
88
|
+
|
|
89
|
+
const age = calculateAge({birth: birthDate});
|
|
90
|
+
if (age < 18) throw new Error("UNDERAGE");
|
|
91
|
+
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Validates a zip code.
|
|
97
|
+
* Must be exactly 5 digits.
|
|
98
|
+
* @param {string} zip - Zip code
|
|
99
|
+
* @returns {boolean} Returns true if zip is valid
|
|
100
|
+
* @throws {Error} Throws "INVALID_ZIP" if zip is invalid
|
|
101
|
+
*/
|
|
102
|
+
export function validateZipCode(zip) {
|
|
103
|
+
if (typeof zip !== "string" || !/^\d{5}$/.test(zip)) {
|
|
104
|
+
throw new Error("INVALID_ZIP");
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Validate a city name.
|
|
111
|
+
* Only letters, accents, spaces and hyphens are allowed.
|
|
112
|
+
* Rejects simple XSS patterns.
|
|
113
|
+
* @param {string} city - The city name to validate
|
|
114
|
+
* @returns {boolean} true if valid
|
|
115
|
+
* @throws {Error} INVALID_CITY if format is incorrect
|
|
116
|
+
* @throws {Error} XSS_DETECTED if a basic XSS pattern is detected
|
|
117
|
+
*/
|
|
118
|
+
export function validateCity(city) {
|
|
119
|
+
if (typeof city !== "string") throw new Error("INVALID_CITY");
|
|
120
|
+
if (/<[^>]*>/.test(city)) throw new Error("XSS_DETECTED");
|
|
121
|
+
if (!/^[A-Za-zÀ-ÖØ-öø-ÿ\s-]+$/.test(city)) {
|
|
122
|
+
throw new Error("INVALID_CITY");
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Validate a name (first or last) and return specific error messages
|
|
130
|
+
* @param {string} name - The name to validate
|
|
131
|
+
* @param {string} type - "firstName" or "lastName" for custom error messages
|
|
132
|
+
* @returns {boolean} true if valid
|
|
133
|
+
* @throws {Error} with message INVALID_FIRST_NAME or INVALID_LAST_NAME, XSS_DETECTED
|
|
134
|
+
*/
|
|
135
|
+
export function validateName(name, type = "firstName") {
|
|
136
|
+
if (typeof name !== "string") throw new Error(type === "firstName" ? "INVALID_FIRST_NAME" : "INVALID_LAST_NAME");
|
|
137
|
+
if (/<[^>]*>/.test(name)) throw new Error("XSS_DETECTED");
|
|
138
|
+
if (!/^[A-Za-zÀ-ÖØ-öø-ÿ-]+$/.test(name)) {
|
|
139
|
+
throw new Error(type === "firstName" ? "INVALID_FIRST_NAME" : "INVALID_LAST_NAME");
|
|
140
|
+
}
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Validates an email address.
|
|
146
|
+
* Must be in standard email format.
|
|
147
|
+
* @param {string} email - Email to validate
|
|
148
|
+
* @returns {boolean} Returns true if email is valid
|
|
149
|
+
* @throws {Error} Throws "INVALID_EMAIL" if email format is incorrect
|
|
150
|
+
*/
|
|
151
|
+
export function validateEmail(email) {
|
|
152
|
+
if (typeof email !== "string" || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
|
153
|
+
throw new Error("INVALID_EMAIL");
|
|
154
|
+
}
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
</code></pre>
|
|
158
|
+
</article>
|
|
159
|
+
</section>
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
</div>
|
|
165
|
+
|
|
166
|
+
<nav>
|
|
167
|
+
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#calculateAge">calculateAge</a></li><li><a href="global.html#validateAge">validateAge</a></li><li><a href="global.html#validateCity">validateCity</a></li><li><a href="global.html#validateEmail">validateEmail</a></li><li><a href="global.html#validateName">validateName</a></li><li><a href="global.html#validatePerson">validatePerson</a></li><li><a href="global.html#validateZipCode">validateZipCode</a></li></ul>
|
|
168
|
+
</nav>
|
|
169
|
+
|
|
170
|
+
<br class="clear">
|
|
171
|
+
|
|
172
|
+
<footer>
|
|
173
|
+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.5</a> on Thu Feb 19 2026 12:22:47 GMT+0100 (heure normale d’Europe centrale)
|
|
174
|
+
</footer>
|
|
175
|
+
|
|
176
|
+
<script> prettyPrint(); </script>
|
|
177
|
+
<script src="scripts/linenumber.js"> </script>
|
|
178
|
+
</body>
|
|
179
|
+
</html>
|
package/public/vite.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|