Geographical Data Processing Package
npm install terra-packbash
npm install terra-pack
`
Usage
$3
You can import the functions you need from the package as follows:
`typescript
import { getCountry, listContinents } from "terra-pack";
`
$3
- countriesByContinent(continent: string, filter?: exclusion): Get countries by continent.
- countriesBySubContinent(subContinent: string, filter?: exclusion): Get countries by subcontinent.
- listContinents(): List all continents.
- listSubContinents(): List all subcontinents.
- getCountry(countryName: string, filter?: exclusion): Get a country by its name.
- getAllCountries(filter?: exclusion): Get all countries.
- getCountryByISO2(ISO2: string, filter?: exclusion): Get a country by its ISO2 code.
- reverseGeoLocate(latitude: number, longitude: number, extend?: boolean): Find the closest city to a set of coordinates.
- getStatesOfCountry(countryName: string, includeRegions?: boolean): Get states of a specific country.
- getRegionsOfState(stateName: string): Get regions (cities) of a specific state.
- getCountryByCityName(cityName: string, filter?: exclusion): Get a country by a city's name.
- getCountryByStateName(stateName: string, filter?: exclusion): Get a country by a state's name.
- distanceBetweenCoordinates(lat1: number, lon1: number, lat2: number, lon2: number): Calculate the distance between two coordinates.
- getAllStates(filter?: exclusion): Get all states.
- getAllCities(filter?: exclusion): Get all cities.
TypeScript Interfaces
$3
`typescript
export interface Country {
name: string;
iso3: string;
iso2: string;
phone_code: string;
capital: string;
currency: string;
currency_name: string;
tld: string;
native: string;
region: string;
subregion: string;
nationality: string;
timezones?: TimeZone[];
translations?: { [key: string]: string };
latitude: string;
longitude: string;
emoji: string;
emojiU: string;
states?: State[];
}
`
$3
`typescript
export interface State {
name: string;
state_code: string;
latitude: string;
longitude: string;
type: "city" | "province" | null;
cities?: City[];
}
`
$3
`typescript
export interface City {
name: string;
latitude: string;
longitude: string;
}
`
$3
`typescript
export interface GeoLocate extends City {
distance: number;
state?: State;
country?: Country;
closestHit?: GeoLocate[];
}
`
$3
`typescript
export type exclusion = Exclude[];
``