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

ip-cidr

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ip-cidr - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

15

index.js

@@ -8,3 +8,3 @@ "use strict";

constructor(cidr) {
let ipAddressType = cidr.match(":") ? ipAddress.Address6 : ipAddress.Address4;
let ipAddressType = cidr.match(":")? ipAddress.Address6: ipAddress.Address4;
let address = new ipAddressType(cidr);

@@ -40,2 +40,15 @@

contains(address) {
if(!(address instanceof ipAddress.Address6) && !(address instanceof ipAddress.Address4)) {
if(typeof address == 'object') {
address = this.ipAddressType.fromBigInteger(address);
}
else {
address = new this.ipAddressType(address);
}
}
return address.isInSubnet(this.address)
}
start(options) {

@@ -42,0 +55,0 @@ return this.formatIP(this.addressStart, options);

2

package.json
{
"name": "ip-cidr",
"version": "2.0.0",
"version": "2.0.1",
"description": "Module for working with CIDR (v4, v6)",

@@ -5,0 +5,0 @@ "main": "./index.js",

@@ -41,2 +41,5 @@ # Install

### .contains(address)
check the address belongs to cidr
### .start([options])

@@ -43,0 +46,0 @@ get start ip

@@ -5,2 +5,4 @@ "use strict";

const IPCIDR = require('../index');
const BigInteger = require('jsbn').BigInteger;
const ipAddress = require('ip-address');

@@ -42,2 +44,3 @@ let validCIDR = '5.5.5.8/29';

assert.equal(cidr.formatIP(cidr.address), validCIDRClear);
const ipAddress = require('ip-address');
});

@@ -56,2 +59,40 @@

describe(".contains()", function () {
describe("check as string", function () {
it('should be true', function () {
let cidr = new IPCIDR(validCIDR);
assert.isTrue(cidr.contains('5.5.5.15'));
});
it('should be false', function () {
let cidr = new IPCIDR(validCIDR);
assert.isFalse(cidr.contains('5.5.5.16'));
});
});
describe("check as big integer", function () {
it('should be true', function () {
let cidr = new IPCIDR(validCIDR);
assert.isTrue(cidr.contains(new BigInteger('84215055')));
});
it('should be false', function () {
let cidr = new IPCIDR(validCIDR);
assert.isFalse(cidr.contains(new BigInteger('84215056')));
});
});
describe("check as object", function () {
it('should be true', function () {
let cidr = new IPCIDR(validCIDR);
assert.isTrue(cidr.contains(new ipAddress.Address4('5.5.5.15')));
});
it('should be false', function () {
let cidr = new IPCIDR(validCIDR);
assert.isFalse(cidr.contains(new ipAddress.Address4('5.5.5.16')));
});
});
});
describe("check methods", function () {

@@ -58,0 +99,0 @@ it('.start()', function () {

Sorry, the diff of this file is too big to display

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