var M=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},k={exports:{}};(function(c){(function(p){const a="(0?\\d+|0x[a-f0-9]+)",u={fourOctet:new RegExp(`^${a}\\.${a}\\.${a}\\.${a}$`,"i"),threeOctet:new RegExp(`^${a}\\.${a}\\.${a}$`,"i"),twoOctet:new RegExp(`^${a}\\.${a}$`,"i"),longValue:new RegExp(`^${a}$`,"i")},l=new RegExp("^0[0-7]+$","i"),d=new RegExp("^0x[a-f0-9]+$","i"),w="%[0-9a-z]{1,}",P="(?:[0-9a-f]+::?)+",v={zoneIndex:new RegExp(w,"i"),native:new RegExp(`^(::)?(${P})?([0-9a-f]+)?(::)?(${w})?$`,"i"),deprecatedTransitional:new RegExp(`^(?:::)(${a}\\.${a}\\.${a}\\.${a}(${w})?)$`,"i"),transitional:new RegExp(`^((?:${P})|(?:::)(?:${P})?)${a}\\.${a}\\.${a}\\.${a}(${w})?$`,"i")};function y(t,e){if(t.indexOf("::")!==t.lastIndexOf("::"))return null;let n=0,r=-1,i=(t.match(v.zoneIndex)||[])[0],o,f;for(i&&(i=i.substring(1),t=t.replace(/%.+$/,""));(r=t.indexOf(":",r+1))>=0;)n++;if(t.substr(0,2)==="::"&&n--,t.substr(-2,2)==="::"&&n--,n>e)return null;for(f=e-n,o=":";f--;)o+="0:";return t=t.replace("::",o),t[0]===":"&&(t=t.slice(1)),t[t.length-1]===":"&&(t=t.slice(0,-1)),e=function(){const $=t.split(":"),b=[];for(let g=0;g<$.length;g++)b.push(parseInt($[g],16));return b}(),{parts:e,zoneId:i}}function m(t,e,n,r){if(t.length!==e.length)throw new Error("ipaddr: cannot match CIDR for objects with different lengths");let i=0,o;for(;r>0;){if(o=n-r,o<0&&(o=0),t[i]>>o!==e[i]>>o)return!1;r-=n,i+=1}return!0}function I(t){if(d.test(t))return parseInt(t,16);if(t[0]==="0"&&!isNaN(parseInt(t[1],10))){if(l.test(t))return parseInt(t,8);throw new Error(`ipaddr: cannot parse ${t} as octal`)}return parseInt(t,10)}function E(t,e){for(;t.length=0;i-=1)if(o=this.octets[i],o in r){if(f=r[o],n&&f!==0)return null;f!==8&&(n=!0),e+=f}else return null;return 32-e},t.prototype.range=function(){return s.subnetMatch(this,this.SpecialRanges)},t.prototype.toByteArray=function(){return this.octets.slice(0)},t.prototype.toIPv4MappedAddress=function(){return s.IPv6.parse(`::ffff:${this.toString()}`)},t.prototype.toNormalizedString=function(){return this.toString()},t.prototype.toString=function(){return this.octets.join(".")},t}(),s.IPv4.broadcastAddressFromCIDR=function(t){try{const e=this.parseCIDR(t),n=e[0].toByteArray(),r=this.subnetMaskFromPrefixLength(e[1]).toByteArray(),i=[];let o=0;for(;o<4;)i.push(parseInt(n[o],10)|parseInt(r[o],10)^255),o++;return new this(i)}catch(e){throw new Error("ipaddr: the address does not have IPv4 CIDR format")}},s.IPv4.isIPv4=function(t){return this.parser(t)!==null},s.IPv4.isValid=function(t){try{return new this(this.parser(t)),!0}catch(e){return!1}},s.IPv4.isValidFourPartDecimal=function(t){return!!(s.IPv4.isValid(t)&&t.match(/^(0|[1-9]\d*)(\.(0|[1-9]\d*)){3}$/))},s.IPv4.networkAddressFromCIDR=function(t){let e,n,r,i,o;try{for(e=this.parseCIDR(t),r=e[0].toByteArray(),o=this.subnetMaskFromPrefixLength(e[1]).toByteArray(),i=[],n=0;n<4;)i.push(parseInt(r[n],10)&parseInt(o[n],10)),n++;return new this(i)}catch(f){throw new Error("ipaddr: the address does not have IPv4 CIDR format")}},s.IPv4.parse=function(t){const e=this.parser(t);if(e===null)throw new Error("ipaddr: string is not formatted like an IPv4 Address");return new this(e)},s.IPv4.parseCIDR=function(t){let e;if(e=t.match(/^(.+)\/(\d+)$/)){const n=parseInt(e[2]);if(n>=0&&n<=32){const r=[this.parse(e[1]),n];return Object.defineProperty(r,"toString",{value:function(){return this.join("/")}}),r}}throw new Error("ipaddr: string is not formatted like an IPv4 CIDR range")},s.IPv4.parser=function(t){let e,n,r;if(e=t.match(u.fourOctet))return function(){const i=e.slice(1,6),o=[];for(let f=0;f4294967295||r<0)throw new Error("ipaddr: address outside defined range");return function(){const i=[];let o;for(o=0;o<=24;o+=8)i.push(r>>o&255);return i}().reverse()}else return(e=t.match(u.twoOctet))?function(){const i=e.slice(1,4),o=[];if(r=I(i[1]),r>16777215||r<0)throw new Error("ipaddr: address outside defined range");return o.push(I(i[0])),o.push(r>>16&255),o.push(r>>8&255),o.push(r&255),o}():(e=t.match(u.threeOctet))?function(){const i=e.slice(1,5),o=[];if(r=I(i[2]),r>65535||r<0)throw new Error("ipaddr: address outside defined range");return o.push(I(i[0])),o.push(I(i[1])),o.push(r>>8&255),o.push(r&255),o}():null},s.IPv4.subnetMaskFromPrefixLength=function(t){if(t=parseInt(t),t<0||t>32)throw new Error("ipaddr: invalid IPv4 prefix length");const e=[0,0,0,0];let n=0;const r=Math.floor(t/8);for(;n=0;f-=1)if(i=this.parts[f],i in r){if(o=r[i],n&&o!==0)return null;o!==16&&(n=!0),e+=o}else return null;return 128-e},t.prototype.range=function(){return s.subnetMatch(this,this.SpecialRanges)},t.prototype.toByteArray=function(){let e;const n=[],r=this.parts;for(let i=0;i>8),n.push(e&255);return n},t.prototype.toFixedLengthString=function(){const e=function(){const r=[];for(let i=0;i>8,n&255,r>>8,r&255])},t.prototype.toNormalizedString=function(){const e=function(){const r=[];for(let i=0;ii&&(r=o.index,i=o[0].length);return i<0?n:`${n.substring(0,r)}::${n.substring(r+i)}`},t.prototype.toString=function(){return this.toRFC5952String()},t}(),s.IPv6.broadcastAddressFromCIDR=function(t){try{const e=this.parseCIDR(t),n=e[0].toByteArray(),r=this.subnetMaskFromPrefixLength(e[1]).toByteArray(),i=[];let o=0;for(;o<16;)i.push(parseInt(n[o],10)|parseInt(r[o],10)^255),o++;return new this(i)}catch(e){throw new Error(`ipaddr: the address does not have IPv6 CIDR format (${e})`)}},s.IPv6.isIPv6=function(t){return this.parser(t)!==null},s.IPv6.isValid=function(t){if(typeof t=="string"&&t.indexOf(":")===-1)return!1;try{const e=this.parser(t);return new this(e.parts,e.zoneId),!0}catch(e){return!1}},s.IPv6.networkAddressFromCIDR=function(t){let e,n,r,i,o;try{for(e=this.parseCIDR(t),r=e[0].toByteArray(),o=this.subnetMaskFromPrefixLength(e[1]).toByteArray(),i=[],n=0;n<16;)i.push(parseInt(r[n],10)&parseInt(o[n],10)),n++;return new this(i)}catch(f){throw new Error(`ipaddr: the address does not have IPv6 CIDR format (${f})`)}},s.IPv6.parse=function(t){const e=this.parser(t);if(e.parts===null)throw new Error("ipaddr: string is not formatted like an IPv6 Address");return new this(e.parts,e.zoneId)},s.IPv6.parseCIDR=function(t){let e,n,r;if((n=t.match(/^(.+)\/(\d+)$/))&&(e=parseInt(n[2]),e>=0&&e<=128))return r=[this.parse(n[1]),e],Object.defineProperty(r,"toString",{value:function(){return this.join("/")}}),r;throw new Error("ipaddr: string is not formatted like an IPv6 CIDR range")},s.IPv6.parser=function(t){let e,n,r,i,o,f;if(r=t.match(v.deprecatedTransitional))return this.parser(`::ffff:${r[1]}`);if(v.native.test(t))return y(t,8);if((r=t.match(v.transitional))&&(f=r[6]||"",e=y(r[1].slice(0,-1)+f,6),e.parts)){for(o=[parseInt(r[2]),parseInt(r[3]),parseInt(r[4]),parseInt(r[5])],n=0;n128)throw new Error("ipaddr: invalid IPv6 prefix length");const e=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];let n=0;const r=Math.floor(t/8);for(;nx.isValid(c),h=c=>{const p=x.IPv4.parse(c).toByteArray();return p[0]<<24|p[1]<<16|p[2]<<8|p[3]},R=c=>x.fromByteArray([c>>24&255,c>>16&255,c>>8&255,c&255]).toString(),A=c=>{if(!x.IPv4.isIPv4(c))return!1;let p=0,a=h(c);for(let u=31;u>=0&&(a&1<{let l=h(c)&h(p),d=h(a),w=h(u),v=~h(p);return dl+1&&w{let a=h(p),u=h(c)&a,l=~a,d;return l>=105?(d=u|l-5,u=u|100):l>=3?(d=u|l-1,u=u|2):(u=u|1,d=u),[R(u),R(d)]};var z={isValidMask:A,isValidIP:C,isValidMaskRange:S,calcMaskRange:O};export{M as c,z as i};