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.

dnsDomainLevels.js 561B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Module exports.
  3. */
  4. module.exports = dnsDomainLevels;
  5. /**
  6. * Returns the number (integer) of DNS domain levels (number of dots) in the
  7. * hostname.
  8. *
  9. * Examples:
  10. *
  11. * ``` js
  12. * dnsDomainLevels("www")
  13. * // returns 0.
  14. * dnsDomainLevels("www.netscape.com")
  15. * // returns 2.
  16. * ```
  17. *
  18. * @param {String} host is the hostname from the URL.
  19. * @return {Number} number of domain levels
  20. */
  21. function dnsDomainLevels (host) {
  22. var match = String(host).match(/\./g);
  23. var levels = 0;
  24. if (match) {
  25. levels = match.length;
  26. }
  27. return levels;
  28. }