foundryvtt-reve-de-dragon/module/grammar.js

40 lines
1.0 KiB
JavaScript
Raw Normal View History

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) {
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
}