mirror of https://github.com/pelias/api.git
Diana Shkolnikov
9 years ago
7 changed files with 99 additions and 77 deletions
@ -0,0 +1,32 @@
|
||||
|
||||
var _ = require('lodash'), |
||||
check = require('check-types'); |
||||
|
||||
var DEFAULT_DETAILS_BOOL = true; |
||||
|
||||
// validate inputs, convert types and apply defaults
|
||||
function sanitize( raw, clean ){ |
||||
|
||||
// error & warning messages
|
||||
var messages = { errors: [], warnings: [] }; |
||||
|
||||
if( !check.undefined( raw.details ) ){ |
||||
clean.details = isTruthy( raw.details ); |
||||
} else { |
||||
clean.details = DEFAULT_DETAILS_BOOL; |
||||
} |
||||
|
||||
return messages; |
||||
} |
||||
|
||||
// be lenient with 'truthy' values
|
||||
function isTruthy(val) { |
||||
if( check.string( val ) ){ |
||||
return _.contains( ['true', '1'], val ); |
||||
} |
||||
|
||||
return val === 1 || val === true; |
||||
} |
||||
|
||||
// export function
|
||||
module.exports = sanitize; |
Loading…
Reference in new issue