A javascript utility package to parse email addresses
npm i --save @js-genie/email-parser
isValid()
function is used to check if the input is a valid email address or not.
const { isValid } = require('@js-genie/email-parser');
isValid('[email protected]'); // returns true
isValid('[email protected]'); // returns true
isValid('{key : [email protected]}'); // returns false
isValid('[email protected]'); // returns false
getUsername()
function is used to get the username part of the input email address.
const { getUsername } = require('@js-genie/email-parser');
getUsername("{}teststring"); // returns ''
getUsername({key: '[email protected]'}); // returns ''
getUsername("[email protected]"); // returns 'testemail'
getDomain()
function is used to get the domain part of the input email address.
const { getDomain } = require('@js-genie/email-parser');
getDomain("{}teststring"); // returns ''
getDomain({key: '[email protected]'}); // returns ''
getDomain("[email protected]"); // returns 'test.com'
Note: If the typeof
input email address is not string or the input email is not valid, an empty value is returned.