pols-validator 3.0.1 → 4.1.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/dist/rules.d.ts +2 -1
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +52 -62
- package/dist/rulesEngine.d.ts +1 -1
- package/dist/rulesEngine.d.ts.map +1 -1
- package/dist/rulesEngine.js +3 -3
- package/eslint.config.mjs +4 -1
- package/package.json +2 -2
package/dist/rules.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export type PSanitizeParams = {
|
|
|
4
4
|
forbiddenTags?: string[];
|
|
5
5
|
};
|
|
6
6
|
export declare class PRules extends PRulesEngine {
|
|
7
|
+
isString(): this;
|
|
7
8
|
isAlphanumeric(): this;
|
|
8
9
|
isEmailAddress(): this;
|
|
9
10
|
isDateTime(): this;
|
|
@@ -14,7 +15,7 @@ export declare class PRules extends PRulesEngine {
|
|
|
14
15
|
isInteger(): this;
|
|
15
16
|
isNatural(): this;
|
|
16
17
|
isNaturalNoZero(): this;
|
|
17
|
-
|
|
18
|
+
isNumeric(): this;
|
|
18
19
|
maxLength(limit: number): this;
|
|
19
20
|
minLength(limit: number): this;
|
|
20
21
|
hasFixedLength(limit: number): this;
|
package/dist/rules.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../src/rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAiB,MAAM,eAAe,CAAA;AAK3D,MAAM,MAAM,eAAe,GAAG;IAC7B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;CACxB,CAAA;AAED,qBAAa,MAAO,SAAQ,YAAY;IACvC,cAAc;
|
|
1
|
+
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../src/rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAiB,MAAM,eA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AE,KAAK,MAAM,CAAC;IAMlG,UAAU;IAMV,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAMhC,IAAI,CAAC,SAAS,EAAE,MAAM;IAMtB,KAAK;IAML,IAAI;IAMJ,QAAQ,CAAC,MAAM,CAAC,EAAE,eAAe;CAajC"}
|
package/dist/rules.js
CHANGED
|
@@ -6,23 +6,28 @@ const pols_date_1 = require("pols-date");
|
|
|
6
6
|
const isomorphic_dompurify_1 = require("isomorphic-dompurify");
|
|
7
7
|
const pols_utils_1 = require("pols-utils");
|
|
8
8
|
class PRules extends rulesEngine_1.PRulesEngine {
|
|
9
|
-
|
|
10
|
-
this.add(this.
|
|
9
|
+
isString() {
|
|
10
|
+
return this.add(this.isString.name, (wrapper) => {
|
|
11
11
|
if (typeof wrapper.value == 'number') {
|
|
12
12
|
wrapper.value = wrapper.value.toString();
|
|
13
13
|
}
|
|
14
14
|
else if (typeof wrapper.value != 'string') {
|
|
15
|
-
return `'${wrapper.label}' debe ser
|
|
15
|
+
return `'${wrapper.label}' debe ser una cadena de texto`;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
isAlphanumeric() {
|
|
20
|
+
return this.isString().add(this.isAlphanumeric.name, (wrapper) => {
|
|
21
|
+
if (!wrapper.value.match(/^[a-zA-Z0-9ñÑáéíóúÁÉÍÓÚüÜ]+$/)) {
|
|
22
|
+
return `'${wrapper.label}' debe contener sólo letras y números`;
|
|
16
23
|
}
|
|
17
24
|
});
|
|
18
|
-
return this;
|
|
19
25
|
}
|
|
20
26
|
isEmailAddress() {
|
|
21
|
-
this.
|
|
22
|
-
this.add(this.isEmailAddress.name, (wrapper) => {
|
|
27
|
+
return this.isString().add(this.isEmailAddress.name, (wrapper) => {
|
|
23
28
|
const message = `'${wrapper.label}' debe ser una dirección de correo válida`;
|
|
24
29
|
if (wrapper.value.match(/^[^\sñáéíóúäëïöü@]+@[^\sñáéíóúäëïöü@]+\.[^\sñáéíóúäëïöü@]{2,}$/i)) {
|
|
25
|
-
if (wrapper.value.match(/[.]{2}
|
|
30
|
+
if (wrapper.value.match(/[.]{2}|,/)) {
|
|
26
31
|
return message;
|
|
27
32
|
}
|
|
28
33
|
}
|
|
@@ -30,17 +35,15 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
30
35
|
return message;
|
|
31
36
|
}
|
|
32
37
|
});
|
|
33
|
-
return this;
|
|
34
38
|
}
|
|
35
39
|
isDateTime() {
|
|
36
|
-
this.add(this.isDateTime.name, (wrapper) => {
|
|
40
|
+
return this.add(this.isDateTime.name, (wrapper) => {
|
|
37
41
|
const message = `'${wrapper.label}' tiene un formato de fecha y hora no válido`;
|
|
38
42
|
const newDate = new pols_date_1.PDate(wrapper.value);
|
|
39
43
|
if (newDate.isInvalidDate)
|
|
40
44
|
return message;
|
|
41
45
|
wrapper.value = newDate;
|
|
42
46
|
});
|
|
43
|
-
return this;
|
|
44
47
|
}
|
|
45
48
|
isDate() {
|
|
46
49
|
return this.isDateTime().add(this.isDate.name, (wrapper) => {
|
|
@@ -48,7 +51,7 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
48
51
|
});
|
|
49
52
|
}
|
|
50
53
|
isTime() {
|
|
51
|
-
this.add(this.isTime.name, (wrapper) => {
|
|
54
|
+
return this.add(this.isTime.name, (wrapper) => {
|
|
52
55
|
const message = `'${wrapper.label}' contiene un formato de hora no válido`;
|
|
53
56
|
const value = wrapper.value.toString();
|
|
54
57
|
const parts = value.replace(/[.,]/g, ':').replace('m', '').match(/^([0-2]?[0-9])(:?)([0-5]?[0-9]?)(:?)([0-5]?[0-9]?)([ap]?)\.?m?\.?$/);
|
|
@@ -62,8 +65,14 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
62
65
|
/* Si middle es diferente de vacío, es porque el usuario tiene la intención de especificar una hora del día, caso contrario, está indicando una duración. */
|
|
63
66
|
if (middle) {
|
|
64
67
|
if (hours >= 1 && hours <= 12) {
|
|
65
|
-
if (middle === 'p')
|
|
66
|
-
hours
|
|
68
|
+
if (middle === 'p') {
|
|
69
|
+
if (hours !== 12)
|
|
70
|
+
hours += 12;
|
|
71
|
+
}
|
|
72
|
+
else { // middle === 'a'
|
|
73
|
+
if (hours === 12)
|
|
74
|
+
hours = 0;
|
|
75
|
+
}
|
|
67
76
|
wrapper.value = `${pols_utils_1.PUtilsString.padStart(hours, 2)}:${pols_utils_1.PUtilsString.padStart(minutes, 2)}:${pols_utils_1.PUtilsString.padStart(seconds, 2)}`;
|
|
68
77
|
return;
|
|
69
78
|
}
|
|
@@ -75,33 +84,27 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
75
84
|
}
|
|
76
85
|
return message;
|
|
77
86
|
});
|
|
78
|
-
return this;
|
|
79
87
|
}
|
|
80
88
|
match(pattern) {
|
|
81
|
-
this.
|
|
82
|
-
this.add(this.match.name, (wrapper) => {
|
|
89
|
+
return this.isString().add(this.match.name, (wrapper) => {
|
|
83
90
|
if (!wrapper.value.match(pattern))
|
|
84
91
|
return `'${wrapper.label}' no cumple con el formato de texto deseado`;
|
|
85
92
|
});
|
|
86
|
-
return this;
|
|
87
93
|
}
|
|
88
94
|
isNumber() {
|
|
89
|
-
this.add(this.isNumber.name, (wrapper) => {
|
|
95
|
+
return this.add(this.isNumber.name, (wrapper) => {
|
|
90
96
|
const message = `'${wrapper.label}' debe ser un número`;
|
|
91
97
|
const value = Number(wrapper.value);
|
|
92
98
|
if (isNaN(value) || value == Infinity)
|
|
93
99
|
return message;
|
|
94
100
|
wrapper.value = value;
|
|
95
101
|
});
|
|
96
|
-
return this;
|
|
97
102
|
}
|
|
98
103
|
isInteger() {
|
|
99
|
-
this.isNumber()
|
|
100
|
-
this.add(this.isInteger.name, (wrapper) => {
|
|
104
|
+
return this.isNumber().add(this.isInteger.name, (wrapper) => {
|
|
101
105
|
if (wrapper.value != Math.floor(wrapper.value))
|
|
102
106
|
return `'${wrapper.label}' debe ser un número entero`;
|
|
103
107
|
});
|
|
104
|
-
return this;
|
|
105
108
|
}
|
|
106
109
|
isNatural() {
|
|
107
110
|
return this.isInteger().isGte(0);
|
|
@@ -109,18 +112,16 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
109
112
|
isNaturalNoZero() {
|
|
110
113
|
return this.isInteger().isGt(0);
|
|
111
114
|
}
|
|
112
|
-
|
|
113
|
-
this.
|
|
114
|
-
this.add(this.onlyNumbers.name, (wrapper) => {
|
|
115
|
+
isNumeric() {
|
|
116
|
+
return this.isString().add(this.isNumeric.name, (wrapper) => {
|
|
115
117
|
if (!wrapper.value.match(/^[0-9]+$/))
|
|
116
118
|
return `'${wrapper.label}' debe contener sólo números`;
|
|
117
119
|
});
|
|
118
|
-
return this;
|
|
119
120
|
}
|
|
120
121
|
maxLength(limit) {
|
|
121
122
|
return this.add(this.maxLength.name, (wrapper) => {
|
|
122
123
|
if (wrapper.value instanceof Array) {
|
|
123
|
-
return wrapper.value.length > limit ? `'${wrapper.label}' debe contener '${limit} ${limit == 1 ? '
|
|
124
|
+
return wrapper.value.length > limit ? `'${wrapper.label}' debe contener '${limit} ${limit == 1 ? 'elemento' : 'elementos'}' como máximo` : null;
|
|
124
125
|
}
|
|
125
126
|
else if (typeof wrapper.value == 'string') {
|
|
126
127
|
return wrapper.value.length > limit ? `'${wrapper.label}' debe contener '${limit} ${limit == 1 ? 'caracter' : 'caracteres'}' como máximo` : null;
|
|
@@ -133,7 +134,7 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
133
134
|
minLength(limit) {
|
|
134
135
|
return this.add(this.minLength.name, (wrapper) => {
|
|
135
136
|
if (wrapper.value instanceof Array) {
|
|
136
|
-
return wrapper.value.length < limit ? `'${wrapper.label}' debe contener '${limit} ${limit == 1 ? '
|
|
137
|
+
return wrapper.value.length < limit ? `'${wrapper.label}' debe contener '${limit} ${limit == 1 ? 'elemento' : 'elementos'}' como mínimo` : null;
|
|
137
138
|
}
|
|
138
139
|
else if (typeof wrapper.value == 'string') {
|
|
139
140
|
return wrapper.value.length < limit ? `'${wrapper.label}' debe contener '${limit} ${limit == 1 ? 'caracter' : 'caracteres'}' como mínimo` : null;
|
|
@@ -146,10 +147,10 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
146
147
|
hasFixedLength(limit) {
|
|
147
148
|
return this.add(this.hasFixedLength.name, (wrapper) => {
|
|
148
149
|
if (wrapper.value instanceof Array) {
|
|
149
|
-
return wrapper.value.length
|
|
150
|
+
return wrapper.value.length !== limit ? `'${wrapper.label}' debe contener sólo '${limit} ${limit == 1 ? 'elemento' : 'elementos'}'` : null;
|
|
150
151
|
}
|
|
151
152
|
else if (typeof wrapper.value == 'string') {
|
|
152
|
-
return wrapper.value.length
|
|
153
|
+
return wrapper.value.length !== limit ? `'${wrapper.label}' debe contener sólo '${limit} ${limit == 1 ? 'caracter' : 'caracteres'}'` : null;
|
|
153
154
|
}
|
|
154
155
|
else {
|
|
155
156
|
return `'${wrapper.label}' no es de un tipo válido`;
|
|
@@ -157,7 +158,7 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
157
158
|
});
|
|
158
159
|
}
|
|
159
160
|
left(limit) {
|
|
160
|
-
return this.
|
|
161
|
+
return this.isString().add(this.left.name, (wrapper) => {
|
|
161
162
|
wrapper.value = wrapper.value.substring(0, limit);
|
|
162
163
|
});
|
|
163
164
|
}
|
|
@@ -171,7 +172,7 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
171
172
|
return message;
|
|
172
173
|
wrapper.value = value;
|
|
173
174
|
}
|
|
174
|
-
catch
|
|
175
|
+
catch {
|
|
175
176
|
return message;
|
|
176
177
|
}
|
|
177
178
|
}
|
|
@@ -185,8 +186,9 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
185
186
|
const messages = [];
|
|
186
187
|
for (const [i, element] of wrapper.value.entries()) {
|
|
187
188
|
const rules = rulesGenerator(i);
|
|
188
|
-
|
|
189
|
-
const
|
|
189
|
+
const elementLabel = rules.label ?? `Elemento ${i + 1}`;
|
|
190
|
+
const nestedLabel = `${wrapper.label ? `${wrapper.label}${this.separator}` : ''}${elementLabel}`;
|
|
191
|
+
const result = rules.validate(element, false, nestedLabel);
|
|
190
192
|
if (result.error == true) {
|
|
191
193
|
wrapper.value[i] = result.interim;
|
|
192
194
|
messages.push(...result.messages);
|
|
@@ -223,7 +225,7 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
223
225
|
hasElements(rulesGenerator) {
|
|
224
226
|
return this.isArray(rulesGenerator).add(this.hasElements.name, (wrapper) => {
|
|
225
227
|
if (!wrapper.value.length)
|
|
226
|
-
return `'${wrapper.label}' debe
|
|
228
|
+
return `'${wrapper.label}' debe contener al menos un elemento`;
|
|
227
229
|
});
|
|
228
230
|
}
|
|
229
231
|
isGt(limit) {
|
|
@@ -283,9 +285,9 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
283
285
|
const errorMessages = [];
|
|
284
286
|
for (const key in schema) {
|
|
285
287
|
const rulesInside = schema[key];
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
const propertyResult = rulesInside.validate(wrapper.value[key], false);
|
|
288
|
+
const labelInside = rulesInside.label ?? key;
|
|
289
|
+
const nestedLabel = `${wrapper.label ? `${wrapper.label}${this.separator}` : ''}${labelInside}`;
|
|
290
|
+
const propertyResult = rulesInside.validate(wrapper.value[key], false, nestedLabel);
|
|
289
291
|
if (propertyResult.error == true) {
|
|
290
292
|
if (propertyResult.interim !== undefined)
|
|
291
293
|
interim[key] = propertyResult.interim;
|
|
@@ -317,11 +319,13 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
317
319
|
case 'SÍ':
|
|
318
320
|
case 'Y':
|
|
319
321
|
case 'YES':
|
|
322
|
+
case 'TRUE':
|
|
320
323
|
wrapper.value = true;
|
|
321
324
|
return;
|
|
322
325
|
case '0':
|
|
323
326
|
case 'N':
|
|
324
327
|
case 'NO':
|
|
328
|
+
case 'FALSE':
|
|
325
329
|
wrapper.value = false;
|
|
326
330
|
return;
|
|
327
331
|
default: {
|
|
@@ -357,63 +361,49 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
357
361
|
});
|
|
358
362
|
}
|
|
359
363
|
upper() {
|
|
360
|
-
this.
|
|
361
|
-
this.add(this.upper.name, (wrapper) => {
|
|
364
|
+
return this.isString().add(this.upper.name, (wrapper) => {
|
|
362
365
|
wrapper.value = wrapper.value.toUpperCase();
|
|
363
366
|
});
|
|
364
|
-
return this;
|
|
365
367
|
}
|
|
366
368
|
lower() {
|
|
367
|
-
this.
|
|
368
|
-
this.add(this.lower.name, (wrapper) => {
|
|
369
|
+
return this.isString().add(this.lower.name, (wrapper) => {
|
|
369
370
|
wrapper.value = wrapper.value.toLowerCase();
|
|
370
371
|
});
|
|
371
|
-
return this;
|
|
372
372
|
}
|
|
373
373
|
decodeURI() {
|
|
374
|
-
this.
|
|
375
|
-
this.add(this.decodeURI.name, (wrapper) => {
|
|
374
|
+
return this.isString().add(this.decodeURI.name, (wrapper) => {
|
|
376
375
|
wrapper.value = decodeURI(wrapper.value);
|
|
377
376
|
});
|
|
378
|
-
return this;
|
|
379
377
|
}
|
|
380
378
|
round(decimals) {
|
|
381
|
-
this.isNumber()
|
|
382
|
-
this.add(this.round.name, (wrapper) => {
|
|
379
|
+
return this.isNumber().add(this.round.name, (wrapper) => {
|
|
383
380
|
wrapper.value = pols_utils_1.PUtilsNumber.round(wrapper.value, decimals);
|
|
384
381
|
});
|
|
385
|
-
return this;
|
|
386
382
|
}
|
|
387
383
|
/* Reemplaza todos los dobles (o más) espacios juntos por uno simple */
|
|
388
384
|
cleanDoubleSpaces() {
|
|
389
|
-
this.
|
|
390
|
-
this.add(this.cleanDoubleSpaces.name, (wrapper) => {
|
|
385
|
+
return this.isString().add(this.cleanDoubleSpaces.name, (wrapper) => {
|
|
391
386
|
wrapper.value = wrapper.value.replace(/\s{2,}/g, ' ');
|
|
392
387
|
});
|
|
393
|
-
return this;
|
|
394
388
|
}
|
|
395
389
|
noSpaces() {
|
|
396
|
-
this.
|
|
397
|
-
this.add(this.noSpaces.name, (wrapper) => {
|
|
390
|
+
return this.isString().add(this.noSpaces.name, (wrapper) => {
|
|
398
391
|
if (wrapper.value.match(/\s/))
|
|
399
392
|
return `'${wrapper.label}' no debe contener 'espacios'`;
|
|
400
393
|
});
|
|
401
|
-
return this;
|
|
402
394
|
}
|
|
403
395
|
replace(search, replace) {
|
|
404
|
-
return this.
|
|
396
|
+
return this.isString().add(this.replace.name, (wrapper) => {
|
|
405
397
|
wrapper.value = wrapper.value.replace(search, replace);
|
|
406
398
|
});
|
|
407
399
|
}
|
|
408
400
|
capitalize() {
|
|
409
|
-
this.
|
|
410
|
-
this.add(this.capitalize.name, (wrapper) => {
|
|
401
|
+
return this.isString().add(this.capitalize.name, (wrapper) => {
|
|
411
402
|
wrapper.value = pols_utils_1.PUtilsString.capitalize(wrapper.value);
|
|
412
403
|
});
|
|
413
|
-
return this;
|
|
414
404
|
}
|
|
415
405
|
split(separator) {
|
|
416
|
-
return this.
|
|
406
|
+
return this.isString().add(this.split.name, (wrapper) => {
|
|
417
407
|
wrapper.value = wrapper.value.split(separator);
|
|
418
408
|
});
|
|
419
409
|
}
|
|
@@ -433,7 +423,7 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
433
423
|
});
|
|
434
424
|
}
|
|
435
425
|
sanitize(params) {
|
|
436
|
-
return this.
|
|
426
|
+
return this.isString().add(this.sanitize.name, (wrapper) => {
|
|
437
427
|
const config = {};
|
|
438
428
|
if (params) {
|
|
439
429
|
if (params.allowedTags)
|
package/dist/rulesEngine.d.ts
CHANGED
|
@@ -34,6 +34,6 @@ export declare class PRulesEngine {
|
|
|
34
34
|
constructor(required?: boolean, _default?: unknown);
|
|
35
35
|
constructor(params?: PRulesParams);
|
|
36
36
|
protected add(name: string, validationFunction: PRulesFunction): this;
|
|
37
|
-
validate<T>(target: unknown, safe?: boolean): PRulesResponse<T>;
|
|
37
|
+
validate<T>(target: unknown, safe?: boolean, customLabel?: string): PRulesResponse<T>;
|
|
38
38
|
}
|
|
39
39
|
//# sourceMappingURL=rulesEngine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rulesEngine.d.ts","sourceRoot":"","sources":["../src/rulesEngine.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;CAClB,GAAG,CAAC;IACJ,QAAQ,CAAC,EAAE,OAAO,CAAA;CAClB,GAAG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CACjB,CAAC,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAA;AAExH,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,OAAO,IAAI;IACxC,KAAK,EAAE,CAAC,CAAA;IACR,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,CAAC,CAAA;CACX,CAAA;AAED,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;IAC/B,KAAK,EAAE,KAAK,CAAA;IACZ,OAAO,EAAE,IAAI,CAAA;IACb,SAAS,EAAE,CAAC,CAAA;CACZ,GAAG;IACH,KAAK,EAAE,IAAI,CAAA;IACX,OAAO,EAAE,KAAK,CAAA;IACd,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,OAAO,EAAE,CAAC,CAAA;CACV,CAAA;AAED,qBAAa,YAAY;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,OAAO,CAAQ;IACzB,OAAO,EAAE,OAAO,CAAO;IAEvB,OAAO,CAAC,mBAAmB,CAAuB;IAClD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,EAAE,MAAM,EAAE,CAAA;IAClB,OAAO,EAAE,CAAC,CAAA;CACV,CAAA;AAED,qBAAa,YAAY;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,OAAO,CAAQ;IACzB,OAAO,EAAE,OAAO,CAAO;IAEvB,OAAO,CAAC,mBAAmB,CAAuB;IAClD,OAAO,CAAC,eAAe,CAAe;gBAE1B,KAAK,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,OAAO;gBACtD,QAAQ,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,OAAO;gBACtC,MAAM,CAAC,EAAE,YAAY;IAmBjC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,kBAAkB,EAAE,cAAc;IAQ9D,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,UAAO,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC;CAmElF"}
|
package/dist/rulesEngine.js
CHANGED
|
@@ -35,13 +35,13 @@ class PRulesEngine {
|
|
|
35
35
|
}
|
|
36
36
|
return this;
|
|
37
37
|
}
|
|
38
|
-
validate(target, safe = true) {
|
|
38
|
+
validate(target, safe = true, customLabel) {
|
|
39
39
|
const errorMessages = [];
|
|
40
40
|
if (typeof target == 'string')
|
|
41
41
|
target = target.trim();
|
|
42
42
|
const defaultIsEmpty = this.default == null || (typeof this.default == 'string' && !this.default);
|
|
43
43
|
const isEmpty = target == null || (typeof target == 'string' && !target);
|
|
44
|
-
const label = this.label;
|
|
44
|
+
const label = customLabel ?? this.label ?? 'El valor';
|
|
45
45
|
if (this.required && isEmpty) {
|
|
46
46
|
return {
|
|
47
47
|
error: true,
|
|
@@ -70,7 +70,7 @@ class PRulesEngine {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
const wrapper = {
|
|
73
|
-
value: safe ?
|
|
73
|
+
value: safe ? structuredClone(target) : target,
|
|
74
74
|
label
|
|
75
75
|
};
|
|
76
76
|
for (const validationFunction of this.collectionFunctions) {
|
package/eslint.config.mjs
CHANGED
|
@@ -3,6 +3,9 @@ import pluginJs from "@eslint/js";
|
|
|
3
3
|
import tseslint from "typescript-eslint";
|
|
4
4
|
|
|
5
5
|
export default [
|
|
6
|
+
{
|
|
7
|
+
ignores: ["dist/**"]
|
|
8
|
+
},
|
|
6
9
|
{
|
|
7
10
|
files: ["**/*.{ts}"],
|
|
8
11
|
},
|
|
@@ -12,7 +15,7 @@ export default [
|
|
|
12
15
|
{
|
|
13
16
|
rules: {
|
|
14
17
|
"@typescript-eslint/no-unused-vars": "warn",
|
|
15
|
-
"@typescript-eslint/no-explicit-any":
|
|
18
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
16
19
|
"no-use-before-define": "off"
|
|
17
20
|
}
|
|
18
21
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pols-validator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "npx tsc",
|
|
9
|
-
"test": "npx ts-node-dev -r tsconfig-paths/register --project tsconfig.json",
|
|
9
|
+
"test": "npx ts-node-dev -r tsconfig-paths/register --project tsconfig.json test/validaciones.ts",
|
|
10
10
|
"export": "npm run build && npm publish"
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|