Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 exceptions added #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Gender-es

> Finds the gender of spanish nouns.
> Finds the gender of Spanish nouns.

## Installation
```
Expand Down Expand Up @@ -44,23 +44,23 @@ gender.addIndefiniteArticle('mapa',5); {

Type: `string`

Get the gender of the french noun.
Get the gender of the Spanish noun.

### isMasculine(str)

#### str

Type: `string`

Is the french noun masculine?
Is the Spanish noun masculine?

### isFeminine(str)

#### str

Type: `string`

Is the french noun feminine?
Is the Spanish noun feminine?

### indefiniteArticle(str[,amount])

Expand Down
37 changes: 18 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

function contains(a, obj) {
var i = a.length;
let i = a.length;
while (i--) {
if (a[i] === obj) {
return true;
Expand All @@ -10,23 +10,21 @@ function contains(a, obj) {
return false;
}

module.exports.genderForNoun = function(str) {
module.exports.genderForNoun = function (str) {

//info can be found here http://www.spanishdict.com/topics/show/1

//If it ends in -o, -e, an accented vowel (á, é, í, ó, ú), -ma, or a consonant other than -d, -z, or ión, it's masculine.


var last_letter = str[str.length - 1], // Last letter of str
const last_letter = str[str.length - 1], // Last letter of str
last_2_letters = str.slice(-2), // Last 3 letters of str
last_3_letters = str.slice(-3);

var isMasculine = false;

if (last_2_letters === 'ma') return 'm';

if (last_3_letters === 'ión' || last_3_letters === 'zón') {
var exeptions = ['corazón', 'sentención', 'notición', 'roción', 'ansión'];
const exeptions = ['corazón', 'sentención', 'notición', 'roción', 'ansión'];
if (exeptions.indexOf(str) > -1) {
return 'm';
}
Expand All @@ -44,7 +42,8 @@ module.exports.genderForNoun = function(str) {
case 'ó':
case 'ú':
{
var exeptions = ['foto', 'llave', 'fe', 'mano', 'calle', 'moto', 'fiebre', 'libido', 'carne', 'radio', 'frase', 'polio', 'gente', 'virago', 'nieve', 'noche', 'nube', 'sangre', 'suerte', 'tarde', 'muerte', 'madre', 'base', 'clase', 'clave', 'corriente', 'fuente', 'llave', 'sede', 'serpiente', 'torre'];
const exeptions = ['foto', 'llave', 'fe', 'mano', 'calle', 'moto', 'fiebre', 'libido', 'carne', 'radio', 'frase', 'polio', 'gente', 'virago', 'nieve', 'noche', 'nube', 'sangre', 'suerte', 'tarde', 'muerte', 'madre', 'base', 'clase', 'clave', 'corriente', 'fuente', 'llave', 'sede', 'serpiente', 'torre',
'disco'];
if (exeptions.indexOf(str) > -1) {
return 'f';
}
Expand All @@ -57,7 +56,7 @@ module.exports.genderForNoun = function(str) {
switch (last_letter) { //a,d,z are feminin
case 'a':
{
var exeptions = ['panda', 'buda', 'día', 'planeta', 'mapa', 'estratega'];
const exeptions = ['panda', 'buda', 'día', 'planeta', 'mapa', 'estratega'];
if (exeptions.indexOf(str) > -1) {
return 'm';
}
Expand All @@ -67,7 +66,7 @@ module.exports.genderForNoun = function(str) {
}
case 'd':
{
var exeptions = ['huésped', 'ataúd', 'abad', 'alud', 'áspid', 'laúd', 'récord', 'milord', 'césped'];
const exeptions = ['huésped', 'ataúd', 'abad', 'alud', 'áspid', 'laúd', 'récord', 'milord', 'césped'];
if (exeptions.indexOf(str) > -1) {
return 'm';
}
Expand All @@ -77,7 +76,7 @@ module.exports.genderForNoun = function(str) {
}
case 'z':
{
var exeptions = ['aprendiz', 'cáliz', 'arroz', 'pez', 'lápiz', 'ajedrez', 'antifaz', 'maíz', 'albornoz', 'avestruz', 'altavoz', 'altramuz', 'arroz', 'barniz', 'cariz', 'disfraz', 'haz', 'matiz'];
const exeptions = ['aprendiz', 'cáliz', 'arroz', 'pez', 'lápiz', 'ajedrez', 'antifaz', 'maíz', 'albornoz', 'avestruz', 'altavoz', 'altramuz', 'arroz', 'barniz', 'cariz', 'disfraz', 'haz', 'matiz'];
if (exeptions.indexOf(str) > -1) {
return 'm';
}
Expand All @@ -90,7 +89,7 @@ module.exports.genderForNoun = function(str) {

//the rest are masculine except

var exeptions = ['miel', 'sal', 'hiel', 'piel', 'coliflor', 'sor', 'labor', 'flor'];
const exeptions = ['miel', 'sal', 'hiel', 'piel', 'coliflor', 'sor', 'labor', 'flor', 'mujer'];
if (exeptions.indexOf(str) > -1) {
return 'f';
}
Expand All @@ -100,34 +99,34 @@ module.exports.genderForNoun = function(str) {

};

module.exports.isMasculine = function(str) {
module.exports.isMasculine = function (str) {
return this.genderForNoun(str) === 'm';
};

module.exports.isFeminine = function(str) {
module.exports.isFeminine = function (str) {
return this.genderForNoun(str) === 'f';
};

module.exports.indefiniteArticle = function(str, amount) {
module.exports.indefiniteArticle = function (str, amount) {
if (amount === undefined || amount === 1) {
return this.isFeminine(str) ? 'una' : 'un';
} else {
return this.isFeminine(str) ? 'unas' : 'unos';
}
};

module.exports.addIndefiniteArticle = function(str,amount) {
return this.indefiniteArticle(str,amount) + ' ' + str;
module.exports.addIndefiniteArticle = function (str, amount) {
return this.indefiniteArticle(str, amount) + ' ' + str;
};

module.exports.definiteArticle = function(str, amount) {
module.exports.definiteArticle = function (str, amount) {
if (amount === undefined || amount === 1) {
return this.isFeminine(str) ? 'la' : 'el';
} else {
return this.isFeminine(str) ? 'las' : 'los';
}
};

module.exports.addDefiniteArticle = function(str,amount) {
return this.definiteArticle(str,amount) + ' ' + str;
module.exports.addDefiniteArticle = function (str, amount) {
return this.definiteArticle(str, amount) + ' ' + str;
};
Loading