Skip to content

Instantly share code, notes, and snippets.

@AndreiCalazans
Created November 4, 2025 13:37
Show Gist options
  • Save AndreiCalazans/c34b18543eb36c632d3dcd3e96aa4d02 to your computer and use it in GitHub Desktop.
Save AndreiCalazans/c34b18543eb36c632d3dcd3e96aa4d02 to your computer and use it in GitHub Desktop.
Look up a name in Censo's 2022 data.
async function lookupName(name) {
const baseUrl = "https://servicodados.ibge.gov.br/api/v3/nomes/2022/localidade/0/ranking/nome";
let page = 1;
const pageSize = 30; // API returns 30 items per page
while (true) {
const response = await fetch(`${baseUrl}?page=${page}`, {
headers: {
"sec-ch-ua": "\"Google Chrome\";v=\"141\", \"Not?A_Brand\";v=\"8\", \"Chromium\";v=\"141\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"macOS\"",
"Referer": "https://censo2022.ibge.gov.br/"
}
});
const data = await response.json();
// Search for the name in current page
const result = data.items.find(item => item.nome.toLowerCase() === name.toLowerCase());
if (result) {
return result;
}
// Check if there are more pages
if (page >= data.totalPages) {
break;
}
page++;
}
return null; // Name not found
}
// Usage example:
lookupName("soter").then(result => {
if (result) {
console.log(`Name: ${result.nome}, Rank: ${result.rank}, Frequency: ${result.frequencia}, Percent: ${result.percent}%`);
} else {
console.log("Name not found in the ranking.");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment