-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
42 additions
and
2,394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- stable | ||
- '10' | ||
- '12' | ||
- '13' | ||
- '14' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
import ipaddr from 'ipaddr.js' | ||
import {IPv4, IPv6, IPv6Exception} from './cidrs' | ||
import {IPv4, IPv6, IPv6Exception} from './cidrs.js' | ||
|
||
function parseCIDR(cidr) { | ||
return ipaddr.parseCIDR(cidr) | ||
} | ||
|
||
let IPv4Subnets = IPv4.map(parseCIDR) | ||
let IPv6Subnets = IPv6.map(parseCIDR) | ||
let exceptionalSubnet = parseCIDR(IPv6Exception) | ||
const IPv4Subnets = IPv4.map(parseCIDR) | ||
const IPv6Subnets = IPv6.map(parseCIDR) | ||
const exceptionalSubnet = parseCIDR(IPv6Exception) | ||
|
||
export default function isMartianIP(ip) { | ||
if (!ipaddr.isValid(ip)) { | ||
throw new Error(`Expected valid IP address, called with "${ip}"`) | ||
} | ||
let parsedIP = ipaddr.parse(ip) | ||
|
||
const parsedIP = ipaddr.parse(ip) | ||
function matchIP(subnet) { | ||
return parsedIP.match(subnet) | ||
} | ||
|
||
if (ipaddr.IPv4.isIPv4(ip)) { | ||
return IPv4Subnets.some(matchIP) | ||
} | ||
|
||
return IPv6Subnets.some(matchIP) && !parsedIP.match(exceptionalSubnet) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.