Browse Source

Refactor truthy check into separate function

pull/140/head
Diana Shkolnikov 10 years ago
parent
commit
1f6f5a9d52
  1. 19
      sanitiser/_details.js

19
sanitiser/_details.js

@ -18,16 +18,7 @@ function sanitize( req, default_value ){
} }
if (params.details !== undefined) { if (params.details !== undefined) {
var details = params.details; clean.details = isTruthy(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;
} else { } else {
clean.details = default_value; 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 // export function
module.exports = sanitize; module.exports = sanitize;

Loading…
Cancel
Save