Giter VIP home page Giter VIP logo

obfuscate-mail's Introduction

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('[email protected]', {
  // 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 *********@****.**

Web assembly binary (WASI-compatible)

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

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

Examples

const result = obfuscate('[email protected]');
expect(result).equal('exa******@***.com');
const result = obfuscate('[email protected]');
expect(result).equal('exa***.e***le@***.com');
const result = obfuscate('[email protected]');
expect(result).equal('******@***.com');
const result = obfuscate('[email protected]');
expect(result).equal('******@***.com');
const result = obfuscate('[email protected]');
expect(result).equal('e******@***.com');
const result = obfuscate('[email protected]', {
  showDomainName: true,
});
expect(result).equal('exa******@example.com');
const result = obfuscate('[email protected]', {
  asterisksLength: 12,
});
expect(result).equal('exa******mp******st@*********.com');
const result = obfuscate('[email protected]', {
  showDomainName: true,
  showDomainExtension: false,
});
expect(result).equal('exa******@example.***');
const result = obfuscate('[email protected]', {
  asterisksLength: 8,
  visibleCharactersStartLength: 2,
  visibleCharactersEndLength: 3,
  showDomainName: false,
});
expect(result).equal('co****ny****ame@*****.com');
const result = obfuscate('[email protected]', {
  visibleCharactersStartLength: 4,
  visibleCharactersEndLength: 1,
  minimumNameObfuscationLength: 6,
});
expect(result).equal('comp***.***e@***.com');
const result = obfuscate('[email protected]', {
  visibleCharactersStartLength: 3,
  visibleCharactersEndLength: 2,
  minimumNameObfuscationLength: 6,
});
expect(result).equal('com***y***me@***.com');
const result = obfuscate('[email protected]', {
  visibleCharactersStartLength: 2,
  visibleCharactersMiddleLength: 3,
  visibleCharactersEndLength: 2,
  minimumNameObfuscationLength: 6,
});
expect(result).equal('co***y.e***le@***.com');
const result = obfuscate('[email protected]', {
  visibleCharactersStartLength: 3,
  visibleCharactersEndLength: 2,
  minimumNameObfuscationLength: 10,
});
expect(result).equal('co******@***.com');
const result = obfuscate('[email protected]', {
  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('[email protected]', {
  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');

obfuscate-mail's People

Contributors

dependabot[bot] avatar rawpixel-vincent avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.