Utilities to validate/ensure emails against a whitelist. 👮📧
$ npm install furey/email-whitelist#semver:^v1
// example.js
const { isSafeEmail, getSafeEmail } = require('email-whitelist')
/**
* Assuming the following `process.env` variables are set…
*
* - [email protected],@work-domain.com
* - [email protected]
*
* */
console.log(isSafeEmail('[email protected]')) // true
console.log(isSafeEmail('[email protected]')) // true
console.log(isSafeEmail('[email protected]')) // false
console.log(getSafeEmail('[email protected]')) // '[email protected]'
console.log(getSafeEmail('[email protected]')) // '[email protected]'
console.log(getSafeEmail('[email protected]')) // '[email protected]'
$ node example.js
true
true
false
[email protected]
[email protected]
[email protected]
Returns whether email
validates against the set EMAIL_WHITELIST
.
Returns email
if isSafeEmail(email)
, otherwise returns EMAIL_DEFAULT
.
The comma-delimited list of values to test against, e.g.:
EMAIL_WHITELIST[email protected],@work-domain.com
EMAIL_WHITELIST
values should be complete email addresses…
…and/or whole domains:
@domain.com
The optional default value to return from getSafeEmail()
when an email fails validation, e.g.:
EMAIL_DEFAULT[email protected]
$ npm ci
$ npm run test
ISC License
Copyright (c) 2019, James Furey
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.