Skip to content

Native Typescript library to obfuscate email while leaving them more or less recognizable.

License

Notifications You must be signed in to change notification settings

teamdunno/obfuscatemail

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image

the Artwork was made by vintheweirdass

Note: this is a friendlier option for Node.js users and other runtimes (Bun, Deno, and others) that wants to use ESM instead of Commonjs. It also supports types too!

Why we made this package?

Even though the original package (npm:obfuscate-mail) provides the types, but the package explicitly exporting to the plain, javascript bundle version. That makes the types gone

Screenshot image
To install, you need to use JSR so it passes to the compile/transpille whatever it is process automatically

Installation for Nodejs

For npm

$ npx jsr add @dunno/obfuscatemail

For Yarn

Note: You need to upgrade to v4+, because when installing Yarn, the distribution for Linux only sticks to v1 (thats why the dlx command dosent found)

$ yarn upgrade
$ yarn dlx jsr add @dunno/obfuscatemail

For pnpm

$ pnpm dlx jsr add @dunno/obfuscatemail

Installation for non-Nodejs

For Bun

$ bunx jsr add @dunno/obfuscatemail

For Deno

$ deno add jsr:@dunno/obfuscatemail

obfuscate mail

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

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

import { obfuscateMail } from '@dunno/obfuscatemail';
obfuscateMail('example.example@example.com', {
  // asterisksLength: 6,
  // minimumNameObfuscationLength: 4,
  // visibleCharacters:{
  //    startLength: 3,
  //    middleLength: 2,
  //    endLength:2,
  // }
  // showDomainName: false,
  // showDomainExtension: true,
  // invalidEmailValue: '*********@****.**',
});

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


(click me to hide the `Migration` section)

Migration

This page is only for those who use the npm:obfuscate-mail package. For newcomer, its fine 😉

After those imports, you need some changed to your files also

For Options,

  • minimumNameObfuscationLength was moved to minimumLength
  • Variables that starts with visibleCharacters are going to be inside the object itself, as follows:
/* from these */
{
  visibleCharactersStartLength:number,
  visibleCharactersMiddleLength:number,
  visibleCharactersEndLength:number
}
/* to these */
{
  visibleCharacters:{
    startLength:number,
    middleLength:number,
    endLength:number
  }
}

Also, wasm (for this package) was deprecated for some reason. So theres no separate preloader wasm.js or the wasm itself bundle.wasm

Options

  • asterisksLength - default 6
  • minimumLength - default 4
  • visibleCharacters : {
    • startLength - default 3
    • middleLength - default 2
    • endLength - default 2
  • }
  • showDomainName - default false
  • showDomainExtension - default true
  • invalidEmailValue - default *********@****.**

Examples

Setup

You may need to install jsr:@std/expect. Install & import like the first setup, or open the detailed version at the bottom of the text

Installation for Nodejs

For npm

$ npx jsr add @std/expect

For Yarn

Note: You need to upgrade to v4+, because when installing Yarn, the distribution for Linux only sticks to v1 (thats why the dlx command dosent found)

$ yarn upgrade
$ yarn dlx jsr add @std/expect

For pnpm

$ pnpm dlx jsr add @std/expect

Installation for non-Nodejs

For Bun

$ bunx jsr add @std/expect

For Deno

$ deno add jsr:@std/expect

Usage (for any runtime)

import { expect } from "@std/expect"
Heres the examples
const result = obfuscateMail('example@example.com');
expect(result).equal('exa******@***.com');
const result = obfuscateMail('example.example@example.com');
expect(result).equal('exa***.e***le@***.com');
const result = obfuscateMail('e@example.com');
expect(result).equal('******@***.com');
const result = obfuscateMail('exa@example.com');
expect(result).equal('******@***.com');
const result = obfuscateMail('examp@example.com');
expect(result).equal('e******@***.com');
const result = obfuscateMail('example@example.com', {
  showDomainName: true,
});
const result = obfuscateMail('email.without@domain-extension');
expect(result).equal('ema***wi***ut@***.***');
const result = obfuscateMail('invalid email');
expect(result).equal('*********@****.**');
const result = obfuscateMail(null, { invalidEmailValue: 'invalid email' });
expect(result).equal('invalid email');

About

Native Typescript library to obfuscate email while leaving them more or less recognizable.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%