diff --git a/src/App.vue b/src/App.vue index 313a0e7..95107d6 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,86 +1,21 @@ + + + + + + + + + + + + + + {{ domain }} + diff --git a/src/components/PageInput.vue b/src/components/PageInput.vue new file mode 100644 index 0000000..d5fce47 --- /dev/null +++ b/src/components/PageInput.vue @@ -0,0 +1,61 @@ + + + + + + + + + Génerer + Generate + + + + + + diff --git a/src/components/PageRandom.vue b/src/components/PageRandom.vue new file mode 100644 index 0000000..516e227 --- /dev/null +++ b/src/components/PageRandom.vue @@ -0,0 +1,155 @@ + + + + + + + + + + Chargement de la Cool Domain Factory™ + Loading the Cool Domain Factory™ + + + + Création d'un domaine cool + Generating a new cool domain + + + + Vérification de la disponibilité + Checking domain availability + + + + Ce domaine semble + disponible + ! + This domain seems + available! + + + Ce domaine n'est pas disponible. + This domain is not available. + + + Une erreur est survenue, merci de recharger la page. + An error has occured, please reload the page. + + + Nouveau domaine + New domain + + + diff --git a/src/lib/factory.ts b/src/lib/factory.ts index 32e5bdb..05c2dd7 100644 --- a/src/lib/factory.ts +++ b/src/lib/factory.ts @@ -15,15 +15,19 @@ export class DomainFactory { this.words.english = this.initWords(englishWords); } + escapeWord(word: string): string { + return word + .normalize("NFD") + .toLowerCase() + .replace(/[^a-z0-9-]/g, "") + .trim(); + } + initWords(raw: string): string[] { return raw .split("\n") .map((word) => { - word = word - .normalize("NFD") - .toLowerCase() - .replace(/[^a-z0-9-]/g, "") - .trim(); + word = this.escapeWord(word); if (word.length == 0) { return null; } @@ -40,13 +44,12 @@ export class DomainFactory { return randomElement(this.words[lang]); } - randomDomain(lang: string): string | null { - const word = this.randomWord(lang); + randomDomain(word: string): string | null { for (const tld of shuffled(TLD_LIST.slice())) { const tldEscaped: string = tld.replace(".", ""); if (word.endsWith(tldEscaped) && word.length > tldEscaped.length + 2) { const domain = `${word.substring(0, word.length - tldEscaped.length)}.${tld}`; - if (!domain.includes("-.")) { + if (!domain.includes("-.") && !this.generated.includes(domain)) { this.generated.push(domain); return domain; } @@ -60,7 +63,8 @@ export class DomainFactory { let k = 10000; while (k > 0) { k--; - const domain = this.randomDomain(lang); + const word = this.randomWord(lang); + const domain = this.randomDomain(word); if (domain) { resolve(domain); return; @@ -70,4 +74,20 @@ export class DomainFactory { reject(new Error(this.error)); }); } + + nextFromWord(word: string): Promise { + const escapedWord = this.escapeWord(word.replace(/ /gm, "-")); + return new Promise((resolve, reject) => { + let k = 10000; + while (k > 0) { + k--; + const domain = this.randomDomain(escapedWord); + if (domain) { + resolve(domain); + return; + } + } + reject(new Error("Could not generate a valid domain")); + }); + } }
+ +
+ Chargement de la Cool Domain Factory™ + Loading the Cool Domain Factory™ + +
+ Création d'un domaine cool + Generating a new cool domain + +
+ Vérification de la disponibilité + Checking domain availability + +