Skip to content

Commit

Permalink
Fixed a bug about the use without lang param.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidemiceli committed Aug 9, 2016
1 parent 62fb713 commit a81669c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 21 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

## Description
A node.js module to determine a person's gender based on his/her first name.
It works also for many languages other than english. It support international names.
This module is able to clean the text detecting gender from dirty or unclear names.

It works also for many languages other than english, supporting international names, using an own datasource of 40.000 records that can be extended.
This module is able to clean the text, detecting gender from dirty or unclear names.

## Installation

$ npm install gender-detection

Or using github:

$ npm install git+https://[email protected]/davidemiceli/gender-detection.git

## Example
```javascript
// Require gender detection module
Expand Down
4 changes: 2 additions & 2 deletions genders/female.js
Original file line number Diff line number Diff line change
Expand Up @@ -13067,7 +13067,7 @@ module.exports = {
"nimet": { en: 1 },
"nimete": { en: 1 },
"nimfodora": { en: 1 },
"nina": { en: 1 },
"nina": { en: 1, it: 1 },
"ņina": { en: 1 },
"nína": { en: 1 },
"ninako": { en: 1 },
Expand Down Expand Up @@ -15698,7 +15698,7 @@ module.exports = {
"sharman": { en: 1 },
"sharmila": { en: 1 },
"sharmistha": { en: 1 },
"sharon": { en: 1 },
"sharon": { en: 1, it: 1 },
"sharona": { en: 1 },
"sharonda": { en: 1 },
"sharri": { en: 1 },
Expand Down
16 changes: 8 additions & 8 deletions genders/male.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ module.exports = {
"alessandrino": { en: 1 },
"alessandro": { en: 1 },
"alessio": { en: 1 },
"alex": { en: 1 },
"alex": { en: 1, it: 1 },
"alexan": { en: 1 },
"alexandar": { en: 1 },
"alexander": { en: 1 },
Expand Down Expand Up @@ -3586,7 +3586,7 @@ module.exports = {
"dániel": { en: 1 },
"daníel": { en: 1 },
"daniël": { en: 1 },
"daniele": { en: 1 },
"daniele": { en: 1, it: 1 },
"danielius": { en: 1 },
"daniels": { en: 1 },
"daniil": { en: 1 },
Expand Down Expand Up @@ -6005,7 +6005,7 @@ module.exports = {
"gabrand": { en: 1 },
"gabriel": { en: 1 },
"gabríel": { en: 1 },
"gabriele": { en: 1 },
"gabriele": { en: 1, it: 1 },
"gabriello": { en: 1 },
"gabrijel": { en: 1 },
"gad": { en: 1 },
Expand Down Expand Up @@ -6472,7 +6472,7 @@ module.exports = {
"gifford": { en: 1 },
"giga": { en: 1 },
"gigel": { en: 1 },
"gigi": { en: 1 },
"gigi": { en: 1, it: 1 },
"giglio": { en: 1 },
"gijs": { en: 1 },
"gijsbert": { en: 1 },
Expand Down Expand Up @@ -10773,7 +10773,7 @@ module.exports = {
"luboš": { en: 1 },
"luboslav": { en: 1 },
"luc": { en: 1 },
"luca": { en: 1 },
"luca": { en: 1, it: 1 },
"lucas": { en: 1 },
"luchezar": { en: 1 },
"lucian": { en: 1 },
Expand Down Expand Up @@ -14474,7 +14474,7 @@ module.exports = {
"ricklef": { en: 1 },
"rickleff": { en: 1 },
"rickmer": { en: 1 },
"ricky": { en: 1 },
"ricky": { en: 1, it: 1 },
"rico": { en: 1 },
"ricu": { en: 1 },
"rida": { en: 1 },
Expand Down Expand Up @@ -15970,7 +15970,7 @@ module.exports = {
"simon": { en: 1 },
"símon": { en: 1 },
"simonas": { en: 1 },
"simone": { en: 1 },
"simone": { en: 1, it: 1 },
"simonetto": { en: 1 },
"simons": { en: 1 },
"simpert": { en: 1 },
Expand Down Expand Up @@ -16986,7 +16986,7 @@ module.exports = {
"tenjo": { en: 1 },
"tenshi": { en: 1 },
"tenyo": { en: 1 },
"teo": { en: 1 },
"teo": { en: 1, it: 1 },
"teobaldo": { en: 1 },
"teodolindo": { en: 1 },
"teodor": { en: 1 },
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ exports.detect = function(fullName, lang) {

function getGender(firstName, lang) {
gender = 'unknown';
if (lang && male[firstName][lang] && female[firstName][lang]) {
if (lang && male[firstName] && male[firstName][lang] && female[firstName] && female[firstName][lang]) {
gender = 'unisex';
} else if (lang && male[firstName][lang]) {
} else if (lang && male[firstName] && male[firstName][lang]) {
gender = 'male';
} else if (lang && female[firstName][lang]) {
} else if (lang && female[firstName] && female[firstName][lang]) {
gender = 'female';
} else if (male[firstName] && female[firstName]) {
gender = 'unisex';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gender-detection",
"version": "0.0.4",
"version": "0.0.5",
"description": "Detect the gender of a person using his/her first name.",
"license": "GPL-3.0",
"main": "index.js",
Expand Down
10 changes: 9 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var gender = require('../index.js');

describe('Simple names', function() {
it('It should return male, female, or unknown', function() {
assert.equal('male', gender.detect('John'));
assert.equal('male', gender.detect('John','en'));
assert.equal('female', gender.detect('Holly'));
});
});
Expand All @@ -29,3 +29,11 @@ describe('Bad formatted names', function() {
assert.equal('female', gender.detect('::Jenni♥fer::'));
});
});

describe('Simple names with languages variable', function() {
it('It should return male, female, or unknown', function() {
assert.equal('male', gender.detect('Johnny','en'));
assert.equal('male', gender.detect('Andrea','it'));
assert.equal('unisex', gender.detect('Andrea','hgjj'));
});
});

0 comments on commit a81669c

Please sign in to comment.