diff options
Diffstat (limited to 'scripts/lib/net.js')
-rw-r--r-- | scripts/lib/net.js | 36 |
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); +})(); |