Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/is/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ export function isWindowObject(value) {
return value != null && typeof value === 'object' && 'setInterval' in value;
}

/**
Copy link
Owner

@joeltankam joeltankam Oct 12, 2018

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.jsas mentioned in the issue.
Check out @boristane pull request #40

* 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,}))$/;
Copy link
Owner

Choose a reason for hiding this comment

The 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,
Expand All @@ -142,4 +152,5 @@ export default {
regexp: isRegexp,
undefined: isUndefined,
windowObject: isWindowObject,
email: isEmail,
};
12 changes: 12 additions & 0 deletions test/is/types.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Copy link
Owner

Choose a reason for hiding this comment

The 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();
});
Copy link
Owner

Choose a reason for hiding this comment

The 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);
});