DomainParser

1.1.0

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

What's New

Update & Performance

2022-09-29T14:10:15Z

Update domain list and improve performance.

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
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Oct 20 2024 05:11:33 GMT-0900 (Hawaii-Aleutian Daylight Time)