Comparing version 1.0.4 to 1.1.0
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" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
303876
9861
3
5
2
5