@helpdotcom/is
Advanced tools
Comparing version 2.0.2 to 2.1.0
@@ -0,1 +1,5 @@ | ||
# 2017-03-02, Version 2.1.0 (Stable) | ||
* [[1451e498b3](https://git.help.com/common-backend/is/commit/1451e498b3)] - **(SEMVER-MINOR)** is: add isEmailAllowName() (Evan Lucas) [CHAT-2199](https://helpdotcom.atlassian.net/browse/CHAT-2199) | ||
# 2017-02-22, Version 2.0.2 (Stable) | ||
@@ -2,0 +6,0 @@ |
14
index.js
@@ -5,2 +5,6 @@ 'use strict' | ||
const emailRE = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[A-Za-z]{2,}$/ | ||
const EMAIL_NAME_RE = new RegExp('^[a-z\\d!#\\$%&\'\\*\\+\\-\\/=\\?\\^_"`{\\|' | ||
+ '}~\\.\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]+[a-z\\d!#\\$%&\'\\*' | ||
+ '\\+\\-\\/=\\?\\^_`{\\|}~\\.\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-' | ||
+ '\\uFFEF\\s]*<(.+)>$', 'i') | ||
const uuidRE = new RegExp('^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]' + | ||
@@ -23,2 +27,12 @@ '{3}-[89ABab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$') | ||
exports.isEmailAllowName = function isEmailAllowName(s) { | ||
if (typeof s !== 'string') return false | ||
const match = s.match(EMAIL_NAME_RE) | ||
if (match) { | ||
return exports.isEmail(match[1]) | ||
} | ||
return exports.isEmail(s) | ||
} | ||
// TODO(evanlucas) benchmark the difference between the current implementation | ||
@@ -25,0 +39,0 @@ // and using a a custom implementation. |
{ | ||
"name": "@helpdotcom/is", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"description": "isDate, isUUID, and isEmail for use with help-gen", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -37,2 +37,15 @@ # is | ||
### isEmailAllowName(s) | ||
* `s` [`<String>`][] The email string | ||
Returns `true` if `s` is a valid email address with an optional name. | ||
Otherwise, returns `false`. | ||
The following formats are supported: | ||
* `evan.lucas@help.com` | ||
* `Evan Lucas <evan.lucas@help.com>` | ||
* `"Evan Lucas" <evan.lucas@help.com>` | ||
### isUUID(s) | ||
@@ -39,0 +52,0 @@ |
10
test.js
@@ -43,2 +43,12 @@ 'use strict' | ||
test('isEmailAllowName', (t) => { | ||
const is = helpIs.isEmailAllowName | ||
t.equal(is(null), false) | ||
t.equal(is('evan@me.com'), true) | ||
t.equal(is('Evan <evan@me.com>'), true) | ||
t.equal(is('"Evan" <evan@me.com>'), true) | ||
t.equal(is('Evan <evan@me.com'), false) | ||
t.end() | ||
}) | ||
test('isUUID', (t) => { | ||
@@ -45,0 +55,0 @@ const is = helpIs.isUUID |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9110
93
64