smartstring/dist/smartstring.domain.js

52 lines
4.2 KiB
JavaScript
Raw Normal View History

2016-05-25 03:06:19 +00:00
"use strict";
2016-07-17 15:30:26 +00:00
class Domain {
constructor(domainStringArg) {
let regexMatches = domainRegex(domainStringArg);
2016-10-31 23:22:38 +00:00
this.fullName = '';
2016-07-17 15:30:26 +00:00
for (let i = 1; i <= 5; i++) {
if (regexMatches[i - 1]) {
2016-07-17 15:30:26 +00:00
let localMatch = regexMatches[i - 1];
2016-10-31 23:22:38 +00:00
this['level' + i.toString()] = localMatch;
if (this.fullName === '') {
2016-06-21 16:59:05 +00:00
this.fullName = localMatch;
}
else {
2016-10-31 23:22:38 +00:00
this.fullName = localMatch + '.' + this.fullName;
2016-06-21 16:59:05 +00:00
}
}
else {
2016-10-31 23:22:38 +00:00
this['level' + i.toString()] = undefined;
}
;
}
;
this.protocol = protocolRegex(domainStringArg);
2016-10-31 23:22:38 +00:00
this.zoneName = this.level2 + '.' + this.level1;
2016-05-25 03:06:19 +00:00
// aliases
this.topLevel = this.level1;
this.domainName = this.level2;
this.subDomain = this.level3;
}
2016-07-17 15:30:26 +00:00
}
2016-05-25 03:06:19 +00:00
exports.Domain = Domain;
2016-07-17 15:30:26 +00:00
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
2016-07-17 15:30:26 +00:00
let regexMatchesFiltered = regexMatches.filter(function (stringArg) {
2016-10-31 23:22:38 +00:00
return (stringArg !== '');
2016-05-25 03:06:19 +00:00
});
return regexMatchesFiltered;
};
2016-07-17 15:30:26 +00:00
let protocolRegex = function (stringArg) {
let regexString = /^([a-zA-Z0-9]*):\/\//;
let regexMatches = regexString.exec(stringArg);
if (regexMatches) {
return regexMatches[1];
}
else {
return undefined;
}
};
2016-10-31 23:22:38 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdHJpbmcuZG9tYWluLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzdHJpbmcuZG9tYWluLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFFQTtJQWFJLFlBQVksZUFBc0I7UUFDOUIsSUFBSSxZQUFZLEdBQUcsV0FBVyxDQUFDLGVBQWUsQ0FBQyxDQUFDO1FBQ2hELElBQUksQ0FBQyxRQUFRLEdBQUcsRUFBRSxDQUFBO1FBQ2xCLEdBQUcsQ0FBQyxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsRUFBRSxDQUFDLElBQUksQ0FBQyxFQUFFLENBQUMsRUFBRSxFQUFFLENBQUM7WUFDMUIsRUFBRSxDQUFDLENBQUMsWUFBWSxDQUFDLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7Z0JBQ3RCLElBQUksVUFBVSxHQUFHLFlBQVksQ0FBQyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUE7Z0JBQ3BDLElBQUksQ0FBQyxPQUFPLEdBQUcsQ0FBQyxDQUFDLFFBQVEsRUFBRSxDQUFDLEdBQUcsVUFBVSxDQUFBO2dCQUN6QyxFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsUUFBUSxLQUFLLEVBQUUsQ0FBQyxDQUFBLENBQUM7b0JBQ3RCLElBQUksQ0FBQyxRQUFRLEdBQUcsVUFBVSxDQUFBO2dCQUM5QixDQUFDO2dCQUFDLElBQUksQ0FBQyxDQUFDO29CQUNKLElBQUksQ0FBQyxRQUFRLEdBQUcsVUFBVSxHQUFHLEdBQUcsR0FBRyxJQUFJLENBQUMsUUF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