0.1.0 • Published 6 months ago

@rrrm/countries v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Countries and Cities

This node package provides functions for working with countries and cities data.

Installation

pnpm i @rrrm/countries

Usage

  • countries: An array of countries.
  • cities: An array of cities.
  • findCountry(countryCode: string, {withCity:false //default}): Find a country by its country code.
  • findCities(cityName: string, {withCountry:false //default}): Find cities by name.
  • getAllCitiesByCountry(countryCode: string): Get all cities in a specific country.
import { findCities, findCountry, getAllCitiesByCountry } from "@rrrm/countries"

// find cities with country information
const bissau = findCities("bissau", { withCountry: true })
console.log("findCities-> ", bissau)

// find a country with all cities
const gw = findCountry("GW", { withCity: true })
console.log("findCountry-> ", gw)

// get all cities for a country
const citiesBycountry = getAllCitiesByCountry("GW")
console.log("getAllCitiesByCountry-> ", citiesBycountry)

Utilities

this is helpful if you want to import the data into your own database.

  • convertJson(fileName: string, data: any | Country[] | City[]): Convert data to JSON format and save it to a file.
  • convertCSV(fileName: string, data: any | Country[] | City[]): Convert data to CSV format and save it to a file.
import { convertJson, convertCSV } from './convert.ts';

const data = [{ /* Your data here */ }];
convertJson('data.json', data);
convertCSV('data.csv', data);

Data Files

This utility assumes the presence of data files in JSON format. Ensure you have the required data files in the specified locations before using the utility.

  • countries.json: Country data file.
  • cities.json: City data file.

There is also csv files of both countries and cities this is to make it easier to import data to any database as the package size is quite large.

Schema

schema folder will contain sql files so data can be added to a database

License

This utility is provided under the MIT License.

Credits

this package is a comnbination of both restcountries and cities.json

0.1.0

6 months ago

0.0.23

6 months ago

0.0.21

6 months ago

0.0.19

7 months ago

0.0.16

7 months ago

0.0.9

7 months ago

0.0.8

7 months ago

0.0.7

7 months ago

0.0.6

7 months ago

0.0.5

7 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago