smartstring/dist/smartstring.domain.js

56 lines
7.2 KiB
JavaScript
Raw Permalink Normal View History

2016-05-25 03:06:19 +00:00
"use strict";
require("typings-global");
var Domain = (function () {
function Domain(domainStringArg) {
var regexMatches = domainRegex(domainStringArg);
2016-06-21 16:59:05 +00:00
this.fullName = "";
for (var i = 1; i <= 5; i++) {
if (regexMatches[i - 1]) {
2016-06-21 16:59:05 +00:00
var 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;
2016-05-25 03:06:19 +00:00
// aliases
this.topLevel = this.level1;
this.domainName = this.level2;
this.subDomain = this.level3;
}
return Domain;
}());
exports.Domain = Domain;
var domainRegex = function (stringArg) {
2016-06-22 10:55:29 +00:00
var 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}$/;
2016-05-25 03:06:19 +00:00
var 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-05-25 03:06:19 +00:00
var regexMatchesFiltered = regexMatches.filter(function (stringArg) {
return (stringArg != "");
});
return regexMatchesFiltered;
};
var protocolRegex = function (stringArg) {
var regexString = /^([a-zA-Z0-9]*):\/\//;
var regexMatches = regexString.exec(stringArg);
if (regexMatches) {
return regexMatches[1];
}
else {
return undefined;
}
};
2016-05-25 03:06:19 +00:00
2016-06-22 10:55:29 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0c3RyaW5nLmRv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