Skip to main content

Module punycode

Module punycode 

Source
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 (no xn-- prefix).
  • toASCII(domain) / toUnicode(domain) — per dot-separated label, with the xn-- ACE prefix convention.
  • ucs2Decode/ucs2Encode — the code-point split/join. Node exposes these as punycode.ucs2.decode / .encode; that nested object is built by constant("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”.

Constants§

METHODS

Functions§

call
constant
punycode.ucs2 nested object and punycode.version, served through stdlib::constant (needs the parent "punycode" => punycode::constant(name) arm). Its decode/encode are the routed ucs2Decode/ucs2Encode methods.