@helpdotcom/is
Advanced tools
Comparing version 2.2.0 to 2.2.1
@@ -0,1 +1,5 @@ | ||
# 2017-05-17, Version 2.2.1 (Stable) | ||
* [[977aec635a](https://git.help.com/common-backend/is/commit/977aec635a)] - index: add isIp() (Christy Leung) [CHAT-2328](https://helpdotcom.atlassian.net/browse/CHAT-2328) | ||
# 2017-04-19, Version 2.2.0 (Stable) | ||
@@ -2,0 +6,0 @@ |
11
index.js
@@ -5,2 +5,4 @@ 'use strict' | ||
const tld = require('tldjs') | ||
const net = require('net') | ||
const ipAddress = require('ip-address') | ||
const emailRE = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[A-Za-z]{2,}$/ | ||
@@ -59,1 +61,10 @@ const EMAIL_NAME_RE = new RegExp( | ||
} | ||
exports.isIp = function isIp(s) { | ||
if (typeof s !== 'string') return false | ||
if (net.isIP(s) !== 0) return true | ||
const IpAddressType = s.indexOf(':') > -1 | ||
? ipAddress.Address6 : ipAddress.Address4 | ||
const address = new IpAddressType(s) | ||
return address.isValid() | ||
} |
{ | ||
"name": "@helpdotcom/is", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "isDate, isUUID, and isEmail for use with help-gen", | ||
@@ -14,2 +14,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"ip-address": "~5.8.8", | ||
"tldjs": "~1.6.2" | ||
@@ -16,0 +17,0 @@ }, |
@@ -65,3 +65,9 @@ # is | ||
### isIp(s) | ||
* `s` [`<String>`][] The url to test. | ||
Returns `true` if `s` is a valid ip. Otherwise, returns `false`. | ||
## Author | ||
@@ -68,0 +74,0 @@ |
17
test.js
@@ -92,1 +92,18 @@ 'use strict' | ||
}) | ||
test('isIp', (t) => { | ||
const is = helpIs.isIp | ||
t.equal(is('172.0.0.1'), true) | ||
t.equal(is('0.0.0.0'), true) | ||
t.equal(is('2001:0db8:85a3:0000:0000:8a2e:0370:7334'), true) | ||
t.equal(is('192.168.100.0/22'), true) | ||
t.equal(is('172.255.255.255'), true) | ||
t.equal(is('10.0.0.0'), true) | ||
t.equal(is('173.a.0.0'), false) | ||
t.equal(is('204.0.113.4255'), false) | ||
t.equal(is('hellohello'), false) | ||
t.equal(is(' '), false) | ||
t.equal(is('SELECT\0x33:~;_-\\\\'), false) | ||
t.equal(is(1234), false) | ||
t.end() | ||
}) |
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
Network access
Supply chain riskThis module accesses the network.
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
13083
159
79
2
1
+ Addedip-address@~5.8.8
+ Addedip-address@5.8.9(transitive)
+ Addedjsbn@1.1.0(transitive)
+ Addedlodash.find@4.6.0(transitive)
+ Addedlodash.max@4.0.1(transitive)
+ Addedlodash.merge@4.6.2(transitive)
+ Addedlodash.padstart@4.6.1(transitive)
+ Addedlodash.repeat@4.1.0(transitive)
+ Addedsprintf-js@1.1.0(transitive)