diff --git a/src/affixes.ts b/src/affixes.ts index 2390a6e..2368bb3 100644 --- a/src/affixes.ts +++ b/src/affixes.ts @@ -20,20 +20,20 @@ export interface LenitionTable { } /** -* get table of all the possible lenition changes -* -* @return {LenitionTable} table of all possible lenition changes -*/ + * get table of all the possible lenition changes + * + * @return {LenitionTable} table of all possible lenition changes + */ export function getLenitionTable(): LenitionTable { return { - "kx": "k", - "px": "p", - "tx": "t", - "k": "h", - "p": "f", - "ts": "s", - "t": "s", - "'": "", + kx: 'k', + px: 'p', + tx: 't', + k: 'h', + p: 'f', + ts: 's', + t: 's', + "'": '' } } @@ -53,21 +53,30 @@ export function prefix(inputWord: Word): Word { // pull this out of the switch because the pos data for verbs is so irregular, // the switch condition would be like 25 possibilities long - if (word.data.PartOfSpeech.startsWith('v') || word.data.PartOfSpeech.startsWith('svin') || word.data.PartOfSpeech === '') { + if ( + word.data.PartOfSpeech.startsWith('v') || + word.data.PartOfSpeech.startsWith('svin') || + word.data.PartOfSpeech === '' + ) { const inf = word.data.Affixes.Infix if (inf.length > 0 && (inf[0] === 'us' || inf[0] === 'awn')) { reString = '(a|tì)?' - } else if (word.target.includes('ketsuk') || word.target.includes("tsuk")) { + } else if (word.target.includes('ketsuk') || word.target.includes('tsuk')) { reString = '(a)?(ketsuk|tsuk)?' - } else if (word.target.includes('siyu') && word.data.PartOfSpeech === 'vin.') { - reString = '^(pep|pem|pe|fray|tsay|fay|pay|fra|fì|tsa)?(ay|me|pxe|pe)?(fne)?(munsna)?' + } else if ( + word.target.includes('siyu') && + word.data.PartOfSpeech === 'vin.' + ) { + reString = + '^(pep|pem|pe|fray|tsay|fay|pay|fra|fì|tsa)?(ay|me|pxe|pe)?(fne)?(munsna)?' } } else { switch (word.data.PartOfSpeech) { case 'n.': case 'pn.': case 'prop.n.': - reString = '^(pep|pem|pe|fray|tsay|fay|pay|fra|fì|tsa)?(ay|me|pxe|pe)?(fne)?(munsna)?' + reString = + '^(pep|pem|pe|fray|tsay|fay|pay|fra|fì|tsa)?(ay|me|pxe|pe)?(fne)?(munsna)?' break case 'adj.': reString = '^(nìk|nì|a)?(ke|a)?' @@ -77,7 +86,11 @@ export function prefix(inputWord: Word): Word { } } - if (word.target.startsWith('me') || word.target.startsWith('pxe') || word.target.startsWith('pe')) { + if ( + word.target.startsWith('me') || + word.target.startsWith('pxe') || + word.target.startsWith('pe') + ) { if (word.attempt.startsWith('e')) { reString = reString + '(e)?' word.attempt = word.attempt.slice(1) @@ -112,8 +125,22 @@ export function prefix(inputWord: Word): Word { if (containsArr(matchPrefixes, ['fne', 'munsna'])) { return word } - const lenPre = ['pep', 'pem', 'pe', 'fray', 'tsay', 'fay', 'pay', 'ay', 'me', 'pxe'] - if (containsArr(matchPrefixes, ['fì', 'tsa', 'fra']) && !containsArr(matchPrefixes, lenPre)) { + const lenPre = [ + 'pep', + 'pem', + 'pe', + 'fray', + 'tsay', + 'fay', + 'pay', + 'ay', + 'me', + 'pxe' + ] + if ( + containsArr(matchPrefixes, ['fì', 'tsa', 'fra']) && + !containsArr(matchPrefixes, lenPre) + ) { return word } } @@ -151,7 +178,8 @@ export function suffix(inputWord: Word): Word { let matchSuffixes: string[] = [] const adjSufRe = '(a|sì)?$' - const nSufRe = "(nga'|tsyìp|tu)?(o)?(pe)?(mungwrr|kxamlä|tafkip|pxisre|pximaw|ftumfa|mìkam|nemfa|takip|lisre|talun|krrka|teri|fkip|pxaw|pxel|luke|rofa|fpi|ftu|kip|vay|lok|maw|sìn|sre|few|kam|kay|nuä|sko|yoa|äo|eo|fa|hu|ka|mì|na|ne|ta|io|uo|ro|wä|sì|ìri|ìl|eyä|yä|ä|it|ri|ru|ti|ur|l|r|t)?$" + const nSufRe = + "(nga'|tsyìp|tu)?(o)?(pe)?(mungwrr|kxamlä|tafkip|pxisre|pximaw|ftumfa|mìkam|nemfa|takip|lisre|talun|krrka|teri|fkip|pxaw|pxel|luke|rofa|fpi|ftu|kip|vay|lok|maw|sìn|sre|few|kam|kay|nuä|sko|yoa|äo|eo|fa|hu|ka|mì|na|ne|ta|io|uo|ro|wä|sì|ìri|ìl|eyä|yä|ä|it|ri|ru|ti|ur|l|r|t)?$" const ngey = 'ngey' // hardcoded hack for tseyä @@ -176,7 +204,11 @@ export function suffix(inputWord: Word): Word { } // verbs - if (!word.data.PartOfSpeech.includes('adv.') && word.data.PartOfSpeech.includes('v') || word.data.PartOfSpeech === '') { + if ( + (!word.data.PartOfSpeech.includes('adv.') && + word.data.PartOfSpeech.includes('v')) || + word.data.PartOfSpeech === '' + ) { const inf = word.data.Affixes.Infix const pre = word.data.Affixes.Prefix // word is verb with or @@ -232,10 +264,56 @@ export function suffix(inputWord: Word): Word { reString = word.attempt.replace(/a/g, '[ae]') + reString } else if (word.data.Navi === 'tsaw') { const tsaSuf = [ - 'mungwrr', 'kxamlä', 'tafkip', 'pxisre', 'pximaw', 'ftumfa', 'mìkam', 'nemfa', 'takip', 'lisre', 'talun', - 'krrka', 'teri', 'fkip', 'pxaw', 'pxel', 'luke', 'rofa', 'fpi', 'ftu', 'kip', 'vay', 'lok', 'maw', 'sìn', 'sre', - 'few', 'kam', 'kay', 'nuä', 'sko', 'yoa', 'äo', 'eo', 'fa', 'hu', 'ka', 'mì', 'na', 'ne', 'ta', 'io', 'uo', - 'ro', 'wä', 'ìri', 'ri', 'ru', 'ti', 'r' + 'mungwrr', + 'kxamlä', + 'tafkip', + 'pxisre', + 'pximaw', + 'ftumfa', + 'mìkam', + 'nemfa', + 'takip', + 'lisre', + 'talun', + 'krrka', + 'teri', + 'fkip', + 'pxaw', + 'pxel', + 'luke', + 'rofa', + 'fpi', + 'ftu', + 'kip', + 'vay', + 'lok', + 'maw', + 'sìn', + 'sre', + 'few', + 'kam', + 'kay', + 'nuä', + 'sko', + 'yoa', + 'äo', + 'eo', + 'fa', + 'hu', + 'ka', + 'mì', + 'na', + 'ne', + 'ta', + 'io', + 'uo', + 'ro', + 'wä', + 'ìri', + 'ri', + 'ru', + 'ti', + 'r' ] for (let s of tsaSuf) { if (word.target.endsWith('tsa' + s) || word.target.endsWith('sa' + s)) { @@ -301,37 +379,44 @@ export function suffix(inputWord: Word): Word { export function infix(inputWord: Word): Word { const word = inputWord.clone() // Have we already attempted infixes or does the word even have infix positions?? - if (word.data.Affixes.Infix.length !== 0 || word.data.InfixLocations === "NULL") { + if ( + word.data.Affixes.Infix.length !== 0 || + word.data.InfixLocations === 'NULL' + ) { return word } let re: RegExp let reString: string let attempt: string - let pos0InfixRe = "(äp)?(eyk)?" - let pos1InfixRe = "(ìyev|iyev|ìlm|ìly|ìrm|ìry|ìsy|alm|aly|arm|ary|asy|ìm|imv|ilv|irv|ìy|am|ay|er|iv|ol|us|awn)?" - let pos2InfixRe = "(eiy|ei|äng|eng|ats|uy)?" + let pos0InfixRe = '(äp)?(eyk)?' + let pos1InfixRe = + '(ìyev|iyev|ìlm|ìly|ìrm|ìry|ìsy|alm|aly|arm|ary|asy|ìm|imv|ilv|irv|ìy|am|ay|er|iv|ol|us|awn)?' + let pos2InfixRe = '(eiy|ei|äng|eng|ats|uy)?' let pos0InfixString: string = '' let pos1InfixString: string = '' let pos2InfixString: string = '' let matchInfixes: string[] = [] // Hardcode hack for z**enke - if (word.data.Navi === "zenke" && (word.target.includes("uy") || word.target.includes("ats"))) { + if ( + word.data.Navi === 'zenke' && + (word.target.includes('uy') || word.target.includes('ats')) + ) { word.data.InfixLocations = word.data.InfixLocations.replace(/ke$/, 'eke') } - reString = word.data.InfixLocations.replace("<0>", pos0InfixRe) + reString = word.data.InfixLocations.replace('<0>', pos0InfixRe) // handle
    ll and rr - if (reString.includes("<1>ll")) { - reString = reString.replace("<1>ll", pos1InfixRe + "(ll)?") - } else if (word.data.InfixLocations.includes("<1>rr")) { - reString = reString.replace("<1>rr", pos1InfixRe + "(rr)?") + if (reString.includes('<1>ll')) { + reString = reString.replace('<1>ll', pos1InfixRe + '(ll)?') + } else if (word.data.InfixLocations.includes('<1>rr')) { + reString = reString.replace('<1>rr', pos1InfixRe + '(rr)?') } else { - reString = reString.replace("<1>", pos1InfixRe) + reString = reString.replace('<1>', pos1InfixRe) } - reString = reString.replace("<2>", pos2InfixRe) + reString = reString.replace('<2>', pos2InfixRe) re = new RegExp(reString, 'g') const tmp = Array.from(word.target.matchAll(re)) @@ -339,38 +424,41 @@ export function infix(inputWord: Word): Word { matchInfixes = tmp[0].slice(1) } matchInfixes = deleteEmpty(matchInfixes) - matchInfixes = deleteElement(matchInfixes, "ll") - matchInfixes = deleteElement(matchInfixes, "rr") + matchInfixes = deleteElement(matchInfixes, 'll') + matchInfixes = deleteElement(matchInfixes, 'rr') for (const i of matchInfixes) { - if (i === "äp" || i === "eyk") { + if (i === 'äp' || i === 'eyk') { pos0InfixString = pos0InfixString + i - } else if (["eiy", "ei", "äng", "eng", "ats", "uy"].includes(i)) { + } else if (['eiy', 'ei', 'äng', 'eng', 'ats', 'uy'].includes(i)) { pos2InfixString = i } else { pos1InfixString = i } } - attempt = word.data.InfixLocations.replace("<0>", pos0InfixString) - attempt = attempt.replace("<1>", pos1InfixString) - attempt = attempt.replace("<2>", pos2InfixString) + attempt = word.data.InfixLocations.replace('<0>', pos0InfixString) + attempt = attempt.replace('<1>', pos1InfixString) + attempt = attempt.replace('<2>', pos2InfixString) // eiy override? - if (matchInfixes.includes("eiy")) { - const eiy = matchInfixes.indexOf("eiy") - matchInfixes[eiy] = "ei" + if (matchInfixes.includes('eiy')) { + const eiy = matchInfixes.indexOf('eiy') + matchInfixes[eiy] = 'ei' } // handle
      ll and rr - if (attempt.includes("olll")) { - attempt = attempt.replace("olll", "ol") - } else if (attempt.includes("errr")) { - attempt = attempt.replace("errr", "er") + if (attempt.includes('olll')) { + attempt = attempt.replace('olll', 'ol') + } else if (attempt.includes('errr')) { + attempt = attempt.replace('errr', 'er') } if (matchInfixes.length !== 0) { - const combined = combineArrays(word.data.Affixes.Infix, matchInfixes) + const combined = combineArrays( + word.data.Affixes.Infix, + matchInfixes + ) if (combined != null) { word.data.Affixes.Infix = combined } @@ -383,7 +471,7 @@ export function infix(inputWord: Word): Word { /** * Lenite the word, based on the attempt. The target is not relevant here, so not given. * Returns the lenite attempt. - * + * * @param {Word} inputWord - the Fwew Word on which to track lenition * @return {Word} The lenited version of this word */ @@ -421,7 +509,10 @@ export function reconstruct(inputWord: Word, target: string): Word | undefined { word.attempt = word.data.Navi // only try to infix verbs - if (word.data.PartOfSpeech.startsWith("v") || word.data.PartOfSpeech.startsWith('svin.')) { + if ( + word.data.PartOfSpeech.startsWith('v') || + word.data.PartOfSpeech.startsWith('svin.') + ) { word = word.infix() if (word.attempt === word.target) { @@ -472,5 +563,5 @@ export function reconstruct(inputWord: Word, target: string): Word | undefined { if (word2.attempt === word2.target) { return word2 } - return undefined; + return undefined } diff --git a/src/fwew.ts b/src/fwew.ts index d74747e..31b73a1 100644 --- a/src/fwew.ts +++ b/src/fwew.ts @@ -20,7 +20,7 @@ import { stripChars } from './util' * !! Only one word is allowed, if spaces are found, they will be treated like part of the word !! * This will return an array of Words, that fit the input text * One Navi-Word can have multiple meanings and words (e.g. synonyms) - * + * * @param {string} searchNaviWord word to search * @return {Word[]} array of matching Fwew Word */ @@ -47,7 +47,7 @@ export function translateFromNavi(searchNaviWord: string): Word[] { * fwew function: searches for Na'vi words in the dictionary * * Will run on each entry of the dictionary, appending matching Word entries to the previously-defined results array - * + * * @param {Word} word in the dictionary we are currently comparing to the user's search input */ const fwew = (word: Word): void => { @@ -67,12 +67,12 @@ export function translateFromNavi(searchNaviWord: string): Word[] { // skip words that obviously won't work const similarityScore = word.similarity(searchNaviWord) - if (similarityScore < 0.50 && !searchNaviWord.endsWith("eyä")) { + if (similarityScore < 0.5 && !searchNaviWord.endsWith('eyä')) { return } // check if applying affix rules to word will yield any matches against the user's search input, and add them if so - const result = word.reconstruct(searchNaviWord); + const result = word.reconstruct(searchNaviWord) if (result != null) { result.data.Navi = naviWord fwewResults.push(result) @@ -99,7 +99,7 @@ export function translateToNavi(searchWord: string, langCode: string): Word[] { * fwewReverse function: searches for Na'vi words in the dictionary in the reverse direction * * Will run on each entry of the dictionary, appending matching Word entries to the previously-defined results array - * + * * @param {Word} word in the dictionary we are currently comparing to the user's search input */ const fwewReverse = (word: Word): void => { diff --git a/src/index.ts b/src/index.ts index 1372fc0..825054b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,23 +16,30 @@ import { Affix, WordData, Word, getWords } from './word' import { list } from './list' import { random } from './random' import * as numbers from './numbers' -import { getLenitionTable, prefix, suffix, infix, lenite, reconstruct } from './affixes' +import { + getLenitionTable, + prefix, + suffix, + infix, + lenite, + reconstruct +} from './affixes' import * as util from './util' export { - fwew, - Affix, - WordData, - Word, - getWords, - list, - random, - numbers, - getLenitionTable, - prefix, - suffix, - infix, - lenite, - reconstruct, - util + fwew, + Affix, + WordData, + Word, + getWords, + list, + random, + numbers, + getLenitionTable, + prefix, + suffix, + infix, + lenite, + reconstruct, + util } diff --git a/src/list.ts b/src/list.ts index 393bc99..25b8a04 100644 --- a/src/list.ts +++ b/src/list.ts @@ -57,176 +57,176 @@ function listWords(args: string[], words: Word[]): Word[] { for (const [i, word] of Object.entries(words)) { let ispec: number switch (what) { - case text("w_pos"): + case text('w_pos'): const pos = word.data.PartOfSpeech.toLowerCase() switch (cond) { - case text("c_starts"): + case text('c_starts'): if (pos.startsWith(spec)) { results.push(word) } break - case text("c_ends"): + case text('c_ends'): if (pos.endsWith(spec)) { results.push(word) } break - case text("c_is"): + case text('c_is'): if (pos === spec) { results.push(word) } break - case text("c_has"): + case text('c_has'): if (pos.includes(spec)) { results.push(word) } break - case text("c_like"): + case text('c_like'): if (glob(spec, pos)) { results.push(word) } break - case text("c_not-starts"): + case text('c_not-starts'): if (!pos.startsWith(spec)) { results.push(word) } break - case text("c_not-ends"): + case text('c_not-ends'): if (!pos.endsWith(spec)) { results.push(word) } break - case text("c_not-is"): + case text('c_not-is'): if (pos !== spec) { results.push(word) } break - case text("c_not-has"): + case text('c_not-has'): if (!pos.includes(spec)) { results.push(word) } break - case text("c_not-like"): + case text('c_not-like'): if (!glob(spec, pos)) { results.push(word) } } break - case text("w_word"): + case text('w_word'): const navi = word.data.Navi.toLowerCase() switch (cond) { - case text("c_starts"): + case text('c_starts'): if (navi.startsWith(spec)) { results.push(word) } break - case text("c_ends"): + case text('c_ends'): if (navi.endsWith(spec)) { results.push(word) } break - case text("c_has"): + case text('c_has'): if (navi.includes(spec)) { results.push(word) } break - case text("c_like"): + case text('c_like'): if (glob(spec, navi)) { results.push(word) } break - case text("c_not-starts"): + case text('c_not-starts'): if (!navi.startsWith(spec)) { results.push(word) } break - case text("c_not-ends"): + case text('c_not-ends'): if (!navi.endsWith(spec)) { results.push(word) } break - case text("c_not-has"): + case text('c_not-has'): if (!navi.includes(spec)) { results.push(word) } break - case text("c_not-like"): + case text('c_not-like'): if (!glob(spec, navi)) { results.push(word) } } break - case text("w_words"): + case text('w_words'): const specNumber = +spec if (isNaN(specNumber)) { return words } switch (cond) { - case text("c_first"): + case text('c_first'): if (Number(i) < specNumber) { results.push(word) } break - case text("c_last"): + case text('c_last'): if (Number(i) >= wordsLen - specNumber && Number(i) <= wordsLen) { results.push(word) } } break - case text("w_syllables"): + case text('w_syllables'): ispec = +spec if (isNaN(ispec)) { return words } switch (cond) { - case "<": + case '<': if (word.syllableCount() < ispec) { results.push(word) } break - case "<=": + case '<=': if (word.syllableCount() <= ispec) { results.push(word) } break - case "=": + case '=': if (word.syllableCount() === ispec) { results.push(word) } break - case ">=": + case '>=': if (word.syllableCount() >= ispec) { results.push(word) } break - case ">": + case '>': if (word.syllableCount() > ispec) { results.push(word) } break - case "!=": + case '!=': if (word.syllableCount() !== ispec) { results.push(word) } } break - case text("w_stress"): + case text('w_stress'): ispec = +spec if (isNaN(ispec)) { return words } const istress = +word.data.Stressed switch (cond) { - case "<": + case '<': if (istress < ispec) { results.push(word) } break - case "<=": + case '<=': if (istress <= ispec) { results.push(word) } break - case "=": + case '=': if (ispec < 0) { if (word.syllableCount() + ispec + 1 === istress) { results.push(word) @@ -235,17 +235,17 @@ function listWords(args: string[], words: Word[]): Word[] { results.push(word) } break - case ">=": + case '>=': if (istress >= ispec) { results.push(word) } break - case ">": + case '>': if (istress > ispec) { results.push(word) } break - case "!=": + case '!=': if (ispec < 0) { if (word.syllableCount() + ispec + 1 !== istress) { results.push(word) diff --git a/src/numbers.ts b/src/numbers.ts index b150df2..ad975f7 100644 --- a/src/numbers.ts +++ b/src/numbers.ts @@ -15,15 +15,15 @@ const naviVocab: string[][] = [ // 0 1 2 3 4 5 6 7 actual - ["kew", "'aw", "mune", "pxey", "tsìng", "mrr", "pukap", "kinä"], + ['kew', "'aw", 'mune', 'pxey', 'tsìng', 'mrr', 'pukap', 'kinä'], // 0 1 2 3 4 5 6 7 last digit - ["", "aw", "mun", "pey", "sìng", "mrr", "fu", "hin"], + ['', 'aw', 'mun', 'pey', 'sìng', 'mrr', 'fu', 'hin'], // 0 1 2 3 4 5 6 7 first or middle digit - ["", "", "me", "pxe", "tsì", "mrr", "pu", "ki"], + ['', '', 'me', 'pxe', 'tsì', 'mrr', 'pu', 'ki'], // 0 1 2 3 4 powers of 8 - ["", "vo", "za", "vozam", "zazam"], + ['', 'vo', 'za', 'vozam', 'zazam'], // 0 1 2 3 4 powers of 8 last digit - ["", "l", "", "", ""], + ['', 'l', '', '', ''] ] export interface NumTableEntry { @@ -34,148 +34,122 @@ export interface NumTableEntry { // the upper array is the digit. const numTable: NumTableEntry[] = [ { - "kizazam": 0o70000, - "kizaza": 0o70000, - "puzazam": 0o60000, - "puzaza": 0o60000, - "mrrzazam": 0o50000, - "mrrzaza": 0o50000, - "rrzazam": 0o50000, - "rrzaza": 0o50000, - "tsìzazam": 0o40000, - "tsìzaza": 0o40000, - "pxezazam": 0o30000, - "pxezaza": 0o30000, - "mezazam": 0o20000, - "mezaza": 0o20000, - "ezazam": 0o20000, - "ezaza": 0o20000, - "zazam": 0o10000, - "zaza": 0o10000, + kizazam: 0o70000, + kizaza: 0o70000, + puzazam: 0o60000, + puzaza: 0o60000, + mrrzazam: 0o50000, + mrrzaza: 0o50000, + rrzazam: 0o50000, + rrzaza: 0o50000, + tsìzazam: 0o40000, + tsìzaza: 0o40000, + pxezazam: 0o30000, + pxezaza: 0o30000, + mezazam: 0o20000, + mezaza: 0o20000, + ezazam: 0o20000, + ezaza: 0o20000, + zazam: 0o10000, + zaza: 0o10000 }, { - "kivozam": 0o7000, - "kivoza": 0o7000, - "puvozam": 0o6000, - "puvoza": 0o6000, - "mrrvozam": 0o5000, - "mrrvoza": 0o5000, - "rrvozam": 0o5000, - "rrvoza": 0o5000, - "tsìvozam": 0o4000, - "tsìvoza": 0o4000, - "pxevozam": 0o3000, - "pxevoza": 0o3000, - "mevozam": 0o2000, - "mevoza": 0o2000, - "evozam": 0o2000, - "evoza": 0o2000, - "vozam": 0o1000, - "voza": 0o1000, + kivozam: 0o7000, + kivoza: 0o7000, + puvozam: 0o6000, + puvoza: 0o6000, + mrrvozam: 0o5000, + mrrvoza: 0o5000, + rrvozam: 0o5000, + rrvoza: 0o5000, + tsìvozam: 0o4000, + tsìvoza: 0o4000, + pxevozam: 0o3000, + pxevoza: 0o3000, + mevozam: 0o2000, + mevoza: 0o2000, + evozam: 0o2000, + evoza: 0o2000, + vozam: 0o1000, + voza: 0o1000 }, { - "kizam": 0o700, - "kiza": 0o700, - "puzam": 0o600, - "puza": 0o600, - "mrrzam": 0o500, - "mrrza": 0o500, - "rrzam": 0o500, - "rrza": 0o500, - "tsìzam": 0o400, - "tsìza": 0o400, - "pxezam": 0o300, - "pxeza": 0o300, - "mezam": 0o200, - "meza": 0o200, - "ezam": 0o200, - "eza": 0o200, - "zam": 0o100, - "za": 0o100, + kizam: 0o700, + kiza: 0o700, + puzam: 0o600, + puza: 0o600, + mrrzam: 0o500, + mrrza: 0o500, + rrzam: 0o500, + rrza: 0o500, + tsìzam: 0o400, + tsìza: 0o400, + pxezam: 0o300, + pxeza: 0o300, + mezam: 0o200, + meza: 0o200, + ezam: 0o200, + eza: 0o200, + zam: 0o100, + za: 0o100 }, { - "kivol": 0o70, - "kivo": 0o70, - "puvol": 0o60, - "puvo": 0o60, - "mrrvol": 0o50, - "mrrvo": 0o50, - "rrvol": 0o50, - "rrvo": 0o50, - "tsìvol": 0o40, - "tsìvo": 0o40, - "pxevol": 0o30, - "pxevo": 0o30, - "mevol": 0o20, - "mevo": 0o20, - "evol": 0o20, - "evo": 0o20, - "vol": 0o10, - "vo": 0o10, + kivol: 0o70, + kivo: 0o70, + puvol: 0o60, + puvo: 0o60, + mrrvol: 0o50, + mrrvo: 0o50, + rrvol: 0o50, + rrvo: 0o50, + tsìvol: 0o40, + tsìvo: 0o40, + pxevol: 0o30, + pxevo: 0o30, + mevol: 0o20, + mevo: 0o20, + evol: 0o20, + evo: 0o20, + vol: 0o10, + vo: 0o10 }, { - "hin": 0o7, - "fu": 0o6, - "mrr": 0o5, - "rr": 0o5, - "sìng": 0o4, - "pey": 0o3, - "mun": 0o2, - "un": 0o2, - "aw": 0o1, - }, + hin: 0o7, + fu: 0o6, + mrr: 0o5, + rr: 0o5, + sìng: 0o4, + pey: 0o3, + mun: 0o2, + un: 0o2, + aw: 0o1 + } ] // The regex values for the different values. // The upper array is the digit. const numTableRegexp: string[][] = [ [ - "kizazam?", - "puzazam?", - "m?rrzazam?", - "tsìzazam?", - "pxezazam?", - "m?ezazam?", - "zazam?", + 'kizazam?', + 'puzazam?', + 'm?rrzazam?', + 'tsìzazam?', + 'pxezazam?', + 'm?ezazam?', + 'zazam?' ], [ - "kivozam?", - "puvozam?", - "m?rrvozam?", - "tsìvozam?", - "pxevozam?", - "m?evozam?", - "vozam?", - ], - [ - "kizam?", - "puzam?", - "m?rrzam?", - "tsìzam?", - "pxezam?", - "m?ezam?", - "zam?", - ], - [ - "kivol?", - "puvol?", - "m?rrvol?", - "tsìvol?", - "pxevol?", - "m?evol?", - "vol?", - ], - [ - "hin", - "fu", - "mrr", - "rr", - "sìng", - "pey", - "mun", - "un", - "aw", + 'kivozam?', + 'puvozam?', + 'm?rrvozam?', + 'tsìvozam?', + 'pxevozam?', + 'm?evozam?', + 'vozam?' ], + ['kizam?', 'puzam?', 'm?rrzam?', 'tsìzam?', 'pxezam?', 'm?ezam?', 'zam?'], + ['kivol?', 'puvol?', 'm?rrvol?', 'tsìvol?', 'pxevol?', 'm?evol?', 'vol?'], + ['hin', 'fu', 'mrr', 'rr', 'sìng', 'pey', 'mun', 'un', 'aw'] ] /** @@ -189,14 +163,14 @@ const numTableRegexp: string[][] = [ export function naviToNumber(input: string): number { input = input.toLowerCase() // kew - if (input === "kew") { + if (input === 'kew') { return 0 } // 'aw mune pxey tsìng mrr pukap kinä // literal numbers 1-7 for (let [i, w] of Object.entries(naviVocab[0])) { - if (input === w && w !== "") { + if (input === w && w !== '') { return Number(i) } } @@ -210,12 +184,12 @@ export function naviToNumber(input: string): number { for (let number of digit) { if (!first) { - regexpString += "|" + regexpString += '|' } regexpString += number first = false } - regexpString += ")?" + regexpString += ')?' } const re = new RegExp(regexpString) @@ -277,14 +251,23 @@ export function numberToNavi(input: number): string { let future = naviVocab[2][n] + naviVocab[3][i] // override to add `l` to vo, if at second digit and last digit is 0|1 - if (i === 1 && n !== 0 && (previousDigit === 0 || previousDigit === 1)) { - future = future + "l" + if ( + i === 1 && + n !== 0 && + (previousDigit === 0 || previousDigit === 1) + ) { + future = future + 'l' } // override to add `m` to za // only run if at third digit and second digit is not 0|1, also run when digits are x00|x01 - if (i === 2 && n !== 0 && ((previousDigit !== 0 && previousDigit !== 1) || (previousDigit === 0 && (firstDigit === 0 || firstDigit === 1)))) { - future = future + "m" + if ( + i === 2 && + n !== 0 && + ((previousDigit !== 0 && previousDigit !== 1) || + (previousDigit === 0 && (firstDigit === 0 || firstDigit === 1))) + ) { + future = future + 'm' } output = future + output @@ -293,7 +276,7 @@ export function numberToNavi(input: number): string { } } - output = output.replace(/mm/g, "m") + output = output.replace(/mm/g, 'm') return output -} \ No newline at end of file +} diff --git a/src/random.ts b/src/random.ts index 5df282b..f1ef6c2 100644 --- a/src/random.ts +++ b/src/random.ts @@ -79,4 +79,4 @@ export function random(amount: number, args: string[]): Word[] { } return results -} \ No newline at end of file +} diff --git a/src/txt.ts b/src/txt.ts index 3b05f2d..a32ea7c 100644 --- a/src/txt.ts +++ b/src/txt.ts @@ -19,24 +19,24 @@ export interface TextMap { let texts: TextMap = { // strings - "w_pos": "pos", - "w_word": "word", - "w_words": "words", - "w_syllables": "syllables", - "w_stress": "stress", + w_pos: 'pos', + w_word: 'word', + w_words: 'words', + w_syllables: 'syllables', + w_stress: 'stress', // strings - "c_is": "is", - "c_has": "has", - "c_like": "like", - "c_starts": "starts", - "c_ends": "ends", - "c_not-is": "not-is", - "c_not-has": "not-has", - "c_not-like": "not-like", - "c_not-starts": "not-starts", - "c_not-ends": "not-ends", - "c_first": "first", - "c_last": "last" + c_is: 'is', + c_has: 'has', + c_like: 'like', + c_starts: 'starts', + c_ends: 'ends', + 'c_not-is': 'not-is', + 'c_not-has': 'not-has', + 'c_not-like': 'not-like', + 'c_not-starts': 'not-starts', + 'c_not-ends': 'not-ends', + c_first: 'first', + c_last: 'last' } // Text function is the accessor for texts string[] diff --git a/src/util.ts b/src/util.ts index 7af2557..2121d13 100644 --- a/src/util.ts +++ b/src/util.ts @@ -46,7 +46,7 @@ export function containsArr(arr1: string[], arr2: string[]): boolean { * @returns {string[]} new array containing original items minus all str */ export function deleteElement(arr: string[], str: string): string[] { - return arr.filter(s => s !== str) + return arr.filter((s) => s !== str) } /** @@ -57,7 +57,7 @@ export function deleteElement(arr: string[], str: string): string[] { */ export function deleteEmpty(arr: string[] | null): string[] { if (arr == null) return [] - return arr.filter(s => s !== '' && s != null) + return arr.filter((s) => s !== '' && s != null) } /** @@ -68,7 +68,7 @@ export function deleteEmpty(arr: string[] | null): string[] { */ export function isLetter(str: string): boolean { if (str == null) return false - return ['\'', '‘'].includes(str) || str.toLowerCase() !== str.toUpperCase() + return ["'", '‘'].includes(str) || str.toLowerCase() !== str.toUpperCase() } /** @@ -114,7 +114,10 @@ export function stripChars(str: string, chr: string): string { * @param {string} b - second string * @return {string} the sequence of characters that both strings have in common, from left to right */ -export function intersection(a: string | undefined, b: string | undefined): string | undefined { +export function intersection( + a: string | undefined, + b: string | undefined +): string | undefined { if (a == null || b == null) return undefined // initialize the map with all the characters in a diff --git a/src/word.ts b/src/word.ts index 3c9fe04..c56073e 100644 --- a/src/word.ts +++ b/src/word.ts @@ -66,9 +66,7 @@ export class Word { target: string = '' data: WordData - constructor( - data?: WordData - ) { + constructor(data?: WordData) { this.data = data || { ID: '', Navi: '', @@ -102,7 +100,7 @@ export class Word { const clone = new Word(JSON.parse(JSON.stringify(this.data))) clone.attempt = this.attempt clone.target = this.target - return clone; + return clone } /** @@ -114,7 +112,19 @@ export class Word { // function to compress digraphs const compress = (word: string): string => { // compression map - const cMap: { [key: string]: string } = { aw: '0', ay: '1', ew: '2', ey: '3', kx: '4', ll: '5', ng: '6', px: '7', rr: '8', ts: '9', tx: 'Q' } + const cMap: { [key: string]: string } = { + aw: '0', + ay: '1', + ew: '2', + ey: '3', + kx: '4', + ll: '5', + ng: '6', + px: '7', + rr: '8', + ts: '9', + tx: 'Q' + } for (const c in cMap) { word = word.replace(c, cMap[c]) } @@ -122,11 +132,26 @@ export class Word { } let numSyllables = 0 - const vowels = ["a", "ä", "e", "é", "i", "ì", "o", "u", "aw", "ay", "ew", "ey", "ll", "rr"].map(v => compress(v)) + const vowels = [ + 'a', + 'ä', + 'e', + 'é', + 'i', + 'ì', + 'o', + 'u', + 'aw', + 'ay', + 'ew', + 'ey', + 'll', + 'rr' + ].map((v) => compress(v)) const word = compress(this.data.Navi.toLowerCase()) for (let p of vowels) { - numSyllables += word.split('').filter(x => x === p).length + numSyllables += word.split('').filter((x) => x === p).length } return numSyllables @@ -134,7 +159,7 @@ export class Word { /** * Calculate similarity score between user's word and current Na'vi word - * + * * @param {string} other - other Na'vi word to compare to this Na'vi word * @return {number} the similarity score, in range [0, 1.0] (representing from 0% up to 100% similarity) */ @@ -167,7 +192,12 @@ export class Word { const thisWordVowelsOther = intersection(thisWordVowels, other) // empty intersection yields 0 similarity score - if (thisWordVowels == null || otherWordVowels == null || wordIntersection == null || thisWordVowelsOther == null) { + if ( + thisWordVowels == null || + otherWordVowels == null || + wordIntersection == null || + thisWordVowelsOther == null + ) { return 0.0 } @@ -242,7 +272,7 @@ export class Word { /** * Lenite the word, based on the attempt. The target is not relevant here, so not given. * Returns the lenite attempt. - * + * * @return {Word} The lenited version of this word */ lenite(): Word { diff --git a/test/affixes.test.js b/test/affixes.test.js index c4df633..688d401 100644 --- a/test/affixes.test.js +++ b/test/affixes.test.js @@ -12,22 +12,36 @@ // You should have received a copy of the GNU General Public License // along with fwew.js. If not, see http://gnu.org/licenses/ /* spell-checker: disable */ -const expect = require('chai').expect; -const { getLenitionTable, prefix, suffix, infix, lenite, reconstruct, Word } = require('../lib') +const expect = require('chai').expect +const { + getLenitionTable, + prefix, + suffix, + infix, + lenite, + reconstruct, + Word +} = require('../lib') describe('affixes module', () => { describe('#getLenitionTable()', () => { it('should return the lenition table', () => { const lenitionTable = getLenitionTable() expect(lenitionTable).to.exist - expect(JSON.stringify(lenitionTable)).to.equal(`{"kx":"k","px":"p","tx":"t","k":"h","p":"f","ts":"s","t":"s","'":""}`) + expect(JSON.stringify(lenitionTable)).to.equal( + `{"kx":"k","px":"p","tx":"t","k":"h","p":"f","ts":"s","t":"s","'":""}` + ) }) }) describe('#prefix()', () => { it('should handle prefixes', () => { // fwew tsayfnesänumvi - const wordData = { Navi: 'sänumvi', PartOfSpeech: 'n.', Affixes: { Prefix: [], Lenition: [] } } + const wordData = { + Navi: 'sänumvi', + PartOfSpeech: 'n.', + Affixes: { Prefix: [], Lenition: [] } + } const w = new Word(wordData) w.target = 'tsayfnesänumvi' w.attempt = w.data.Navi @@ -40,10 +54,10 @@ describe('affixes module', () => { it('should handle gerund', () => { // fwew tìnusume - const wordData = { + const wordData = { Navi: 'nume', PartOfSpeech: 'vin.', - InfixLocations: 'n<0><1>um<2>e', + InfixLocations: 'n<0><1>um<2>e', Affixes: { Prefix: [], Infix: ['us'], Lenition: [] } } const w = new Word(wordData) @@ -57,10 +71,10 @@ describe('affixes module', () => { it('should handle passive participle', () => { // fwew ahawnawnu - const wordData = { + const wordData = { Navi: 'hawnu', PartOfSpeech: 'vtr.', - InfixLocations: 'h<0><1>awn<2>u', + InfixLocations: 'h<0><1>awn<2>u', Affixes: { Prefix: [], Infix: ['awn'], Lenition: [] } } const w = new Word(wordData) @@ -74,7 +88,11 @@ describe('affixes module', () => { it('should handle tsuk-verb', () => { // fwew tsukstawm - const wordData = { Navi: 'stawm', PartOfSpeech: 'vtr.', Affixes: { Prefix: [], Infix: [], Lenition: [] } } + const wordData = { + Navi: 'stawm', + PartOfSpeech: 'vtr.', + Affixes: { Prefix: [], Infix: [], Lenition: [] } + } const w = new Word(wordData) w.target = 'tsukstawm' w.attempt = w.data.Navi @@ -86,7 +104,11 @@ describe('affixes module', () => { it('should handle ketsuk-verb', () => { // fwew ketsukkanom - const wordData = { Navi: 'kanom', PartOfSpeech: 'vtr.', Affixes: { Prefix: [], Infix: [], Lenition: [] } } + const wordData = { + Navi: 'kanom', + PartOfSpeech: 'vtr.', + Affixes: { Prefix: [], Infix: [], Lenition: [] } + } const w = new Word(wordData) w.target = 'ketsukkanom' w.attempt = w.data.Navi @@ -98,7 +120,11 @@ describe('affixes module', () => { it('should handle -siyu', () => { // fwew fnepamrelsiyu - const wordData = { Navi: 'pamrelsiyu', PartOfSpeech: 'vin.', Affixes: { Prefix: [], Infix: [], Lenition: [] } } + const wordData = { + Navi: 'pamrelsiyu', + PartOfSpeech: 'vin.', + Affixes: { Prefix: [], Infix: [], Lenition: [] } + } const w = new Word(wordData) w.target = 'fnepamrelsiyu' w.attempt = w.data.Navi @@ -110,9 +136,13 @@ describe('affixes module', () => { it("should handle me with 'e", () => { // fwew men - const wordData = { Navi: "'en", PartOfSpeech: 'n.', Affixes: { Prefix: [], Lenition: [] } } + const wordData = { + Navi: "'en", + PartOfSpeech: 'n.', + Affixes: { Prefix: [], Lenition: [] } + } const w = new Word(wordData) - w.target = "men" + w.target = 'men' w.attempt = w.data.Navi const p = prefix(w) expect(p.attempt).to.equal(p.target) @@ -122,7 +152,11 @@ describe('affixes module', () => { it("should handle pxe with 'e", () => { // fwew pxen - const wordData = { Navi: "'en", PartOfSpeech: 'n.', Affixes: { Prefix: [], Lenition: [] } } + const wordData = { + Navi: "'en", + PartOfSpeech: 'n.', + Affixes: { Prefix: [], Lenition: [] } + } const w = new Word(wordData) w.target = 'pxen' w.attempt = w.data.Navi @@ -134,7 +168,11 @@ describe('affixes module', () => { it("should handle pe with 'e", () => { // fwew pen - const wordData = { Navi: "'en", PartOfSpeech: 'n.', Affixes: { Prefix: [], Infix: [], Lenition: [] } } + const wordData = { + Navi: "'en", + PartOfSpeech: 'n.', + Affixes: { Prefix: [], Infix: [], Lenition: [] } + } const w = new Word(wordData) w.target = 'pen' w.attempt = w.data.Navi @@ -144,9 +182,13 @@ describe('affixes module', () => { expect(p.data.Affixes.Prefix[0]).to.equal('pe') }) - it("should handle pe with e", () => { + it('should handle pe with e', () => { // fwew pekxan - const wordData = { Navi: "ekxan", PartOfSpeech: 'n.', Affixes: { Prefix: [], Infix: [], Lenition: [] } } + const wordData = { + Navi: 'ekxan', + PartOfSpeech: 'n.', + Affixes: { Prefix: [], Infix: [], Lenition: [] } + } const w = new Word(wordData) w.target = 'pekxan' w.attempt = w.data.Navi @@ -158,7 +200,11 @@ describe('affixes module', () => { it('should handle soaiä', () => { // fwew aysoaiä - const wordData = { Navi: "soaia", PartOfSpeech: 'n.', Affixes: { Prefix: [], Suffix: ['ä'], Lenition: [] } } + const wordData = { + Navi: 'soaia', + PartOfSpeech: 'n.', + Affixes: { Prefix: [], Suffix: ['ä'], Lenition: [] } + } const w = new Word(wordData) w.target = 'aysoaiä' w.attempt = 'soaiä' @@ -170,7 +216,11 @@ describe('affixes module', () => { it('should reject non-lenition-causing fne prefix with lenition', () => { // fwew fnetele - const wordData = { Navi: "txele", PartOfSpeech: 'n.', Affixes: { Prefix: [], Suffix: [], Lenition: ['tx→t'] } } + const wordData = { + Navi: 'txele', + PartOfSpeech: 'n.', + Affixes: { Prefix: [], Suffix: [], Lenition: ['tx→t'] } + } const w = new Word(wordData) w.target = 'fnetele' w.attempt = 'tele' @@ -181,7 +231,11 @@ describe('affixes module', () => { it('should reject non-lenition-causing tsa prefix with lenition', () => { // fwew tsatele - const wordData = { Navi: "txele", PartOfSpeech: 'n.', Affixes: { Prefix: [], Suffix: [], Lenition: ['tx→t'] } } + const wordData = { + Navi: 'txele', + PartOfSpeech: 'n.', + Affixes: { Prefix: [], Suffix: [], Lenition: ['tx→t'] } + } const w = new Word(wordData) w.target = 'tsatele' w.attempt = 'tele' @@ -193,7 +247,11 @@ describe('affixes module', () => { describe('#suffix()', () => { it('should handle suffixes', () => { - const wordData = { Navi: "'awkx", PartOfSpeech: 'n.', Affixes: { Suffix: [] } } + const wordData = { + Navi: "'awkx", + PartOfSpeech: 'n.', + Affixes: { Suffix: [] } + } const w = new Word(wordData) w.target = "'awkxit" w.attempt = w.data.Navi @@ -204,9 +262,9 @@ describe('affixes module', () => { }) it('should handle tseyä', () => { - const wordData = { Navi: "tsaw", Affixes: { Suffix: [] } } + const wordData = { Navi: 'tsaw', Affixes: { Suffix: [] } } const w = new Word(wordData) - w.target = "tseyä" + w.target = 'tseyä' w.attempt = w.data.Navi const s = suffix(w) expect(s.attempt).to.equal(s.target) @@ -215,9 +273,9 @@ describe('affixes module', () => { }) it('should handle oey', () => { - const wordData = { Navi: "oe", Affixes: { Suffix: [] } } + const wordData = { Navi: 'oe', Affixes: { Suffix: [] } } const w = new Word(wordData) - w.target = "oey" + w.target = 'oey' w.attempt = w.data.Navi const s = suffix(w) expect(s.attempt).to.equal(s.target) @@ -226,9 +284,9 @@ describe('affixes module', () => { }) it('should handle ngey', () => { - const wordData = { Navi: "nga", Affixes: { Suffix: [] } } + const wordData = { Navi: 'nga', Affixes: { Suffix: [] } } const w = new Word(wordData) - w.target = "ngey" + w.target = 'ngey' w.attempt = w.data.Navi const s = suffix(w) expect(s.attempt).to.equal(s.target) @@ -237,55 +295,75 @@ describe('affixes module', () => { }) it('should handle gerund', () => { - const wordData = { Navi: "kar", PartOfSpeech: 'vtr.', Affixes: { Prefix: ['tì'], Infix: ['us'], Suffix: [] } } + const wordData = { + Navi: 'kar', + PartOfSpeech: 'vtr.', + Affixes: { Prefix: ['tì'], Infix: ['us'], Suffix: [] } + } const w = new Word(wordData) - w.target = "tìkusarti" - w.attempt = "tìkusar" + w.target = 'tìkusarti' + w.attempt = 'tìkusar' const s = suffix(w) - + expect(s.attempt).to.equal(s.target) expect(s.data.Affixes.Suffix.length).to.equal(1) expect(s.data.Affixes.Suffix[0]).to.equal('ti') }) it('should handle participle', () => { - const wordData = { Navi: "kame", PartOfSpeech: 'vtr.', Affixes: { Prefix: [], Infix: ['awn'], Suffix: [] } } + const wordData = { + Navi: 'kame', + PartOfSpeech: 'vtr.', + Affixes: { Prefix: [], Infix: ['awn'], Suffix: [] } + } const w = new Word(wordData) - w.target = "kawnamea" - w.attempt = "kawname" + w.target = 'kawnamea' + w.attempt = 'kawname' const s = suffix(w) - + expect(s.attempt).to.equal(s.target) expect(s.data.Affixes.Suffix.length).to.equal(1) expect(s.data.Affixes.Suffix[0]).to.equal('a') }) it('should handle ketsuk-', () => { - const wordData = { Navi: "tslam", PartOfSpeech: 'vtr.', Affixes: { Prefix: ['ketsuk'], Infix: [], Suffix: [] } } + const wordData = { + Navi: 'tslam', + PartOfSpeech: 'vtr.', + Affixes: { Prefix: ['ketsuk'], Infix: [], Suffix: [] } + } const w = new Word(wordData) - w.target = "ketsuktslama" - w.attempt = "ketsuktslam" + w.target = 'ketsuktslama' + w.attempt = 'ketsuktslam' const s = suffix(w) - + expect(s.attempt).to.equal(s.target) expect(s.data.Affixes.Suffix.length).to.equal(1) expect(s.data.Affixes.Suffix[0]).to.equal('a') }) it('should handle tsuk-', () => { - const wordData = { Navi: "tslam", PartOfSpeech: 'vtr.', Affixes: { Prefix: ['tsuk'], Infix: [], Suffix: [] } } + const wordData = { + Navi: 'tslam', + PartOfSpeech: 'vtr.', + Affixes: { Prefix: ['tsuk'], Infix: [], Suffix: [] } + } const w = new Word(wordData) - w.target = "tsuktslama" - w.attempt = "tsuktslam" + w.target = 'tsuktslama' + w.attempt = 'tsuktslam' const s = suffix(w) - + expect(s.attempt).to.equal(s.target) expect(s.data.Affixes.Suffix.length).to.equal(1) expect(s.data.Affixes.Suffix[0]).to.equal('a') }) it('should handle suffixing after -tswo on verbs', () => { - const wordData = { Navi: "tse'a", PartOfSpeech: 'vtr.', Affixes: { Prefix: [], Infix: [], Suffix: [] } } + const wordData = { + Navi: "tse'a", + PartOfSpeech: 'vtr.', + Affixes: { Prefix: [], Infix: [], Suffix: [] } + } const w = new Word(wordData) w.target = "tse'atswot" w.attempt = w.data.Navi @@ -297,9 +375,13 @@ describe('affixes module', () => { }) it('should handle soaiä', () => { - const wordData = { Navi: "soaia", PartOfSpeech: 'n.', Affixes: { Prefix: [], Infix: [], Suffix: [] } } + const wordData = { + Navi: 'soaia', + PartOfSpeech: 'n.', + Affixes: { Prefix: [], Infix: [], Suffix: [] } + } const w = new Word(wordData) - w.target = "soaiä" + w.target = 'soaiä' w.attempt = w.data.Navi const s = suffix(w) expect(s.attempt).to.equal(s.target) @@ -308,9 +390,13 @@ describe('affixes module', () => { }) it('should handle w dropping on tsaw when suffixed', () => { - const wordData = { Navi: "tsaw", PartOfSpeech: 'pn.', Affixes: { Prefix: [], Infix: [], Suffix: [] } } + const wordData = { + Navi: 'tsaw', + PartOfSpeech: 'pn.', + Affixes: { Prefix: [], Infix: [], Suffix: [] } + } const w = new Word(wordData) - w.target = "tsamì" + w.target = 'tsamì' w.attempt = w.data.Navi const s = suffix(w) expect(s.attempt).to.equal(s.target) @@ -319,9 +405,13 @@ describe('affixes module', () => { }) it('should handle -siyu', () => { - const wordData = { Navi: "uvan si", PartOfSpeech: 'vin.', Affixes: { Prefix: [], Infix: [], Suffix: [] } } + const wordData = { + Navi: 'uvan si', + PartOfSpeech: 'vin.', + Affixes: { Prefix: [], Infix: [], Suffix: [] } + } const w = new Word(wordData) - w.target = "uvansiyu" + w.target = 'uvansiyu' w.attempt = w.data.Navi const s = suffix(w) expect(s.attempt).to.equal(s.target) @@ -330,7 +420,11 @@ describe('affixes module', () => { }) it('should handle ngeyä', () => { - const wordData = { Navi: 'nga', PartOfSpeech: 'pn.', Affixes: { Prefix: [], Infix: [], Suffix: [] } } + const wordData = { + Navi: 'nga', + PartOfSpeech: 'pn.', + Affixes: { Prefix: [], Infix: [], Suffix: [] } + } const w = new Word(wordData) w.target = 'ngeyä' w.attempt = w.data.Navi @@ -341,7 +435,11 @@ describe('affixes module', () => { }) it('should handle peyä', () => { - const wordData = { Navi: 'po', PartOfSpeech: 'pn.', Affixes: { Prefix: [], Infix: [], Suffix: [] } } + const wordData = { + Navi: 'po', + PartOfSpeech: 'pn.', + Affixes: { Prefix: [], Infix: [], Suffix: [] } + } const w = new Word(wordData) w.target = 'peyä' w.attempt = w.data.Navi @@ -354,13 +452,20 @@ describe('affixes module', () => { describe('#infix()', () => { it('should handle infixes', () => { - const wordData = { Navi: "'ampi", PartOfSpeech: 'vtr.', InfixLocations: "'<0><1>amp<2>i", Affixes: { Infix: [] } } + const wordData = { + Navi: "'ampi", + PartOfSpeech: 'vtr.', + InfixLocations: "'<0><1>amp<2>i", + Affixes: { Infix: [] } + } const w = new Word(wordData) w.target = "'äpeykiyevampatsi" w.mpt = w.data.Navi w.attempt = w.data.Navi const i = infix(w) - const { Affixes: { Infix } } = i.data + const { + Affixes: { Infix } + } = i.data expect(i.attempt).to.equal(i.target) expect(Infix.length).to.equal(4) expect(Infix[0]).to.equal('äp') @@ -379,7 +484,7 @@ describe('affixes module', () => { }) it('should not try to operate on non-verbs', () => { - const wordData = { InfixLocations: "NULL", Affixes: { Infix: [] } } + const wordData = { InfixLocations: 'NULL', Affixes: { Infix: [] } } const w = new Word(wordData) w.target = 'target' w.attempt = w.data.Navi @@ -388,7 +493,11 @@ describe('affixes module', () => { }) it('should handle zenke with ats', () => { - const wordData = { Navi: 'zenke', InfixLocations: "z<0><1>en<2>ke", Affixes: { Infix: [] } } + const wordData = { + Navi: 'zenke', + InfixLocations: 'z<0><1>en<2>ke', + Affixes: { Infix: [] } + } const w = new Word(wordData) w.target = 'zenatseke' w.attempt = w.data.Navi @@ -397,7 +506,11 @@ describe('affixes module', () => { }) it('should handle zenke with uy', () => { - const wordData = { Navi: 'zenke', InfixLocations: "z<0><1>en<2>ke", Affixes: { Infix: [] } } + const wordData = { + Navi: 'zenke', + InfixLocations: 'z<0><1>en<2>ke', + Affixes: { Infix: [] } + } const w = new Word(wordData) w.target = 'zenuyeke' w.attempt = w.data.Navi @@ -406,7 +519,11 @@ describe('affixes module', () => { }) it('should handle seiyi', () => { - const wordData = { Navi: 'irayo si', InfixLocations: "irayo s<0><1><2>i", Affixes: { Infix: [] } } + const wordData = { + Navi: 'irayo si', + InfixLocations: 'irayo s<0><1><2>i', + Affixes: { Infix: [] } + } const w = new Word(wordData) w.target = 'irayo seiyi' w.attempt = w.data.Navi @@ -415,7 +532,11 @@ describe('affixes module', () => { }) it('should handle poltxe', () => { - const wordData = { Navi: 'plltxe', InfixLocations: "p<0><1>lltx<2>e", Affixes: { Infix: [] } } + const wordData = { + Navi: 'plltxe', + InfixLocations: 'p<0><1>lltx<2>e', + Affixes: { Infix: [] } + } const w = new Word(wordData) w.target = 'poltxe' w.attempt = w.data.Navi @@ -424,7 +545,11 @@ describe('affixes module', () => { }) it('should handle frrfen', () => { - const wordData = { Navi: 'frrfen', InfixLocations: "f<0><1>rrf<2>en", Affixes: { Infix: [] } } + const wordData = { + Navi: 'frrfen', + InfixLocations: 'f<0><1>rrf<2>en', + Affixes: { Infix: [] } + } const w = new Word(wordData) w.target = 'frrfeien' w.attempt = w.data.Navi @@ -435,7 +560,11 @@ describe('affixes module', () => { describe('#lenite()', () => { it('should handle lenition', () => { - const wordData = { Navi: 'teylu', PartOfSpeech: 'n.', Affixes: { Lenition: [] } } + const wordData = { + Navi: 'teylu', + PartOfSpeech: 'n.', + Affixes: { Lenition: [] } + } const w = new Word(wordData) w.target = 'seylu' w.attempt = w.data.Navi @@ -448,7 +577,12 @@ describe('affixes module', () => { describe('#reconstruct()', () => { it('should handle infix for verb', () => { - const wordData = { Navi: 'kä', PartOfSpeech: 'vin.', InfixLocations: 'k<0><1><2>ä', Affixes: { Infix: [] } } + const wordData = { + Navi: 'kä', + PartOfSpeech: 'vin.', + InfixLocations: 'k<0><1><2>ä', + Affixes: { Infix: [] } + } const w = new Word(wordData) const target = 'kivä' const result = reconstruct(w, target) @@ -456,7 +590,11 @@ describe('affixes module', () => { }) it('should handle prefix', () => { - const wordData = { Navi: 'utral', PartOfSpeech: 'n.', Affixes: { Lenition: [], Prefix: [] } } + const wordData = { + Navi: 'utral', + PartOfSpeech: 'n.', + Affixes: { Lenition: [], Prefix: [] } + } const w = new Word(wordData) const target = 'ayutral' const result = reconstruct(w, target) @@ -464,7 +602,11 @@ describe('affixes module', () => { }) it('should handle suffix', () => { - const wordData = { Navi: 'ikran', PartOfSpeech: 'n.', Affixes: { Lenition: [], Suffix: [] } } + const wordData = { + Navi: 'ikran', + PartOfSpeech: 'n.', + Affixes: { Lenition: [], Suffix: [] } + } const w = new Word(wordData) const target = 'ikranit' const result = reconstruct(w, target) @@ -472,7 +614,11 @@ describe('affixes module', () => { }) it('should handle lenition', () => { - const wordData = { Navi: 'teylu', PartOfSpeech: 'n.', Affixes: { Lenition: [] } } + const wordData = { + Navi: 'teylu', + PartOfSpeech: 'n.', + Affixes: { Lenition: [] } + } const w = new Word(wordData) const target = 'seylu' const result = reconstruct(w, target) @@ -480,25 +626,37 @@ describe('affixes module', () => { }) it('should handle prefix suffix lenite', () => { - const wordData = { Navi: "payoang", PartOfSpeech: 'n.', Affixes: { Lenition: [], Prefix: [], Infix: [], Suffix: [] } } + const wordData = { + Navi: 'payoang', + PartOfSpeech: 'n.', + Affixes: { Lenition: [], Prefix: [], Infix: [], Suffix: [] } + } const w = new Word(wordData) - const target = "fayfayoang" + const target = 'fayfayoang' const result = reconstruct(w, target) expect(result).not.to.be.undefined }) it('should handle prefix suffix', () => { - const wordData = { Navi: "'u", PartOfSpeech: 'n.', Affixes: { Lenition: [], Prefix: [], Infix: [], Suffix: [] } } + const wordData = { + Navi: "'u", + PartOfSpeech: 'n.', + Affixes: { Lenition: [], Prefix: [], Infix: [], Suffix: [] } + } const w = new Word(wordData) - const target = "tsayuti" + const target = 'tsayuti' const result = reconstruct(w, target) expect(result).not.to.be.undefined }) it('should handle lenition prefix', () => { - const wordData = { Navi: "kelku", PartOfSpeech: 'n.', Affixes: { Lenition: [], Prefix: [], Infix: [], Suffix: [] } } + const wordData = { + Navi: 'kelku', + PartOfSpeech: 'n.', + Affixes: { Lenition: [], Prefix: [], Infix: [], Suffix: [] } + } const w = new Word(wordData) - const target = "pepefnekelkut" + const target = 'pepefnekelkut' const result = reconstruct(w, target) expect(result).not.to.be.true }) diff --git a/test/fwew.test.js b/test/fwew.test.js index 71503da..99e3fac 100644 --- a/test/fwew.test.js +++ b/test/fwew.test.js @@ -11,7 +11,7 @@ // // You should have received a copy of the GNU General Public License // along with fwew.js. If not, see http://gnu.org/licenses/ -const expect = require('chai').expect; +const expect = require('chai').expect const { fwew: { translateFromNavi, translateToNavi } } = require('../lib') @@ -68,7 +68,11 @@ describe('fwew module', () => { for (const result of results) { expect(result).to.exist expect(result.data).to.exist - expect(result.data[param.languageCode.toUpperCase()].includes(param.localized)).to.be.true + expect( + result.data[param.languageCode.toUpperCase()].includes( + param.localized + ) + ).to.be.true } }) } @@ -82,10 +86,10 @@ describe('fwew module', () => { { languageCode: 'nl', localized: 'één', numResults: 3 }, { languageCode: 'pl', localized: 'jeden', numResults: 2 }, { languageCode: 'ru', localized: 'один', numResults: 2 }, - { languageCode: 'sv', localized: 'hammarhuvud', numResults: 1}, - { languageCode: 'tr', localized: 'ingilizce', numResults: 1 }, + { languageCode: 'sv', localized: 'hammarhuvud', numResults: 1 }, + { languageCode: 'tr', localized: 'ingilizce', numResults: 1 } ] params.forEach(parameterizedText) }) -}) \ No newline at end of file +}) diff --git a/test/list.test.js b/test/list.test.js index 1e4f1e8..dae0502 100644 --- a/test/list.test.js +++ b/test/list.test.js @@ -12,7 +12,7 @@ // You should have received a copy of the GNU General Public License // along with fwew.js. If not, see http://gnu.org/licenses/ /* spell-checker: disable */ -const expect = require('chai').expect; +const expect = require('chai').expect const { list, getWords } = require('../lib') const dictionary = getWords() @@ -22,143 +22,168 @@ describe('list module', () => { it('should list all words whose part of speech starts with given string', () => { const results = list(['pos', 'starts', 'v']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.PartOfSpeech.startsWith('v')).to.be.true) + results.forEach( + (w) => expect(w.data.PartOfSpeech.startsWith('v')).to.be.true + ) }) // list pos ends m. it('should list all words whose part of speech ends with given string', () => { const results = list(['pos', 'ends', 'm.']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.PartOfSpeech.endsWith('m.')).to.be.true) + results.forEach( + (w) => expect(w.data.PartOfSpeech.endsWith('m.')).to.be.true + ) }) // list pos has vin. it('should list all word whose part of speech contains given string', () => { const results = list(['pos', 'has', 'vin.']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.PartOfSpeech.includes('vin.')).to.be.true) + results.forEach( + (w) => expect(w.data.PartOfSpeech.includes('vin.')).to.be.true + ) }) // list pos is v. it('should list all word whose part of speech is exactly the given string', () => { const results = list(['pos', 'is', 'intj.']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.PartOfSpeech === 'intj.').to.be.true) + results.forEach((w) => expect(w.data.PartOfSpeech === 'intj.').to.be.true) }) // list pos like v%. it('should list all word whose part of speech is like the given string', () => { const results = list(['pos', 'like', 'v%.']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.PartOfSpeech.match(/v.*\./g).length > 0).to.be.true) + results.forEach( + (w) => expect(w.data.PartOfSpeech.match(/v.*\./g).length > 0).to.be.true + ) }) // list pos not-starts v it('should list all words whose part of speech does not start with given string', () => { const results = list(['pos', 'not-starts', 'v']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.PartOfSpeech.startsWith('v')).to.be.false) + results.forEach( + (w) => expect(w.data.PartOfSpeech.startsWith('v')).to.be.false + ) }) // list pos not-ends m. it('should list all words whose part of speech does not end with given string', () => { const results = list(['pos', 'not-ends', 'm.']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.PartOfSpeech.endsWith('m.')).to.be.false) + results.forEach( + (w) => expect(w.data.PartOfSpeech.endsWith('m.')).to.be.false + ) }) // list pos not-has vin. it('should list all words whose part of speech does not contain given string', () => { const results = list(['pos', 'not-has', 'vin.']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.PartOfSpeech.includes('vin.')).to.be.false) + results.forEach( + (w) => expect(w.data.PartOfSpeech.includes('vin.')).to.be.false + ) }) // list pos not-is v. it('should list all words whose part of speech is exactly not the given string', () => { const results = list(['pos', 'not-is', 'v.']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.PartOfSpeech === 'v.').to.be.false) + results.forEach((w) => expect(w.data.PartOfSpeech === 'v.').to.be.false) }) // list pos not-like v%. it('should list all words whose part of speech is not like the given string', () => { const results = list(['pos', 'not-like', 'v%.']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => { - expect(w.data.Navi.startsWith('v') && w.data.Navi.endsWith('.')).to.be.false + results.forEach((w) => { + expect(w.data.Navi.startsWith('v') && w.data.Navi.endsWith('.')).to.be + .false }) }) // list word starts ft it('should list all words that start with given string', () => { const results = list(['word', 'starts', 'ft']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.Navi.startsWith('ft')).to.be.true) + results.forEach((w) => expect(w.data.Navi.startsWith('ft')).to.be.true) }) // list word ends ang it('should list all words that end with given string', () => { const results = list(['word', 'ends', 'ang']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.Navi.endsWith('ang')).to.be.true) + results.forEach((w) => expect(w.data.Navi.endsWith('ang')).to.be.true) }) // list word has ts it('should list all words that include given string', () => { const results = list(['word', 'has', 'ts']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.Navi.toLowerCase().includes('ts')).to.be.true) + results.forEach( + (w) => expect(w.data.Navi.toLowerCase().includes('ts')).to.be.true + ) }) // list word like f%w it('should list all words that are like given string', () => { const results = list(['word', 'like', 'f%w']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.Navi.match(/f.*w/g).length > 0).to.be.true) + results.forEach( + (w) => expect(w.data.Navi.match(/f.*w/g).length > 0).to.be.true + ) }) // list word not-starts ft it('should list all words that do not start with given string', () => { const results = list(['word', 'not-starts', 'ft']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.Navi.startsWith('ft')).to.be.false) + results.forEach((w) => expect(w.data.Navi.startsWith('ft')).to.be.false) }) // list word not-ends ang it('should list all words that do not end with given string', () => { const results = list(['word', 'not-ends', 'ang']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.Navi.endsWith('ang')).to.be.false) + results.forEach((w) => expect(w.data.Navi.endsWith('ang')).to.be.false) }) // list word not-has ts it('should list all words that do not include with given string', () => { const results = list(['word', 'not-has', 'ts']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.Navi.includes('ts')).to.be.false) + results.forEach((w) => expect(w.data.Navi.includes('ts')).to.be.false) }) // list word not-like f%w it('should list all words that are not like given string', () => { const results = list(['word', 'not-like', 'f%w']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => { - expect(w.data.Navi.startsWith('f') && w.data.Navi.endsWith('w')).to.be.false + results.forEach((w) => { + expect(w.data.Navi.startsWith('f') && w.data.Navi.endsWith('w')).to.be + .false }) }) // list words first 20 it('should list first 20 words released', () => { const results = list(['words', 'first', '20']) expect(results.length).to.equal(20) - results.forEach((w, i) => expect(w.data.ID === dictionary[i].data.ID).to.be.true) + results.forEach( + (w, i) => expect(w.data.ID === dictionary[i].data.ID).to.be.true + ) }) // list words last 30 it('should list last 30 words released', () => { const results = list(['words', 'last', '30']) expect(results.length).to.equal(30) - results.forEach((w, i) => expect(w.data.ID === dictionary.slice(-30)[i].data.ID).to.be.true) + results.forEach( + (w, i) => + expect(w.data.ID === dictionary.slice(-30)[i].data.ID).to.be.true + ) }) // list syllables > 1 it('should list all words with more than 1 syllable', () => { const results = list(['syllables', '>', '1']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.syllableCount() > 1).to.be.true) + results.forEach((w) => expect(w.syllableCount() > 1).to.be.true) }) // list syllables = 2 it('should list all words with 2 syllables', () => { const results = list(['syllables', '=', '2']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.syllableCount() === 2).to.be.true) + results.forEach((w) => expect(w.syllableCount() === 2).to.be.true) }) // list syllables <= 3 it('should list all words with at most 3 syllables', () => { const results = list(['syllables', '<=', '3']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.syllableCount() <= 3).to.be.true) + results.forEach((w) => expect(w.syllableCount() <= 3).to.be.true) }) // list syllables < 1 it('should return empty list for syllables < 1', () => { @@ -168,13 +193,13 @@ describe('list module', () => { it('should return empty list for syllables < 2', () => { const results = list(['syllables', '<', '2']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.syllableCount() < 2).to.be.true) + results.forEach((w) => expect(w.syllableCount() < 2).to.be.true) }) // list syllables >= 1 it('should return empty list for syllables >= 1', () => { const results = list(['syllables', '>=', '1']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.syllableCount() >= 1).to.be.true) + results.forEach((w) => expect(w.syllableCount() >= 1).to.be.true) }) // list syllables >= 10 it('should return empty list for syllables >= 10', () => { @@ -184,7 +209,7 @@ describe('list module', () => { it('should return empty list for syllables != 1', () => { const results = list(['syllables', '!=', '1']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.syllableCount() !== 1).to.be.true) + results.forEach((w) => expect(w.syllableCount() !== 1).to.be.true) }) // list syllables = NaN it('should return all words when spec is NaN on syllables', () => { @@ -194,31 +219,33 @@ describe('list module', () => { it('should return empty list for stress < 2', () => { const results = list(['stress', '<', '2']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.Stressed < 2).to.be.true) + results.forEach((w) => expect(w.data.Stressed < 2).to.be.true) }) // list stress <= 2 it('should return empty list for stress <= 2', () => { const results = list(['stress', '<=', '2']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.Stressed <= 2).to.be.true) + results.forEach((w) => expect(w.data.Stressed <= 2).to.be.true) }) // list stress = 1 it('should list all words with stressed syllable position 1', () => { const results = list(['stress', '=', '1']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(+w.data.Stressed === 1).to.be.true) + results.forEach((w) => expect(+w.data.Stressed === 1).to.be.true) }) // list stress = -1 it('should list all words with stressed syllable position -1', () => { const results = list(['stress', '=', '-1']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(+w.data.Stressed === w.syllableCount()).to.be.true) + results.forEach( + (w) => expect(+w.data.Stressed === w.syllableCount()).to.be.true + ) }) // list stress >= 1 it('should list all words with stressed syllable position >= 1', () => { const results = list(['stress', '>=', '1']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(+w.data.Stressed >= 1).to.be.true) + results.forEach((w) => expect(+w.data.Stressed >= 1).to.be.true) }) // list stress >= 10 it('return empty list for stressed syllable position >= 10', () => { @@ -228,26 +255,36 @@ describe('list module', () => { it('should return empty list for stress > 2', () => { const results = list(['stress', '>', '2']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.Stressed > 2).to.be.true) + results.forEach((w) => expect(w.data.Stressed > 2).to.be.true) }) // list stress != 1 it('should return empty list for stress !== 1', () => { const results = list(['stress', '!=', '1']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.Stressed !== 1).to.be.true) + results.forEach((w) => expect(w.data.Stressed !== 1).to.be.true) }) // list stress != -1 it('should return empty list for stress !== -1', () => { const results = list(['stress', '!=', '-1']) expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w.data.Stressed !== w.syllableCount()).to.be.true) + results.forEach( + (w) => expect(w.data.Stressed !== w.syllableCount()).to.be.true + ) }) // list word starts fme and word ends tok it('should support multiple sets of args (AND)', () => { - const results = list(['word', 'starts', 'fme', 'and', 'word', 'ends', 'tok']) + const results = list([ + 'word', + 'starts', + 'fme', + 'and', + 'word', + 'ends', + 'tok' + ]) expect(results.length).to.equal(1) - results.forEach(w => expect(w.data.Navi).to.equal('fmetok')) + results.forEach((w) => expect(w.data.Navi).to.equal('fmetok')) }) // words errors it('should return all words when first / last spec input is NaN', () => { diff --git a/test/number.test.js b/test/number.test.js index 38a364e..9263cc3 100644 --- a/test/number.test.js +++ b/test/number.test.js @@ -12,15 +12,17 @@ // You should have received a copy of the GNU General Public License // along with fwew.js. If not, see http://gnu.org/licenses/ /* spell-checker: disable */ -const expect = require('chai').expect; -const { numbers: { naviToNumber, numberToNavi } } = require('../lib') +const expect = require('chai').expect +const { + numbers: { naviToNumber, numberToNavi } +} = require('../lib') describe('numbers module', () => { describe('#naviToNumber()', () => { it('should convert number string to number', () => { expect(naviToNumber('volaw')).to.equal(0o11) }) - + it('should convert kew to 0', () => { expect(naviToNumber('kew')).to.equal(0) }) diff --git a/test/random.test.js b/test/random.test.js index 64fcd37..2e59a95 100644 --- a/test/random.test.js +++ b/test/random.test.js @@ -12,7 +12,7 @@ // You should have received a copy of the GNU General Public License // along with fwew.js. If not, see http://gnu.org/licenses/ /* spell-checker: disable */ -const expect = require('chai').expect; +const expect = require('chai').expect const { random, getWords } = require('../lib') const dictionary = getWords() @@ -22,21 +22,21 @@ describe('random module', () => { const results = random(8, []) expect(results).to.exist expect(results.length).to.equal(8) - results.forEach(w => expect(w).to.exist) + results.forEach((w) => expect(w).to.exist) }) it('should get random number of random words', () => { const results = random(-1, []) expect(results).to.exist expect(results.length).to.be.greaterThan(0) - results.forEach(w => expect(w).to.exist) + results.forEach((w) => expect(w).to.exist) }) it('should get 10 random transitive verbs', () => { const results = random(10, ['pos', 'is', 'vtr.']) expect(results).to.exist expect(results.length).to.equal(10) - results.forEach(w => expect(w.data.PartOfSpeech).to.equal('vtr.')) + results.forEach((w) => expect(w.data.PartOfSpeech).to.equal('vtr.')) }) it('should return empty array when no words satify condition', () => { @@ -51,4 +51,4 @@ describe('random module', () => { expect(results.length).to.equal(dictionary.length) }) }) -}) \ No newline at end of file +}) diff --git a/test/util.test.js b/test/util.test.js index 5cda3b7..631d1a8 100644 --- a/test/util.test.js +++ b/test/util.test.js @@ -12,7 +12,7 @@ // You should have received a copy of the GNU General Public License // along with fwew.js. If not, see http://gnu.org/licenses/ -const expect = require('chai').expect; +const expect = require('chai').expect const { util: { containsArr, @@ -54,7 +54,7 @@ describe('util module', () => { it('should delete all given string in array', () => { const arr = ['b', 'a', 'b', 'c', 'b'] const result = deleteElement(arr, 'b') - result.forEach(r => expect(r === 'b').to.be.false) + result.forEach((r) => expect(r === 'b').to.be.false) }) }) @@ -69,7 +69,7 @@ describe('util module', () => { }) it('should remove all empty items from array', () => { const result = deleteEmpty(['a', 'b', '', undefined, null, '', 'd']) - result.forEach(r => { + result.forEach((r) => { expect(r).not.to.equal('') expect(r).not.to.equal(null) expect(r).not.to.equal(undefined) @@ -246,9 +246,9 @@ describe('util module', () => { it('should return undefined when 1st array is null and 2nd array is undefined', () => { expect(combineArrays(null, undefined)).to.be.undefined }) - + it('should return undefined when 1nd array is undefined and 2nd array is null', () => { expect(combineArrays(undefined, null)).to.be.undefined }) }) -}) \ No newline at end of file +})