Merge pull request #532 from Khez/string-validate-email

#142 #461 Adding Doctests to String/ValidateEmail.js
This commit is contained in:
marsonya
2021-01-22 08:18:29 +05:30
committed by GitHub

View File

@ -1,11 +1,22 @@
/*
function that takes a string input and return either it is true of false
a valid email address
e.g.: mahfoudh.arous@gmail.com -> true
e.g.: mahfoudh.arous@helsinki.edu -> true
e.g.: mahfoudh.arous.com ->false
Function that takes a string input and return either true or false
If it is a valid email address
*/
/*
* Doctests
*
* > validateEmail('mahfoudh.arous@gmail.com')
* true
* > validateEmail('mahfoudh.arous@helsinki.edu')
* true
* > validateEmail('mahfoudh.arous.com')
* false
* > validateEmail('')
* ! TypeError
* > validateEmail(null)
* ! TypeError
*/
const validateEmail = (str) => {
if (str === '' || str === null) {
throw new TypeError('Email Address String Null or Empty.')