Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

obfuscate-mail

Package Overview
Dependencies
Maintainers
3
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

obfuscate-mail

Obfuscate email

  • 1.5.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

obfuscate mail

npm Tests Coverage Status CodeQL license

Email addresses should never been displayed by an api unless specifically requested by a recently authentified user.

This node.js library gives the options to obfuscate email addresses will leaving them more or less identifiable.

npm install obfuscate-mail
yarn add obfuscate-mail
const obfuscate = require('obfuscate-mail');
import obfuscate from 'obfuscate-mail';
obfuscate('example.example@example.com', {
  // asterisksLength: 6,
  // minimumNameObfuscationLength: 4,
  // visibleCharactersStartLength: 3,
  // visibleCharactersMiddleLength: 2,
  // visibleCharactersEndLength: 2,
  // showDomainName: false,
  // showDomainExtension: true,
  // invalidEmailValue: '*********@****.**',
});

=> exa***.e***le@***.com

Options

  • asterisksLength - default 6
  • minimumNameObfuscationLength - default 4
  • visibleCharactersStartLength - default 3
  • visibleCharactersMiddleLength - default 2
  • visibleCharactersEndLength - default 2
  • showDomainName - default false
  • showDomainExtension - default true
  • invalidEmailValue - default *********@****.**

Test it with runKit

Web assembly binary (WASI-compatible)

curl -o obfuscate.wasm https://raw.githubusercontent.com/rawpixel-vincent/obfuscate-mail/main/dist/bundle.wasm
echo '{ "email": "example.example@example.com", "options": {} }' | wasmtime obfuscate.wasm

=> "exa***.e***le@***.com"%

Examples

const result = obfuscate('example@example.com');
expect(result).equal('exa******@***.com');
const result = obfuscate('example.example@example.com');
expect(result).equal('exa***.e***le@***.com');
const result = obfuscate('e@example.com');
expect(result).equal('******@***.com');
const result = obfuscate('exa@example.com');
expect(result).equal('******@***.com');
const result = obfuscate('examp@example.com');
expect(result).equal('e******@***.com');
const result = obfuscate('example@example.com', {
  showDomainName: true,
});
expect(result).equal('exa******@example.com');
const result = obfuscate('example.company+test@example.com', {
  asterisksLength: 12,
});
expect(result).equal('exa******mp******st@*********.com');
const result = obfuscate('example@example.com', {
  showDomainName: true,
  showDomainExtension: false,
});
expect(result).equal('exa******@example.***');
const result = obfuscate('company.name@test.com', {
  asterisksLength: 8,
  visibleCharactersStartLength: 2,
  visibleCharactersEndLength: 3,
  showDomainName: false,
});
expect(result).equal('co****ny****ame@*****.com');
const result = obfuscate('company.name@test.com', {
  visibleCharactersStartLength: 4,
  visibleCharactersEndLength: 1,
  minimumNameObfuscationLength: 6,
});
expect(result).equal('comp***.***e@***.com');
const result = obfuscate('company.name@test.com', {
  visibleCharactersStartLength: 3,
  visibleCharactersEndLength: 2,
  minimumNameObfuscationLength: 6,
});
expect(result).equal('com***y***me@***.com');
const result = obfuscate('company.example@test.com', {
  visibleCharactersStartLength: 2,
  visibleCharactersMiddleLength: 3,
  visibleCharactersEndLength: 2,
  minimumNameObfuscationLength: 6,
});
expect(result).equal('co***y.e***le@***.com');
const result = obfuscate('company.name@test.com', {
  visibleCharactersStartLength: 3,
  visibleCharactersEndLength: 2,
  minimumNameObfuscationLength: 10,
});
expect(result).equal('co******@***.com');
const result = obfuscate('company.name@test.com', {
  visibleCharactersStartLength: 0,
  visibleCharactersEndLength: 4,
});
expect(result).equal('***pa***name@***.com');
const result = obfuscate('email.without@domain-extension');
expect(result).equal('ema***wi***ut@***.***');
const result = obfuscate('abcdefgh.ijklmno@domain.com', {
  visibleCharactersStartLength: 4,
  visibleCharactersMiddleLength: 4,
  visibleCharactersEndLength: 4,
});
expect(result).equal('abcd***gh.i***lmno@***.com');
const result = obfuscate('invalid email');
expect(result).equal('*********@****.**');
const result = obfuscate(null, { invalidEmailValue: 'invalid email' });
expect(result).equal('invalid email');

Keywords

FAQs

Package last updated on 19 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc