You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
651 B

var check = require('check-types');
var DEFAULT_DETAILS_BOOL = true;
10 years ago
// validate inputs, convert types and apply defaults
function sanitize( unclean, clean ){
// error & warning messages
var messages = { errors: [], warnings: [] };
if( !check.undefined( unclean.details ) ){
clean.details = isTruthy( unclean.details );
} else {
clean.details = DEFAULT_DETAILS_BOOL;
}
return messages;
}
// be lenient with 'truthy' values
function isTruthy(val) {
if( check.string( val ) ){
return ['true', '1', 'yes', 'y'].indexOf(val) !== -1;
}
return val === 1 || val === true;
}
// export function
module.exports = sanitize;