Explore the World with Worldpedia: A JavaScript Library for Geographical Data
Are you a developer looking for a comprehensive JavaScript library that provides easy access to geographical data like continents, subregions, countries, states, and cities? Look no further! Introducing "Worldpedia," a powerful and user-friendly JavaScript library that opens the door to a world of geographical information at your fingertips.
⛳ Features
Worldpedia offers a wide range of features that can greatly simplify your geographical data handling. Here are some of its key features:
Continents and Subregions: With Worldpedia, you can effortlessly fetch a list of all continents and their respective subregions. This information can be invaluable for various applications like mapping, data visualization, or simply for educational purposes.
Countries and States: The library allows you to access data for individual countries and their respective states or regions. This can be extremely useful when you need to filter data based on geographical boundaries.
Cities: Worldpedia also provides data on cities from around the globe. Whether you need to list cities within a specific state or country, or if you're building a location-based application, this feature will prove indispensable.
⚙️ Install
Installing Worldpedia is as simple as running an npm command. Open your terminal and execute the following:
npm i worldpedia
With just one line of code, you'll have the entire library at your disposal.
🔭 Usage
Using Worldpedia is a breeze, thanks to its straightforward module system. You can import specific modules based on the data you need. Let's take a look at how you can use each module:
Continent
The Continent module provides functions to access information related to continents.
getAllContinents()
This function returns an array of all available continents along with their codes.
import { Continent } from 'worldpedia';
const allContinents = Continent.getAllContinents();
console.log(allContinents);
Output:
[
{
"code": "AF",
"name": "Africa"
},
{
"code": "AN",
"name": "Antarctica"
},
{
"code": "AS",
"name": "Asia"
},
{
"code": "EU",
"name": "Europe"
},
{
"code": "NA",
"name": "North America"
},
{
"code": "OC",
"name": "Oceania"
},
{
"code": "SA",
"name": "South America"
}
]
getContinentByCode(continentCode)
This function accepts a continent code as a parameter and returns the continent object matching the code.
import { Continent } from 'worldpedia';
const continentCode = 'AS';
const continent = Continent.getContinentByCode(continentCode);
console.log(continent);
Output:
{
"code": "AS",
"name": "Asia"
}
Subregion
The Subregion module allows you to access data related to geographical subregions.
getAllSubregion()
This function returns an array of all available subregions along with their continent information.
import { Subregion } from 'worldpedia';
const allSubregions = Subregion.getAllSubregion();
console.log(allSubregions);
Output:
[
{
"name": "Southern Asia",
"continent": "Asia",
"continent_code": "AS"
},
{
"name": "Northern Europe",
"continent": "Europe",
"continent_code": "EU"
},
//...
]
getAllSubregionByContinent(continentCode)
This function accepts a continent code as a parameter and returns an array of subregions belonging to that continent.
import { Subregion } from 'worldpedia';
const continentCode = 'AS';
const subregionsInContinent = Subregion.getAllSubregionByContinent(continentCode);
console.log(subregionsInContinent);
Output:
[
{
"name": "Southern Asia",
"continent": "Asia",
"continent_code": "AS"
},
{
"name": "Western Asia",
"continent": "Asia",
"continent_code": "AS"
},
//...
]
Country
The Country module provides functions to access information related to countries.
getAllCountries()
This function returns an array of all available countries.
import { Country } from 'worldpedia';
const allCountries = Country.getAllCountries();
console.log(allCountries);
Output:
[
{
"id": 1,
"name": "Afghanistan",
"iso3": "AFG",
"iso2": "AF",
//...
"continent": "Asia",
"continent_code": "AS"
},
//...
]
getCountryByCode(code)
This function accepts a country code as a parameter and returns the country object matching the code.
import { Country } from 'worldpedia';
const countryCode = 'IN';
const country = Country.getCountryByCode(countryCode);
console.log(country);
Output:
{
"name": "India",
"iso3": "IND",
"iso2": "IN",
//...
"continent": "Asia",
"continent_code": "AS"
}
getAllCountriesByContinent(continentCode)
This function accepts a continent code as a parameter and returns an array of all countries in that continent.
import { Country } from 'worldpedia';
const continentCode = 'AS';
const countriesInContinent = Country.getAllCountriesByContinent(continentCode);
console.log(countriesInContinent);
Output:
[
{
"name": "Afghanistan",
"iso3": "AFG",
"iso2": "AF",
//...
"continent": "Asia",
"continent_code": "AS"
},
//...
]
getAllCountriesBySubregion(subregion)
This function accepts a subregion name as a parameter and returns an array of all countries in that subregion.
import { Country } from 'worldpedia';
const subregion = 'Southern Asia';
const countriesInSubregion = Country.getAllCountriesBySubregion(subregion);
console.log(countriesInSubregion);
Output:
[
{
"name": "Afghanistan",
"iso3": "AFG",
"iso2": "AF",
//...
"continent": "Asia",
"continent_code": "AS"
},
//...
]
State
The State module provides functions to access information related to states or regions within countries.
getAllStates()
This function returns an array of all available states.
import { State } from 'worldpedia';
const allStates = State.getAllStates();
console.log(allStates);
Output:
[
{
"name": "Maharashtra",
"isoCode": "MH",
"
countryCode": "IN",
//...
},
//...
]
getAllStatesByCountry(countryCode)
This function accepts a country code as a parameter and returns an array of all states in that country.
import { State } from 'worldpedia';
const countryCode = 'IN';
const statesInCountry = State.getAllStatesByCountry(countryCode);
console.log(statesInCountry);
Output:
[
{
"name": "Maharashtra",
"isoCode": "MH",
"countryCode": "IN",
//...
},
//...
]
getStateByCodeAndCountry(stateCode, countryCode)
This function accepts a state ISO code and a country code as parameters and returns the state object matching the codes.
import { State } from 'worldpedia';
const stateCode = 'MH';
const countryCode = 'IN';
const state = State.getStateByCodeAndCountry(stateCode, countryCode);
console.log(state);
Output:
{
"name": "Maharashtra",
"isoCode": "MH",
"countryCode": "IN",
//...
}
City
The City module provides functions to access information related to cities.
getAllCities()
This function returns an array of all available cities.
import { City } from 'worldpedia';
const allCities = City.getAllCities();
console.log(allCities);
Output:
[
{
"name": "Achalpur",
"countryCode": "IN",
"stateCode": "MH",
//...
},
//...
]
getAllCitiesOfState(stateCode, countryCode)
This function accepts a state code and a country code as parameters and returns an array of all cities in that state.
import { City } from 'worldpedia';
const stateCode = 'MH';
const countryCode = 'IN';
const citiesInState = City.getAllCitiesOfState(stateCode, countryCode);
console.log(citiesInState);
Output:
[
{
"name": "Achalpur",
"countryCode": "IN",
"stateCode": "MH",
//...
},
//...
]
getAllCitiesByCountry(countryCode)
This function accepts a country code as a parameter and returns an array of all cities in that country.
import { City } from 'worldpedia';
const countryCode = 'IN';
const citiesInCountry = City.getAllCitiesByCountry(countryCode);
console.log(citiesInCountry);
Output:
[
{
"name": "Achalpur",
"countryCode": "IN",
"stateCode": "MH",
//...
},
//...
]
✍️ How to Contribute
If you're excited about Worldpedia and want to contribute to its development, here's how you can get started:
- Clone the repository and create a new branch:
$ git clone https://github.com/meswapnilwagh/worldpedia -b branch-name
Make your changes and test them thoroughly.
Submit a Pull Request with a comprehensive description of your changes.
Don't miss out on the opportunity to explore the world in a whole new way with Worldpedia! Install the library today and unlock a world of geographical data for your next project. Happy coding! 🌍