smartstring/dist/smartstring.domain.js
2017-10-11 14:52:22 +02:00

53 lines
4.3 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Domain {
constructor(domainStringArg) {
let regexMatches = domainRegex(domainStringArg);
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
this.topLevel = this.level1;
this.domainName = this.level2;
this.subDomain = this.level3;
}
}
exports.Domain = Domain;
let domainRegex = function (stringArg) {
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(); //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) {
return (stringArg !== '');
});
return regexMatchesFiltered;
};
let protocolRegex = function (stringArg) {
let regexString = /^([a-zA-Z0-9]*):\/\//;
let regexMatches = regexString.exec(stringArg);
if (regexMatches) {
return regexMatches[1];
}
else {
return undefined;
}
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdHJpbmcuZG9tYWluLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzdHJpbmcuZG9tYWluLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBRUE7SUFhRSxZQUFhLGVBQXVCO1FBQ2xDLElBQUksWUFBWSxH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