br-gender

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

Usage no npm install needed!

<script type="module">
  import brGender from 'https://cdn.skypack.dev/br-gender';
</script>

README

Brazilian Gender predict

TypeScript License: MIT

While I was searching for a NodeJS library that could predict a person gender by its name, I've come across this blog: https://fmeireles.com/blog/rstats/genderbr-predizer-sexo/

So it gave me the idea I need to build up my own lib, since I didn't find anything similar in npm.

Original library has a lot of options that don't suit my project, so I didn't write them down. Maybe one day.

Getting Started

You can install the package via npm or yarn

npm install br-gender
yarn add br-gender

Example

Usage is pretty straightforward. Import getGenderByName from package and pass a name to it.

import { getGenderByName } from 'br-gender';

const gender = await getGenderByName('Thiago');
// OUTPUT: 'Male'

You can also pass a boolean property to get back the percentual of gender over every entry:

import { getGenderByName } from 'br-gender';

const gender = await getGenderByName('Thiago', { percentage: true });
// OUTPUT: { gender: 'Male', percentage: 99.30}

How it works under the hood

Basically, it searches the brazilian census API with the given name and sum all occurrences from both genders, male and female. For example, if the given name is 'Thiago', it will perform a search from both genders and sum them. If the male percentage is greater than 95% over the total, so the gender of the name should be male.

I know it isn't perfect, but it suited my project back in the day.

Authors

  • Thiago Vasconcellos - Initial work - brzipcode

License

This project is licensed under the MIT License - see the LICENSE.md file for details

QW*wR9B!Ew5k;nv