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

insubnet

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

insubnet - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

35

insubnet.js

@@ -7,3 +7,3 @@ /*

var proto = {
version: '0.0.5',
version: '0.0.6',
Auto: function (ip, subnet, prefix) {

@@ -52,3 +52,3 @@ if (!ip || !subnet) {

__isIPv6: function (ip) {
return /^([0-9a-f]{4}|0)(\:([0-9a-f]{4}|0)){7}$/i.test(ip);
return /^([0-9a-f]{1,4})(\:([0-9a-f]{1,4})){7}$/i.test(ip);
},

@@ -106,4 +106,4 @@ isIP: function (ip) {

__Validate: function (ip) {
if (this.subnets && this.isIP(ip) && (!!(this.subnets[this.isIPv4(ip)?"ipv4":"ipv6"].length))) {
var subs = this.subnets[(this.isIPv4(ip)?"ipv4":"ipv6")];
if (this.subnets && this.isIP(ip) && (!!(this.subnets[this.isIPv4(ip)?'ipv4':'ipv6'].length))) {
var subs = this.subnets[(this.isIPv4(ip)?'ipv4':'ipv6')];
for (var num in subs) {

@@ -130,7 +130,3 @@ if (/\/(\d+){1,3}$/.test(subs[num]) && this.Auto(ip,subs[num])) {

if (/\/(\d+){1,3}$/.test(subnet)) {
try {
var split = subnet.split('/');
subnet = split[0],
prefix = split[1];
} catch (e) { }; // Handle the error!?
return subnet.split('/');
};

@@ -142,3 +138,3 @@ return [subnet,prefix];

case 6:
return this.Expand(ip).split(":").map(function(x){return parseInt(x,16)});
return this.Expand(ip).split(':').map(function(x){return parseInt(x,16)});
case 4:

@@ -149,14 +145,17 @@ default:

},
Expand: function (ip) {
Expand: function (ip, zero) {
var ip = String(ip);
if (ip.indexOf("::") != -1) {
if (ip.indexOf('::') != -1) {
if (ip.match(/::/g).length > 1) {
return false;
};
var split = ip.split("::"),
res = (split[0]+Array(9-(split[0].split(":").length+split[1].split(":").length)).join(':0000')+':'+split[1]).split(":");
var split = ip.split(/::/),
first = (!split[0]?'0':split[0]),
last = (!split[1]?'0':split[1]),
zeros = ':'+(!zero?'0000':'0'),
res = (first+Array(9-(first.split(':').length+last.split(':').length)).join(zeros)+':'+last).split(':');
};
var ip = (res||ip.split(":")).map(function (x) {
return (x.length<4?(new Array(5-x.length).join('0')+x):x);
}).join(":");
var ip = (res||ip.split(':')).map(function (x) {
return (zero?(/^0+$/.test(x)?0:x.replace(/^0+/,'')):(x.length<4?('0000'+x).slice(-4):x));
}).join(':');
return (this.__isIPv6(ip)?ip:false);

@@ -166,3 +165,3 @@ },

return Object.create(proto);
},"inSubnet");
},'inSubnet');

@@ -169,0 +168,0 @@ /*

{
"name": "insubnet",
"version": "0.0.5",
"version": "0.0.6",
"homepage": "http://louist.github.io/inSubnet/",

@@ -5,0 +5,0 @@ "author": {

@@ -1,2 +0,2 @@

inSubnet (v0.0.5)
inSubnet (v0.0.6)
======

@@ -9,2 +9,3 @@

However, if you make something interesting, I would like to check it out.
I'm also accepting pull requests.

@@ -19,3 +20,3 @@ [![Build Status](https://travis-ci.org/LouisT/inSubnet.png?branch=master)](https://travis-ci.org/LouisT/inSubnet)

inSubnet.Auto(ip, subnet[, mask]) - Check to find out if <ip> is in <subnet>. Works with IPv4 and IPv6. Returns boolean.
inSubnet.Auto(ip, subnet[, prefix length]) - Check to find out if <ip> is in <subnet>. Works with IPv4 and IPv6. Returns boolean.

@@ -26,7 +27,7 @@ Examples: inSubnet.Auto('1.2.3.4','1.2.0.0/16'); // true

inSubnet.IPv4(ip, subnet[, mask]) - Same as "Auto()" but for IPv4 only. - Returns boolean.
inSubnet.IPv4(ip, subnet[, prefix length]) - Same as "Auto()" but for IPv4 only. - Returns boolean.
Examples: See "Auto()" examples.
inSubnet.IPv6(ip, subnet[, mask]) - Same as "Auto()" but for IPv6 only. - Returns boolean.
inSubnet.IPv6(ip, subnet[, prefix length]) - Same as "Auto()" but for IPv6 only. - Returns boolean.

@@ -52,6 +53,9 @@ Examples: inSubnet.IPv6('2400:cb00::123','2400:cb00::/32'); // true

inSubnet.Expand(ipv6) - Expands an IPv6. - Returns IPv6 or false.
inSubnet.Expand(ipv6[, zero]) - Expands an IPv6.
If <zero> is true, use single zeros. - Returns IPv6 or false.
Examples: inSubnet.Expand("afd::1"); // 0afd:0000:0000:0000:0000:0000:0000:0001
inSubnet.Expand("2001:4860:4860::8888"); // 2001:4860:4860:0000:0000:0000:0000:8888
inSubnet.Expand("afd::1",true); // afd:0:0:0:0:0:0:1
inSubnet.Expand("asd::1"); // false

@@ -93,1 +97,9 @@ inSubnet.Validate(ip[, subnets]) - Check <ip> or an Array of IPs against an array of subnets set by "setSubnets()".

- [ ] Make "Exporter" better.
Functionality Requests:
------
- [ ] *Add support for IPv6 dotted notation. (::127.0.0.1) - This isn't important to me, if it is for you, fork it!
- [ ] *Add support for more IPv4 notations. (192.11010115, 3232235587) - This isn't important to me, if it is for you, fork it!
*I probably wont get to this any time soon... Sorry for those who need/want it. (Again, you can fork!)

@@ -92,3 +92,3 @@ var assert = require('assert'),

try {
assert(!inSubnet.isIPv6('asd::1'),"afd::1 should NOT be an IPv6.");
assert(!inSubnet.isIPv6('asd::1'),"asd::1 should NOT be an IPv6.");
pass++;

@@ -160,4 +160,4 @@ } catch (e) { errors.push(e.message); };

};
if (!subTests() || !arrTests() || !ipTests()) {
if ([subTests(),arrTests(),ipTests()].indexOf(false) !== -1) {
process.exit(1);
};
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