Skip to content

Commit

Permalink
Expose a shortcut method for fetching the neaest country.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidarvan committed Jun 10, 2020
1 parent bbd66a2 commit 916355f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Expand Up @@ -21,6 +21,7 @@ const WorldCities = {
getByName: City.getByName,
getCountry: Country.getByCountryCode,
getNearestCity: City.getNearest,
getNearestCountry: City.getNearestCountry,
getSqlitePath,
};

Expand Down
6 changes: 6 additions & 0 deletions src/lib/city.test.ts
Expand Up @@ -48,6 +48,12 @@ test('.getNearest finds the correct closest cities', () => {
});


test('.getNearestCountry finds the correct countries', () => {
expect(City.getNearestCountry(50.4727969, -0.0509147645).name).toBe('United Kingdom');
expect(City.getNearestCountry(16.540405, -114.39702284).currencyName).toBe('Peso');
});


test('City schema exported', () => {
const schema = City.schema;
expect(Object.keys(schema.properties).length).toBe(6);
Expand Down
9 changes: 9 additions & 0 deletions src/lib/city.ts
Expand Up @@ -103,6 +103,15 @@ export class City {
}


/**
* Get the country nearest to the GPS coordinates, as determined by the distance,
* as the crow flies.
*/
static getNearestCountry(lat: number, lng: number) {
return City.getNearest(lat, lng).getCountry();
}


static get schema() {
return schema;
}
Expand Down

0 comments on commit 916355f

Please sign in to comment.