From 0e4cc45439dac6a8ae5fe150f0c5054c39fa3b14 Mon Sep 17 00:00:00 2001 From: Klemek Date: Tue, 16 Jun 2026 18:38:09 +0200 Subject: [PATCH] feat: input page (wip) --- src/App.vue | 193 ++++++---------------------------- src/components/CoolDomain.vue | 29 +++++ src/components/PageInput.vue | 61 +++++++++++ src/components/PageRandom.vue | 155 +++++++++++++++++++++++++++ src/lib/factory.ts | 38 +++++-- 5 files changed, 304 insertions(+), 172 deletions(-) create mode 100644 src/components/CoolDomain.vue create mode 100644 src/components/PageInput.vue create mode 100644 src/components/PageRandom.vue 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 @@ + + 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 @@ + + + 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 @@ + + + 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")); + }); + } }