mirror of https://github.com/pelias/api.git
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.
33 lines
654 B
33 lines
654 B
9 years ago
|
|
||
9 years ago
|
var _ = require('lodash'),
|
||
|
check = require('check-types');
|
||
|
|
||
9 years ago
|
var DEFAULT_DETAILS_BOOL = true;
|
||
10 years ago
|
|
||
10 years ago
|
// validate inputs, convert types and apply defaults
|
||
9 years ago
|
function sanitize( raw, clean ){
|
||
10 years ago
|
|
||
9 years ago
|
// error & warning messages
|
||
|
var messages = { errors: [], warnings: [] };
|
||
10 years ago
|
|
||
9 years ago
|
if( !check.undefined( raw.details ) ){
|
||
|
clean.details = isTruthy( raw.details );
|
||
10 years ago
|
} else {
|
||
9 years ago
|
clean.details = DEFAULT_DETAILS_BOOL;
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
9 years ago
|
return messages;
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
// be lenient with 'truthy' values
|
||
10 years ago
|
function isTruthy(val) {
|
||
9 years ago
|
if( check.string( val ) ){
|
||
9 years ago
|
return _.includes( ['true', '1'], val );
|
||
10 years ago
|
}
|
||
|
|
||
|
return val === 1 || val === true;
|
||
|
}
|
||
|
|
||
10 years ago
|
// export function
|
||
|
module.exports = sanitize;
|