Skip to content

Add 'flattened' city names #25

@ajmas

Description

@ajmas

Would it be possible to add support for flattened city names, where the accents are removed, so we can look up cities irrespective of their accents?

Right now I have a workaround:
When I load:

    for (let i = 0; i < cityTimezones.cityMapping.length; i++) {
      // eslint-disable-next-line camelcase
      (cityTimezones.cityMapping[i] as any).city_flattened
        = removeAccents(cityTimezones.cityMapping[i].city_ascii).toLowerCase();
    }

and then when I lookup:

   cityName = removeAccents(cityName).toLowerCase();
    cities = CityTimezones.cityMapping;
    for (let i = 0; i < cities.length; i++) {
      if ((cities[i] as any).city_flattened === cityName) {
        return cities[i];
      }
    }

and the implementation for the removeAccents function:

function removeAccents (text: string): string {
  return text.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions