Domain

1 min read

Take domain names and URLs apart: the host of a URL, and a domain without its subdomain.

Reference

FunctionDescription
domainBareIs like domainHost, and also strips a leading www. subdomain.
domainHostStrips surrounding whitespace, https:// or http:// prefix, and trailing /.

Functions

domainBare

domainBare is like domainHost, and also strips a leading www. subdomain. Returns "" for nil or non-string input. Idempotent.

{{ domainBare "https://www.acme.com/" }}  → "acme.com"

domainHost

domainHost strips surrounding whitespace, https:// or http:// prefix, and trailing /. Returns the bare hostname. Returns "" for nil or non-string input. Idempotent — calling it on an already-clean hostname is a no-op.

{{ domainHost "https://acme.example.com/" }}  → "acme.example.com"