Skip to content

Commit 7ed96ef

Browse files
committed
Add documentation
1 parent e4df048 commit 7ed96ef

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,36 @@ is.windowObject(dom.window); // true
220220

221221
This group of methods allows to verify _if_ a given string _is_ from a specific known type of value.
222222

223-
_To be implemented_
223+
##### `email(value)`
224+
Check _if_ a given string _is_ an email. This verification is done according to [RFC5322](https://tools.ietf.org/html/rfc5322#section-3.2.3) official standard.
225+
226+
```js
227+
is.email('simple@example.com') // true
228+
is.email('very.common@example.com') // true
229+
is.email('disposable.style.email.with+symbol@example.com') // true
230+
is.email('other.email-with-hyphen@example.com') // true
231+
is.email('fully-qualified-domain@example.com') // true
232+
is.email('user.name+tag+sorting@example.com') // true
233+
is.email('x@example.com') // true
234+
is.email('example-indeed@strange-example.com') // true
235+
is.email('example@s.example') // true
236+
is.email('" "@example.org') // true
237+
is.email('"john..doe"@example.com') // true
238+
is.email('example.with.ip@[192.168.2.1]') // true
239+
is.email('"with(comment)@example.com') // true
240+
is.email('"with@(comment)example.com') // true
241+
242+
is.email('Abc.example.com') // false, no @ character
243+
is.email('@example.com') // false, no local part
244+
is.email('A@b@c@example.com') // false, only one @ is allowed outside quotation marks
245+
is.email('a"b(c)d,e:f;g<h>i[j\k]l@example.com') // false, none of the special characters in this local-part are allowed outside quotation marks
246+
is.email('just"not"right@example.com') // false, quoted strings must be dot separated or the only element making up the local-part
247+
is.email('this is"not\allowed@example.com') // false, spaces, quotes, and backslashes may only exist when within quoted strings and preceded by a backslash
248+
is.email('this\ still\"not\\allowed@example.com') // false, even if escaped (preceded by a backslash), spaces, quotes, and backslashes must still be contained by quotes
249+
is.email('1234567890123456789012345678901234567890123456789012345678901234+x@example.com') // false, local part is longer than 64 characters
250+
is.email('john..doe@example.com') // false, double dot before @
251+
is.email('john.doe@example..com') // false, double dot after @
252+
```
224253

225254
#### String
226255

test/is/regexp.test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,33 @@ import { testIntegrationWithAllHasCheckers } from '../has.test';
44

55
describe('isEmail', () => {
66
test('returns true on email strings', () => {
7+
expect(is.email('simple@example.com')).toBeTruthy();
8+
expect(is.email('very.common@example.com')).toBeTruthy();
9+
expect(is.email('disposable.style.email.with+symbol@example.com')).toBeTruthy();
10+
expect(is.email('other.email-with-hyphen@example.com')).toBeTruthy();
11+
expect(is.email('fully-qualified-domain@example.com')).toBeTruthy();
12+
expect(is.email('user.name+tag+sorting@example.com')).toBeTruthy();
13+
expect(is.email('x@example.com')).toBeTruthy();
14+
expect(is.email('example-indeed@strange-example.com')).toBeTruthy();
15+
expect(is.email('example@s.example')).toBeTruthy();
16+
expect(is.email('" "@example.org')).toBeTruthy();
17+
expect(is.email('"john..doe"@example.com')).toBeTruthy();
18+
expect(is.email('example.with.ip@[192.168.2.1')).toBeTruthy();
19+
expect(is.email('with(comment)@example.com')).toBeTruthy();
20+
expect(is.email('with@(comment)example.com')).toBeTruthy();
721
});
822
test('returns false on anything else', () => {
23+
expect(is.email('Abc.example.com')).toBeFalsy();
24+
expect(is.email('@example.com')).toBeFalsy();
25+
expect(is.email('A@b@c@example.com')).toBeFalsy();
26+
expect(is.email('a"b(c)d,e:f;g<h>i[j\k]l@example.com')).toBeFalsy();
27+
expect(is.email('just"not"right@example.com')).toBeFalsy();
28+
expect(is.email('this is"not\allowed@example.com')).toBeFalsy();
29+
expect(is.email('this\ still\"not\\allowed@example.com')).toBeFalsy();
30+
expect(is.email('1234567890123456789012345678901234567890123456789012345678901234+x@example.com')).toBeFalsy();
31+
expect(is.email('john..doe@example.com')).toBeFalsy();
32+
expect(is.email('john.doe@example..com')).toBeFalsy();
933
});
10-
//testIntegrationWithAllHasCheckers(is.email, 'abc', 'A', 'B');
34+
testIntegrationWithAllHasCheckers(is.email, 'simple@example.com', '@not.email', 'not.email');
1135
testFalsyWithNullable(is.email);
1236
});

0 commit comments

Comments
 (0)