english-verbs-helper
Advanced tools
Comparing version 2.4.0 to 3.0.0
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
export declare type Numbers = 'S' | 'P'; | ||
export declare type Person = 0 | 1 | 2 | 3 | 4 | 5; | ||
interface EnglishGerunds { | ||
@@ -22,7 +22,10 @@ [inf: string]: string; | ||
WILL?: boolean; | ||
NEGATIVE?: boolean; | ||
CONTRACT?: boolean; | ||
NO_DO?: boolean; | ||
} | ||
export declare function mergeVerbsData(irregularsInfo: EnglishVerbsIrregular, gerundsInfo: EnglishGerunds): VerbsInfo; | ||
export declare function getIngPart(verbInfo: VerbInfo, verb: string): string; | ||
export declare function getIngPart(verbsInfo: VerbsInfo, verb: string): string; | ||
export declare function getVerbInfo(verbsInfo: VerbsInfo, verb: string): VerbInfo; | ||
export declare function getConjugation(verbsInfo: VerbsInfo, verb: string, tense: string, number: Numbers, extraParams: ExtraParams): string; | ||
export declare function getConjugation(verbsInfo: VerbsInfo, verb: string, tense: string, person: Person, extraParams: ExtraParams): string; | ||
export {}; |
@@ -34,3 +34,3 @@ "use strict"; | ||
]; | ||
const modals = ['can', 'could', 'may', 'might', 'must', 'shall', 'should', 'will', 'would']; | ||
const modals = ['can', 'could', 'may', 'might', 'must', 'shall', 'should', 'will', 'would', 'ought']; | ||
// helpers | ||
@@ -74,3 +74,4 @@ function mergeVerbsData(irregularsInfo, gerundsInfo) { | ||
exports.mergeVerbsData = mergeVerbsData; | ||
function getIrregularHelper(verbInfo, index) { | ||
function getIrregularHelper(verbsInfo, verb, index) { | ||
const verbInfo = getVerbInfo(verbsInfo, verb); | ||
if (verbInfo && verbInfo.length != 0) { | ||
@@ -102,3 +103,3 @@ return verbInfo[index]; | ||
} | ||
function getPastPart(verbInfo, verb) { | ||
function getPastPart(verbsInfo, verb) { | ||
let irregular; | ||
@@ -108,3 +109,3 @@ if (verb === 'be') { | ||
} | ||
else if ((irregular = getIrregularHelper(verbInfo, 1))) { | ||
else if ((irregular = getIrregularHelper(verbsInfo, verb, 1))) { | ||
return irregular; | ||
@@ -116,13 +117,13 @@ } | ||
} | ||
function getPreteritPart(verbInfo, verb, number) { | ||
function getPreteritPart(verbsInfo, verb, person) { | ||
let irregular; | ||
if (verb === 'be') { | ||
if (number === 'P') { | ||
return 'were'; | ||
if (person === 0 || person === 2) { | ||
return 'was'; | ||
} | ||
else { | ||
return 'was'; | ||
return 'were'; | ||
} | ||
} | ||
else if ((irregular = getIrregularHelper(verbInfo, 0))) { | ||
else if ((irregular = getIrregularHelper(verbsInfo, verb, 0))) { | ||
return irregular; | ||
@@ -134,6 +135,6 @@ } | ||
} | ||
function getIngPart(verbInfo, verb) { | ||
function getIngPart(verbsInfo, verb) { | ||
const consonants = 'bcdfghjklmnpqrstvxzw'; | ||
let irregular; | ||
if ((irregular = getIrregularHelper(verbInfo, 2))) { | ||
if ((irregular = getIrregularHelper(verbsInfo, verb, 2))) { | ||
return irregular; | ||
@@ -160,12 +161,17 @@ } | ||
// 1 per tense | ||
function getSimplePast(verbInfo, verb, number) { | ||
return getPreteritPart(verbInfo, verb, number); | ||
function getSimplePast(verbsInfo, verb, person) { | ||
return getPreteritPart(verbsInfo, verb, person); | ||
} | ||
function yWithVowel(verb) { | ||
return verb.match(/[aeiouy]y$/); | ||
return verb.match(/[aeiouy]y$/) !== null; | ||
} | ||
function getSimplePresent(verb, number) { | ||
if (number === 'P') { | ||
function getSimplePresent(verb, person) { | ||
if (person != 2) { | ||
if (verb === 'be') { | ||
return 'are'; | ||
if (person === 0) { | ||
return 'am'; | ||
} | ||
else { | ||
return 'are'; | ||
} | ||
} | ||
@@ -209,44 +215,41 @@ else { | ||
} | ||
function getSimpleFuture(verb, number, extraParams) { | ||
function getSimpleFuture(verb, person, extraParams, negative) { | ||
if (extraParams && extraParams.GOING_TO) { | ||
if (number === 'P') { | ||
return 'are going to ' + verb; | ||
} | ||
else { | ||
return 'is going to ' + verb; | ||
} | ||
return getSimplePresent('be', person) + ' ' + getNegative(negative) + 'going to ' + verb; | ||
} | ||
else { | ||
// default is will | ||
return 'will ' + verb; | ||
return 'will ' + getNegative(negative) + verb; | ||
} | ||
} | ||
function getProgressivePast(gerund, number) { | ||
return (number === 'P' ? 'were ' : 'was ') + gerund; | ||
function getNegative(negative) { | ||
return negative ? 'not ' : ''; | ||
} | ||
function getProgressivePresent(gerund, number) { | ||
return (number === 'P' ? 'are ' : 'is ') + gerund; | ||
function getProgressivePast(verbsInfo, verb, person, negative) { | ||
return getPreteritPart(verbsInfo, 'be', person) + ' ' + getNegative(negative) + getIngPart(verbsInfo, verb); | ||
} | ||
function getProgressiveFuture(gerund) { | ||
return 'will be ' + gerund; | ||
function getProgressivePresent(verbsInfo, verb, person, negative) { | ||
return getSimplePresent('be', person) + ' ' + getNegative(negative) + getIngPart(verbsInfo, verb); | ||
} | ||
function getPerfectPast(pastPart) { | ||
return 'had ' + pastPart; | ||
function getProgressiveFuture(verbsInfo, verb, negative) { | ||
return 'will ' + getNegative(negative) + 'be ' + getIngPart(verbsInfo, verb); | ||
} | ||
function getPerfectPresent(number, pastPart) { | ||
return (number === 'P' ? 'have ' : 'has ') + pastPart; | ||
function getPerfectPast(verbsInfo, verb, negative) { | ||
return 'had ' + getNegative(negative) + getPastPart(verbsInfo, verb); | ||
} | ||
function getPerfectFuture(pastPart) { | ||
return 'will have ' + pastPart; | ||
function getPerfectPresent(verbsInfo, verb, person, negative) { | ||
return getSimplePresent('have', person) + ' ' + getNegative(negative) + getPastPart(verbsInfo, verb); | ||
} | ||
function getPerfectProgressivePast(gerund) { | ||
return 'had been ' + gerund; | ||
function getPerfectFuture(verbsInfo, verb, negative) { | ||
return 'will ' + getNegative(negative) + 'have ' + getPastPart(verbsInfo, verb); | ||
} | ||
function getPerfectProgressivePresent(gerund, number) { | ||
return (number === 'P' ? 'have ' : 'has ') + 'been ' + gerund; | ||
function getPerfectProgressivePast(verbsInfo, verb, negative) { | ||
return 'had ' + getNegative(negative) + 'been ' + getIngPart(verbsInfo, verb); | ||
} | ||
function getPerfectProgressiveFuture(gerund) { | ||
return 'will have been ' + gerund; | ||
function getPerfectProgressivePresent(verbsInfo, verb, person, negative) { | ||
return getSimplePresent('have', person) + ' ' + getNegative(negative) + 'been ' + getIngPart(verbsInfo, verb); | ||
} | ||
function getConjugation(verbsInfo, verb, tense, number, extraParams) { | ||
function getPerfectProgressiveFuture(verbsInfo, verb, negative) { | ||
return 'will ' + getNegative(negative) + 'have been ' + getIngPart(verbsInfo, verb); | ||
} | ||
function getConjugation(verbsInfo, verb, tense, person, extraParams) { | ||
if (!verb) { | ||
@@ -264,40 +267,98 @@ const err = new Error(); | ||
} | ||
if (number != 'S' && number != 'P') { | ||
if ([0, 1, 2, 3, 4, 5].indexOf(person) === -1) { | ||
const err = new Error(); | ||
err.name = 'TypeError'; | ||
err.message = 'number must be S or P'; | ||
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]); | ||
} | ||
} | ||
return res; | ||
} | ||
switch (tense) { | ||
case 'PAST': | ||
case 'SIMPLE_PAST': | ||
return getSimplePast(getVerbInfo(verbsInfo, verb), verb, number); | ||
if (isNegative) { | ||
if (verb === 'be' || verb === 'do' || modals.indexOf(verb) > -1 || isHaveNoDo) { | ||
return addContract(getSimplePast(verbsInfo, verb, person) + ' not'); | ||
} | ||
else { | ||
// 'do ...' form | ||
return addContract(getSimplePast(verbsInfo, 'do', person) + ' not ' + verb); | ||
} | ||
} | ||
else { | ||
return getSimplePast(verbsInfo, verb, person); | ||
} | ||
case 'PRESENT': | ||
case 'SIMPLE_PRESENT': | ||
return getSimplePresent(verb, number); | ||
if (isNegative) { | ||
if (verb === 'be' || verb === 'do' || modals.indexOf(verb) > -1 || isHaveNoDo) { | ||
return addContract(getSimplePresent(verb, person) + ' not'); | ||
} | ||
else { | ||
// 'do ...' form | ||
return addContract(getSimplePresent('do', person) + ' not ' + verb); | ||
} | ||
} | ||
else { | ||
return getSimplePresent(verb, person); | ||
} | ||
case 'FUTURE': | ||
case 'SIMPLE_FUTURE': | ||
return getSimpleFuture(verb, number, extraParams); | ||
return addContract(getSimpleFuture(verb, person, extraParams, isNegative)); | ||
case 'PROGRESSIVE_PAST': | ||
return getProgressivePast(getIngPart(getVerbInfo(verbsInfo, verb), verb), number); | ||
return addContract(getProgressivePast(verbsInfo, verb, person, isNegative)); | ||
case 'PROGRESSIVE_PRESENT': | ||
return getProgressivePresent(getIngPart(getVerbInfo(verbsInfo, verb), verb), number); | ||
return addContract(getProgressivePresent(verbsInfo, verb, person, isNegative)); | ||
case 'PROGRESSIVE_FUTURE': | ||
return getProgressiveFuture(getIngPart(getVerbInfo(verbsInfo, verb), verb)); | ||
return addContract(getProgressiveFuture(verbsInfo, verb, isNegative)); | ||
case 'PERFECT_PAST': | ||
return getPerfectPast(getPastPart(getVerbInfo(verbsInfo, verb), verb)); | ||
return addContract(getPerfectPast(verbsInfo, verb, isNegative)); | ||
case 'PERFECT_PRESENT': | ||
return getPerfectPresent(number, getPastPart(getVerbInfo(verbsInfo, verb), verb)); | ||
return addContract(getPerfectPresent(verbsInfo, verb, person, isNegative)); | ||
case 'PERFECT_FUTURE': | ||
return getPerfectFuture(getPastPart(getVerbInfo(verbsInfo, verb), verb)); | ||
return addContract(getPerfectFuture(verbsInfo, verb, isNegative)); | ||
case 'PERFECT_PROGRESSIVE_PAST': | ||
return getPerfectProgressivePast(getIngPart(getVerbInfo(verbsInfo, verb), verb)); | ||
return addContract(getPerfectProgressivePast(verbsInfo, verb, isNegative)); | ||
case 'PERFECT_PROGRESSIVE_PRESENT': | ||
return getPerfectProgressivePresent(getIngPart(getVerbInfo(verbsInfo, verb), verb), number); | ||
return addContract(getPerfectProgressivePresent(verbsInfo, verb, person, isNegative)); | ||
case 'PERFECT_PROGRESSIVE_FUTURE': | ||
return getPerfectProgressiveFuture(getIngPart(getVerbInfo(verbsInfo, verb), verb)); | ||
return addContract(getPerfectProgressiveFuture(verbsInfo, verb, isNegative)); | ||
case 'PARTICIPLE_PRESENT': | ||
return getIngPart(getVerbInfo(verbsInfo, verb), verb); | ||
return getIngPart(verbsInfo, verb); | ||
case 'PARTICIPLE_PAST': | ||
return getPastPart(getVerbInfo(verbsInfo, verb), verb); | ||
return getPastPart(verbsInfo, verb); | ||
} | ||
@@ -304,0 +365,0 @@ } |
{ | ||
"name": "english-verbs-helper", | ||
"version": "2.4.0", | ||
"version": "3.0.0", | ||
"description": "English verbs conjugation", | ||
@@ -48,4 +48,4 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"english-verbs-gerunds": "2.4.0", | ||
"english-verbs-irregular": "2.4.0" | ||
"english-verbs-gerunds": "3.0.0", | ||
"english-verbs-irregular": "3.0.0" | ||
}, | ||
@@ -63,3 +63,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "8306d0f4f01556a596db289cdbb98d5bc1dd088f" | ||
"gitHead": "f29cc6f345687b2901f66077f413cecb0ba0d6d7" | ||
} |
@@ -28,4 +28,6 @@ <!-- | ||
- the tense | ||
- number: `S` for he/she/it, `P` for they | ||
- `ExtraParams`: for `SIMPLE_FUTURE`, you can add `{ GOING_TO: true }` to trigger the _going to_ form; default is `{ WILL: true }` | ||
- the person: 0=I, 1=you (singular), 2=he/she/it, 3=we, 4=you (plural), 5=they. | ||
- `ExtraParams`: | ||
- for `SIMPLE_FUTURE`, you can add `{ GOING_TO: true }` to trigger the _going to_ form; default is `{ WILL: true }` | ||
- use `{ NEGATIVE: true }` to trigger the negative form; additionnaly add `CONTRACT: true` to get the contracted version (will not => won't, etc.); when using the verb `to have`, you can choose whether to generate `hasn't` or `does not have` using `NO_DO: true` | ||
@@ -41,4 +43,2 @@ Available tenses are: `SIMPLE_PAST` (or `PAST`), `SIMPLE_PRESENT` (or `PRESENT`), `SIMPLE_FUTURE` (or `FUTURE`), `PROGRESSIVE_PAST`, `PROGRESSIVE_PRESENT`, `PROGRESSIVE_FUTURE`, `PERFECT_PAST`, `PERFECT_PRESENT`, `PERFECT_FUTURE`, `PERFECT_PROGRESSIVE_PAST`, `PERFECT_PROGRESSIVE_PRESENT`, `PERFECT_PROGRESSIVE_FUTURE`. | ||
- only `he` (singular S) or `they` (plural P) forms | ||
- no negative form | ||
- no interrogative form | ||
@@ -62,10 +62,10 @@ - modals | ||
// eats | ||
console.log(EnglishVerbs.getConjugation(null, 'eat', 'PRESENT', 'S')); | ||
// (he/she) eats | ||
console.log(EnglishVerbs.getConjugation(null, 'eat', 'PRESENT', 2)); | ||
// ate | ||
console.log(EnglishVerbs.getConjugation(VerbsData, 'eat', 'SIMPLE_PAST', 'S')); | ||
// (he/she) ate | ||
console.log(EnglishVerbs.getConjugation(VerbsData, 'eat', 'SIMPLE_PAST', 2)); | ||
// swimming | ||
console.log(EnglishVerbs.getIngPart(VerbsData['swim'], 'swim')); | ||
console.log(EnglishVerbs.getIngPart(VerbsData, 'swim')); | ||
``` |
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
40219
386