Allow numberOrBooleanParser to parse string correctly. Improve error message in numberParser. Add env variable PARSE_SERVER_CLUSTER for cluster. Add tests (#3034)
This commit is contained in:
committed by
Florent Vilmart
parent
9abf17730f
commit
5082609937
@@ -1,10 +1,10 @@
|
||||
export function numberParser(key) {
|
||||
return function(opt) {
|
||||
opt = parseInt(opt);
|
||||
if (!Number.isInteger(opt)) {
|
||||
throw new Error(`The ${key} is invalid`);
|
||||
const intOpt = parseInt(opt);
|
||||
if (!Number.isInteger(intOpt)) {
|
||||
throw new Error(`Key ${key} has invalid value ${opt}`);
|
||||
}
|
||||
return opt;
|
||||
return intOpt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,12 @@ export function numberOrBoolParser(key) {
|
||||
if (typeof opt === 'boolean') {
|
||||
return opt;
|
||||
}
|
||||
if (opt === 'true') {
|
||||
return true;
|
||||
}
|
||||
if (opt === 'false') {
|
||||
return false;
|
||||
}
|
||||
return numberParser(key)(opt);
|
||||
}
|
||||
}
|
||||
@@ -45,7 +51,7 @@ export function moduleOrObjectParser(opt) {
|
||||
}
|
||||
|
||||
export function booleanParser(opt) {
|
||||
if (opt == true || opt == "true" || opt == "1") {
|
||||
if (opt == true || opt == 'true' || opt == '1') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user