DomainParser

master

A Full Swift Lightweight Framework that uses the Public Suffix list to Parse URLs
Dashlane/SwiftDomainParser

Domain Parser

Carthage Compatible

A full-swift simple library which allows to parse host to parse hostnames, and public suffix, using the Public Suffix List

This Library allows to know which is the domain name for a given URL.

What is Public Suffix List ?

PSL list all the known public suffix (like: com, co.uk, nt.edu.au, ...). Without this information we are not able to determine which part of a URL is the domain, Since a suffix can have more than one Label. The PSL includes ICANN (official top level domains) but also privates one (like us-east-1.amazonaws.com)

Examples:

URL Domain
sub.domain.co.uk domain.co.uk
auth.impala.dashlane.com dashlane.com

Usage

Initialization:

import DomainParser
let domainParse = try DomainParser()

You should use the same instance when you parse multiple URLs.

let domain = domainParser.parse("awesome.dashlane.com").domain
print(domain) // dashlane.com
let suffix = domainParser.parse("awesome.dashlane.com").suffix
print(suffix) // com
let suffix = domainParser.parse("awesome.dashlane.co.uk").suffix
print(suffix) // co.uk

Update the Public Suffist List

In the script folder, run:

swift UpdatePSL.swift 

Description

  • Swift Tools 5.3.0

Dependencies

  • None
Last updated: Tue Dec 01 2020 02:11:19 GMT-0500 (GMT-05:00)