@helpdotcom/is
Advanced tools
Comparing version 2.2.1 to 3.0.0
@@ -0,1 +1,5 @@ | ||
# 2017-05-23, Version 3.0.0 (Stable) | ||
* [[34ce49f5c8](https://git.help.com/common-backend/is/commit/34ce49f5c8)] - **(SEMVER-MAJOR)** index: added isIpAllowCIDR() (Christy Leung) [CHAT-2328](https://helpdotcom.atlassian.net/browse/CHAT-2328) | ||
# 2017-05-17, Version 2.2.1 (Stable) | ||
@@ -2,0 +6,0 @@ |
@@ -5,3 +5,2 @@ 'use strict' | ||
const tld = require('tldjs') | ||
const net = require('net') | ||
const ipAddress = require('ip-address') | ||
@@ -14,2 +13,3 @@ const emailRE = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[A-Za-z]{2,}$/ | ||
) | ||
const uuidRE = new RegExp('^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]' + | ||
@@ -63,9 +63,9 @@ '{3}-[89ABab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$') | ||
exports.isIp = function isIp(s) { | ||
exports.isIpAllowCIDR = function isIpAllowCIDR(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.1", | ||
"version": "3.0.0", | ||
"description": "isDate, isUUID, and isEmail for use with help-gen", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -65,7 +65,7 @@ # is | ||
### isIp(s) | ||
### isIpAllowCIDR(s) | ||
* `s` [`<String>`][] The url to test. | ||
Returns `true` if `s` is a valid ip. Otherwise, returns `false`. | ||
Returns `true` if `s` is a valid ip with CIDR notation. Otherwise, returns `false`. | ||
@@ -72,0 +72,0 @@ |
18
test.js
@@ -93,14 +93,16 @@ '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) | ||
test('isIpAllowCIDR', (t) => { | ||
const is = helpIs.isIpAllowCIDR | ||
t.equal(is('127.0.0.1/32'), true) | ||
t.equal(is('2001:db8:abcd:8000::/50'), true) | ||
t.equal(is('127.0.0.1/24'), 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('127.0.0.1/12'), true) | ||
t.equal(is('127.0.0.1/8'), true) | ||
t.equal(is('10.a.0.0'), false) | ||
t.equal(is('204.0.113.4255'), false) | ||
t.equal(is('hellohello'), false) | ||
t.equal(is('69.89.31.226'), true) | ||
t.equal(is(' '), false) | ||
t.equal(is('2002:4559:1FE2::4559:1FE2'), true) | ||
t.equal(is('SELECT\0x33:~;_-\\\\'), false) | ||
@@ -107,0 +109,0 @@ t.equal(is(1234), false) |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
13404
0