remusao / tldts

JavaScript Library to extract domains, subdomains and public suffixes from complex URIs.
https://npmjs.com/tldts
MIT License
484 stars 19 forks source link

Confusion over public suffixes #1810

Closed intrnl closed 1 year ago

intrnl commented 1 year ago

I'm a little confused over how the library matches public suffixes, I can see that pages.dev is in the public suffix list, however the publicSuffix would only be dev whereas co.uk would be co.uk, is there something I'm misunderstanding here?

remusao commented 1 year ago

Hi @intrnl,

Thanks for reaching out. I think the confusion comes from the fact that there are two sections in the public suffix list:

  1. ICANN (.co.uk is in this section)
  2. PRIVATE (.pages.dev is in this section)

By default, tldts will only consider the former (ICANN) when looking up publix suffix. The reason is that historically this is the behavior that is expected most of the time by default. If you wanna look suffixes from both sections you can use the option { allowPrivateDomains: true } with any tldts function. For example:

import { parse } from "tldts";

parse("https://foo.pages.dev/", { allowPrivateDomains: true });

I hope that helps,

intrnl commented 1 year ago

ooh, thank you, i've completely missed this. works as expected