Mask an email address for logs

Keep the first character and the domain; hide the rest of the local part.

JavaScript Version 1.0.0 · MIT · by Oveyon · .md

mask-an-email-address.js
function maskEmail(address) { return `${address.slice(0, 1)}•••${address.slice(address.lastIndexOf('@'))}`; }

Input & expected output

Input

"ana.silva@example.com"

Expected output

"a•••@example.com"

The edge case

Input

"a@example.com"

Expected output

"a•••@example.com"

Know the limits

  • Masking reduces exposure in logs; it is not anonymization, and the domain stays visible.
  • The mask has a fixed width, so it does not reveal the length of the local part. Prefer logging a message or delivery identifier instead.

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.

Its file in the public edition: contents/mask-an-email-address.mdx in akamind/1loc, commit 0a77f131b22d. The function above is the implementation the lab runs and the tests exercise; the test suite checks that it is the code that file carries. 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”.