-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@yourssu/utils): change isEmail to return boolean value
- Loading branch information
Showing
2 changed files
with
13 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@yourssu/utils': minor | ||
--- | ||
|
||
change isEmail to return boolean value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,13 @@ | ||
export const isEmail = (email: string, domain?: string) => { | ||
const regFull = | ||
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | ||
if (regFull.test(String(email).toLowerCase())) { | ||
return email; | ||
export const isEmail = (email: string, domain?: string): boolean => { | ||
if (!domain) { | ||
const regFull = | ||
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | ||
|
||
return regFull.test(String(email).toLowerCase()); | ||
} | ||
|
||
const regHalf = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))$/; | ||
const regHalf = /^(([^<>()[\]\\.,;:\s@"]+(\[^<>()[\]\\.,;:\s@"]+)*)|(".+"))$/; | ||
const refDomain = | ||
/^@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | ||
|
||
if (domain) { | ||
if (regHalf.test(String(email).toLowerCase()) && refDomain.test(String(domain).toLowerCase())) { | ||
return email + domain; | ||
} | ||
} | ||
|
||
throw new Error('given value is not valid'); | ||
return regHalf.test(String(email).toLowerCase()) && refDomain.test(String(domain).toLowerCase()); | ||
}; |