Skip to content

Commit baf4b38

Browse files
committed
Require Node.js 12 and move to ESM
1 parent b61e575 commit baf4b38

File tree

8 files changed

+29
-33
lines changed

8 files changed

+29
-33
lines changed

.github/workflows/main.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 16
1314
- 14
1415
- 12
15-
- 10
16-
- 8
1716
steps:
1817
- uses: actions/checkout@v2
19-
- uses: actions/setup-node@v1
18+
- uses: actions/setup-node@v2
2019
with:
2120
node-version: ${{ matrix.node-version }}
2221
- run: npm install

index.d.ts

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

1412
/**
@@ -18,7 +16,7 @@ Use it for finding email addresses or checking if something is email like. [You
1816
1917
@example
2018
```
21-
import emailRegex = require('email-regex');
19+
import emailRegex from 'email-regex';
2220
2321
// Contains an email address
2422
emailRegex().test('unicorn [email protected]');
@@ -32,6 +30,4 @@ emailRegex({exact: true}).test('[email protected]');
3230
3331
```
3432
*/
35-
declare function emailRegex(options?: emailRegex.Options): RegExp;
36-
37-
export = emailRegex
33+
export default function emailRegex(options?: Options): RegExp;

index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
'use strict';
2-
31
const regex = '[^\\.\\s@:](?:[^\\s@:]*[^\\s@:\\.])?@[^\\.\\s@]+(?:\\.[^\\.\\s@]+)*';
42

5-
module.exports = ({exact} = {}) => exact ? new RegExp(`^${regex}$`) : new RegExp(regex, 'g');
3+
export default function emailRegex({exact} = {}) {
4+
return exact ? new RegExp(`^${regex}$`) : new RegExp(regex, 'g');
5+
}

index.test-d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {expectType} from 'tsd';
2-
import emailRegex = require('.');
2+
import emailRegex from './index.js';
33

44
expectType<RegExp>(emailRegex());
55
expectType<RegExp>(emailRegex({}));

license

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
3+
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
"description": "Regular expression for matching email addresses",
55
"license": "MIT",
66
"repository": "sindresorhus/email-regex",
7+
"funding": "https://github.com/sponsors/sindresorhus",
78
"author": {
89
"name": "Sindre Sorhus",
910
"email": "[email protected]",
10-
"url": "sindresorhus.com"
11+
"url": "https://sindresorhus.com"
1112
},
13+
"type": "module",
14+
"exports": "./index.js",
1215
"engines": {
13-
"node": ">=8"
16+
"node": ">=12"
1417
},
1518
"scripts": {
1619
"test": "xo && ava && tsd"
@@ -33,8 +36,8 @@
3336
"validate"
3437
],
3538
"devDependencies": {
36-
"ava": "^2.1.0",
37-
"tsd": "^0.7.3",
38-
"xo": "^0.24.0"
39+
"ava": "^3.15.0",
40+
"tsd": "^0.14.0",
41+
"xo": "^0.39.1"
3942
}
4043
}

readme.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ Use it for finding email addresses or checking if something is email like.
66

77
[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.
88

9-
109
## Install
1110

1211
```
1312
$ npm install email-regex
1413
```
1514

16-
1715
## Usage
1816

1917
```js
20-
const emailRegex = require('email-regex');
18+
import emailRegex from 'email-regex';
2119

2220
// Contains an email address
2321
emailRegex().test('unicorn [email protected]');
@@ -31,7 +29,6 @@ emailRegex({exact: true}).test('[email protected]');
3129
3230
```
3331

34-
3532
## API
3633

3734
### emailRegex(options?)
@@ -44,8 +41,9 @@ Type: `object`
4441

4542
##### exact
4643

47-
Type: `boolean`<br>
44+
Type: `boolean`\
4845
Default: `false` *(Matches any email address in a string)*
4946

50-
Only match an exact string.<br>
47+
Only match an exact string.
48+
5149
Useful with `RegExp#test` to check if a string is an email address.

test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test from 'ava';
2-
import emailRegex from '.';
2+
import emailRegex from './index.js';
33

44
const fixtures = [
55

0 commit comments

Comments
 (0)