summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorportix <portix@gmx.net>2013-06-04 16:56:53 +0200
committerportix <portix@gmx.net>2013-06-04 16:56:53 +0200
commit8d350c6fee5d63d202dcc4de55e0842b12d1546c (patch)
treee735eac0afc5a566426fc04a4b6395af0450d492
parentd4a3f3760eab2caa45a68d854b33b101783a1d27 (diff)
downloaddwb-8d350c6fee5d63d202dcc4de55e0842b12d1546c.zip
Implementing net.domainMatch
-rw-r--r--scripts/lib/net.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/scripts/lib/net.js b/scripts/lib/net.js
new file mode 100644
index 00000000..a53ee533
--- /dev/null
+++ b/scripts/lib/net.js
@@ -0,0 +1,36 @@
+(function() {
+ var tldEnd = new RegExp("\\.tld$");
+ /**
+ * Checks if a domain matches checking for .tld which matches all top level
+ * domains
+ * @name domainMatch
+ * @memberOf net
+ * @function
+ *
+ * @param {String} domain
+ * The domain to test
+ * @param {String} match
+ * A domain that may contain .tld as top level domain
+ *
+ * @returns {Boolean}
+ * Whether the domains match
+ * */
+ Object.defineProperties(net, {
+ "domainMatch" :
+ {
+ value : function(domain, match) {
+ var result = false;
+ if (tldEnd.test(match))
+ {
+ result = domain.substring(0, domain.indexOf(".")) === match.substring(0, match.indexOf("."));
+ }
+ else
+ {
+ result = domain === match;
+ }
+ return result;
+ }
+ }
+ });
+ Object.freeze(net);
+})();