![image](https://private-user-images.githubusercontent.com/70825723/393689185-708de802-6cb8-4422-a548-84d707e2f66b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwNTY4MjksIm5iZiI6MTczOTA1NjUyOSwicGF0aCI6Ii83MDgyNTcyMy8zOTM2ODkxODUtNzA4ZGU4MDItNmNiOC00NDIyLWE1NDgtODRkNzA3ZTJmNjZiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDIzMTUyOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWFjZTM4MDcwOGIzYTM1OTU1MzJiODQ3MWVkNzgwZWI5MTFhNTJmMGU2NTJjYmM2ZjIxMzY3MTMxNjI1NTQ2NDAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.if1osWlX3V4lZM-_mmmPCzQig6dHNks3qxCKdjJiPgw)
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
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
For Bun
$ bunx jsr add @dunno/obfuscatemail
For Deno
$ deno add jsr:@dunno/obfuscatemail
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)
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 tominimumLength
- 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
asterisksLength
- default6
minimumLength
- default4
visibleCharacters
: {startLength
- default3
middleLength
- default2
endLength
- default2
- }
showDomainName
- defaultfalse
showDomainExtension
- defaulttrue
invalidEmailValue
- default*********@****.**
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
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
For Bun
$ bunx jsr add @std/expect
For Deno
$ deno add jsr:@std/expect
import { expect } from "@std/expect"
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');