Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cidr-tools

Package Overview
Dependencies
Maintainers
1
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cidr-tools - npm Package Compare versions

Comparing version 7.0.4 to 7.0.5

36

index.js
import {parseIp, stringifyIp, normalizeIp, ipVersion} from "ip-bigint";
const bits = {
4: 32,
6: 128,
};
const bits = {4: 32, 6: 128};
const uniq = arr => Array.from(new Set(arr));

@@ -44,3 +40,2 @@ const cidrVersion = cidr => cidr.includes("/") ? ipVersion(cidr) : 0;

const parsed = Object.create(null);
parsed.single = false;

@@ -55,3 +50,2 @@ if (cidrVer) {

parsed.version = version;
parsed.single = true;
} else {

@@ -64,2 +58,3 @@ throw new Error(`Network is not a CIDR or IP: ${str}`);

parsed.prefix = prefix;
parsed.single = prefix === String(bits[parsed.version]);
const {number, version} = parseIp(ip);

@@ -229,9 +224,6 @@ const numBits = bits[version];

function formatPart(part, v) {
const ip = normalize(stringifyIp({
number: BigInt(part.start.toString()),
version: v,
}));
function formatPart(part, version) {
const ip = normalize(stringifyIp({number: BigInt(part.start.toString()), version}));
const zeroes = diff(part.end, part.start).toString(2);
const prefix = bits[v] - (zeroes.match(/0/g) || []).length;
const prefix = bits[version] - (zeroes.match(/0/g) || []).length;
return `${ip}/${prefix}`;

@@ -242,16 +234,16 @@ }

const maps = {4: {}, 6: {}};
for (const {start, end, version: v} of nets) {
if (!maps[v][start]) maps[v][start] = {};
if (!maps[v][end]) maps[v][end] = {};
for (const {start, end, version} of nets) {
if (!maps[version][start]) maps[version][start] = {};
if (!maps[version][end]) maps[version][end] = {};
if (maps[v][start].start) {
maps[v][start].start += 1;
if (maps[version][start].start) {
maps[version][start].start += 1;
} else {
maps[v][start].start = 1;
maps[version][start].start = 1;
}
if (maps[v][end].end) {
maps[v][end].end += 1;
if (maps[version][end].end) {
maps[version][end].end += 1;
} else {
maps[v][end].end = 1;
maps[version][end].end = 1;
}

@@ -258,0 +250,0 @@ }

{
"name": "cidr-tools",
"version": "7.0.4",
"version": "7.0.5",
"author": "silverwind <me@silverwind.io>",

@@ -21,13 +21,13 @@ "description": "Tools to work with IPv4 and IPv6 CIDR",

"dependencies": {
"ip-bigint": "^8.0.1"
"ip-bigint": "^8.0.2"
},
"devDependencies": {
"eslint": "8.54.0",
"eslint-config-silverwind": "79.3.5",
"tsd": "0.29.0",
"updates": "15.0.4",
"versions": "12.0.0",
"vitest": "0.34.6",
"vitest-config-silverwind": "3.0.0"
"eslint": "8.56.0",
"eslint-config-silverwind": "80.0.3",
"tsd": "0.30.4",
"updates": "15.1.2",
"versions": "12.0.1",
"vitest": "1.2.2",
"vitest-config-silverwind": "5.1.1"
}
}

@@ -74,11 +74,11 @@ # cidr-tools

Returns a `parsed` Object which is used internally by this module. It can be used to test whether the passed network is IPv4 or IPv6 or work with the BigInts directly.
Returns a `parsed` Object which is used internally by this module. It can be used to test whether the passed network is IPv4 or IPv6 or to work with the BigInts directly.
`parsed`: `Object`
- `cidr` String: The CIDR of the network.
- `version` Number: Either `4` or `6`.
- `version` Number: IP protocol version. Either `4` or `6`.
- `prefix` String: The network prefix, e.g. `/64`.
- `start` BigInt: Start of the network.
- `end` BigInt: Start of the network.
- `single` Boolean: `true` when is a single IP.
- `single` Boolean: `true` when the network is a single IP.

@@ -85,0 +85,0 @@ ## Related

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc