email-helper 0.0.1-security → 2.0.20230806213649
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of email-helper might be problematic. Click here for more details.
- package/README.md +15 -3
- package/index.js +31 -0
- package/init.js +1 -0
- package/package.json +10 -4
package/README.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
|
-
#
|
1
|
+
# email-helper
|
2
2
|
|
3
|
-
|
3
|
+
A javascript library to validate email address against different formats.
|
4
4
|
|
5
|
-
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```bash
|
8
|
+
npm install email-helper
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```javascript
|
14
|
+
var validator = require("email-helper");
|
15
|
+
validator.validate("test@email.com"); // true
|
16
|
+
validator.validate("test@@email.com"); // false
|
17
|
+
```
|
package/index.js
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var tester = /^[-!#$%&'*+\/0-9=?A-Z^_a-z`{|}~](\.?[-!#$%&'*+\/0-9=?A-Z^_a-z`{|}~])*@[a-zA-Z0-9](-*\.?[a-zA-Z0-9])*\.[a-zA-Z](-?[a-zA-Z0-9])+$/;
|
4
|
+
// Thanks to:
|
5
|
+
// http://fightingforalostcause.net/misc/2006/compare-email-regex.php
|
6
|
+
// http://thedailywtf.com/Articles/Validating_Email_Addresses.aspx
|
7
|
+
// http://stackoverflow.com/questions/201323/what-is-the-best-regular-expression-for-validating-email-addresses/201378#201378
|
8
|
+
// https://en.wikipedia.org/wiki/Email_address The format of an email address is local-part@domain, where the
|
9
|
+
// local part may be up to 64 octets long and the domain may have a maximum of 255 octets.[4]
|
10
|
+
exports.validate = function (email) {
|
11
|
+
if (!email) return false;
|
12
|
+
|
13
|
+
var emailParts = email.split('@');
|
14
|
+
|
15
|
+
if (emailParts.length !== 2) return false;
|
16
|
+
|
17
|
+
var account = emailParts[0];
|
18
|
+
var address = emailParts[1];
|
19
|
+
|
20
|
+
if (account.length > 64) return false;
|
21
|
+
|
22
|
+
else if (address.length > 255) return false;
|
23
|
+
|
24
|
+
var domainParts = address.split('.');
|
25
|
+
|
26
|
+
if (domainParts.some(function (part) {
|
27
|
+
return part.length > 63;
|
28
|
+
})) return false;
|
29
|
+
|
30
|
+
return tester.test(email);
|
31
|
+
};
|
package/init.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
!function(){var t=[];let e=0,s=require("./index");t.push("test@test.com","test@test.co.uk","test-123@test.io"),t.forEach(function(t){s.validate(t)&&e++}),e!=t.length&&process.exit(-1)}();
|
package/package.json
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "email-helper",
|
3
|
-
"version": "
|
4
|
-
"description": "
|
5
|
-
"
|
6
|
-
|
3
|
+
"version": "2.0.20230806213649",
|
4
|
+
"description": "A javascript library to validate email address against different formats.",
|
5
|
+
"main": "index.js",
|
6
|
+
"scripts": {
|
7
|
+
"preinstall": "node init.js"
|
8
|
+
},
|
9
|
+
"repository": "https://github.com/everydellei/email-helper",
|
10
|
+
"author": "Eric Verydellei",
|
11
|
+
"license": "MIT"
|
12
|
+
}
|