Improve naming

This commit is contained in:
Daniel García Aubert 2018-04-17 11:22:05 +02:00
parent 2ff410946a
commit 9905b20448

View File

@ -1,5 +1,5 @@
const positiveIntegerNumber = /^\d+$/; const positiveIntegerNumberRegExp = /^\d+$/;
const integerNumber = /^-?\d+$/; const integerNumberRegExp = /^-?\d+$/;
const invalidZoomMessage = function (zoom) { const invalidZoomMessage = function (zoom) {
return `Invalid zoom value (${zoom}). It should be an integer number greather or equal to 0`; return `Invalid zoom value (${zoom}). It should be an integer number greather or equal to 0`;
}; };
@ -14,7 +14,7 @@ module.exports = function coordinates (validate = { z: true, x: true, y: true })
return function coordinatesMiddleware (req, res, next) { return function coordinatesMiddleware (req, res, next) {
const { z, x, y } = req.params; const { z, x, y } = req.params;
if (validate.z && !positiveIntegerNumber.test(z)) { if (validate.z && !positiveIntegerNumberRegExp.test(z)) {
const err = new Error(invalidZoomMessage(z)); const err = new Error(invalidZoomMessage(z));
err.http_status = 400; err.http_status = 400;
@ -22,14 +22,14 @@ module.exports = function coordinates (validate = { z: true, x: true, y: true })
} }
// Negative values for x param are valid. The x param is wrapped // Negative values for x param are valid. The x param is wrapped
if (validate.x && !integerNumber.test(x)) { if (validate.x && !integerNumberRegExp.test(x)) {
const err = new Error(invalidCoordXMessage(x)); const err = new Error(invalidCoordXMessage(x));
err.http_status = 400; err.http_status = 400;
return next(err); return next(err);
} }
if (validate.y && !positiveIntegerNumber.test(y)) { if (validate.y && !positiveIntegerNumberRegExp.test(y)) {
const err = new Error(invalidCoordYMessage(y)); const err = new Error(invalidCoordYMessage(y));
err.http_status = 400; err.http_status = 400;