UNPKG

br-gender

Version:

Package to determine gender by name. Some database doest not have GENDER intel, so it can be very helpful a lib that can predict gender based on a person's first name. Be aware, this lib was built upon Brazilians census. So it will work with Brazilian nam

29 lines (26 loc) 774 B
import axios from 'axios'; const evaluateMen = async (name: string): Promise<number> => { try { let total = 0; const { data } = await axios.get(`https://servicodados.ibge.gov.br/api/v2/censos/nomes/${name}?sexo=M`); data[0].res.forEach((results: any) => { total = total + results.frequencia; }); return total; } catch (error) { return 0; } }; const evaluateWomen = async (name: string): Promise<number> => { try { let total = 0; const { data } = await axios.get(`https://servicodados.ibge.gov.br/api/v2/censos/nomes/${name}?sexo=F`); data[0].res.forEach((results: any) => { total = total + results.frequencia; }); return total; } catch (error) { return 0; } }; export { evaluateMen, evaluateWomen };