english-verbs-helper
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -41,4 +41,3 @@ "use strict"; | ||
const gerundKeys = Object.keys(gerundsInfo); | ||
for (let i = 0; i < gerundKeys.length; i++) { | ||
const gerundKey = gerundKeys[i]; | ||
for (const gerundKey of gerundKeys) { | ||
const gerundVal = gerundsInfo[gerundKey]; | ||
@@ -51,14 +50,4 @@ res[gerundKey] = [null, null, gerundVal]; | ||
const irregularKeys = Object.keys(irregularsInfo); | ||
for (let i = 0; i < irregularKeys.length; i++) { | ||
const irregularKey = irregularKeys[i]; | ||
for (const irregularKey of irregularKeys) { | ||
const irregularVal = irregularsInfo[irregularKey]; | ||
/* | ||
if (irregularVal.length > 1) { | ||
console.log( | ||
`WARNING: multiple conjugations for ${irregularKey}: ${JSON.stringify( | ||
irregularVal, | ||
)} - will always take the first one`, | ||
); | ||
} | ||
*/ | ||
if (!res[irregularKey]) { | ||
@@ -104,11 +93,13 @@ res[irregularKey] = [irregularVal[0][0], irregularVal[0][1], null]; | ||
function getPastPart(verbsInfo, verb) { | ||
let irregular; | ||
if (verb === 'be') { | ||
return 'been'; | ||
} | ||
else if ((irregular = getIrregularHelper(verbsInfo, verb, 1))) { | ||
return irregular; | ||
} | ||
else { | ||
return getCommonEdPart(verb); | ||
const irregular = getIrregularHelper(verbsInfo, verb, 1); | ||
if (irregular) { | ||
return irregular; | ||
} | ||
else { | ||
return getCommonEdPart(verb); | ||
} | ||
} | ||
@@ -135,4 +126,4 @@ } | ||
const consonants = 'bcdfghjklmnpqrstvxzw'; | ||
let irregular; | ||
if ((irregular = getIrregularHelper(verbsInfo, verb, 2))) { | ||
const irregular = getIrregularHelper(verbsInfo, verb, 2); | ||
if (irregular) { | ||
return irregular; | ||
@@ -165,2 +156,34 @@ } | ||
} | ||
function getSimplePresentHeShe(verb) { | ||
if (modals.indexOf(verb) > -1) { | ||
return verb; | ||
} | ||
else if (verb === 'have') { | ||
return 'has'; | ||
} | ||
else if (verb === 'be') { | ||
return 'is'; | ||
} | ||
else if (verb === 'do') { | ||
return 'does'; | ||
} | ||
else if (verb === 'go') { | ||
return 'goes'; | ||
} | ||
else if (yWithVowel(verb)) { | ||
// vowel + y: play -> plays | ||
return verb + 's'; | ||
} | ||
else if (verb.endsWith('y')) { | ||
// no vowel + y: fly -> flies | ||
return verb.substring(0, verb.length - 1) + 'ies'; | ||
} | ||
else if (verb.endsWith('ss') || verb.endsWith('x') || verb.endsWith('sh') || verb.endsWith('ch')) { | ||
return verb + 'es'; | ||
} | ||
else { | ||
// default | ||
return verb + 's'; | ||
} | ||
} | ||
function getSimplePresent(verb, person) { | ||
@@ -181,36 +204,7 @@ if (person != 2) { | ||
else { | ||
if (modals.indexOf(verb) > -1) { | ||
return verb; | ||
} | ||
else if (verb === 'have') { | ||
return 'has'; | ||
} | ||
else if (verb === 'be') { | ||
return 'is'; | ||
} | ||
else if (verb === 'do') { | ||
return 'does'; | ||
} | ||
else if (verb === 'go') { | ||
return 'goes'; | ||
} | ||
else if (yWithVowel(verb)) { | ||
// vowel + y: play -> plays | ||
return verb + 's'; | ||
} | ||
else if (verb.endsWith('y')) { | ||
// no vowel + y: fly -> flies | ||
return verb.substring(0, verb.length - 1) + 'ies'; | ||
} | ||
else if (verb.endsWith('ss') || verb.endsWith('x') || verb.endsWith('sh') || verb.endsWith('ch')) { | ||
return verb + 'es'; | ||
} | ||
else { | ||
// default | ||
return verb + 's'; | ||
} | ||
return getSimplePresentHeShe(verb); | ||
} | ||
} | ||
function getSimpleFuture(verb, person, extraParams, negative) { | ||
if (extraParams && extraParams.GOING_TO) { | ||
function getSimpleFuture(verb, person, isGoingTo, negative) { | ||
if (isGoingTo) { | ||
return getSimplePresent('be', person) + ' ' + getNegative(negative) + 'going to ' + verb; | ||
@@ -252,57 +246,38 @@ } | ||
} | ||
function getConjugation(verbsInfo, verb, tense, person, extraParams) { | ||
if (!verb) { | ||
const err = new Error(); | ||
err.name = 'TypeError'; | ||
err.message = 'verb must not be null'; | ||
throw err; | ||
} | ||
if (tenses.indexOf(tense) == -1) { | ||
const err = new Error(); | ||
err.name = 'TypeError'; | ||
err.message = `invalid tense: ${tense}`; | ||
throw err; | ||
} | ||
if ([0, 1, 2, 3, 4, 5].indexOf(person) === -1) { | ||
const err = new Error(); | ||
err.name = 'TypeError'; | ||
err.message = 'person must be 0 1 2 3 4 or 5'; | ||
throw err; | ||
} | ||
const isNegative = extraParams && extraParams.NEGATIVE; | ||
const isHaveNoDo = extraParams && extraParams.NEGATIVE && verb === 'have' && extraParams.NO_DO; | ||
function addContract(original) { | ||
let res = original; | ||
if (isNegative && (extraParams.CONTRACT || isHaveNoDo)) { | ||
// Note that in the form without the auxiliary verb DO, the verb HAVE is always contracted with the adverb not. | ||
const contractions = [ | ||
// present | ||
['does not', "doesn't"], | ||
['do not', "don't"], | ||
['is not', "isn't"], | ||
['are not', "aren't"], | ||
['has not', "hasn't"], | ||
['have not', "haven't"], | ||
['can not', "can't"], | ||
['could not', "couldn't"], | ||
['may not', "mayn't"], | ||
['might not', "mightn't"], | ||
['will not', "won't"], | ||
['shall not', "shan't"], | ||
['would not', "wouldn't"], | ||
['should not', "shouldn't"], | ||
['must not', "mustn't"], | ||
['ought not', "oughtn't"], | ||
// past | ||
['did not', "didn't"], | ||
['was not', "wasn't"], | ||
['were not', "weren't"], | ||
['had not', "hadn't"], | ||
]; | ||
for (const contraction of contractions) { | ||
res = res.replace(contraction[0], contraction[1]); | ||
} | ||
function doContract(original) { | ||
const contractions = [ | ||
// present | ||
['does not', "doesn't"], | ||
['do not', "don't"], | ||
['is not', "isn't"], | ||
['are not', "aren't"], | ||
['has not', "hasn't"], | ||
['have not', "haven't"], | ||
['can not', "can't"], | ||
['could not', "couldn't"], | ||
['may not', "mayn't"], | ||
['might not', "mightn't"], | ||
['will not', "won't"], | ||
['shall not', "shan't"], | ||
['would not', "wouldn't"], | ||
['should not', "shouldn't"], | ||
['must not', "mustn't"], | ||
['ought not', "oughtn't"], | ||
// past | ||
['did not', "didn't"], | ||
['was not', "wasn't"], | ||
['were not', "weren't"], | ||
['had not', "hadn't"], | ||
]; | ||
for (const contraction of contractions) { | ||
const replaced = original.replace(contraction[0], contraction[1]); | ||
if (replaced !== original) { | ||
// finding one in fine, then we stop | ||
return replaced; | ||
} | ||
return res; | ||
} | ||
// istanbul ignore next | ||
return original; | ||
} | ||
function getConjugatedVerb(verbsInfo, verb, tense, person, isNegative, isHaveNoDo, isGoingTo) { | ||
switch (tense) { | ||
@@ -313,7 +288,7 @@ case 'PAST': | ||
if (verb === 'be' || verb === 'do' || modals.indexOf(verb) > -1 || isHaveNoDo) { | ||
return addContract(getSimplePast(verbsInfo, verb, person) + ' not'); | ||
return getSimplePast(verbsInfo, verb, person) + ' not'; | ||
} | ||
else { | ||
// 'do ...' form | ||
return addContract(getSimplePast(verbsInfo, 'do', person) + ' not ' + verb); | ||
return getSimplePast(verbsInfo, 'do', person) + ' not ' + verb; | ||
} | ||
@@ -328,7 +303,7 @@ } | ||
if (verb === 'be' || verb === 'do' || modals.indexOf(verb) > -1 || isHaveNoDo) { | ||
return addContract(getSimplePresent(verb, person) + ' not'); | ||
return getSimplePresent(verb, person) + ' not'; | ||
} | ||
else { | ||
// 'do ...' form | ||
return addContract(getSimplePresent('do', person) + ' not ' + verb); | ||
return getSimplePresent('do', person) + ' not ' + verb; | ||
} | ||
@@ -341,28 +316,59 @@ } | ||
case 'SIMPLE_FUTURE': | ||
return addContract(getSimpleFuture(verb, person, extraParams, isNegative)); | ||
return getSimpleFuture(verb, person, isGoingTo, isNegative); | ||
case 'PROGRESSIVE_PAST': | ||
return addContract(getProgressivePast(verbsInfo, verb, person, isNegative)); | ||
return getProgressivePast(verbsInfo, verb, person, isNegative); | ||
case 'PROGRESSIVE_PRESENT': | ||
return addContract(getProgressivePresent(verbsInfo, verb, person, isNegative)); | ||
return getProgressivePresent(verbsInfo, verb, person, isNegative); | ||
case 'PROGRESSIVE_FUTURE': | ||
return addContract(getProgressiveFuture(verbsInfo, verb, isNegative)); | ||
return getProgressiveFuture(verbsInfo, verb, isNegative); | ||
case 'PERFECT_PAST': | ||
return addContract(getPerfectPast(verbsInfo, verb, isNegative)); | ||
return getPerfectPast(verbsInfo, verb, isNegative); | ||
case 'PERFECT_PRESENT': | ||
return addContract(getPerfectPresent(verbsInfo, verb, person, isNegative)); | ||
return getPerfectPresent(verbsInfo, verb, person, isNegative); | ||
case 'PERFECT_FUTURE': | ||
return addContract(getPerfectFuture(verbsInfo, verb, isNegative)); | ||
return getPerfectFuture(verbsInfo, verb, isNegative); | ||
case 'PERFECT_PROGRESSIVE_PAST': | ||
return addContract(getPerfectProgressivePast(verbsInfo, verb, isNegative)); | ||
return getPerfectProgressivePast(verbsInfo, verb, isNegative); | ||
case 'PERFECT_PROGRESSIVE_PRESENT': | ||
return addContract(getPerfectProgressivePresent(verbsInfo, verb, person, isNegative)); | ||
return getPerfectProgressivePresent(verbsInfo, verb, person, isNegative); | ||
case 'PERFECT_PROGRESSIVE_FUTURE': | ||
return addContract(getPerfectProgressiveFuture(verbsInfo, verb, isNegative)); | ||
return getPerfectProgressiveFuture(verbsInfo, verb, isNegative); | ||
case 'PARTICIPLE_PRESENT': | ||
return getIngPart(verbsInfo, verb); | ||
return (isNegative ? 'not ' : '') + getIngPart(verbsInfo, verb); | ||
case 'PARTICIPLE_PAST': | ||
return getPastPart(verbsInfo, verb); | ||
return (isNegative ? 'not ' : '') + getPastPart(verbsInfo, verb); | ||
} | ||
} | ||
function getConjugation(verbsInfo, verb, tense, person, extraParams) { | ||
if (!verb) { | ||
const err = new Error(); | ||
err.name = 'TypeError'; | ||
err.message = 'verb must not be null'; | ||
throw err; | ||
} | ||
if (tenses.indexOf(tense) == -1) { | ||
const err = new Error(); | ||
err.name = 'TypeError'; | ||
err.message = `invalid tense: ${tense}`; | ||
throw err; | ||
} | ||
if ([0, 1, 2, 3, 4, 5].indexOf(person) === -1) { | ||
const err = new Error(); | ||
err.name = 'TypeError'; | ||
err.message = 'person must be 0 1 2 3 4 or 5'; | ||
throw err; | ||
} | ||
const isGoingTo = extraParams && extraParams.GOING_TO; | ||
const isNegative = extraParams && extraParams.NEGATIVE; | ||
const isHaveNoDo = isNegative && verb === 'have' && extraParams.NO_DO; | ||
const conjugated = getConjugatedVerb(verbsInfo, verb, tense, person, isNegative, isHaveNoDo, isGoingTo); | ||
if (isNegative && (extraParams.CONTRACT || isHaveNoDo)) { | ||
// Note that in the form without the auxiliary verb DO, the verb HAVE is always contracted with the adverb not. | ||
return doContract(conjugated); | ||
} | ||
else { | ||
return conjugated; | ||
} | ||
} | ||
exports.getConjugation = getConjugation; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "english-verbs-helper", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "English verbs conjugation", | ||
@@ -48,4 +48,4 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"english-verbs-gerunds": "3.0.0", | ||
"english-verbs-irregular": "3.0.0" | ||
"english-verbs-gerunds": "3.1.0", | ||
"english-verbs-irregular": "3.1.0" | ||
}, | ||
@@ -63,3 +63,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "f29cc6f345687b2901f66077f413cecb0ba0d6d7" | ||
"gitHead": "11645a24749c02832b29d6ef71cdf943f89ea81a" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
392
40001