public_suffix
Version, currently 0.1.13 versions
- 0.1.3latestMar 30, 2021
- 0.1.2not indexedMay 1, 2021
- 0.1.1not indexedMay 1, 2021
github.com/toddsundsted/public_suffix
A small Crystal library designed to make the Public Suffix List (https://publicsuffix.org/) easier to use.
Nothing has been indexed for 0.1.1 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
public_suffix:
github: toddsundsted/public_suffix
version: ~> 0.1.1Then run:
shards installshard.yml
No shard.yml has been indexed for 0.1.1. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
public_suffix
The Public Suffix List is "a cross-vendor initiative to provide an accurate list of domain name suffixes". Such a list is necessary because "there was and remains no algorithmic method of finding the highest level at which a domain may be registered for a particular top-level domain...".
public_suffix is a small Crystal library designed to make the Public
Suffix List easier to use. The library will transparently download the
latest list of rules, parse the rules, and optionally cache
them. Source URL, cache directory, and cache expiry are all
configurable.
The public API is as simple as I could make it. Instantiating the
PublicSuffix class creates a new instance with reasonable defaults
(downloads and caches the official list of rules for 30 days).
There are three instance methods:
PublicSuffix#tldreturns the top-level domain namePublicSuffix#cdnreturns the canonical domain namePublicSuffix#splitsplits the domain name into parts
Features
- Transparent download of the official domain rules file
- Optional caching of domain rules data, with refetch upon expiry
- Tiny API
Installation
-
Add the dependency to your
shard.yml:dependencies: public_suffix: github: toddsundsted/public_suffix -
Run
shards install
Synopsis
require "public_suffix"
# Downloads and parses the latest data file and returns
# the top-level domain name
PublicSuffix.new.tld("foobar.com") # => "com"
# Downloads and parses the latest data file and returns
# the canonical domain name
PublicSuffix.new.cdn("foobar.com") # => "foobar.com"
# Downloads and parses the latest data file, caches it in /tmp,
# and splits the domain name into parts
PublicSuffix.new(cache_dir: "/tmp").split("abc.xyz.co.uk") # => ["abc", "xyz", "co.uk"].
# Downloads and caches data in /tmp if it is less than
# 100 seconds old, parses it, and splits the domain name
# into parts
PublicSuffix.new(cache_dir: "/tmp", cache_expiry_period: 100).split("test.parliament.uk") # => ["test", "parliament", "uk"]
# You don't have to instantiate PublicSuffix every time you use it
p = PublicSuffix.new
p.split("fee.fi.fo.com") # => ["fee.fi", "fo", "com"]
p.cdn("fee.fi.fo.com") # => "fo.com", "cdn" means "canonical domain name"
p.tld("fee.fi.fo.com") # => "com", "tld" means "top-level domain"
# You can even use other data files, both local and remote
# (as long as they conform to the Public Suffix List file format)
PublicSuffix.new(url: "file://./spec/test.dat")
Contributing
- Fork it (https://github.com/toddsundsted/public_suffix/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Todd Sundsted - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.1.1- Tagged
- May 1, 2021
- Commit
2ad49b4f0060- Indexed
- not yet
Dependents
No indexed shard depends on this one yet.
Repository
github.com/toddsundsted/public_suffix
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 15, 2026
- Synced
- Aug 14, 2026
- Versions
- 3