fix(types): improve TypeScript strictness compatibility and modernize test exports

This commit is contained in:
2026-05-01 11:28:39 +00:00
parent 0e0bd5cd6c
commit 94f994ee6c
21 changed files with 2582 additions and 2257 deletions
+25 -27
View File
@@ -1,17 +1,17 @@
export class Domain {
public fullName: string;
public level1: string;
public level2: string;
public level3: string;
public level4: string;
public level5: string;
public protocol: string;
public level1?: string;
public level2?: string;
public level3?: string;
public level4?: string;
public level5?: string;
public protocol?: string;
public zoneName: string;
// aliases
public topLevel: string;
public domainName;
public subDomain;
public port;
public topLevel?: string;
public domainName?: string;
public subDomain?: string;
public port: string;
public nodeParsedUrl: URL;
constructor(domainStringArg: string) {
// lets do the node standard stuff first
@@ -26,21 +26,16 @@ export class Domain {
const regexMatches = this._domainRegex(
domainStringArg.replace(this.nodeParsedUrl.pathname, '')
);
[this.level1, this.level2, this.level3, this.level4, this.level5] = regexMatches;
this.fullName = '';
for (let i = 1; i <= 5; i++) {
if (regexMatches[i - 1]) {
const localMatch = regexMatches[i - 1];
this['level' + i.toString()] = localMatch;
if (this.fullName === '') {
this.fullName = localMatch;
} else {
this.fullName = localMatch + '.' + this.fullName;
}
for (const localMatch of regexMatches) {
if (this.fullName === '') {
this.fullName = localMatch;
} else {
this['level' + i.toString()] = undefined;
this.fullName = localMatch + '.' + this.fullName;
}
}
this.zoneName = this.level2 + '.' + this.level1;
this.zoneName = [this.level2, this.level1].filter(Boolean).join('.');
// aliases
this.topLevel = this.level1;
@@ -51,19 +46,22 @@ export class Domain {
// helper functions
/** */
private _domainRegex(stringArg: string) {
private _domainRegex(stringArg: string): string[] {
const regexString =
/([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}([a-zA-Z0-9\-\_]*)\.{0,1}$/;
const regexMatches = regexString.exec(stringArg);
regexMatches.reverse(); //make sure we build the domain from toplevel to subdomain (reversed order)
regexMatches.pop(); // pop the last element, which is, since we reversed the Array, the full String of matched elements
const regexMatchesFiltered = regexMatches.filter(function (stringArg: string) {
if (!regexMatches) {
return [];
}
const reversedMatches = [...regexMatches].reverse(); // make sure we build the domain from top level to subdomain
reversedMatches.pop(); // pop the last element, which is, since we reversed the Array, the full String of matched elements
const regexMatchesFiltered = reversedMatches.filter(function (stringArg: string) {
return stringArg !== '';
});
return regexMatchesFiltered;
}
private _protocolRegex(stringArg: string) {
private _protocolRegex(stringArg: string): string | undefined {
const regexString = /^([a-zA-Z0-9]*):\/\//;
const regexMatches = regexString.exec(stringArg);
if (regexMatches) {
@@ -73,7 +71,7 @@ export class Domain {
}
}
private _portRegex(stringArg: string) {
private _portRegex(stringArg: string): string | undefined {
const regexString = /^([a-zA-Z0-9]*):\/\//;
const regexMatches = regexString.exec(stringArg);
if (regexMatches) {