A Swift package that uses the Public Suffix List to parse domain names.
let components = SuffixList.default.parse("www.example.com")
print(components?.tld) // com
print(components?.sld) // example
print(components?.domain) // example.com
print(components?.subdomain) // www
A SuffixList
is used to parse domain names.
A bundled version of the public suffix list is included as SuffixList.default
. You may also use your own custom suffix list.
- Select File > Swift Packages > Add Package Dependency...
- Enter the package repository URL:
https://github.com/jameshurst/PublicSuffix-Swift.git
- Confirm the version and let Xcode resolve the package
This library is released under the MIT license. See LICENSE for details.