Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

haraka-tld

haraka12.4kMIT1.2.4

Haraka TLD utilities

haraka, tld, domain

readme

Build Status Code Coverage Code Climate

haraka-tld

Haraka TLD utilities

Installation

npm install haraka-tld

Usage

const tlds = require('haraka-tld');
if (tlds.get_organizational_domain('mail.example.com') === 'example.com') {
    // do something
}

Functions exported

get_organizational_domain

Reduces a hostname to an Organizational Domain.

The O.D. is the portion of a domain name immediately delegated by a registrar and the portion that is no longer 'Public'

com               <-- TLD (or Public Suffix)
example.com       <-- Organizational Domain
mail.example.com  <-- hostmame

get_organizational_domain('mail.example.com'); // -> example.com

Haraka usage example:

const tlds = require('haraka-tld');
const from_dom = tlds.get_organizational_domain(connection.transaction.mail_from.host);
const to_dom = tlds.get_organizational_domain(connection.transaction.rcpt_to.host);
if (from_dom == to_dom) {
    // the envelope sender domain matches the envelope receiver domain
    // eg: root@mail.example.com would match sysadmin@example.com
}

split_hostname

Split FQDN to host and domain

const split = tlds.split_hostname('host.sub1.sub2.domain.com');
// split[0] = 'host.sub1.sub2';
// split[1] = 'domain.com';

is_public_suffix

if (tlds.is_public_suffix('com')) {
    // true
}
if (tlds.is_public_suffix('wikipedia.org')) {
    // false
}

Directly access lists

Check for a TLD

if (tlds.top_level_tlds['com']) {
    // true
}

The following files are included

  • public-suffix-list

A list of all Public Suffixes (the parts of a domain name exactly one level below the registrar). Includes punycoded international domains, is maintained by the Mozilla project, and accomplishes roughly the same task as the *-tlds files.

  • top-level-tlds

The list of TLDs valid on the internet. Update URL

  • two-level-tlds

A list of 2nd level TLDs. Update URL

  • three-level-tlds

A list of 3rd level TLDs. Update URL

  • extra-tlds

This allows for additional 2nd and 3rd level TLDs from a single file. Used for site customizations or for the URIBL hosters.txt. Update URL

Updating

  • update the TLD files with ./update_tld_files
  • use the .release scripts to roll a new release. If the .release dir is empty (first time), populate it with git submodule update --init --recursive.
.release/start.sh patch
$edit CHANGELOG.md
git add . && git commit
.release/submit.sh

changelog

Changelog

The format is based on Keep a Changelog.

Unreleased

1.2.4 - 2025-04-10

  • updated TLD files

1.2.3 - 2025-01-09

  • updated TLD files
  • lint: updated to eslint 9
  • prefix node builtin modules with 'node:'

1.2.2 - 2024-09-27

  • updated TLD files
  • doc(CONTRIBUTORS): added
  • chore: automated code formatting
  • lint: remove duplicate / stale rules from .eslintrc

1.2.1 - 2024-04-03

  • dep(punycode): specify as punycode.js
    • which always avoid name conflict with stale node.js built-in
  • doc(README): update ci badge URLs (#82)
  • dep(mocha & eslint): remove from devDeps (install with npx)
  • pkg: add ./test to .npmignore

1.2.0 - 2023-12-12

  • dep(punycode): correctly specify (with trailing /)
    • to override built-in, which emits warnings

1.1.2 - 2023-12-11

  • updated TLD files
  • Update README.md (#78)

1.1.1 - 2023-06-16

  • updated TLD files
  • fix: update_tld_files and update installed copies (#76)

1.1.0 - 2022-09-29

  • updated TLD files
  • switch http -> https for extra-tlds URL
  • for PSL updater, use project root, #74

1.0.34 - 2022-06-05

  • ci: reusable workflows from haraka/.github
  • ci: fix publish workflow (#66)
  • ci: workflow tweaks (#64)
  • ci: add codeql.yml (#65)
  • ci: update codeclimate config
  • chore: replace some promises with async/await

1.0.30 - 2022-05-23

  • update TLD files
  • dep(*): pin major versions

1.0.29 - 2021-10-10

  • update TLD files
  • upon merge to master, automatically publish new version

1.0.28 - 2021-06-09

  • update TLD files & bump version
  • allow disabling logging with env.HARAKA_LOGS_SUPPRESS

1.0.27 - 2021-01-05

  • update TLD files & bump version

1.0.26 - 2020-10-23

  • bump version
  • replace travis & AppVeyor with GH workflow

2019-08-19

  • unref interval, so node.js process exits normally (#52)

1.0.24 - 2019-04-09

  • add an automatic PSL updater, updates the PSL each 15 days
  • assuming no ill effects, after some release validation, extend to the other TLD files
  • and say goodbye to update TLD files releases

1.0.23 - 2019-03-30

  • update TLD files

1.0.22 - 2018-11-14

  • update TLD files

1.0.21 - 2018-07-20

  • update TLD files

1.0.20 - 2018-06-15

  • update TLD files

1.0.19 - 2018-03-07

  • update TLD files

1.0.18 - 2017-12-30

  • update TLD files

1.0.17 - 2017-09-10

  • update TLD files

1.0.16 - 2017-07-30

  • update TLD files
  • dev/CI updates

1.0.15 - 2017-06-16

  • update TLD files
  • update for eslint4 compat

1.0.14 - 2017-05-22

  • update TLD files

1.0.13 - Feb 01, 2017

  • update TLD files
  • added INSTALL section to README
  • inherit lint rules from eslint-plugin-haraka
  • remove grunt-version-check (replaced by greenkeeper)
  • remove Grunt entirely

1.0.12 - Dec 28, 2016

  • update TLD files

1.0.11 - Nov 13, 2016

  • update TLD files

1.0.10 - Oct 06, 2016

  • update TLD files
  • update lint / code coverage meta

1.0.9 - Aug 22, 2016

  • update TLD files

1.0.7 - Jul 20, 2016

  • update TLD files
  • update dep version numbers

1.0.6 - Jun 20, 2016

  • update TLD files
  • added curl -S (report errors) and -f (don't save files when HTTP errors encountered)

1.0.5 - May 16, 2016

  • updated TLD files

1.0.4 - Feb 22, 2016

  • use __dirname for installed base path

1.0.2 - Feb 05, 2016

  • updated lists
  • added Gruntfile.js

1.0.1 - Feb 05, 2016

  • update path to etc dir