Merge pull request #7 from pierotofy/master

Added enum data type
pull/8/head
Piero Toffanin 2017-04-11 16:38:18 -04:00 zatwierdzone przez GitHub
commit 3ed48cffbb
2 zmienionych plików z 16 dodań i 10 usunięć

Wyświetl plik

@ -95,7 +95,7 @@ module.exports = {
}
if (Array.isArray(values.choices)){
type = "string"; // TODO: change to enum
type = "enum";
domain = values.choices;
}
@ -148,6 +148,9 @@ module.exports = {
},
'path': function(value){
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
}
}
// TODO: handle enum
];
let checkDomain = function(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)`);
if (Array.isArray(domain)){
// Special case for enum checks
if (domain.indexOf(value) === -1) throw new Error(`Invalid value ${value} (not in enum)`);
}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