Parsing Hostname for TLD, domain name, and SLD
does anyone know of any packages to parse a URL's hostname for the top level domain, domain name, and sublevel domains? I found one, but it actually just doesn't work. It just errors saying the label is too short for everything I give it. https://github.com/lupomontero/psl
GitHub
GitHub - lupomontero/psl: JavaScript domain name parser based on th...
JavaScript domain name parser based on the Public Suffix List - GitHub - lupomontero/psl: JavaScript domain name parser based on the Public Suffix List
6 Replies
I'm suprised this isn't already in the URL object for Javascript
Would these not work for you?
no I need the sub level domain of the url, which comes from the
URL.hostname
why not use some regex for that
I just woke up, there may be better ways to do it
I'd also recommend regex if you need to parse other components. Here is what I
would have done:
My regex string is a little safer as it looks for specific pieces of a URL in their respective spot instead of just matching on any string containing a char/num.
@ybabts Here is a URL parsing library that looks infinitely easier to use than juggling regex: https://github.com/remusao/tldts
GitHub
GitHub - remusao/tldts: JavaScript Library to work against complex ...
JavaScript Library to work against complex domain names, subdomains and URIs. - GitHub - remusao/tldts: JavaScript Library to work against complex domain names, subdomains and URIs.