Skip to content

Commit

Permalink
Merge pull request #83 from Clafter/master
Browse files Browse the repository at this point in the history
Added german Names List
  • Loading branch information
DavideViolante authored Mar 1, 2024
2 parents e378aba + 6d58d18 commit 09249f3
Show file tree
Hide file tree
Showing 5 changed files with 2,333 additions and 7 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ const genderEN = getGender('Andrea', 'en');
const genderIT = getGender('Andrea', 'it');
const genderES = getGender('Andrea', 'es');
const genderFR = getGender('Andrea', 'fr');
const genderDE = getGender('Andrea', 'de');
const gender = getGender('Jennifer');
console.log(genderEN); // female
console.log(genderIT); // male
console.log(genderES); // male
console.log(genderFR); // male
console.log(genderDE); // female
console.log(gender); // female
```

### Supported languages
`en`, `it`, `es`, `fr`
`en`, `it`, `es`, `fr`, `de`

### Run tests
```npm test```
Expand Down
5 changes: 4 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
declare module "gender-detection-from-name" {
export function getGender(name: string, lang?: 'en' | 'it' | 'es'| 'fr'): string;
export function getGender(
name: string,
lang?: "en" | "it" | "es" | "fr" | "de"
): string;
}
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const enMap = require('./names/en');
const itMap = require('./names/it');
const esMap = require('./names/es');
const frMap = require('./names/fr');
const deMap = require('./names/de');

/**
* Gender detection from first name and optional language
Expand All @@ -21,7 +22,8 @@ function getGender(name, lang = 'all') {
it: itMap,
es: esMap,
fr: frMap,
all: new Map([...itMap, ...enMap, ...esMap, ...frMap]),
de: deMap,
all: new Map([...itMap, ...enMap, ...esMap, ...frMap, ...deMap]),
};
// Use the Map of input language, or use all
const mapToUse = maps[lang] || maps.all;
Expand Down
Loading

0 comments on commit 09249f3

Please sign in to comment.