@brmorillo/global-locations
v5.0.0
Published
Production-ready library for global location data — countries, states and cities behind one type-safe API. Dual CJS + ESM build.
Maintainers
Readme
@brmorillo/global-locations
Library for accessing global location data such as countries, states, and cities.
Installation
npm install @brmorillo/global-locationsUsage
import { GlobalLocations } from '@brmorillo/global-locations';
// Get all countries
const countries = GlobalLocations.Countries.getAllCountries();
// Get a specific country by ID
const brazil = GlobalLocations.Countries.getCountryBy({
property: 'id',
value: 'BR',
selectStates: true
});
// Get states of a country
const brazilStates = GlobalLocations.Countries.getStatesByCountryId('BR');
// Get cities of a state
const saoPauloCities = GlobalLocations.Countries.getCitiesByStateId({
countryId: 'BR',
stateId: '35'
});API
Countries
findCountryByProperty(property, value): Finds a country by an arbitrary propertygetAllCountriesAndData(): Returns all countries with complete datagetAllCountries(): Returns all countries without state datagetCountryBy({ property, value, selectStates }): Returns a specific countrygetAllStates(): Returns all states from all countriesgetStatesByCountryId(countryId): Returns states of a specific countrygetStateByParams({ countryId, params }): Searches for a specific stateisStateInCountry({ countryId, stateId }): Checks if a state belongs to a countrygetAllCities({ countryId }): Returns all cities of a countrygetCitiesByStateId({ countryId, stateId }): Returns cities of a specific stategetCitiesByParams({ countryId, stateId, params }): Searches for a specific citygetCityById(cityId): Finds a city by its numeric id across all countriessearchCitiesByName(name, caseSensitive?): Searches cities by (partial) namegetCountriesByContinent(continent, includeStates?): Filters countries by continentgetCountriesByEconomicGroup(group, includeStates?): Filters countries by economic group
Quality & testing
- Dual build: ships CommonJS (
require) and ESM (import) plus its own.d.ts. - TypeScript strict end to end.
- 92 tests (unit + integration) on jest, 100% coverage (statements, branches, functions, lines).
- External consumer smoke test validates the published artifact via both
requireandimport— see CONTRIBUTING.md.
bun install
bun run test # unit + integration + benchmark
bun run test:coverage # coverage report
bun run build # CJS + ESM + d.tsDocumentation
- docs/README.md — documentation index and data shapes.
- docs/countries/README.md — full
Countriesreference: every method, parameters, return values and examples.
Contributing & security
- CONTRIBUTING.md — setup, workflow, testing, release flow.
- SECURITY.md — supported versions and how to report a vulnerability.
- CLAUDE.md — architecture, conventions and context for contributors/AI assistants.
