-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCProtypes.js
54 lines (46 loc) · 1.56 KB
/
CProtypes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import CValidateProptypes from "./js/CValidateProptypes.js";
// Validacion de los datos de cada parametro
export class CProtypes {
/**
*
* @param funct
* @param params los valores enviados en los parametros
* @constructor
*/
static VALIDATE(funct,params) {
const { name, prototype } = funct;
const arg = (params.length === 1) ? params[0] : params;
this.VerificarProptypes(name, prototype, arg);
}
static VerificarProptypes(nameFunction, prop, args) {
const key = Object.values(args);
for (let i = 0; i < key.length; i++) {
const valor = key[i];
const clave = Object.keys(prop)[i];
const value = Object.values(prop)[i];
switch (value) {
case 'string':
CValidateProptypes.string(valor, clave, nameFunction);
break;
case 'number':
CValidateProptypes.number(valor, clave, nameFunction);
break;
case 'boolean':
CValidateProptypes.boolean(valor, clave, nameFunction);
break;
case 'object':
CValidateProptypes.object(valor, clave, nameFunction);
break;
default:
throw new Error('Error Type Verify');
}
}
}
}
export const PropTypes = {
string: ()=> 'string',
boolean: ()=> 'boolean',
number: ()=> 'number',
object: ()=> 'object',
undefined: ()=> 'undefined',
}