@cofondateurauchomage/libs 1.1.82 → 1.1.86
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/build/api.validate.js
CHANGED
|
@@ -6,24 +6,24 @@ const regex_1 = require("./regex");
|
|
|
6
6
|
const validate_1 = require("./validate");
|
|
7
7
|
//////////////
|
|
8
8
|
// Validators
|
|
9
|
-
const business = (0, validate_1.isString)().
|
|
9
|
+
const business = (0, validate_1.isString)().setMax(1000);
|
|
10
10
|
const city = (0, validate_1.isMatchRegex)(regex_1.RGX.Name.regex);
|
|
11
|
-
const description = (0, validate_1.isString)().
|
|
11
|
+
const description = (0, validate_1.isString)().setMax(1000);
|
|
12
12
|
const email = (0, validate_1.isString)();
|
|
13
13
|
const firstName = (0, validate_1.isMatchRegex)(regex_1.RGX.Name.regex);
|
|
14
14
|
const invest = (0, validate_1.isNumber)().setMin(0).setMax(1000000).isOptional();
|
|
15
15
|
const lastName = (0, validate_1.isMatchRegex)(regex_1.RGX.Name.regex);
|
|
16
16
|
const linkedin = (0, validate_1.isMatchRegex)(regex_1.RGX.Linkedin.regex).isOptional();
|
|
17
17
|
const website = (0, validate_1.isString)().isOptional();
|
|
18
|
-
const motivations = (0, validate_1.isString)().
|
|
19
|
-
const name = (0, validate_1.isString)().
|
|
20
|
-
const partner = (0, validate_1.isString)().
|
|
18
|
+
const motivations = (0, validate_1.isString)().setMax(1000);
|
|
19
|
+
const name = (0, validate_1.isString)().setMax(50);
|
|
20
|
+
const partner = (0, validate_1.isString)().setMax(1000);
|
|
21
21
|
const skills = new validate_1.Validator((value) => !!(value &&
|
|
22
22
|
Array.isArray(value) &&
|
|
23
23
|
value.length >= 1 &&
|
|
24
24
|
value.length <= 2 &&
|
|
25
25
|
value.every((skill) => const_1.SKILLS.includes(skill))));
|
|
26
|
-
const stripeId = (0, validate_1.isString)().
|
|
26
|
+
const stripeId = (0, validate_1.isString)().setMax(50);
|
|
27
27
|
const zipCode = (0, validate_1.isNumber)().setMin(1000).setMax(97680);
|
|
28
28
|
const newsletterMarketing = (0, validate_1.isBoolean)().isOptional();
|
|
29
29
|
const status = (0, validate_1.isMatchEnum)(const_1.PROJECT_STATUS).isOptional();
|
package/build/utils/index.d.ts
CHANGED
package/build/utils/index.js
CHANGED
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./arrayUtils"), exports);
|
|
18
18
|
__exportStar(require("./objectUtils"), exports);
|
|
19
|
+
__exportStar(require("./stringUtils"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.capitalize = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Capitalize the first letter of each words separated by a space or a hyphen
|
|
6
|
+
* and prevent double space
|
|
7
|
+
* @param str
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
function capitalize(str) {
|
|
11
|
+
return str
|
|
12
|
+
.toLowerCase()
|
|
13
|
+
.split(" ")
|
|
14
|
+
.map((w) => w && w[0].toUpperCase() + w.slice(1))
|
|
15
|
+
.join(" ")
|
|
16
|
+
.split("-")
|
|
17
|
+
.map((w) => w && w[0].toUpperCase() + w.slice(1))
|
|
18
|
+
.join("-")
|
|
19
|
+
.replace(" ", " ");
|
|
20
|
+
}
|
|
21
|
+
exports.capitalize = capitalize;
|
package/build/validate.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
//////////////
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.validateBody = exports.ValidationError = exports.isMatchEnum = exports.isMatchRegex = exports.isArray = exports.isBoolean = exports.isString = exports.isNumber = exports.Validator = void 0;
|
|
5
|
+
const utils_1 = require("./utils");
|
|
5
6
|
const arrayUtils_1 = require("./utils/arrayUtils");
|
|
6
7
|
/**
|
|
7
8
|
* Class representing a custom validator.
|
|
@@ -32,7 +33,12 @@ class Validator {
|
|
|
32
33
|
return true;
|
|
33
34
|
}
|
|
34
35
|
if (!this.fn(value)) {
|
|
35
|
-
|
|
36
|
+
if (!value) {
|
|
37
|
+
throw new ValidationError(400, `${(0, utils_1.capitalize)(key)} requis`);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
throw new ValidationError(400, `${(0, utils_1.capitalize)(key)} invalide`);
|
|
41
|
+
}
|
|
36
42
|
}
|
|
37
43
|
if (this.min !== undefined || this.max !== undefined) {
|
|
38
44
|
return this.checkMinMax(key, value, this.min, this.max);
|
|
@@ -71,13 +77,13 @@ class Validator {
|
|
|
71
77
|
const nb = typeof value === "string" ? value.length : value;
|
|
72
78
|
if (min !== undefined && nb < min) {
|
|
73
79
|
throw new ValidationError(400, typeof value === "string"
|
|
74
|
-
? `Le texte ${key} n'est pas assez long, il manque ${min - nb} caractères`
|
|
75
|
-
: `La valeur de ${key} est trop basse, minimum: ${min}`);
|
|
80
|
+
? `Le texte ${(0, utils_1.capitalize)(key)} n'est pas assez long, il manque ${min - nb} caractères`
|
|
81
|
+
: `La valeur de ${(0, utils_1.capitalize)(key)} est trop basse, minimum: ${min}`);
|
|
76
82
|
}
|
|
77
83
|
if (max !== undefined && nb > max) {
|
|
78
84
|
throw new ValidationError(400, typeof value === "string"
|
|
79
|
-
? `Le texte ${key} est trop long, il y a ${nb - max} caractères en trop`
|
|
80
|
-
: `La valeur de ${key} est trop haute, maximum: ${max}`);
|
|
85
|
+
? `Le texte ${(0, utils_1.capitalize)(key)} est trop long, il y a ${nb - max} caractères en trop`
|
|
86
|
+
: `La valeur de ${(0, utils_1.capitalize)(key)} est trop haute, maximum: ${max}`);
|
|
81
87
|
}
|
|
82
88
|
return true;
|
|
83
89
|
}
|
|
@@ -143,7 +149,7 @@ exports.ValidationError = ValidationError;
|
|
|
143
149
|
*/
|
|
144
150
|
function validateBody(body, validators) {
|
|
145
151
|
if (typeof body !== "object" || body === null) {
|
|
146
|
-
throw new ValidationError(400, "
|
|
152
|
+
throw new ValidationError(400, "Le payload est requis");
|
|
147
153
|
}
|
|
148
154
|
const result = {};
|
|
149
155
|
for (const [key, validator] of Object.entries(validators)) {
|