Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'flattened' city names #25

Open
ajmas opened this issue Aug 26, 2023 · 0 comments
Open

Add 'flattened' city names #25

ajmas opened this issue Aug 26, 2023 · 0 comments

Comments

@ajmas
Copy link

ajmas commented Aug 26, 2023

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, '');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant