23 lines
488 B
JavaScript
23 lines
488 B
JavaScript
const _ = require('lodash')
|
|
|
|
let regions = require('../../data/regions')
|
|
|
|
module.exports = function ({ countries }) {
|
|
if (!countries.length) return []
|
|
|
|
const output = []
|
|
regions = Object.values(regions)
|
|
countries.forEach(country => {
|
|
regions
|
|
.filter(region => region.country_codes.includes(country.code))
|
|
.forEach(found => {
|
|
output.push({
|
|
name: found.name,
|
|
code: found.code
|
|
})
|
|
})
|
|
})
|
|
|
|
return _.uniqBy(output, 'code')
|
|
}
|