npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

get-etld

v1.1.0

Published

Returns the effective top-level domain (eTLD) of the current web page without the use of a public suffix list.

Downloads

20

Readme

get-etld

Returns the effective top-level domain (eTLD) corresponding to the current web page without the use of a public suffix list.

Because of the methodology used, this library is very small.

What's an effective top-level domain (eTLD)?

When someone purchases a domain, the domain always ends in an existing effective top-level domain (eTLD). For example, if you purchase example.com, the eTLD is com. Usually the eTLD is what comes after the last period, but not always. If you purchase example.co.uk, for example, co.uk is the eTLD. No websites or services are hosted on eTLDs; they only serve as the basis for domains that consumers can register.

Requirements

This will only work in a browser and cookies must be enabled.

How detection is accomplished

There are no consistent, logical rules whereby the effective top-level domain can be parsed from a hostname. Instead, the Public Suffix List is a publicly curated list of all known effective top-level domains. Ths list changes over time. The only way to parse the effective top-level domain from a hostname is by comparing the ending of the hostname to the Public Suffix List.

The Public Suffix List is very large, making it prohibitive to load into a browser. Fortunately, there's a second-hand way of accessing this list.

As it turns out, browsers use this list to determine which domains can accept cookies. For example, browsers allow store.example.co.uk to set cookies for store.example.co.uk and example.co.uk, but not co.uk or uk, because co.uk and uk are both on the Public Suffix List.

Because of this, we can determine the top-level domain by attempting to write a cookie on uk, then co.uk, then example.co.uk, then store.example.co.uk, until we succeed in writing a cookie. In this case, the first attempt that will succeed is example.co.uk. By removing the first segment (example), we arrive at co.uk, the effective top-level domain.

Installation

If you use npm for package management, you can install get-etld by running the following command from within your project's directory:

npm install get-etld

Usage

import getEtld from "get-etld";

console.log(getEtld());

If cookies are not enabled, an error will be thrown.

If the hostname is localhost, the eTLD will be localhost.

Special Recognition

Full credit goes to Joe Khoury for devising the strategy used to determine the apex domain.