From 8d350c6fee5d63d202dcc4de55e0842b12d1546c Mon Sep 17 00:00:00 2001 From: portix Date: Tue, 4 Jun 2013 16:56:53 +0200 Subject: Implementing net.domainMatch --- scripts/lib/net.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 scripts/lib/net.js 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); +})(); -- cgit v1.2.3