pols-validator 3.0.0 → 4.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/dist/rules.d.ts +1 -1
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +39 -30
- 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 +4 -4
- package/.vscode/launch.json +0 -22
- package/.vscode/settings.json +0 -4
package/dist/rules.d.ts
CHANGED
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,
|
|
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,QAAQ;IAWR,cAAc;IAed,UAAU;IAUV,MAAM;IAMN,MAAM;IAgCN,KAAK,CAAC,OAAO,EAAE,MAAM;IAQrB,QAAQ;IAUR,SAAS;IAQT,SAAS;IAIT,eAAe;IAIf,WAAW;IAQX,SAAS,CAAC,KAAK,EAAE,MAAM;IAYvB,SAAS,CAAC,KAAK,EAAE,MAAM;IAYvB,cAAc,CAAC,KAAK,EAAE,MAAM;IAY5B,IAAI,CAAC,KAAK,EAAE,MAAM;IAMlB,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM;IAoClD,IAAI,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE;IAY3B,OAAO,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE;IAM9B,WAAW,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM;IAMtD,IAAI,CAAC,KAAK,EAAE,MAAM;IAMlB,KAAK,CAAC,KAAK,EAAE,MAAM;IAMnB,IAAI,CAAC,KAAK,EAAE,MAAM;IAMlB,KAAK,CAAC,KAAK,EAAE,MAAM;IAMnB,iBAAiB;IAOjB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IA4CxC,SAAS;IAiDT,KAAK;IAQL,KAAK;IAQL,SAAS;IAQT,KAAK,CAAC,QAAQ,EAAE,MAAM;IAStB,iBAAiB;IAQjB,QAAQ;IASR,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC;IAMlG,UAAU;IAQV,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,23 @@ 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
|
+
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
16
|
}
|
|
17
17
|
});
|
|
18
18
|
return this;
|
|
19
19
|
}
|
|
20
20
|
isEmailAddress() {
|
|
21
|
-
this.
|
|
21
|
+
this.isString();
|
|
22
22
|
this.add(this.isEmailAddress.name, (wrapper) => {
|
|
23
23
|
const message = `'${wrapper.label}' debe ser una dirección de correo válida`;
|
|
24
24
|
if (wrapper.value.match(/^[^\sñáéíóúäëïöü@]+@[^\sñáéíóúäëïöü@]+\.[^\sñáéíóúäëïöü@]{2,}$/i)) {
|
|
25
|
-
if (wrapper.value.match(/[.]{2}
|
|
25
|
+
if (wrapper.value.match(/[.]{2}|,/)) {
|
|
26
26
|
return message;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -62,8 +62,14 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
62
62
|
/* 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
63
|
if (middle) {
|
|
64
64
|
if (hours >= 1 && hours <= 12) {
|
|
65
|
-
if (middle === 'p')
|
|
66
|
-
hours
|
|
65
|
+
if (middle === 'p') {
|
|
66
|
+
if (hours !== 12)
|
|
67
|
+
hours += 12;
|
|
68
|
+
}
|
|
69
|
+
else { // middle === 'a'
|
|
70
|
+
if (hours === 12)
|
|
71
|
+
hours = 0;
|
|
72
|
+
}
|
|
67
73
|
wrapper.value = `${pols_utils_1.PUtilsString.padStart(hours, 2)}:${pols_utils_1.PUtilsString.padStart(minutes, 2)}:${pols_utils_1.PUtilsString.padStart(seconds, 2)}`;
|
|
68
74
|
return;
|
|
69
75
|
}
|
|
@@ -78,7 +84,7 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
78
84
|
return this;
|
|
79
85
|
}
|
|
80
86
|
match(pattern) {
|
|
81
|
-
this.
|
|
87
|
+
this.isString();
|
|
82
88
|
this.add(this.match.name, (wrapper) => {
|
|
83
89
|
if (!wrapper.value.match(pattern))
|
|
84
90
|
return `'${wrapper.label}' no cumple con el formato de texto deseado`;
|
|
@@ -110,7 +116,7 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
110
116
|
return this.isInteger().isGt(0);
|
|
111
117
|
}
|
|
112
118
|
onlyNumbers() {
|
|
113
|
-
this.
|
|
119
|
+
this.isString();
|
|
114
120
|
this.add(this.onlyNumbers.name, (wrapper) => {
|
|
115
121
|
if (!wrapper.value.match(/^[0-9]+$/))
|
|
116
122
|
return `'${wrapper.label}' debe contener sólo números`;
|
|
@@ -120,7 +126,7 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
120
126
|
maxLength(limit) {
|
|
121
127
|
return this.add(this.maxLength.name, (wrapper) => {
|
|
122
128
|
if (wrapper.value instanceof Array) {
|
|
123
|
-
return wrapper.value.length > limit ? `'${wrapper.label}' debe contener '${limit} ${limit == 1 ? '
|
|
129
|
+
return wrapper.value.length > limit ? `'${wrapper.label}' debe contener '${limit} ${limit == 1 ? 'elemento' : 'elementos'}' como máximo` : null;
|
|
124
130
|
}
|
|
125
131
|
else if (typeof wrapper.value == 'string') {
|
|
126
132
|
return wrapper.value.length > limit ? `'${wrapper.label}' debe contener '${limit} ${limit == 1 ? 'caracter' : 'caracteres'}' como máximo` : null;
|
|
@@ -133,7 +139,7 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
133
139
|
minLength(limit) {
|
|
134
140
|
return this.add(this.minLength.name, (wrapper) => {
|
|
135
141
|
if (wrapper.value instanceof Array) {
|
|
136
|
-
return wrapper.value.length < limit ? `'${wrapper.label}' debe contener '${limit} ${limit == 1 ? '
|
|
142
|
+
return wrapper.value.length < limit ? `'${wrapper.label}' debe contener '${limit} ${limit == 1 ? 'elemento' : 'elementos'}' como mínimo` : null;
|
|
137
143
|
}
|
|
138
144
|
else if (typeof wrapper.value == 'string') {
|
|
139
145
|
return wrapper.value.length < limit ? `'${wrapper.label}' debe contener '${limit} ${limit == 1 ? 'caracter' : 'caracteres'}' como mínimo` : null;
|
|
@@ -146,10 +152,10 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
146
152
|
hasFixedLength(limit) {
|
|
147
153
|
return this.add(this.hasFixedLength.name, (wrapper) => {
|
|
148
154
|
if (wrapper.value instanceof Array) {
|
|
149
|
-
return wrapper.value.length
|
|
155
|
+
return wrapper.value.length !== limit ? `'${wrapper.label}' debe contener sólo '${limit} ${limit == 1 ? 'elemento' : 'elementos'}'` : null;
|
|
150
156
|
}
|
|
151
157
|
else if (typeof wrapper.value == 'string') {
|
|
152
|
-
return wrapper.value.length
|
|
158
|
+
return wrapper.value.length !== limit ? `'${wrapper.label}' debe contener sólo '${limit} ${limit == 1 ? 'caracter' : 'caracteres'}'` : null;
|
|
153
159
|
}
|
|
154
160
|
else {
|
|
155
161
|
return `'${wrapper.label}' no es de un tipo válido`;
|
|
@@ -157,7 +163,7 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
157
163
|
});
|
|
158
164
|
}
|
|
159
165
|
left(limit) {
|
|
160
|
-
return this.
|
|
166
|
+
return this.isString().add(this.left.name, (wrapper) => {
|
|
161
167
|
wrapper.value = wrapper.value.substring(0, limit);
|
|
162
168
|
});
|
|
163
169
|
}
|
|
@@ -171,7 +177,7 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
171
177
|
return message;
|
|
172
178
|
wrapper.value = value;
|
|
173
179
|
}
|
|
174
|
-
catch
|
|
180
|
+
catch {
|
|
175
181
|
return message;
|
|
176
182
|
}
|
|
177
183
|
}
|
|
@@ -185,8 +191,9 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
185
191
|
const messages = [];
|
|
186
192
|
for (const [i, element] of wrapper.value.entries()) {
|
|
187
193
|
const rules = rulesGenerator(i);
|
|
188
|
-
|
|
189
|
-
const
|
|
194
|
+
const elementLabel = rules.label ?? `Elemento ${i + 1}`;
|
|
195
|
+
const nestedLabel = `${wrapper.label ? `${wrapper.label}${this.separator}` : ''}${elementLabel}`;
|
|
196
|
+
const result = rules.validate(element, false, nestedLabel);
|
|
190
197
|
if (result.error == true) {
|
|
191
198
|
wrapper.value[i] = result.interim;
|
|
192
199
|
messages.push(...result.messages);
|
|
@@ -223,7 +230,7 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
223
230
|
hasElements(rulesGenerator) {
|
|
224
231
|
return this.isArray(rulesGenerator).add(this.hasElements.name, (wrapper) => {
|
|
225
232
|
if (!wrapper.value.length)
|
|
226
|
-
return `'${wrapper.label}' debe
|
|
233
|
+
return `'${wrapper.label}' debe contener al menos un elemento`;
|
|
227
234
|
});
|
|
228
235
|
}
|
|
229
236
|
isGt(limit) {
|
|
@@ -283,9 +290,9 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
283
290
|
const errorMessages = [];
|
|
284
291
|
for (const key in schema) {
|
|
285
292
|
const rulesInside = schema[key];
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
const propertyResult = rulesInside.validate(wrapper.value[key], false);
|
|
293
|
+
const labelInside = rulesInside.label ?? key;
|
|
294
|
+
const nestedLabel = `${wrapper.label ? `${wrapper.label}${this.separator}` : ''}${labelInside}`;
|
|
295
|
+
const propertyResult = rulesInside.validate(wrapper.value[key], false, nestedLabel);
|
|
289
296
|
if (propertyResult.error == true) {
|
|
290
297
|
if (propertyResult.interim !== undefined)
|
|
291
298
|
interim[key] = propertyResult.interim;
|
|
@@ -317,11 +324,13 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
317
324
|
case 'SÍ':
|
|
318
325
|
case 'Y':
|
|
319
326
|
case 'YES':
|
|
327
|
+
case 'TRUE':
|
|
320
328
|
wrapper.value = true;
|
|
321
329
|
return;
|
|
322
330
|
case '0':
|
|
323
331
|
case 'N':
|
|
324
332
|
case 'NO':
|
|
333
|
+
case 'FALSE':
|
|
325
334
|
wrapper.value = false;
|
|
326
335
|
return;
|
|
327
336
|
default: {
|
|
@@ -357,21 +366,21 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
357
366
|
});
|
|
358
367
|
}
|
|
359
368
|
upper() {
|
|
360
|
-
this.
|
|
369
|
+
this.isString();
|
|
361
370
|
this.add(this.upper.name, (wrapper) => {
|
|
362
371
|
wrapper.value = wrapper.value.toUpperCase();
|
|
363
372
|
});
|
|
364
373
|
return this;
|
|
365
374
|
}
|
|
366
375
|
lower() {
|
|
367
|
-
this.
|
|
376
|
+
this.isString();
|
|
368
377
|
this.add(this.lower.name, (wrapper) => {
|
|
369
378
|
wrapper.value = wrapper.value.toLowerCase();
|
|
370
379
|
});
|
|
371
380
|
return this;
|
|
372
381
|
}
|
|
373
382
|
decodeURI() {
|
|
374
|
-
this.
|
|
383
|
+
this.isString();
|
|
375
384
|
this.add(this.decodeURI.name, (wrapper) => {
|
|
376
385
|
wrapper.value = decodeURI(wrapper.value);
|
|
377
386
|
});
|
|
@@ -386,14 +395,14 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
386
395
|
}
|
|
387
396
|
/* Reemplaza todos los dobles (o más) espacios juntos por uno simple */
|
|
388
397
|
cleanDoubleSpaces() {
|
|
389
|
-
this.
|
|
398
|
+
this.isString();
|
|
390
399
|
this.add(this.cleanDoubleSpaces.name, (wrapper) => {
|
|
391
400
|
wrapper.value = wrapper.value.replace(/\s{2,}/g, ' ');
|
|
392
401
|
});
|
|
393
402
|
return this;
|
|
394
403
|
}
|
|
395
404
|
noSpaces() {
|
|
396
|
-
this.
|
|
405
|
+
this.isString();
|
|
397
406
|
this.add(this.noSpaces.name, (wrapper) => {
|
|
398
407
|
if (wrapper.value.match(/\s/))
|
|
399
408
|
return `'${wrapper.label}' no debe contener 'espacios'`;
|
|
@@ -401,19 +410,19 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
401
410
|
return this;
|
|
402
411
|
}
|
|
403
412
|
replace(search, replace) {
|
|
404
|
-
return this.
|
|
413
|
+
return this.isString().add(this.replace.name, (wrapper) => {
|
|
405
414
|
wrapper.value = wrapper.value.replace(search, replace);
|
|
406
415
|
});
|
|
407
416
|
}
|
|
408
417
|
capitalize() {
|
|
409
|
-
this.
|
|
418
|
+
this.isString();
|
|
410
419
|
this.add(this.capitalize.name, (wrapper) => {
|
|
411
420
|
wrapper.value = pols_utils_1.PUtilsString.capitalize(wrapper.value);
|
|
412
421
|
});
|
|
413
422
|
return this;
|
|
414
423
|
}
|
|
415
424
|
split(separator) {
|
|
416
|
-
return this.
|
|
425
|
+
return this.isString().add(this.split.name, (wrapper) => {
|
|
417
426
|
wrapper.value = wrapper.value.split(separator);
|
|
418
427
|
});
|
|
419
428
|
}
|
|
@@ -433,7 +442,7 @@ class PRules extends rulesEngine_1.PRulesEngine {
|
|
|
433
442
|
});
|
|
434
443
|
}
|
|
435
444
|
sanitize(params) {
|
|
436
|
-
return this.
|
|
445
|
+
return this.isString().add(this.sanitize.name, (wrapper) => {
|
|
437
446
|
const config = {};
|
|
438
447
|
if (params) {
|
|
439
448
|
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/rul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,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.0.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": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"isomorphic-dompurify": "^2.21.0",
|
|
32
|
-
"pols-date": "^
|
|
33
|
-
"pols-utils": "^
|
|
32
|
+
"pols-date": "^2.0.2",
|
|
33
|
+
"pols-utils": "^6.0.1"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/.vscode/launch.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Use IntelliSense to learn about possible attributes.
|
|
3
|
-
// Hover to view descriptions of existing attributes.
|
|
4
|
-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
-
"version": "0.2.0",
|
|
6
|
-
"configurations": [
|
|
7
|
-
{
|
|
8
|
-
"type": "node",
|
|
9
|
-
"request": "launch",
|
|
10
|
-
"name": "npm run test",
|
|
11
|
-
"skipFiles": [
|
|
12
|
-
"<node_internals>/**"
|
|
13
|
-
],
|
|
14
|
-
"runtimeExecutable": "npm",
|
|
15
|
-
"runtimeArgs": [
|
|
16
|
-
"run",
|
|
17
|
-
"test",
|
|
18
|
-
"test/validaciones.ts"
|
|
19
|
-
]
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
}
|
package/.vscode/settings.json
DELETED