feat: input page (wip)
Lint / Oxlint (push) Successful in 49s
Lint / TypeScript (push) Successful in 54s
Deploy / Build (push) Successful in 1m8s
Lint / ESLint (push) Successful in 1m45s
Deploy / Deploy to Stapler (push) Successful in 8m58s

This commit is contained in:
2026-06-16 18:38:09 +02:00
parent 98f937e9de
commit 0e4cc45439
5 changed files with 304 additions and 172 deletions
+29 -9
View File
@@ -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<string> {
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"));
});
}
}