digitalfabrik/integreat-app

View on GitHub
native/src/utils/cityDisplayName.ts

Summary

Maintainability
A
0 mins
Test Coverage
F
0%
import { CityModel } from 'shared/api'

import dimensions from '../constants/dimensions'

export const forceNewlineAfterChar = (text: string, char: string): string => text.replace(char, `${char}\n`)

const cityDisplayName = (city: CityModel | undefined, deviceWidth: number): string => {
  if (!city) {
    return ''
  }
  const cityType = city.prefix ? ` (${city.prefix})` : ''
  const shortCityName = city.sortingName.length < deviceWidth / dimensions.headerTextSize
  return shortCityName ? `${city.sortingName}${cityType}` : `${forceNewlineAfterChar(city.sortingName, '-')}${cityType}`
}

export default cityDisplayName