-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change eslint from standard to google, update deps
- Loading branch information
1 parent
f1fd630
commit f822408
Showing
8 changed files
with
210 additions
and
5,538 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
{ | ||
"env": { | ||
"es6": true, | ||
"commonjs": true, | ||
"es2021": true, | ||
"node": true, | ||
"mocha": true | ||
}, | ||
"extends": "standard", | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
}, | ||
"extends": "google", | ||
"parserOptions": { | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
"ecmaVersion": 12 | ||
}, | ||
"rules": { | ||
"object-curly-spacing": [ | ||
"error", "always" | ||
], | ||
"space-infix-ops": "error" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
# Gender detection from name | ||
[![](https://github.com/davideviolante/gender-detection-from-name/workflows/Node.js%20CI/badge.svg)](https://github.com/DavideViolante/gender-detection-from-name/actions?query=workflow%3A"Node.js+CI") [![Coverage Status](https://coveralls.io/repos/github/DavideViolante/gender-detection-from-name/badge.svg?branch=master)](https://coveralls.io/github/DavideViolante/gender-detection-from-name?branch=master) [![Maintainability](https://api.codeclimate.com/v1/badges/ded2c349739e4d87130b/maintainability)](https://codeclimate.com/github/DavideViolante/gender-detection-from-name/maintainability) [![Donate](https://img.shields.io/badge/paypal-donate-179BD7.svg)](https://www.paypal.me/dviolante) | ||
|
||
[![NPM](https://nodei.co/npm/gender-detection-from-name.png)](https://nodei.co/npm/gender-detection-from-name/) | ||
|
||
Library to detect the gender of a first name. An optional language parameter can be specified to improve the detection, for example: Andrea in EN is female, in IT is male. If no language is specified, EN has priority. | ||
|
||
### Install | ||
`npm i gender-detection-from-name` | ||
|
||
### Example | ||
```js | ||
const { getGender } = require('gender-detection-from-name') | ||
|
||
const genderEN = getGender('Andrea', 'en') | ||
const genderIT = getGender('Andrea', 'it') | ||
const gender = getGender('Jennifer') | ||
console.log(genderEN) // female | ||
console.log(genderIT) // male | ||
console.log(gender) // female | ||
const { getGender } = require('gender-detection-from-name'); | ||
|
||
const genderEN = getGender('Andrea', 'en'); | ||
const genderIT = getGender('Andrea', 'it'); | ||
const gender = getGender('Jennifer'); | ||
console.log(genderEN); // female | ||
console.log(genderIT); // male | ||
console.log(gender); // female | ||
``` | ||
|
||
### Run tests | ||
- `npm test` | ||
```npm test``` | ||
|
||
### Run lint | ||
- `npm run lint` | ||
```npm run lint``` | ||
|
||
### Author | ||
- [Davide Violante](https://github.com/DavideViolante/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
const enMap = require('./names/en') | ||
const itMap = require('./names/it') | ||
const enMap = require('./names/en'); | ||
const itMap = require('./names/it'); | ||
|
||
/** | ||
* Gender detection from first name and optional language | ||
* @param {String} name First name | ||
* @param {String} [lang] Language | ||
* @returns {String} male, female, unknown | ||
* @return {String} male, female, unknown | ||
*/ | ||
function getGender (name, lang = 'all') { | ||
function getGender(name, lang = 'all') { | ||
if (!name) { | ||
return 'unknown' | ||
return 'unknown'; | ||
} | ||
// Lowercase name and lang to make the match | ||
name = name.toLowerCase() | ||
lang = (lang || 'all').toLowerCase() | ||
name = name.toLowerCase(); | ||
lang = (lang || 'all').toLowerCase(); | ||
const maps = { | ||
en: enMap, | ||
it: itMap, | ||
all: new Map([...itMap, ...enMap]) | ||
} | ||
all: new Map([...itMap, ...enMap]), | ||
}; | ||
// Use the Map of input language, or use all | ||
const mapToUse = maps[lang] || maps.all | ||
// Get the gender from the input language Map, or try with all, otherwise is unknown | ||
const result = mapToUse.get(name) || maps.all.get(name) || 'unknown' | ||
return result | ||
const mapToUse = maps[lang] || maps.all; | ||
// Get the gender from the language Map or try with all, otherwise is unknown | ||
const result = mapToUse.get(name) || maps.all.get(name) || 'unknown'; | ||
return result; | ||
} | ||
|
||
exports.getGender = getGender | ||
exports.getGender = getGender; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.