From 1f6f5a9d52c8c3019ce71457b754c32fc2bd0aa0 Mon Sep 17 00:00:00 2001 From: Diana Shkolnikov Date: Thu, 18 Jun 2015 14:24:34 -0400 Subject: [PATCH] Refactor truthy check into separate function --- sanitiser/_details.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/sanitiser/_details.js b/sanitiser/_details.js index 6e51f829..6dc2b119 100644 --- a/sanitiser/_details.js +++ b/sanitiser/_details.js @@ -18,16 +18,7 @@ function sanitize( req, default_value ){ } if (params.details !== undefined) { - var details = params.details; - - if (typeof params.details === 'string') { - details = params.details === 'true' || - params.details === '1' || - params.details === 'yes' || - params.details === 'y'; - } - - clean.details = details === true || details === 1; + clean.details = isTruthy(params.details); } else { clean.details = default_value; } @@ -38,5 +29,13 @@ function sanitize( req, default_value ){ } +function isTruthy(val) { + if (typeof val === 'string') { + return ['true', '1', 'yes', 'y'].indexOf(val) !== -1; + } + + return val === 1 || val === true; +} + // export function module.exports = sanitize;