fix: fixed list of tlds
This commit is contained in:
+5
-11
@@ -1,22 +1,16 @@
|
||||
import { getTLDList } from "./tld";
|
||||
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";
|
||||
|
||||
const TLD_LIST: string[] = rawTldList.trim().split("\n");
|
||||
|
||||
export class DomainFactory {
|
||||
tldList: string[] = [];
|
||||
error: string | null = null;
|
||||
words: Record<string, string[]> = {};
|
||||
generated: string[] = [];
|
||||
|
||||
async init() {
|
||||
try {
|
||||
this.tldList = await getTLDList();
|
||||
} catch (e) {
|
||||
this.error = "Could not load TLD list";
|
||||
throw e;
|
||||
}
|
||||
|
||||
init() {
|
||||
this.words.french = this.initWords(frenchWords);
|
||||
this.words.english = this.initWords(englishWords);
|
||||
}
|
||||
@@ -48,7 +42,7 @@ export class DomainFactory {
|
||||
|
||||
randomDomain(lang: string): string | null {
|
||||
const word = this.randomWord(lang);
|
||||
for (const tld of shuffled(this.tldList.slice())) {
|
||||
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}`;
|
||||
|
||||
Reference in New Issue
Block a user