|
| 1 | +[](https://github.com/JavaScript-Bits/countries-with-cities-select) [](https://github.com/JavaScript-Bits/countries-with-cities-select) [](https://github.com/JavaScript-Bits/countries-with-cities-select) |
| 2 | + |
| 3 | +# countries-with-cities-select |
| 4 | +Retrieve all countries with cities |
| 5 | + |
| 6 | +## Table of Contents |
| 7 | ++ [Get countries](#get-countries) |
| 8 | ++ [Get countries with details](#get-countries-with-details) |
| 9 | ++ [Get cities](#get-cities) |
| 10 | + |
| 11 | +## Features |
| 12 | ++ Get names, codes and cities of all countries |
| 13 | ++ Filter cities by country name, country code, continent name |
| 14 | + |
| 15 | +## Installing |
| 16 | + |
| 17 | +``` |
| 18 | +npm install countries-with-cities-select |
| 19 | +
|
| 20 | +OR |
| 21 | +
|
| 22 | +yarn add countries-with-cities-select |
| 23 | +
|
| 24 | +``` |
| 25 | +Once the package is installed you use the require/import approach |
| 26 | + |
| 27 | +```javascript |
| 28 | +const countriesWithCities = require('countries-with-cities-select'); |
| 29 | + |
| 30 | +OR |
| 31 | + |
| 32 | +import countriesWithCities from 'countries-with-cities-select' |
| 33 | + |
| 34 | +``` |
| 35 | + |
| 36 | +Or with TypeScript |
| 37 | +```typescript |
| 38 | +import * as countriesWithCities from 'countries-with-cities-select' |
| 39 | +``` |
| 40 | +create a `.d.ts` file and add |
| 41 | +```ts |
| 42 | +declare module 'countries-with-cities-select' |
| 43 | +``` |
| 44 | +
|
| 45 | +## #Get countries |
| 46 | +This will list all countries. |
| 47 | +```javascript |
| 48 | + |
| 49 | +const countriesWithCities = require('countries-with-cities-select'); |
| 50 | +// To get all countries |
| 51 | +countriesWithCities.getCountries(); |
| 52 | + |
| 53 | +``` |
| 54 | + |
| 55 | +## #Get countries with details |
| 56 | +This will retrieve information about countries with code, continent etc. Filter by country name, country code or continent |
| 57 | +```javascript |
| 58 | + |
| 59 | +const countriesWithCities = require('countries-with-cities-select'); |
| 60 | + |
| 61 | +countriesWithCities.getCountriesWithDetails(); |
| 62 | + |
| 63 | +// To get the countries with code, name or continent name |
| 64 | +countriesWithCities.getCountriesWithDetails("kenya"); |
| 65 | +// use exact code to filter country with code |
| 66 | +countriesWithCities.getCountriesWithDetails("KE"); |
| 67 | +countriesWithCities.getCountriesWithDetails("africa"); |
| 68 | + |
| 69 | +``` |
| 70 | + |
| 71 | +## #Get cities |
| 72 | +This will retrieve information about cities. Filter with country name, country code or continent |
| 73 | +Empty filter will return no cities |
| 74 | + |
| 75 | +```javascript |
| 76 | +const countriesWithCities = require('countries-with-cities-select'); |
| 77 | + |
| 78 | +// To get all cities in a country |
| 79 | +countriesWithCities.getCities('kenya'); |
| 80 | + |
| 81 | +// To get all cities in a continent |
| 82 | +countriesWithCities.getCities('africa'); |
| 83 | + |
| 84 | +// To get all cities in a country with code |
| 85 | +countriesWithCities.getCities('ke'); |
| 86 | + |
| 87 | +// To getcity with name |
| 88 | +countriesWithCities.getCities('nairobi'); |
| 89 | + |
| 90 | + |
| 91 | +``` |
| 92 | + |
| 93 | +## License |
| 94 | + |
| 95 | +[MIT](LICENSE) |
| 96 | + |
| 97 | +[](#) |
| 98 | + |
| 99 | +[](#) |
| 100 | + |
| 101 | +Happy coding, Star before Fork 😊💪💯 |
0 commit comments