@brmorillo/global-locations v2.0.2
@brmorillo/global-locations
Project Description
@brmorillo/global-locations is a TypeScript library designed to simplify access and manipulation of hierarchical location data, including countries, states, and cities. It offers powerful methods for retrieving, filtering, and managing location-based information.
Installation and Usage
Install
To add the library to your project, use:
npm install @brmorillo/global-locationsor if you use Yarn:
yarn add @brmorillo/global-locationsor with pnpm:
pnpm add @brmorillo/global-locationsUsage
Import the Countries class to access location utilities:
import { Countries } from '@brmorillo/global-locations';
// Example usage
const countries = Countries.getAllCountriesAndData();
console.log(countries);
const states = Countries.getStatesByCountryId('BR');
console.log(states);
const cities = Countries.getCitiesByStateId({ countryId: 'BR', stateId: '35' });
console.log(cities);Project Features
Country Utility Functions
getAllCountriesAndData: Retrieves all countries with their associated states and cities.const countries = Countries.getAllCountriesAndData(); console.log(countries);getAllCountries: Retrieves all countries without thestatesproperty.const countries = Countries.getAllCountries(); console.log(countries);getCountryBy: Finds a country by a specific property (e.g.,id,name, etc.).const country = Countries.getCountryBy({ property: 'id', value: 'BR', selectStates: true, }); console.log(country);
State Utility Functions
getAllStates: Retrieves all states from all countries.const states = Countries.getAllStates(); console.log(states);getStatesByCountryId: Retrieves all states for a specific country.const states = Countries.getStatesByCountryId('BR'); console.log(states);getStateByParams: Finds a state by specific parameters (e.g.,id,name, etc.).const state = Countries.getStateByParams({ countryId: 'BR', params: { property: 'name', value: 'São Paulo' }, }); console.log(state);isStateInCountry: Checks if a state belongs to a specific country.const isInCountry = Countries.isStateInCountry({ countryId: 'BR', stateId: '35', }); console.log(isInCountry);
City Utility Functions
getAllCities: Retrieves all cities for a specific country.const cities = Countries.getAllCities({ countryId: 'BR' }); console.log(cities);getCitiesByStateId: Retrieves all cities for a specific state within a country.const cities = Countries.getCitiesByStateId({ countryId: 'BR', stateId: '35', }); console.log(cities);getCitiesByParams: Finds a city by specific parameters (e.g.,id,name).const city = Countries.getCitiesByParams({ countryId: 'BR', stateId: '35', params: { property: 'name', value: 'São Paulo' }, }); console.log(city);
Contribution Guidelines
How to Contribute
No direct commits to the
mainbranch: All development must be done in separate branches.Branch naming: Use descriptive names for your branches. Examples:
feat/new-featurefix/location-error
Pull Requests:
- Every pull request (PR) must be reviewed and approved before merging into
main. - Ensure you follow the commit message standards.
- Every pull request (PR) must be reviewed and approved before merging into
Commit Messages: Follow the project's commit message conventions (based on Angular):
feat: description of the new featurefix: description of the bug fixdocs: documentation updates
How to Publish
If you want to contribute and publish updates to this library:
Bump the version: Use the following command to update the version according to SemVer:
npm version patch # For small fixes npm version minor # For new features npm version major # For breaking changesPublish the package:
npm publish
Feel free to fork, contribute, and submit pull requests! Any contributions are welcome.
🫶 Support the Project
If you find @brmorillo/global-locations helpful and want to support its development, consider contributing! Your support is essential for the project to grow.
📌 How to Contribute
Pix: Use the Pix key: bruno@rmorillo.com
Cryptocurrencies:
- Dogecoin (DOGE):
DLwW5LFfXV7wN7a7dVV6TX7kiomVnYABXM - Tether (USDT):
0x2b1f5169e3719E0A25850a178db54d8D1C0c12E0 - Bitcoin (BTC):
bc1qk5cakfryrx8dw3w6uqudwkpm9apvd6h5mgl8kg - Ethereum (ETH):
0x2b1f5169e3719E0A25850a178db54d8D1C0c12E0
- Dogecoin (DOGE):
Other ways: Feedback, code contributions, or simply sharing the project with others are extremely appreciated!
License
This project is licensed under the MIT License. See the LICENSE file for details.