Email addresses characters convertor to HTML entities to protect against spam bots and crawlers.
A JavaScript port of Wordpress antispambot
.
$ npm install --save protect-email
# Or with yarn
$ yarn add protect-email
'use strict';
import { protectEmail, protectEmailAlways, protectEmailFactory } from 'protect-email';
const email = '[email protected]';
// Depends on random
const encoded = protectEmail(email);
// => "test.email@gmail.com"
// or
// => "test.email@gmail.com"
// or
// => "test.email@gmail.com"
// etc. (It depends on random)
// With hex encoding
const encoded = protectEmail(email, true);
// => "test.email@g%6dail.%63om"
// or
// => "te%73t.%65m%61%69%6c%40%67ma%69l.c%6fm"
// or
// => "te%73t%2ee%6d%61il@gmai%6c%2ec%6fm"
// etc. (It depends on random)
// Idempotent (always encodes)
const encoded = protectEmailAlways(email);
// => "test.email@gmail.com"
// Or you can specify your own randomize function (`Math.random` by default)
let i = 0;
const myProtectEmail = protectEmailFactory(() => i++ % 2 / 2);
const encoded = myProtectEmail(email);
// => "test.email@gmail.com"
$ npm install
$ # or
$ yarn
$
$ npm run build
$ npm run test
- Fork it (https://github.com/SuperPaintman/protect-email/fork)
- Create your feature branch (
git checkout -b feature/<feature_name>
) - Commit your changes (
git commit -am '<type>(<scope>): added some feature'
) - Push to the branch (
git push origin feature/<feature_name>
) - Create a new Pull Request
- SuperPaintman SuperPaintman - creator, maintainer