Get Domain
Get hostname from a domain.
get-domain.ts
ts1/** 2 * @description This function takes a URL as input and returns the domain name. 3 * @param url The URL to extract the domain from. 4 * @returns The host name of the URL. 5 */ 6export function getDomain(url: string) { 7 const urlObj = new URL(url); 8 return urlObj.hostname; 9}
Converts https://www.google.com/search?q=itsrakesh&sourceid=chrome&ie=UTF-8
to www.google.com