@arungovil/sanitize-js
v0.1.0
Published
A tiny javascript email sanitizer
Downloads
24
Readme
Installation
Using npm
npm i @arungovil/sanitize-js
Using Yarn
yarn add @arungovil/sanitize-js
Usage
import { sanitize } from "@arungovil/sanitize-js";
const email = "arun(🐞)[email protected]";
const sanitizedEmail = sanitize(email);
Result
❌ Before
arun(🐞)[email protected]
✅ After
[email protected]
Parameters
Options
Examples
Using custom regex
Pass a custom regex to strip out matching characters.
import { sanitize } from "@arungovil/sanitize-js";
const email = "arun(🐞)[email protected]";
const myRegex = /#/g; // regex to strip out #
const sanitizedEmail = sanitize(email, { customRegex: myRegex });
Result
❌ Before
arun#[email protected]
✅ After
[email protected]
Sanitize non email strings
To sanitize only the username of an email or a random string
import { sanitize } from "@arungovil/sanitize-js";
const userName = "arun(🐞)govil";
const sanitizedUserName = sanitize(userName, { isNormalString: true });
Result
❌ Before
arun(🐞)govil
✅ After
arungovil
Note
Sanitize-js is used for email sanitization, if you are looking for an email validator use validator.js