You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dnsDomainIs.js 699B

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * Module exports.
  3. */
  4. module.exports = dnsDomainIs;
  5. /**
  6. * Returns true iff the domain of hostname matches.
  7. *
  8. * Examples:
  9. *
  10. * ``` js
  11. * dnsDomainIs("www.netscape.com", ".netscape.com")
  12. * // is true.
  13. *
  14. * dnsDomainIs("www", ".netscape.com")
  15. * // is false.
  16. *
  17. * dnsDomainIs("www.mcom.com", ".netscape.com")
  18. * // is false.
  19. * ```
  20. *
  21. *
  22. * @param {String} host is the hostname from the URL.
  23. * @param {String} domain is the domain name to test the hostname against.
  24. * @return {Boolean} true iff the domain of the hostname matches.
  25. */
  26. function dnsDomainIs (host, domain) {
  27. host = String(host);
  28. domain = String(domain);
  29. return host.substr(domain.length * -1) === domain;
  30. }