@lsbjordao/ibge-js
v0.0.10
Published
```bash npm i @lsbjordao/ibge-js ```
Downloads
4
Readme
Installing package
npm i @lsbjordao/ibge-jsGet localidades data
It fetches UF, Regions, Mesoregions, Microregions, ImediateRegions, IntermediaryRegions, MetropolitanRegions, Municipalities, Districts, and Subdistricts.
const IBGEjs = require('@lsbjordao/ibge-js').default;
// Initialize an instance of the IBGE library
const IBGE = new IBGEjs();
// Function to fetch municipalities
async function fetchMunicipalities() {
try {
const municipalities = await IBGE.Municipalities();
console.log(municipalities);
} catch (error) {
console.error('Error fetching municipalities:', error.message);
}
}
// Call the function
fetchMunicipalities();Get malhas data
Use mesh as a prefix of the locality level (e.g. meshMesoregions()).
const IBGEjs = require('@lsbjordao/ibge-js').default;
async function main() {
const IBGE = new IBGEjs();
try {
// Fetch all municipalities
const municipalities = await IBGE.Municipalities();
// Map municipalities into a simplified structure
const municipalitiesSet = municipalities.map((municipality) => ({
name: municipality['municipio-nome'],
id: municipality['municipio-id']
}));
// Iterate through each municipality
for (const municipality of municipalitiesSet) {
try {
console.log(`Fetching data for: ${municipality.name}`);
// Fetch mesh data for the municipality
const municipalityMesh = await IBGE.meshMunicipality(municipality.id);
console.log(`Mesh data for ${municipality.name}:`, municipalityMesh);
} catch (error) {
console.error(`Error fetching mesh data for ${municipality.name}:`, error.message);
}
}
} catch (error) {
console.error('Error fetching municipalities or processing data:', error.message);
}
}
// Execute the main function
main();