|
|
@ -1,4 +1,4 @@ |
|
|
|
var isObject = require('is-object'); |
|
|
|
var check = require('check-types'); |
|
|
|
var iso3166 = require('iso3166-1'); |
|
|
|
var iso3166 = require('iso3166-1'); |
|
|
|
|
|
|
|
|
|
|
|
function sanitize(raw, clean) { |
|
|
|
function sanitize(raw, clean) { |
|
|
@ -8,23 +8,25 @@ function sanitize(raw, clean) { |
|
|
|
// init clean.boundary (if not already init)
|
|
|
|
// init clean.boundary (if not already init)
|
|
|
|
clean.boundary = clean.boundary || {}; |
|
|
|
clean.boundary = clean.boundary || {}; |
|
|
|
|
|
|
|
|
|
|
|
if (raw['boundary.country']) { |
|
|
|
if (check.assigned(raw['boundary.country'])) { |
|
|
|
var country = raw['boundary.country']; |
|
|
|
var country = raw['boundary.country']; |
|
|
|
|
|
|
|
|
|
|
|
if (typeof country !== 'string') { |
|
|
|
if (!check.string(country)) { |
|
|
|
messages.warnings.push('boundary.country is not a string'); |
|
|
|
messages.warnings.push('boundary.country is not a string'); |
|
|
|
clean.boundary.country = undefined; |
|
|
|
delete clean.boundary.country; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (!containsIsoCode(country.toUpperCase())) { |
|
|
|
else if (!containsIsoCode(country.toUpperCase())) { |
|
|
|
messages.warnings.push(country + ' is not a valid ISO2/ISO3 country code'); |
|
|
|
messages.warnings.push(country + ' is not a valid ISO2/ISO3 country code'); |
|
|
|
clean.boundary.country = undefined; |
|
|
|
delete clean.boundary.country; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
|
|
|
|
// the only way for boundary.country to be assigned is if input is
|
|
|
|
|
|
|
|
// a string and a known ISO2 or ISO3
|
|
|
|
clean.boundary.country = iso3166.to3(country.toUpperCase()); |
|
|
|
clean.boundary.country = iso3166.to3(country.toUpperCase()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
clean.boundary.country = undefined; |
|
|
|
delete clean.boundary.country; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return messages; |
|
|
|
return messages; |
|
|
|