-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discuss use of cleanHost by default, and API in general #99
Comments
We had some discussion on this topic with @remusao. I'm dumping the summary for review: From the user standpoint, the single polymorphic API may be the best choice. Being able to pass the full URL or just a hostname is not only convenient but also makes code less error prone.
Question: if we detailed function should be still exposed, should they be:
|
I really like this approach and before you posted the issue, I was sketching something very similar. At this point, I am almost regretting we don't have ESModules in Node yet, because I would have even done something like this: import tld, {tldExists} from 'tldjs';
tld('www.google.com').publicSuffix;
tldExists('www.google.com'); |
I will close this issue as the API now provides both a |
@oncletom @ctavan
As discussed in #97, let's open a discussion around the use of
cleanHostValue
in tld.js, and the API in general. As a reminder, I summarize below the points raised so far:cleanHostValue
(which is the current performance bottleneck of most functions in the public API) in each function is not optimal (we will call it more than once if we usegetDomain
, once ingetDomain
and once ingetPublicSuffix
). Also, a user of the library has no way to bypass this step, in case we already have a hostname at hand and don't want to pay the price of parsing/cleaning the input.I would like to propose a solution to this:
extractHostname
(the currentcleanHostValue
) function that can be applied before-hand to URLs to get ahostname
as expected by the functions exposed bytld.js
.isValid
), that would be performed on the input of the functions, to make sure that the input is indeed a valid hostname, and we could either raise an exception or returnnull
.Also, I would like to mention a last point. I have had a look at other libraries offering public suffix parsing, and a common API is to offer
parse
function taking a hostname as input, and returning some object of the form:I find that this greatly simplifies the API. Although I'm not sure it's something we want to do, we could easily add this function in the public API, and express the other functions in terms of this one:
Having one function implementing the logic would remove some redundancy in the code and offer a super simple API for the users of the library. That's just a thought and I'm not sure if this is a worthy addition, but I wanted to mention this possibility.
What do you guys think?
The text was updated successfully, but these errors were encountered: