Expand description
Node punycode module — a faithful implementation of the RFC 3492 Bootstring
algorithm with the Punycode parameter set. The module is deprecated in Node
but still present; the codec is pure and deterministic (no host state beyond
allocating the returned string/array), so it round-trips independently of any
network or locale.
Surface:
encode(str)/decode(str)— the raw label codec (noxn--prefix).toASCII(domain)/toUnicode(domain)— per dot-separated label, with thexn--ACE prefix convention.ucs2Decode/ucs2Encode— the code-point split/join. Node exposes these aspunycode.ucs2.decode/.encode; that nested object is built byconstant("ucs2").
Bootstring parameters (RFC 3492 §5): base 36, tmin 1, tmax 26, skew 38,
damp 700, initial_bias 72, initial_n 128, delimiter -.
RFC-3492 sample verifications reasoned through against this implementation. For “mañana”: basic run “maana” (b=5) → “maana-”; the single non-basic ñ (U+00F1=241) with delta=678 emits digits 15→‘p’, 19→‘t’, 0→‘a’ ⇒ “maana-pta”. Hence toASCII(“mañana.com”) === “xn–maana-pta.com” and the inverse toUnicode round-trips. Likewise toASCII(“bücher”) === “xn–bcher-kva”.