Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ipv4 function return value #5

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "private-ip",
"version": "2.1.0",
"version": "2.1.1",
"description": "Check if IP address is private.",
"main": "index.js",
"repository": {
Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Netmask = require('netmask').Netmask
const isIp = require('is-ip')

function netmaskCheck (params) {
function ipv4Check (params) {
let privateRanges = [
'0.0.0.0/8',
'10.0.0.0/8',
Expand Down Expand Up @@ -31,6 +31,7 @@ function netmaskCheck (params) {
for (let r of privateRanges) {
if (r.contains(params)) return true
}
return false
}

function ipv6Check (params) {
Expand All @@ -51,7 +52,7 @@ function ipv6Check (params) {

export default (ip) => {
if (isIp.v4(ip) || ip.startsWith('0')) {
return netmaskCheck(ip)
return ipv4Check(ip)
}
return ipv6Check(ip)
}