2020-12-08 03:04:00 +01:00
|
|
|
|
|
|
|
const articlesApostrophes = {
|
2021-02-25 02:00:27 +01:00
|
|
|
'de': 'd\'',
|
|
|
|
'le': 'l\'',
|
|
|
|
'la': 'l\''
|
2020-12-08 03:04:00 +01:00
|
|
|
}
|
|
|
|
export class Grammar {
|
|
|
|
|
2021-02-25 02:00:27 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-08 03:04:00 +01:00
|
|
|
static apostrophe(article, word) {
|
|
|
|
if (articlesApostrophes[article] && Grammar.startsWithVoyel(word)) {
|
|
|
|
return articlesApostrophes[article] + word
|
|
|
|
}
|
|
|
|
return article + ' ' + word;
|
|
|
|
}
|
2021-01-26 19:47:18 +01:00
|
|
|
|
2021-02-25 02:00:27 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-08 03:04:00 +01:00
|
|
|
static startsWithVoyel(word) {
|
|
|
|
return word.match(/^[aeiouy]/i)
|
|
|
|
}
|
2021-01-26 19:47:18 +01:00
|
|
|
|
2022-11-04 20:41:16 +01:00
|
|
|
static equalsInsensitive(a, b) {
|
|
|
|
return Grammar.toLowerCaseNoAccent(a) == Grammar.toLowerCaseNoAccent(b)
|
|
|
|
}
|
2022-06-12 08:17:59 +02:00
|
|
|
|
|
|
|
static includesLowerCaseNoAccent(value, content) {
|
|
|
|
return Grammar.toLowerCaseNoAccent(value).includes(Grammar.toLowerCaseNoAccent(content));
|
|
|
|
}
|
2022-11-04 20:41:16 +01:00
|
|
|
|
2021-02-25 02:00:27 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-01-26 19:47:18 +01:00
|
|
|
static toLowerCaseNoAccent(words) {
|
2021-02-06 21:53:25 +01:00
|
|
|
return words?.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "") ?? words;
|
|
|
|
}
|
2021-02-25 02:00:27 +01:00
|
|
|
|
2021-06-05 21:35:43 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static toLowerCaseNoAccentNoSpace(words) {
|
|
|
|
return words?.toLowerCase().normalize("NFD").replace(/[ \u0300-\u036f]/g, "") ?? words;
|
|
|
|
}
|
|
|
|
|
2021-02-25 02:00:27 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-02-06 21:53:25 +01:00
|
|
|
static articleDetermine(genre) {
|
2021-02-28 01:38:40 +01:00
|
|
|
switch (Grammar.toLowerCaseNoAccent(genre)) {
|
2021-02-06 21:53:25 +01:00
|
|
|
case 'f': case 'feminin': return 'la';
|
2021-02-25 02:00:27 +01:00
|
|
|
case 'p': case 'mp': case 'fp': case 'pluriel': return 'les';
|
2021-02-06 21:53:25 +01:00
|
|
|
default:
|
|
|
|
case 'm': case 'masculin': return 'le';
|
|
|
|
}
|
|
|
|
}
|
2021-02-25 02:00:27 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-02-28 01:38:40 +01:00
|
|
|
static articleIndetermine(genre) {
|
|
|
|
switch (Grammar.toLowerCaseNoAccent(genre)) {
|
2021-02-06 21:53:25 +01:00
|
|
|
case 'f': case 'feminin': return 'une';
|
2021-02-25 02:00:27 +01:00
|
|
|
case 'p': case 'fp': case 'mp': case 'pluriel': return 'des';
|
2021-02-06 21:53:25 +01:00
|
|
|
case 'n': case 'neutre': return 'du'
|
|
|
|
default:
|
|
|
|
case 'm': case 'masculin': return 'un';
|
|
|
|
}
|
2021-01-26 19:47:18 +01:00
|
|
|
}
|
2021-02-25 02:00:27 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/**
|
|
|
|
* renvoie un des mots en fonction du genre:
|
|
|
|
*
|
|
|
|
* - masculin/neutre/m/n : mots[0]
|
|
|
|
* - feminin/f : mots[1]
|
|
|
|
* - pluriel/mp/p : mots[2]
|
|
|
|
* - fp : mots[3]
|
|
|
|
*
|
|
|
|
* @param {*} genre
|
|
|
|
* @param {...any} mots
|
|
|
|
*/
|
|
|
|
static accord(genre, ...mots) {
|
2021-02-28 01:38:40 +01:00
|
|
|
switch (Grammar.toLowerCaseNoAccent(genre)) {
|
2021-02-25 02:00:27 +01:00
|
|
|
default:
|
|
|
|
case 'n': case 'neutre':
|
|
|
|
case 'm': case 'masculin': return mots[0];
|
|
|
|
case 'f': case 'feminin': return mots[1];
|
|
|
|
case 'p': case 'mp': case 'pluriel': return mots[2]
|
|
|
|
case 'fp': return mots[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-08 03:04:00 +01:00
|
|
|
}
|