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 1.0.4 to 1.1.0

dist/ip-cidr.js

145

ip-cidr.js

@@ -1,144 +0,1 @@

"use strict";
const ipAddress = require('ip-address');
const BigInteger = require('jsbn').BigInteger;
class IPCIDR {
constructor(cidr) {
let ipAddressType = cidr.match(":") ? ipAddress.Address6 : ipAddress.Address4;
let address = new ipAddressType(cidr);
this._isValid = address.isValid();
if (this._isValid) {
this.cidr = cidr;
this.ipAddressType = ipAddressType;
this.address = address;
this.addressStart = address.startAddress();
this.addressEnd = address.endAddress();
}
}
isValid() {
return this._isValid;
}
formatIP(address, options) {
options = options || {};
if (options.asBigInteger) {
return address.bigInteger();
}
else if (options.asAddressObject) {
return address;
}
return address.addressMinusSuffix;
}
start(options) {
return this.formatIP(this.addressStart, options);
}
end(options) {
return this.formatIP(this.addressEnd, options);
}
toString() {
return this.cidr;
}
toRange(options) {
return [this.formatIP(this.addressStart, options), this.formatIP(this.addressEnd, options)];
}
toObject(options) {
return {
start: this.formatIP(this.addressStart, options),
end: this.formatIP(this.addressEnd, options)
};
}
toArray(options, results) {
options = options || {};
let list = [];
let start = this.addressStart.bigInteger();
let end = this.addressEnd.bigInteger();
let length = end.subtract(start).add(new BigInteger('1'));
let info = this.getChunkInfo(length, options);
if(results) {
Object.assign(results, info);
}
for (let i = info.from; i < info.to; i++) {
let num = start.add(new BigInteger(i + ''));
let ip = this.formatIP(this.ipAddressType.fromBigInteger(num), options);
list.push(ip);
}
return list;
}
arrayAction(fn, options, results) {
options = options || {};
let promise = [];
let start = this.addressStart.bigInteger();
let end = this.addressEnd.bigInteger();
let length = end.subtract(start).add(new BigInteger('1'));
let info = this.getChunkInfo(length, options);
if(results) {
Object.assign(results, info);
}
for (let i = info.from; i < info.to; i++) {
let num = start.add(new BigInteger(i + ''));
let ip = this.formatIP(this.ipAddressType.fromBigInteger(num), options);
promise.push(fn(ip));
}
return Promise.all(promise);
}
getChunkInfo(length, options) {
let from, limit, to;
if(options.from !== undefined) {
if(typeof options.from != 'object') {
from = new BigInteger(options.from + '');
}
}
else {
from = new BigInteger('0');
}
if(options.limit !== undefined) {
if(typeof options.limit != 'object') {
limit = new BigInteger(options.limit + '');
}
}
else {
limit = length;
}
if(limit.compareTo(length) > 0) {
limit = length.subtract(from);
}
to = from.add(limit);
return {
from: from,
to: to,
limit: limit,
length: length
}
}
}
module.exports = IPCIDR;
window.IPCIDR = require('./index');
{
"name": "ip-cidr",
"version": "1.0.4",
"version": "1.1.0",
"description": "Module for working with CIDR (v4, v6)",
"main": "./ip-cidr.js",
"main": "./index.js",
"author": {

@@ -20,3 +20,4 @@ "name": "Balasyan Alexandr",

"scripts": {
"test": "mocha"
"test": "mocha",
"build": "browserify ./ip-cidr.js > ./dist/ip-cidr.js"
},

@@ -28,2 +29,3 @@ "dependencies": {

"devDependencies": {
"browserify": "^14.4.0",
"mocha": "^3.2.0",

@@ -30,0 +32,0 @@ "chai": "^3.5.0"

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