Dev Helpers

JavaScript / Data interchange

Read an internationalized hostname

Dev Helpers · March 13, 2026

A URL parser exposes the canonical host representation of an internationalized name. Keep display text separate from comparison keys.

Worked example

const url = new URL("https://café.example/menu");
console.log(url.hostname, url.pathname);

Result

xn--caf-dma.example /menu

Implementation notes

Do hostname comparisons on parsed hostnames. Comparing the raw address text can conflate a port, user information or path text with the host.

Try it yourself

Inspect hostname and href for a Unicode label and its ASCII encoding.

Open the JavaScript example →

Editorial date March 13, 2026 · Published December 6, 2026

Related articles

Sum distances with a Euclidean norm

A diagonal is longer than either of its components. Math.hypot combines perpendicular distances without making the caller square each input.

Build an OS-independent path

Path conventions belong to the destination. Use an explicit path flavour when generating portable asset names.

Resolve ranked ties

A leaderboard needs an explicit tie policy. Ranking tied scores and sorting their display order are separate decisions.