Convert an email domain to punycode

Keep the local part and convert an international domain to its ASCII xn-- form.

JavaScript Version 1.0.0 · MIT · by Oveyon · .md

convert-an-email-domain-to-punycode.js
function toAsciiAddress(address) { const at = address.lastIndexOf('@'); return `${address.slice(0, at)}@${new URL(`http://${address.slice(at + 1)}`).hostname}`; }

Input & expected output

Input

"ana@bücher.example"

Expected output

"[email protected]"

The edge case

Input

"[email protected]"

Expected output

"[email protected]"

Know the limits

  • Oveyon accepts ASCII addresses only: an international domain must be sent in its xn-- form, anything else is refused with address_not_ascii.
  • Only the domain is converted. A non-ASCII local part (EAI) cannot be made ASCII this way.

The function above is the implementation used by the lab. The lab validates JSON types and caps size before execution; include equivalent validation when accepting untrusted input in your application.

Source & maintenance

Written by Oveyon for this edition of 1loc.dev; it is not part of the original collection. Copyright (c) 2026 Oveyon. MIT licensed.

The function above is the implementation the lab runs and the tests exercise. Read the license.

Local fixture scope · Node.js 22.23.2 · reviewed October 28, 2026. No external service is required.

Keep exploring

Type two or more characters. Try “duplicate”, “webhook” or “retry”.