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

ipaddr.js

Package Overview
Dependencies
Maintainers
0
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ipaddr.js - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

2

ipaddr.min.js

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

(function(){var a,b,c,d,e,f,g,h;b={},h=this,typeof module!="undefined"&&module!==null&&module.exports?module.exports=b:h.ipaddr=b,g=function(a,b,c,d){var e,f;if(a.length!==b.length)throw new Error("ipaddr: cannot match CIDR for objects with different lengths");e=0;while(d>0){f=c-d,f<0&&(f=0);if(a[e]>>f!==b[e]>>f)return!1;d-=c,e+=1}return!0},b.subnetMatch=function(a,b,c){var d,e,f,g,h;c==null&&(c="unicast");for(d in b){e=b[d],toString.call(e[0])!=="[object Array]"&&(e=[e]);for(g=0,h=e.length;g<h;g++){f=e[g];if(a.match.apply(a,f))return d}}return c},b.IPv4=function(){function a(a){var b,c,d;if(a.length!==4)throw new Error("ipaddr: ipv4 octet count should be 4");for(c=0,d=a.length;c<d;c++){b=a[c];if(!(0<=b&&b<=255))throw new Error("ipaddr: ipv4 octet is a byte")}this.octets=a}a.prototype.kind=function(){return"ipv4"},a.prototype.toString=function(){return this.octets.join(".")},a.prototype.match=function(a,b){if(a.kind()!=="ipv4")throw new Error("ipaddr: cannot match ipv4 address with non-ipv4 one");return g(this.octets,a.octets,8,b)},a.prototype.SpecialRanges={broadcast:[[new a([255,255,255,255]),32]],multicast:[[new a([224,0,0,0]),4]],linkLocal:[[new a([169,254,0,0]),16]],loopback:[[new a([127,0,0,0]),8]],"private":[[new a([10,0,0,0]),8],[new a([172,16,0,0]),12],[new a([192,168,0,0]),16]],reserved:[[new a([192,0,0,0]),24],[new a([192,0,2,0]),24],[new a([192,88,99,0]),24],[new a([198,51,100,0]),24],[new a([203,0,113,0]),24],[new a([240,0,0,0]),4]]},a.prototype.range=function(){return b.subnetMatch(this,this.SpecialRanges)},a.prototype.toIPv4MappedAddress=function(){return b.IPv6.parse("::ffff:"+this.toString())};return a}(),c="(0?\\d+|0x[a-f0-9]+)",d={fourOctet:new RegExp("^"+c+"\\."+c+"\\."+c+"\\."+c+"$","i"),longValue:new RegExp("^"+c+"$","i")},b.IPv4.parser=function(a){var b,c,e,f,g,h,i,j;if(b=a.match(d.fourOctet)){i=b.slice(1,6),j=[];for(g=0,h=i.length;g<h;g++)c=i[g],j.push(parseInt(c));return j}if(b=a.match(d.longValue)){f=parseInt(b[1]);return function(){var a,b;a=[];for(e=0,b=8;e<=24;e+=b)a.push(f>>e&255);return a}().reverse()}return null},b.IPv6=function(){function a(a){var b,c,d;if(a.length!==8)throw new Error("ipaddr: ipv6 part count should be 8");for(c=0,d=a.length;c<d;c++){b=a[c];if(!(0<=b&&b<=65535))throw new Error("ipaddr: ipv6 part should fit to two octets")}this.parts=a}a.prototype.kind=function(){return"ipv6"},a.prototype.toString=function(){var a,b,c,d,e,f,g;e=function(){var a,c,d,e;d=this.parts,e=[];for(a=0,c=d.length;a<c;a++)b=d[a],e.push(b.toString(16));return e}.call(this),a=[],c=function(b){return a.push(b)},d=0;for(f=0,g=e.length;f<g;f++){b=e[f];switch(d){case 0:b==="0"?d=1:c(b);break;case 1:b!=="0"&&(c(""),c(b),d=2);break;case 2:c(b)}}d===""&&c("");return a.join(":")},a.prototype.toNormalizedString=function(){var a;return function(){var b,c,d,e;d=this.parts,e=[];for(b=0,c=d.length;b<c;b++)a=d[b],e.push(a.toString(16));return e}.call(this).join(":")},a.prototype.match=function(a,b){if(a.kind()!=="ipv6")throw new Error("ipaddr: cannot match ipv6 address with non-ipv6 one");return g(this.parts,a.parts,16,b)},a.prototype.SpecialRanges={unspecified:[new a([0,0,0,0,0,0,0,0]),128],linkLocal:[new a([65152,0,0,0,0,0,0,0]),10],multicast:[new a([65280,0,0,0,0,0,0,0]),8],loopback:[new a([0,0,0,0,0,0,0,1]),128],uniqueLocal:[new a([64512,0,0,0,0,0,0,0]),7],ipv4Mapped:[new a([0,0,0,0,0,65535,0,0]),96],rfc6145:[new a([0,0,0,0,65535,0,0,0]),96],rfc6052:[new a([100,65435,0,0,0,0,0,0]),96],"6to4":[new a([8194,0,0,0,0,0,0,0]),16],teredo:[new a([8193,0,0,0,0,0,0,0]),32],reserved:[[new a([8193,3512,0,0,0,0,0,0]),32]]},a.prototype.range=function(){return b.subnetMatch(this,this.SpecialRanges)},a.prototype.isIPv4MappedAddress=function(){return this.range()==="ipv4Mapped"},a.prototype.toIPv4Address=function(){var a,c,d;if(!this.isIPv4MappedAddress())throw new Error("ipaddr: trying to convert a generic ipv6 address to ipv4");d=this.parts.slice(-2),a=d[0],c=d[1];return new b.IPv4([a>>8,a&255,c>>8,c&255])};return a}(),e="(?:[0-9a-f]+::?)+",f={"native":new RegExp("^(::)?("+e+")?([0-9a-f]+)?(::)?$","i"),transitional:new RegExp("^((?:"+e+")|(?:::)(?:"+e+")?)"+(""+c+"\\."+c+"\\."+c+"\\."+c+"$"),"i")},a=function(a,b){var c,d,e,f,g,h,i,j,k;if(a.indexOf("::")!==a.lastIndexOf("::"))return null;c=0,d=-1;while((d=a.indexOf(":",d+1))>=0)c++;a[0]===":"&&c--,a[a.length-1]===":"&&c--,g=b-c,f=":";while(g--)f+="0:";a=a.replace("::",f),a[0]===":"&&(a=a.slice(1)),a[a.length-1]===":"&&(a=a.slice(0,-1)),j=a.split(":"),k=[];for(h=0,i=j.length;h<i;h++)e=j[h],k.push(parseInt(e,16));return k},b.IPv6.parser=function(b){var c,d;if(b.match(f["native"]))return a(b,8);if(c=b.match(f.transitional)){d=a(c[1].slice(0,-1),6);if(d){d.push(parseInt(c[2])<<8|parseInt(c[3])),d.push(parseInt(c[4])<<8|parseInt(c[5]));return d}}return null},b.IPv4.isIPv4=b.IPv6.isIPv6=function(a){return this.parser(a)!==null},b.IPv4.isValid=b.IPv6.isValid=function(a){try{new this(this.parser(a));return!0}catch(b){return!1}},b.IPv4.parse=b.IPv6.parse=function(a){var b;b=this.parser(a);if(b===null)throw new Error("ipaddr: string is not formatted like ip address");return new this(b)},b.isValid=function(a){return b.IPv6.isValid(a)||b.IPv4.isValid(a)},b.parse=function(a){if(b.IPv6.isIPv6(a))return b.IPv6.parse(a);if(b.IPv4.isIPv4(a))return b.IPv4.parse(a);throw new Error("ipaddr: the address has neither IPv6 nor IPv4 format")},b.process=function(a){var b;b=this.parse(a);return b.kind()==="ipv6"&&b.isIPv4MappedAddress()?b.toIPv4Address():b}}).call(this)
(function(){var a,b,c,d,e,f,g,h;b={},h=this,typeof module!="undefined"&&module!==null&&module.exports?module.exports=b:h.ipaddr=b,g=function(a,b,c,d){var e,f;if(a.length!==b.length)throw new Error("ipaddr: cannot match CIDR for objects with different lengths");e=0;while(d>0){f=c-d,f<0&&(f=0);if(a[e]>>f!==b[e]>>f)return!1;d-=c,e+=1}return!0},b.subnetMatch=function(a,b,c){var d,e,f,g,h;c==null&&(c="unicast");for(d in b){e=b[d],toString.call(e[0])!=="[object Array]"&&(e=[e]);for(g=0,h=e.length;g<h;g++){f=e[g];if(a.match.apply(a,f))return d}}return c},b.IPv4=function(){function a(a){var b,c,d;if(a.length!==4)throw new Error("ipaddr: ipv4 octet count should be 4");for(c=0,d=a.length;c<d;c++){b=a[c];if(!(0<=b&&b<=255))throw new Error("ipaddr: ipv4 octet is a byte")}this.octets=a}a.prototype.kind=function(){return"ipv4"},a.prototype.toString=function(){return this.octets.join(".")},a.prototype.toByteArray=function(){return this.octets.slice(0)},a.prototype.match=function(a,b){if(a.kind()!=="ipv4")throw new Error("ipaddr: cannot match ipv4 address with non-ipv4 one");return g(this.octets,a.octets,8,b)},a.prototype.SpecialRanges={broadcast:[[new a([255,255,255,255]),32]],multicast:[[new a([224,0,0,0]),4]],linkLocal:[[new a([169,254,0,0]),16]],loopback:[[new a([127,0,0,0]),8]],"private":[[new a([10,0,0,0]),8],[new a([172,16,0,0]),12],[new a([192,168,0,0]),16]],reserved:[[new a([192,0,0,0]),24],[new a([192,0,2,0]),24],[new a([192,88,99,0]),24],[new a([198,51,100,0]),24],[new a([203,0,113,0]),24],[new a([240,0,0,0]),4]]},a.prototype.range=function(){return b.subnetMatch(this,this.SpecialRanges)},a.prototype.toIPv4MappedAddress=function(){return b.IPv6.parse("::ffff:"+this.toString())};return a}(),c="(0?\\d+|0x[a-f0-9]+)",d={fourOctet:new RegExp("^"+c+"\\."+c+"\\."+c+"\\."+c+"$","i"),longValue:new RegExp("^"+c+"$","i")},b.IPv4.parser=function(a){var b,c,e,f,g,h,i,j;if(b=a.match(d.fourOctet)){i=b.slice(1,6),j=[];for(g=0,h=i.length;g<h;g++)c=i[g],j.push(parseInt(c));return j}if(b=a.match(d.longValue)){f=parseInt(b[1]);return function(){var a,b;a=[];for(e=0,b=8;e<=24;e+=b)a.push(f>>e&255);return a}().reverse()}return null},b.IPv6=function(){function a(a){var b,c,d;if(a.length!==8)throw new Error("ipaddr: ipv6 part count should be 8");for(c=0,d=a.length;c<d;c++){b=a[c];if(!(0<=b&&b<=65535))throw new Error("ipaddr: ipv6 part should fit to two octets")}this.parts=a}a.prototype.kind=function(){return"ipv6"},a.prototype.toString=function(){var a,b,c,d,e,f,g;e=function(){var a,c,d,e;d=this.parts,e=[];for(a=0,c=d.length;a<c;a++)b=d[a],e.push(b.toString(16));return e}.call(this),a=[],c=function(b){return a.push(b)},d=0;for(f=0,g=e.length;f<g;f++){b=e[f];switch(d){case 0:b==="0"?c(""):c(b),d=1;break;case 1:b==="0"?d=2:c(b);break;case 2:b!=="0"&&(c(""),c(b),d=3);break;case 3:c(b)}}d===2&&(c(""),c(""));return a.join(":")},a.prototype.toByteArray=function(){var a,b,c,d,e;a=[],e=this.parts;for(c=0,d=e.length;c<d;c++)b=e[c],a.push(b>>8),a.push(b&255);return a},a.prototype.toNormalizedString=function(){var a;return function(){var b,c,d,e;d=this.parts,e=[];for(b=0,c=d.length;b<c;b++)a=d[b],e.push(a.toString(16));return e}.call(this).join(":")},a.prototype.match=function(a,b){if(a.kind()!=="ipv6")throw new Error("ipaddr: cannot match ipv6 address with non-ipv6 one");return g(this.parts,a.parts,16,b)},a.prototype.SpecialRanges={unspecified:[new a([0,0,0,0,0,0,0,0]),128],linkLocal:[new a([65152,0,0,0,0,0,0,0]),10],multicast:[new a([65280,0,0,0,0,0,0,0]),8],loopback:[new a([0,0,0,0,0,0,0,1]),128],uniqueLocal:[new a([64512,0,0,0,0,0,0,0]),7],ipv4Mapped:[new a([0,0,0,0,0,65535,0,0]),96],rfc6145:[new a([0,0,0,0,65535,0,0,0]),96],rfc6052:[new a([100,65435,0,0,0,0,0,0]),96],"6to4":[new a([8194,0,0,0,0,0,0,0]),16],teredo:[new a([8193,0,0,0,0,0,0,0]),32],reserved:[[new a([8193,3512,0,0,0,0,0,0]),32]]},a.prototype.range=function(){return b.subnetMatch(this,this.SpecialRanges)},a.prototype.isIPv4MappedAddress=function(){return this.range()==="ipv4Mapped"},a.prototype.toIPv4Address=function(){var a,c,d;if(!this.isIPv4MappedAddress())throw new Error("ipaddr: trying to convert a generic ipv6 address to ipv4");d=this.parts.slice(-2),a=d[0],c=d[1];return new b.IPv4([a>>8,a&255,c>>8,c&255])};return a}(),e="(?:[0-9a-f]+::?)+",f={"native":new RegExp("^(::)?("+e+")?([0-9a-f]+)?(::)?$","i"),transitional:new RegExp("^((?:"+e+")|(?:::)(?:"+e+")?)"+(""+c+"\\."+c+"\\."+c+"\\."+c+"$"),"i")},a=function(a,b){var c,d,e,f,g,h,i,j,k;if(a.indexOf("::")!==a.lastIndexOf("::"))return null;c=0,d=-1;while((d=a.indexOf(":",d+1))>=0)c++;a[0]===":"&&c--,a[a.length-1]===":"&&c--,g=b-c,f=":";while(g--)f+="0:";a=a.replace("::",f),a[0]===":"&&(a=a.slice(1)),a[a.length-1]===":"&&(a=a.slice(0,-1)),j=a.split(":"),k=[];for(h=0,i=j.length;h<i;h++)e=j[h],k.push(parseInt(e,16));return k},b.IPv6.parser=function(b){var c,d;if(b.match(f["native"]))return a(b,8);if(c=b.match(f.transitional)){d=a(c[1].slice(0,-1),6);if(d){d.push(parseInt(c[2])<<8|parseInt(c[3])),d.push(parseInt(c[4])<<8|parseInt(c[5]));return d}}return null},b.IPv4.isIPv4=b.IPv6.isIPv6=function(a){return this.parser(a)!==null},b.IPv4.isValid=b.IPv6.isValid=function(a){try{new this(this.parser(a));return!0}catch(b){return!1}},b.IPv4.parse=b.IPv6.parse=function(a){var b;b=this.parser(a);if(b===null)throw new Error("ipaddr: string is not formatted like ip address");return new this(b)},b.isValid=function(a){return b.IPv6.isValid(a)||b.IPv4.isValid(a)},b.parse=function(a){if(b.IPv6.isIPv6(a))return b.IPv6.parse(a);if(b.IPv4.isIPv4(a))return b.IPv4.parse(a);throw new Error("ipaddr: the address has neither IPv6 nor IPv4 format")},b.process=function(a){var b;b=this.parse(a);return b.kind()==="ipv6"&&b.isIPv4MappedAddress()?b.toIPv4Address():b}}).call(this)

@@ -68,2 +68,5 @@ (function() {

};
IPv4.prototype.toByteArray = function() {
return this.octets.slice(0);
};
IPv4.prototype.match = function(other, cidrRange) {

@@ -159,23 +162,43 @@ if (other.kind() !== 'ipv4') {

if (part === '0') {
state = 1;
pushPart('');
} else {
pushPart(part);
}
state = 1;
break;
case 1:
if (part === '0') {
state = 2;
} else {
pushPart(part);
}
break;
case 2:
if (part !== '0') {
pushPart('');
pushPart(part);
state = 2;
state = 3;
}
break;
case 2:
case 3:
pushPart(part);
}
}
if (state === '') {
if (state === 2) {
pushPart('');
pushPart('');
}
return compactStringParts.join(":");
};
IPv6.prototype.toByteArray = function() {
var bytes, part, _i, _len, _ref;
bytes = [];
_ref = this.parts;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
part = _ref[_i];
bytes.push(part >> 8);
bytes.push(part & 0xff);
}
return bytes;
};
IPv6.prototype.toNormalizedString = function() {

@@ -182,0 +205,0 @@ var part;

{
"name": "ipaddr.js",
"description": "A library for manipulating IPv4 and IPv6 addresses in JavaScript.",
"version": "0.1.0",
"version": "0.1.1",
"author": "Peter Zotov <whitequark@whitequark.org>",

@@ -6,0 +6,0 @@ "directories": {

@@ -94,2 +94,11 @@ # ipaddr.js — an IPv6 and IPv4 address manipulation library

The addresses can be converted to their byte representation with `toByteArray()`.
(Actually, JavaScript mostly does not know about byte buffers. They are emulated with
arrays of numbers, each in range of 0..255.)
```js
var bytes = ipaddr.parse('2a00:1450:8007::68').toByteArray(); // ipv6.google.com
bytes // => [42, 0x00, 0x14, 0x50, 0x80, 0x07, 0x00, <zeroes...>, 0x00, 0x68 ]
```
The `ipaddr.IPv4` and `ipaddr.IPv6` objects have some methods defined, too. All of them

@@ -96,0 +105,0 @@ have the same interface for both protocols, and are similar to global methods.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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