foundryvtt-reve-de-dragon/module/grammar.js
2021-02-07 00:02:48 +01:00

40 lines
1.0 KiB
JavaScript

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;
}
static startsWithVoyel(word) {
return word.match(/^[aeiouy]/i)
}
static toLowerCaseNoAccent(words) {
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';
}
}
}