Skip to content
This repository has been archived by the owner on Aug 10, 2020. It is now read-only.

furey/email-whitelist

Repository files navigation

email-whitelist

Utilities to validate/ensure emails against a whitelist. 👮‍📧

Contents

Requirements

Installation

$ npm install furey/email-whitelist#semver:^v1

Usage

// 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]

Utilities

isSafeEmail(email)

Returns whether email validates against the set EMAIL_WHITELIST.

getSafeEmail(email)

Returns email if isSafeEmail(email), otherwise returns EMAIL_DEFAULT.

Configuration

EMAIL_WHITELIST

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

EMAIL_DEFAULT

The optional default value to return from getSafeEmail() when an email fails validation, e.g.:

EMAIL_DEFAULT[email protected]

Testing

$ npm ci
$ npm run test

License

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.