fix: tld-list link with correct extension
This commit is contained in:
+13
-2
@@ -10,6 +10,7 @@ export class DomainFactory {
|
||||
generated: string[] = [];
|
||||
history: Domain[] = [];
|
||||
tldList: string[] = [];
|
||||
ignoredTldList: string[] = [];
|
||||
|
||||
async init(lang: string | null = null) {
|
||||
if (lang && !this.words[lang]) {
|
||||
@@ -58,6 +59,9 @@ export class DomainFactory {
|
||||
|
||||
randomDomain(word: string): string | null {
|
||||
for (const tld of shuffled(this.tldList.slice())) {
|
||||
if (this.ignoredTld(tld)) {
|
||||
continue;
|
||||
}
|
||||
const tldEscaped: string = tld.replace(".", "");
|
||||
if (word.endsWith(tldEscaped) && word.length > tldEscaped.length + 2) {
|
||||
const domain = `${word.substring(0, word.length - tldEscaped.length)}.${tld}`;
|
||||
@@ -93,8 +97,8 @@ export class DomainFactory {
|
||||
});
|
||||
}
|
||||
|
||||
removeExt(ext: string): void {
|
||||
this.tldList = this.tldList.filter((tld: string) => tld !== ext && !tld.endsWith(ext));
|
||||
removeExtensions(...extensions: string[]): void {
|
||||
this.ignoredTldList.push(...extensions);
|
||||
}
|
||||
|
||||
newDomain(domain: string): Domain {
|
||||
@@ -106,6 +110,10 @@ export class DomainFactory {
|
||||
};
|
||||
}
|
||||
|
||||
ignoredTld(tld: string): boolean {
|
||||
return this.ignoredTldList.some((ignoredTld: string) => tld.endsWith(ignoredTld));
|
||||
}
|
||||
|
||||
allFromWord(word: string): Promise<Domain[]> {
|
||||
const escapedWord = this.escapeWord(word.replace(/ /gm, "-"));
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -113,6 +121,9 @@ export class DomainFactory {
|
||||
.then(() => {
|
||||
const domains = [];
|
||||
for (const tld of shuffled(this.tldList.slice())) {
|
||||
if (this.ignoredTld(tld)) {
|
||||
continue;
|
||||
}
|
||||
const tldEscaped: string = tld.replace(".", "");
|
||||
if (escapedWord.endsWith(tldEscaped) && escapedWord.length >= tldEscaped.length + 2) {
|
||||
const domain = `${escapedWord.substring(0, escapedWord.length - tldEscaped.length)}.${tld}`;
|
||||
|
||||
Reference in New Issue
Block a user