-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add is email #39
base: master
Are you sure you want to change the base?
Add is email #39
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,6 +125,16 @@ export function isWindowObject(value) { | |
return value != null && typeof value === 'object' && 'setInterval' in value; | ||
} | ||
|
||
/** | ||
* Returns whether a given value is an email | ||
* @param {*} value the value to check | ||
*/ | ||
export function isEmail(value) { | ||
/* eslint-disable-next-line no-useless-escape */ | ||
const re = /^(([^<>()\[\]\\.,;:\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,}))$/; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unreadable code. |
||
return re.test(String(value).toLowerCase()); | ||
} | ||
|
||
export default { | ||
object: isObject, | ||
array: isArray, | ||
|
@@ -142,4 +152,5 @@ export default { | |
regexp: isRegexp, | ||
undefined: isUndefined, | ||
windowObject: isWindowObject, | ||
email: isEmail, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -197,3 +197,15 @@ describe('isWindowObject', () => { | |
}); | ||
testFalsyWithNullable(is.windowObject); | ||
}); | ||
|
||
describe('isEmail', () => { | ||
test('returns true', () => { | ||
expect(is.email('very.common@example.com')).toBeTruthy(); | ||
expect(is.email('other.email-with-hyphen@example.com')).toBeTruthy(); | ||
expect(is.email('user.name+tag+sorting@example.com')).toBeTruthy(); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add more tests (specifications mentioned in the wikipedia page) |
||
test('returns false', () => { | ||
expect(is.email('john..doe@example.com')).toBeFalsy(); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add more tests (specifications mentioned in the wikipedia page) |
||
testFalsyWithNullable(is.email); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be done in this file, but in
regexp.js
as mentioned in the issue.Check out @boristane pull request #40