dnsDomainLevels.js 666 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. /**
  4. * Returns the number (integer) of DNS domain levels (number of dots) in the
  5. * hostname.
  6. *
  7. * Examples:
  8. *
  9. * ``` js
  10. * dnsDomainLevels("www")
  11. * // returns 0.
  12. * dnsDomainLevels("www.netscape.com")
  13. * // returns 2.
  14. * ```
  15. *
  16. * @param {String} host is the hostname from the URL.
  17. * @return {Number} number of domain levels
  18. */
  19. function dnsDomainLevels(host) {
  20. const match = String(host).match(/\./g);
  21. let levels = 0;
  22. if (match) {
  23. levels = match.length;
  24. }
  25. return levels;
  26. }
  27. exports.default = dnsDomainLevels;
  28. //# sourceMappingURL=dnsDomainLevels.js.map