This commit is contained in:
LosslessBot
2016-07-06 10:06:10 +02:00
6 changed files with 74 additions and 27 deletions

View File

@ -14,14 +14,22 @@ export class Domain {
domainName;
subDomain;
constructor(domainStringArg:string){
this.fullName = domainStringArg;
let regexMatches = domainRegex(domainStringArg);
this.level1 = regexMatches[0];
this.level2 = regexMatches[1];
this.level3 = regexMatches[2];
this.level4 = regexMatches[3];
this.level5 = regexMatches[4];
this.protocol = protocolRegex(domainStringArg)[1];
this.fullName = "";
for(let i = 1; i <= 5; i++){
if(regexMatches[i - 1]) {
let localMatch = regexMatches[i - 1]
this["level" + i.toString()] = localMatch;
if (this.fullName == ""){
this.fullName = localMatch;
} else {
this.fullName = localMatch + "." + this.fullName;
}
} else {
this["level" + i.toString()] = undefined;
};
};
this.protocol = protocolRegex(domainStringArg);
this.zoneName = this.level2 + "." + this.level1;
// aliases
@ -33,9 +41,10 @@ export class Domain {
let domainRegex = function(stringArg:string){
let 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}$/;
let 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}$/;
let regexMatches = regexString.exec(stringArg);
regexMatches.reverse();
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
let regexMatchesFiltered = regexMatches.filter(function(stringArg:string){
return(stringArg != "");
});
@ -45,6 +54,9 @@ let domainRegex = function(stringArg:string){
let protocolRegex = function(stringArg:string){
let regexString = /^([a-zA-Z0-9]*):\/\//;
let regexMatches = regexString.exec(stringArg);
console.log(regexMatches);
return regexMatches;
if(regexMatches){
return regexMatches[1];
} else {
return undefined;
}
}