Get Domain

Get hostname from a domain.

get-domain.ts

/**
 * @description This function takes a URL as input and returns the domain name.
 * @param url The URL to extract the domain from.
 * @returns The host name of the URL.
 */
export function getDomain(url: string) {
  const urlObj = new URL(url);
  return urlObj.hostname;
}

Converts https://www.google.com/search?q=itsrakesh&sourceid=chrome&ie=UTF-8 to www.google.com


Loved this post?

Comments

Interested in
working
with me?