Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Simple library for getting the domain part of a hostname.
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
resources
src/url_dom
test/url_dom/test
.gitignore
README
README.md
project.clj

README.md

url_dom

This simple library gives you the domain for a hostname. It is based on the list of domains from http://publicsuffix.org.

For example:

(ns my-ns
 (:require [url_dom.core :as u]))

(u/parse "sub1.sub2.domain.co.uk")
;=> {:public-suffix "co.uk", :domain "domain.co.uk", :rule-used "*.uk"}

Or, using the java.net.URI class:

(ns my-ns
  (:import (java.net URI)))

(domain (URI. "http://www.subA.subB.zombo.co.uk")) ;=> "zombo.co.uk"
(public-suffix (URI. "http://www.subA.subB.zombo.co.uk")) ;=> "co.uk"

If you are trying to follow the code, look at this page:

http://publicsuffix.org/list/

The code uses the same terminology. I don't use algorithm specified on that site, as it doesn't make all the tests pass.

Things I'll do next:

  • Upload to clojars. make sure installation and usage is straightforward.
Something went wrong with that request. Please try again.