mirror of
https://framagit.org/JonathanMM/sutom.git
synced 2024-05-20 22:56:38 +02:00
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import InstanceConfiguration from "./instanceConfiguration";
|
|
import ListeMotsProposables from "./mots/listeMotsProposables";
|
|
export default class Dictionnaire {
|
|
public constructor() {}
|
|
|
|
public static async getMot(idPartie: string, datePartie: Date): Promise<string> {
|
|
return await this.getNomFichier(idPartie, datePartie)
|
|
.then((nom) => fetch("mots/" + nom + ".txt"))
|
|
.then((resultat) => resultat.text());
|
|
}
|
|
|
|
private static async getNomFichier(idPartie: string, datePartie: Date): Promise<string> {
|
|
let datePartieStr =
|
|
datePartie.getFullYear().toString() +
|
|
"-" +
|
|
(datePartie.getMonth() + 1).toString().padStart(2, "0") +
|
|
"-" +
|
|
datePartie.getDate().toString().padStart(2, "0");
|
|
|
|
return btoa(idPartie + "-" + datePartieStr);
|
|
}
|
|
|
|
public static estMotValide(mot: string): boolean {
|
|
mot = this.nettoyerMot(mot);
|
|
return mot.length >= 6 && mot.length <= 9 && ListeMotsProposables.Dictionnaire.includes(mot);
|
|
}
|
|
|
|
public static nettoyerMot(mot: string): string {
|
|
return mot
|
|
.normalize("NFD")
|
|
.replace(/[\u0300-\u036f]/g, "")
|
|
.toUpperCase();
|
|
}
|
|
}
|