Added enum data type

pull/7/head
Piero Toffanin 2017-04-11 16:36:20 -04:00
rodzic 7f62e52c66
commit f0a8f7665d
2 zmienionych plików z 16 dodań i 10 usunięć

Wyświetl plik

@ -95,7 +95,7 @@ module.exports = {
} }
if (Array.isArray(values.choices)){ if (Array.isArray(values.choices)){
type = "string"; // TODO: change to enum type = "enum";
domain = values.choices; domain = values.choices;
} }
@ -148,6 +148,9 @@ module.exports = {
}, },
'path': function(value){ 'path': function(value){
return value; // No conversion needed return value; // No conversion needed
},
'enum': function(value){
return value; // No conversion needed
} }
}; };
@ -202,11 +205,13 @@ module.exports = {
return true; // All strings/paths are fine return true; // All strings/paths are fine
} }
} }
// TODO: handle enum
]; ];
let checkDomain = function(domain, value){ let checkDomain = function(domain, value){
if (Array.isArray(domain)){
// Special case for enum checks
if (domain.indexOf(value) === -1) throw new Error(`Invalid value ${value} (not in enum)`);
}else{
let matches, let matches,
dc = domainChecks.find(dc => matches = domain.match(dc.regex)); dc = domainChecks.find(dc => matches = domain.match(dc.regex));
@ -215,6 +220,7 @@ module.exports = {
}else{ }else{
throw new Error(`Domain value cannot be handled: '${domain}' : '${value}'`); throw new Error(`Domain value cannot be handled: '${domain}' : '${value}'`);
} }
}
}; };
// Scan through all possible options // Scan through all possible options

File diff suppressed because one or more lines are too long