-
Notifications
You must be signed in to change notification settings - Fork 0
/
typeCheck.js
75 lines (63 loc) · 2.31 KB
/
typeCheck.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var typeCheck = {}
typeCheck.isTypeNameValid = function(typeName){
var types = ['any', 'string', 'number', 'boolean', 'date', 'array', 'object', 'smartobject', 'function'];
if(types.indexOf(typeName.toLowerCase()) >= 0){
return true
}
return false;
}
typeCheck.isFunction = function(arg){
return (typeof arg === "function") ? true : false;
}
typeCheck.isArray = function(arg){
return (typeof arg === "object" && Array.isArray(arg)) ? true : false;
}
typeCheck.isSmartObject = function(arg){
if(typeof arg === "object" && ("__$$__isSmartObject" in arg || "__$$__Name" in arg)){
return true;
}
return false;
}
typeCheck.isObject = function(arg){
return (typeof arg === "object" && !Array.isArray(arg) && !this.isSmartObject(arg)) ? true : false;
}
typeCheck.isAny = function(arg){
return (typeof arg === "string" && (arg === "*" || arg === "Any".toLowerCase()) ) ? true : false;
}
module.exports = typeCheck;
/*
//if any, just assign it
if (_objWithType[propsName] === "*" || _objWithType[propsName] === "Any".toLowerCase()){
_objWithValue[propsName] = val;
}
//check if it is array
else if (Array.isArray(val) && _objWithType[propsName] === "Array"){
_objWithValue[propsName] = val;
}
//check if it is a SMARTOBJECT
else if(typeof val === "object" && "__$$__isSmartObject" in val){
var newName = `${_interfaceAPI["__$$__Name"].Name}.${propsName}`;
val["__$$__Name"]["Name"] = newName
_nestedSchema[propsName] = val;
_objWithValue[propsName] = Object.assign({},
{"__$$__Name": {Name: newName}},
val.getSchema()
);
LinkPropsToNestedSchema(_objWithValue[propsName], _nestedSchema[propsName]);
}
//check if it is a function
else if (typeof val === "function"){
if(true){
_objWithValue[propsName] = val;
} else {
errorMessage = `[${_interfaceAPI.__$$__Name.Name}.${propsName}] expected [${_objWithType[propsName]}] , but received a [${typeof val}]`;
}
}
//check and must match the type of _objWithType
else if(typeof val === _objWithType[propsName].toLowerCase()){
_objWithValue[propsName] = val;
}
else {
errorMessage = `[${_interfaceAPI.__$$__Name.Name}.${propsName}] expected [${_objWithType[propsName]}] , but received a [${typeof val}]`;
throw new TypeError(errorMessage)
}*/