pixelnode/node_modules/ipaddr.js/ipaddr.min.js

1 line
8.3 KiB
JavaScript
Raw Permalink Normal View History

2018-04-03 11:42:35 +02:00
(function(){var r,t,e,n,i,o,a,s;t={},s=this,"undefined"!=typeof module&&null!==module&&module.exports?module.exports=t:s.ipaddr=t,a=function(r,t,e,n){var i,o;if(r.length!==t.length)throw new Error("ipaddr: cannot match CIDR for objects with different lengths");for(i=0;n>0;){if((o=e-n)<0&&(o=0),r[i]>>o!=t[i]>>o)return!1;n-=e,i+=1}return!0},t.subnetMatch=function(r,t,e){var n,i,o,a,s;null==e&&(e="unicast");for(o in t)for(!(a=t[o])[0]||a[0]instanceof Array||(a=[a]),n=0,i=a.length;n<i;n++)if(s=a[n],r.match.apply(r,s))return o;return e},t.IPv4=function(){function r(r){var t,e,n;if(4!==r.length)throw new Error("ipaddr: ipv4 octet count should be 4");for(t=0,e=r.length;t<e;t++)if(!(0<=(n=r[t])&&n<=255))throw new Error("ipaddr: ipv4 octet should fit in 8 bits");this.octets=r}return r.prototype.kind=function(){return"ipv4"},r.prototype.toString=function(){return this.octets.join(".")},r.prototype.toByteArray=function(){return this.octets.slice(0)},r.prototype.match=function(r,t){var e;if(void 0===t&&(r=(e=r)[0],t=e[1]),"ipv4"!==r.kind())throw new Error("ipaddr: cannot match ipv4 address with non-ipv4 one");return a(this.octets,r.octets,8,t)},r.prototype.SpecialRanges={unspecified:[[new r([0,0,0,0]),8]],broadcast:[[new r([255,255,255,255]),32]],multicast:[[new r([224,0,0,0]),4]],linkLocal:[[new r([169,254,0,0]),16]],loopback:[[new r([127,0,0,0]),8]],carrierGradeNat:[[new r([100,64,0,0]),10]],private:[[new r([10,0,0,0]),8],[new r([172,16,0,0]),12],[new r([192,168,0,0]),16]],reserved:[[new r([192,0,0,0]),24],[new r([192,0,2,0]),24],[new r([192,88,99,0]),24],[new r([198,51,100,0]),24],[new r([203,0,113,0]),24],[new r([240,0,0,0]),4]]},r.prototype.range=function(){return t.subnetMatch(this,this.SpecialRanges)},r.prototype.toIPv4MappedAddress=function(){return t.IPv6.parse("::ffff:"+this.toString())},r.prototype.prefixLengthFromSubnetMask=function(){var r,t,e,n,i,o,a;for(a={0:8,128:7,192:6,224:5,240:4,248:3,252:2,254:1,255:0},r=0,i=!1,t=e=3;e>=0;t=e+=-1){if(!((n=this.octets[t])in a))return null;if(o=a[n],i&&0!==o)return null;8!==o&&(i=!0),r+=o}return 32-r},r}(),e="(0?\\d+|0x[a-f0-9]+)",n={fourOctet:new RegExp("^"+e+"\\."+e+"\\."+e+"\\."+e+"$","i"),longValue:new RegExp("^"+e+"$","i")},t.IPv4.parser=function(r){var t,e,i,o,a;if(e=function(r){return"0"===r[0]&&"x"!==r[1]?parseInt(r,8):parseInt(r)},t=r.match(n.fourOctet))return function(){var r,n,o,a;for(a=[],r=0,n=(o=t.slice(1,6)).length;r<n;r++)i=o[r],a.push(e(i));return a}();if(t=r.match(n.longValue)){if((a=e(t[1]))>4294967295||a<0)throw new Error("ipaddr: address outside defined range");return function(){var r,t;for(t=[],o=r=0;r<=24;o=r+=8)t.push(a>>o&255);return t}().reverse()}return null},t.IPv6=function(){function r(r){var t,e,n,i,o,a;if(16===r.length)for(this.parts=[],t=e=0;e<=14;t=e+=2)this.parts.push(r[t]<<8|r[t+1]);else{if(8!==r.length)throw new Error("ipaddr: ipv6 part count should be 8 or 16");this.parts=r}for(n=0,i=(a=this.parts).length;n<i;n++)if(!(0<=(o=a[n])&&o<=65535))throw new Error("ipaddr: ipv6 part should fit in 16 bits")}return r.prototype.kind=function(){return"ipv6"},r.prototype.toString=function(){var r,t,e,n,i,o,a;for(a=function(){var r,t,e,i;for(i=[],r=0,t=(e=this.parts).length;r<t;r++)n=e[r],i.push(n.toString(16));return i}.call(this),r=[],i=function(t){return r.push(t)},o=0,t=0,e=a.length;t<e;t++)switch(n=a[t],o){case 0:i("0"===n?"":n),o=1;break;case 1:"0"===n?o=2:i(n);break;case 2:"0"!==n&&(i(""),i(n),o=3);break;case 3:i(n)}return 2===o&&(i(""),i("")),r.join(":")},r.prototype.toByteArray=function(){var r,t,e,n,i;for(r=[],t=0,e=(i=this.parts).length;t<e;t++)n=i[t],r.push(n>>8),r.push(255&n);return r},r.prototype.toNormalizedString=function(){var r;return function(){var t,e,n,i;for(i=[],t=0,e=(n=this.parts).length;t<e;t++)r=n[t],i.push(r.toString(16));return i}.call(this).join(":")},r.prototype.match=function(r,t){var e;if(void 0===t&&(r=(e=r)[0],t=e[1]),"ipv6"!==r.kind())throw new Error("ipaddr: cannot match ipv6 address with non-ipv6 one");return a(this.parts,r.parts,16,t)},r.prototype.SpecialRanges={unspecified:[new r([0,0,0,0,0,0,0,0]),128],linkLocal:[new