Skip to content

Commit

Permalink
Ensure the most populous city is chosen
Browse files Browse the repository at this point in the history
Refs #31, fc0f070
  • Loading branch information
thewilkybarkid committed Aug 6, 2024
1 parent 7702e82 commit 11165b5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lib/Iso3166.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Schema } from '@effect/schema'
import { rawTimeZones } from '@vvo/tzdb'
import cities from 'all-the-cities'
import diacritics from 'diacritics'
import { Array, Option, type Predicate, String, flow } from 'effect'
import { Array, Option, Order, type Predicate, String, flow } from 'effect'
import iso3166 from 'i18n-iso-countries'
import subDivisions from 'world_countries_lists/data/subdivisions/subdivisions.json'

Expand All @@ -13,7 +13,10 @@ export const isAlpha2Code: Predicate.Refinement<unknown, Alpha2Code> = (u): u is

export const Alpha2CodeSchema: Schema.Schema<Alpha2Code, string> = Schema.String.pipe(Schema.filter(isAlpha2Code))

const cities10000 = Array.filter(cities, city => city.population >= 10_000)
const cities10000 = Array.filter(
Array.sortWith(cities, city => city.population, Order.reverse(Order.number)),
city => city.population >= 10_000,
)

export const guessCountry: (location: string) => Option.Option<Alpha2Code> = flow(
String.replaceAll('.', ''),
Expand Down

0 comments on commit 11165b5

Please sign in to comment.