From af22ea6ec9e8bb40b5e3a3a18be1bb9422af0c21 Mon Sep 17 00:00:00 2001 From: Hayleigh Thompson Date: Sat, 25 Jul 2026 23:31:51 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20a=20'domain'=20function=20for?= =?UTF-8?q?=20converting=20nsid=20authorities=20to=20normal=20domain=20nam?= =?UTF-8?q?es.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/at/nsid.gleam | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/at/nsid.gleam b/src/at/nsid.gleam index 8796076..dc4e4f9 100644 --- a/src/at/nsid.gleam +++ b/src/at/nsid.gleam @@ -340,6 +340,17 @@ pub fn name(nsid: Nsid) -> String { nsid.name } +/// Construct a domain name from an [`Nsid`](#Nsid) authority. This reverses the +/// authority segments back into the order they would appear in a typical domain +/// name, such as `"bsky.app"` or `"atproto.com"`. +/// +pub fn domain(nsid: Nsid) -> String { + let assert [tld, ..rest] = nsid.authority + use out, segment <- list.fold(rest, tld) + + segment <> "." <> out +} + // CONVERSIONS ----------------------------------------------------------------- /// Convert an [`Nsid`](#Nsid) back into its string representation. -- 2.51.2