obfuscate-mail
v1.5.1
Published
Obfuscate email
Downloads
4,099
Readme
obfuscate mail
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
- default6
minimumNameObfuscationLength
- default4
visibleCharactersStartLength
- default3
visibleCharactersMiddleLength
- default2
visibleCharactersEndLength
- default2
showDomainName
- defaultfalse
showDomainExtension
- defaulttrue
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": "[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');