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,18 +205,21 @@ 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){
let matches, if (Array.isArray(domain)){
dc = domainChecks.find(dc => matches = domain.match(dc.regex)); // Special case for enum checks
if (domain.indexOf(value) === -1) throw new Error(`Invalid value ${value} (not in enum)`);
if (dc){
if (!dc.validate(matches, value)) throw new Error(`Invalid value ${value} (out of range)`);
}else{ }else{
throw new Error(`Domain value cannot be handled: '${domain}' : '${value}'`); let matches,
dc = domainChecks.find(dc => matches = domain.match(dc.regex));
if (dc){
if (!dc.validate(matches, value)) throw new Error(`Invalid value ${value} (out of range)`);
}else{
throw new Error(`Domain value cannot be handled: '${domain}' : '${value}'`);
}
} }
}; };

File diff suppressed because one or more lines are too long