Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions import/source/whosonfirst/config/generic.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const _ = require('lodash')
const iso3166 = require('iso3166-1')

/**
* This file provides some convenience functions for finding the 'generic name'
Expand Down Expand Up @@ -38,6 +39,13 @@ function getName (properties) {
if (name) { return name.trim() }
}

function toIso3Abbreviation (abbr, placetype) {
if ((placetype === 'country' || placetype === 'dependency') && iso3166.is2(abbr)) {
return iso3166.to3(abbr)
}
return abbr
}

// convenience function to find a generic abbreviation for the place
function getAbbreviation (properties) {
const placeType = _.get(properties, 'wof:placetype')
Expand All @@ -48,18 +56,18 @@ function getAbbreviation (properties) {

// use the 3 letter country code for 'country' placetypes
if (placeType === 'country' && countryCode) {
return countryCode.trim()
return toIso3Abbreviation(countryCode.trim(), placeType)
}

// use shortcode
if (shortCode) { return shortCode.trim() }
if (shortCode) { return toIso3Abbreviation(shortCode.trim(), placeType) }

// use abbreviation
if (abbreviation) { return abbreviation.trim() }
if (abbreviation) { return toIso3Abbreviation(abbreviation.trim(), placeType) }

// support the deprecated 'wof:country' field
if (placeType === 'dependency' && country) {
return country.trim()
return toIso3Abbreviation(country.trim(), placeType)
}
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"express-handlebars": "^3.1.0",
"handlebars-helpers": "^0.10.0",
"iso-639-3": "^1.2.0",
"iso3166-1": "^0.5.1",
"locale": "^0.1.0",
"lodash": "^4.17.15",
"morgan": "^1.9.1",
Expand Down