cidr-tools
Advanced tools
Comparing version 6.4.2 to 7.0.0
29
index.js
@@ -1,5 +0,3 @@ | ||
import ipRegex from "ip-regex"; | ||
import cidrRegex from "cidr-regex"; | ||
import {parseIp, stringifyIp, normalizeIp, ipVersion} from "ip-bigint"; | ||
import naturalCompare from "string-natural-compare"; | ||
import {parseIp, stringifyIp, normalizeIp} from "ip-bigint"; | ||
@@ -12,15 +10,4 @@ const bits = { | ||
const uniq = arr => Array.from(new Set(arr)); | ||
const cidrVersion = cidr => cidr.includes("/") ? ipVersion(cidr) : 0; | ||
export function isIP(ip) { | ||
if (ipRegex.v4({exact: true}).test(ip)) return 4; | ||
if (ipRegex.v6({exact: true}).test(ip)) return 6; | ||
return 0; | ||
} | ||
function isCidr(ip) { | ||
if (cidrRegex.v4({exact: true}).test(ip)) return 4; | ||
if (cidrRegex.v6({exact: true}).test(ip)) return 6; | ||
return 0; | ||
} | ||
function doNormalize(cidr, {compress = true, hexify = false} = {}) { | ||
@@ -46,11 +33,11 @@ const {start, prefix, single, version} = parse(cidr); | ||
export function parse(str) { | ||
const cidrVersion = isCidr(str); | ||
const cidrVer = cidrVersion(str); | ||
const parsed = Object.create(null); | ||
parsed.single = false; | ||
if (cidrVersion) { | ||
if (cidrVer) { | ||
parsed.cidr = str; | ||
parsed.version = cidrVersion; | ||
parsed.version = cidrVer; | ||
} else { | ||
const version = isIP(str); | ||
const version = ipVersion(str); | ||
if (version) { | ||
@@ -315,7 +302,7 @@ parsed.cidr = `${str}/${bits[version]}`; | ||
for (const basenet of basenets) { | ||
bases[isCidr(basenet)].push(basenet); | ||
bases[cidrVersion(basenet)].push(basenet); | ||
} | ||
for (const exclnet of exclnets) { | ||
excls[isCidr(exclnet)].push(exclnet); | ||
excls[cidrVersion(exclnet)].push(exclnet); | ||
} | ||
@@ -322,0 +309,0 @@ |
{ | ||
"name": "cidr-tools", | ||
"version": "6.4.2", | ||
"version": "7.0.0", | ||
"author": "silverwind <me@silverwind.io>", | ||
@@ -14,3 +14,3 @@ "description": "Tools to work with IPv4 and IPv6 CIDR", | ||
"engines": { | ||
"node": ">=16" | ||
"node": ">=18" | ||
}, | ||
@@ -22,5 +22,3 @@ "files": [ | ||
"dependencies": { | ||
"cidr-regex": "4.0.3", | ||
"ip-bigint": "7.3.0", | ||
"ip-regex": "5.0.0", | ||
"string-natural-compare": "3.0.1" | ||
@@ -30,3 +28,3 @@ }, | ||
"eslint": "8.49.0", | ||
"eslint-config-silverwind": "74.1.4", | ||
"eslint-config-silverwind": "75.0.6", | ||
"tsd": "0.29.0", | ||
@@ -33,0 +31,0 @@ "updates": "15.0.2", |
@@ -23,2 +23,4 @@ # cidr-tools | ||
It is expected that the passed CIDRs and IPs are validated as the module's own input validation is rudimentary. You are encouraged to use modules like [is-cidr](https://github.com/silverwind/is-cidr) and [is-ip](https://github.com/sindresorhus/is-ip) to validate before passing to this module. | ||
This module requires [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#browser_compatibility) support in your environment. | ||
@@ -25,0 +27,0 @@ |
2
86
15318
362
- Removedcidr-regex@4.0.3
- Removedip-regex@5.0.0
- Removedcidr-regex@4.0.3(transitive)
- Removedip-regex@5.0.0(transitive)