Skip to content

Commit

Permalink
Change eslint from standard to google, update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideViolante committed Oct 22, 2021
1 parent f1fd630 commit f822408
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 5,538 deletions.
18 changes: 9 additions & 9 deletions .eslintrc.json
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"
}
}
}
22 changes: 12 additions & 10 deletions README.md
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/)
28 changes: 14 additions & 14 deletions index.js
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;
6 changes: 3 additions & 3 deletions names/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -32509,7 +32509,7 @@ const enNames = new Map([
['zyron', 'male'],
['zyrus', 'male'],
['zyshaun', 'male'],
['zyshawn', 'male']
])
['zyshawn', 'male'],
]);

module.exports = enNames
module.exports = enNames;
6 changes: 3 additions & 3 deletions names/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -4278,7 +4278,7 @@ const itNames = new Map([
['diletta', 'female'],
['cosimo', 'male'],
['gianmarco', 'male'],
['carola', 'female']
])
['carola', 'female'],
]);

module.exports = itNames
module.exports = itNames;
Loading

0 comments on commit f822408

Please sign in to comment.