@ -1,5 +1,20 @@
var check = require ( 'check-types' ) ;
var flipNumberAndStreetCountries = [ 'DEU' , 'FIN' , 'SWE' , 'NOR' , 'DNK' , 'ISL' ] ;
function setup ( ) {
function setup ( ) {
var api = require ( 'pelias-config' ) . generate ( ) . api ;
var settings = api . localization ;
if ( settings && settings . flipNumberAndStreetCountries ) {
var countries = settings . flipNumberAndStreetCountries ;
for ( var i = 0 ; i < countries . length ; i ++ ) {
var country = countries [ i ] ;
if ( flipNumberAndStreetCountries . indexOf ( country === - 1 ) ) {
flipNumberAndStreetCountries . push ( country ) ;
}
}
}
return applyLocalNamingConventions ;
return applyLocalNamingConventions ;
}
}
@ -12,8 +27,17 @@ function applyLocalNamingConventions(req, res, next) {
// loop through data items and flip relevant number/street
// loop through data items and flip relevant number/street
res . data . filter ( function ( place ) {
res . data . filter ( function ( place ) {
// only relevant for German addresses
// relevant for some countries
if ( place . parent . country _a . indexOf ( 'DEU' ) === - 1 ) { return false ; }
var flip = false ;
for ( var i = 0 ; i < place . parent . country _a . length ; i ++ ) {
var country _a = place . parent . country _a [ i ] ;
if ( flipNumberAndStreetCountries . indexOf ( country _a ) !== - 1 ) {
flip = true ;
break ;
}
}
if ( ! flip ) { return false ; }
if ( ! place . hasOwnProperty ( 'address' ) ) { return false ; }
if ( ! place . hasOwnProperty ( 'address' ) ) { return false ; }
if ( ! place . address . hasOwnProperty ( 'number' ) ) { return false ; }
if ( ! place . address . hasOwnProperty ( 'number' ) ) { return false ; }
if ( ! place . address . hasOwnProperty ( 'street' ) ) { return false ; }
if ( ! place . address . hasOwnProperty ( 'street' ) ) { return false ; }
@ -24,7 +48,7 @@ function applyLocalNamingConventions(req, res, next) {
next ( ) ;
next ( ) ;
}
}
// DE address should have the housenumber and street name flipped
// flip the housenumber and street name
// eg. '101 Grolmanstraße' -> 'Grolmanstraße 101'
// eg. '101 Grolmanstraße' -> 'Grolmanstraße 101'
function flipNumberAndStreet ( place ) {
function flipNumberAndStreet ( place ) {
var standard = ( place . address . number + ' ' + place . address . street ) ,
var standard = ( place . address . number + ' ' + place . address . street ) ,