Skip to content
Jennifer Programming Language

idna API reference

Internationalized domain names: convert a Unicode domain to its ASCII-compatible (xn--) form and back, over a Punycode (RFC 3492) core. So münchen.de goes on the wire as xn--mnchen-3ya.de (DNS, SMTP envelopes, URL hosts are ASCII-only). Pure Jennifer over strings, convert, and encoding - no networking, TinyGo-clean. This is the Punycode transformation plus lowercasing, not full IDNA2008 (which layers nameprep / mapping tables on top); it covers the common cases. It does reject what would make one name look like or alias another: control, space and invisible characters, U-label hyphen rules, and an xn-- label that is not a canonical A-label of a non-ASCII label. It needs convert.toCodepoint / convert.fromCodepoint for the bootstring arithmetic on rune values.

Import with import "idna.j" as idna;. See the idna guide for prose and examples.

Contents

NameWhat it is
isAsciiReport whether a domain is already all-ASCII (needs no conversion).
toAsciiConvert a domain to its ASCII-compatible form, label by label.
toUnicodeConvert an ASCII-compatible domain back to Unicode, label by label.

Functions

isAscii

jennifer
idna.isAscii(domain as string)

Report whether a domain is already all-ASCII (needs no conversion).

domain
the domain name to test
Returns bool
true when every character is ASCII

toAscii

jennifer
idna.toAscii(domain as string)

Convert a domain to its ASCII-compatible form, label by label.

domain
the (possibly Unicode) domain name
Returns string
the ASCII-compatible domain (Unicode labels get an xn-- prefix)
Throws Error
kind "idna" when a label exceeds 63 octets or the domain 253, carries a control, space or invisible character, a Unicode label breaks the U-label rules, or an xn-- label is not a valid A-label

toUnicode

jennifer
idna.toUnicode(domain as string)

Convert an ASCII-compatible domain back to Unicode, label by label.

domain
the ASCII-compatible domain name
Returns string
the Unicode domain (xn-- labels get Punycode-decoded)
Throws Error
kind "idna" on a malformed, non-canonical or over-long (> 63 octets) xn-- label, one decoding to pure ASCII or nothing, or a label with a control, space or invisible character