feat: input and history pages
Lint / Oxlint (push) Successful in 55s
Lint / TypeScript (push) Successful in 58s
Lint / ESLint (push) Successful in 1m0s
Deploy / Build (push) Successful in 1m13s
Deploy / Deploy to Stapler (push) Successful in 4m27s

This commit is contained in:
2026-06-17 15:44:23 +02:00
parent 0e4cc45439
commit fea4fdba05
13 changed files with 256 additions and 121 deletions
+25 -12
View File
@@ -2,6 +2,7 @@ import rawTldList from "@/data/tld.txt?raw";
import englishWords from "@/data/english.txt?raw";
import frenchWords from "@/data/french.txt?raw";
import { randomElement, shuffled } from "./random";
import type { Domain } from "@/types";
const TLD_LIST: string[] = rawTldList.trim().split("\n");
@@ -9,10 +10,11 @@ export class DomainFactory {
error: string | null = null;
words: Record<string, string[]> = {};
generated: string[] = [];
history: Domain[] = [];
init() {
this.words.french = this.initWords(frenchWords);
this.words.english = this.initWords(englishWords);
this.words.fr = this.initWords(frenchWords);
this.words.en = this.initWords(englishWords);
}
escapeWord(word: string): string {
@@ -58,7 +60,7 @@ export class DomainFactory {
return null;
}
next(lang: string): Promise<string> {
next(lang: string): Promise<Domain> {
return new Promise((resolve, reject) => {
let k = 10000;
while (k > 0) {
@@ -66,7 +68,9 @@ export class DomainFactory {
const word = this.randomWord(lang);
const domain = this.randomDomain(word);
if (domain) {
resolve(domain);
const output = { name: domain, searching: false, available: false };
this.history.push(output);
resolve(output);
return;
}
}
@@ -75,18 +79,27 @@ export class DomainFactory {
});
}
nextFromWord(word: string): Promise<string> {
allFromWord(word: string): Promise<Domain[]> {
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;
const domains = [];
for (const tld of shuffled(TLD_LIST.slice())) {
const tldEscaped: string = tld.replace(".", "");
if (
escapedWord.endsWith(tldEscaped) &&
escapedWord.length >= tldEscaped.length + 2
) {
const domain = `${escapedWord.substring(0, escapedWord.length - tldEscaped.length)}.${tld}`;
if (!domain.includes("-.")) {
const output = { name: domain, searching: false, available: false };
this.history.push(output);
domains.push(output);
}
}
}
if (domains.length) {
resolve(domains);
}
reject(new Error("Could not generate a valid domain"));
});
}