Skip to content

Commit e1e554f

Browse files
committed
Add documentation
1 parent e4df048 commit e1e554f

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,32 @@ 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+
239+
is.email('Abc.example.com') // false, no @ character
240+
is.email('A@b@c@example.com') // false, only one @ is allowed outside quotation marks
241+
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
242+
is.email('just"not"right@example.com') // false, quoted strings must be dot separated or the only element making up the local-part
243+
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
244+
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
245+
is.email('1234567890123456789012345678901234567890123456789012345678901234+x@example.com') // false, local part is longer than 64 characters
246+
is.email('john..doe@example.com') // false, double dot before @
247+
is.email('john.doe@example..com') // false, double dot after @
248+
```
224249

225250
#### String
226251

test/is/regexp.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,28 @@ 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();
718
});
819
test('returns false on anything else', () => {
20+
expect(is.email('Abc.example.com')).toBeFalsy();
21+
expect(is.email('A@b@c@example.com')).toBeFalsy();
22+
expect(is.email('a"b(c)d,e:f;g<h>i[j\k]l@example.com')).toBeFalsy();
23+
expect(is.email('just"not"right@example.com')).toBeFalsy();
24+
expect(is.email('this is"not\allowed@example.com')).toBeFalsy();
25+
expect(is.email('this\ still\"not\\allowed@example.com')).toBeFalsy();
26+
expect(is.email('1234567890123456789012345678901234567890123456789012345678901234+x@example.com')).toBeFalsy();
27+
expect(is.email('john..doe@example.com')).toBeFalsy();
28+
expect(is.email('john.doe@example..com')).toBeFalsy();
929
});
1030
//testIntegrationWithAllHasCheckers(is.email, 'abc', 'A', 'B');
1131
testFalsyWithNullable(is.email);

0 commit comments

Comments
 (0)