2020-12-08 03:04:00 +01:00
|
|
|
|
|
|
|
const articlesApostrophes = {
|
|
|
|
'de' : 'd\'',
|
|
|
|
'le' : 'l\'',
|
|
|
|
'la' : 'l\''
|
|
|
|
}
|
|
|
|
export class Grammar {
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-12-08 03:04:00 +01:00
|
|
|
static startsWithVoyel(word) {
|
|
|
|
return word.match(/^[aeiouy]/i)
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
static articleDetermine(genre) {
|
|
|
|
switch (genre?.toLowerCase()) {
|
|
|
|
case 'f': case 'feminin': return 'la';
|
|
|
|
case 'p': case 'pluriel': return 'les';
|
|
|
|
default:
|
|
|
|
case 'm': case 'masculin': return 'le';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static articleIndétermine(genre) {
|
|
|
|
switch (genre?.toLowerCase()) {
|
|
|
|
case 'f': case 'feminin': return 'une';
|
|
|
|
case 'p': case 'pluriel': return 'des';
|
|
|
|
case 'n': case 'neutre': return 'du'
|
|
|
|
default:
|
|
|
|
case 'm': case 'masculin': return 'un';
|
|
|
|
}
|
2021-01-26 19:47:18 +01:00
|
|
|
}
|
2020-12-08 03:04:00 +01:00
|
|
|
}
|