Skip to content

Commit 5f4d693

Browse files
committed
Require Node.js 8
1 parent 2ef1fc0 commit 5f4d693

File tree

7 files changed

+65
-55
lines changed

7 files changed

+65
-55
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: node_js
22
node_js:
3+
- '12'
34
- '10'
45
- '8'
5-
- '6'

index.d.ts

+34-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
1-
export interface Options {
2-
/**
3-
* Only match an exact string.
4-
*
5-
* @default false
6-
*/
7-
exact?: boolean
1+
declare namespace emailRegex {
2+
export interface Options {
3+
/**
4+
Only match an exact string.
5+
6+
Useful with `RegExp#test` to check if a string is an email address.
7+
8+
@default false
9+
*/
10+
exact?: boolean
11+
}
812
}
913

1014
/**
11-
* Returns a regex for matching email addresses.
12-
*
13-
* @param options - Configure the generated regular expression
14-
* @returns Regex for matching email addresses.
15-
*/
16-
export default function emailRegex(options?: Options): RegExp;
15+
Regular expression for matching email addresses.
16+
17+
Use it for finding email addresses or checking if something is email like. [You shouldn't use this for validating emails.](http://davidcel.is/blog/2012/09/06/stop-validating-email-addresses-with-regex/) Only for hinting to the user.
18+
19+
@example
20+
```
21+
import emailRegex = require('email-regex');
22+
23+
// Contains an email address
24+
emailRegex().test('unicorn [email protected]');
25+
//=> true
26+
27+
// Is an email address
28+
emailRegex({exact: true}).test('[email protected]');
29+
//=> true
30+
31+
'unicorn [email protected] cake [email protected] rainbow'.match(emailRegex());
32+
33+
```
34+
*/
35+
declare function emailRegex(options?: emailRegex.Options): RegExp;
36+
37+
export = emailRegex

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
22

3-
const re = '[^\\.\\s@:](?:[^\\s@:]*[^\\s@:\\.])?@[^\\.\\s@]+(?:\\.[^\\.\\s@]+)*';
3+
const regex = '[^\\.\\s@:](?:[^\\s@:]*[^\\s@:\\.])?@[^\\.\\s@]+(?:\\.[^\\.\\s@]+)*';
44

5-
module.exports = (options = {}) => options.exact ? new RegExp(`^${re}$`) : new RegExp(re, 'g');
5+
module.exports = ({exact} = {}) => exact ? new RegExp(`^${regex}$`) : new RegExp(regex, 'g');

index.test-d.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import {expectType} from 'tsd-check';
2-
import emailRegex from '.';
1+
import {expectType} from 'tsd';
2+
import emailRegex = require('.');
33

4-
(async () => {
5-
expectType<RegExp>(emailRegex());
6-
expectType<RegExp>(emailRegex({}));
7-
expectType<RegExp>(emailRegex({ exact: true }));
8-
})();
4+
expectType<RegExp>(emailRegex());
5+
expectType<RegExp>(emailRegex({}));
6+
expectType<RegExp>(emailRegex({exact: true}));

package.json

+10-16
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,31 @@
1010
"url": "sindresorhus.com"
1111
},
1212
"engines": {
13-
"node": ">=6"
13+
"node": ">=8"
1414
},
1515
"scripts": {
16-
"test": "xo && ava && tsd-check"
16+
"test": "xo && ava && tsd"
1717
},
1818
"files": [
1919
"index.js",
2020
"index.d.ts"
2121
],
2222
"keywords": [
23-
"text",
24-
"string",
23+
"email",
24+
"address",
2525
"regex",
2626
"regexp",
27-
"re",
27+
"string",
2828
"match",
29+
"text",
2930
"test",
3031
"find",
3132
"pattern",
32-
"validate",
33-
"email",
34-
"address"
33+
"validate"
3534
],
3635
"devDependencies": {
37-
"ava": "*",
38-
"tsd-check": "^0.3.0",
39-
"xo": "*"
40-
},
41-
"xo": {
42-
"ignores": [
43-
"*.ts"
44-
]
36+
"ava": "^2.1.0",
37+
"tsd": "^0.7.3",
38+
"xo": "^0.24.0"
4539
}
4640
}

readme.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,18 @@ emailRegex({exact: true}).test('[email protected]');
3434

3535
## API
3636

37-
### emailRegex([options])
37+
### emailRegex(options?)
3838

3939
Returns a regex for matching email addresses.
4040

4141
#### options
4242

43+
Type: `object`
44+
4345
##### exact
4446

4547
Type: `boolean`<br>
4648
Default: `false` *(Matches any email address in a string)*
4749

4850
Only match an exact string.<br>
4951
Useful with `RegExp#test` to check if a string is an email address.
50-
51-
52-
## License
53-
54-
MIT © [Sindre Sorhus](https://sindresorhus.com)

test.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from 'ava';
2-
import m from '.';
2+
import emailRegex from '.';
33

4-
const fixture = [
4+
const fixtures = [
55
66
'foo@bar',
77
@@ -28,7 +28,7 @@ const fixture = [
2828
'foo@[IPv6:2001:db8::2]'
2929
];
3030

31-
const fixtureNot = [
31+
const fixturesNot = [
3232
'@',
3333
'@io',
3434
'@sindresorhus.com',
@@ -43,21 +43,21 @@ const fixtureNot = [
4343
];
4444

4545
test('extract', t => {
46-
for (const x of fixture) {
47-
t.is((m().exec(`foo ${x} bar`) || [])[0], x);
46+
for (const fixture of fixtures) {
47+
t.is((emailRegex().exec(`foo ${fixture} bar`) || [])[0], fixture);
4848
}
4949

50-
t.is(m().exec('mailto:[email protected]')[0], '[email protected]');
50+
t.is(emailRegex().exec('mailto:[email protected]')[0], '[email protected]');
5151
});
5252

5353
test('exact', t => {
54-
for (const x of fixture) {
55-
t.true(m({exact: true}).test(x));
54+
for (const fixture of fixtures) {
55+
t.true(emailRegex({exact: true}).test(fixture));
5656
}
5757
});
5858

5959
test('failures', t => {
60-
for (const x of fixtureNot) {
61-
t.false(m({exact: true}).test(x));
60+
for (const fixture of fixturesNot) {
61+
t.false(emailRegex({exact: true}).test(fixture));
6262
}
6363
});

0 commit comments

Comments
 (0)