Convert an email domain to punycode
Keep the local part and convert an international domain to its ASCII xn-- form.
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.
Keep exploring
- Get the domain of an email address — Take the part after the last @ and lowercase it, for domain checks and grouping.
- Mask an email address for logs — Keep the first character and the domain; hide the rest of the local part.
- Normalize an email address for comparison — Trim whitespace and lowercase only the domain, preserving the local part.