net-address 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +14 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@luolapeikko/result-option");var t=class t{static regex=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;static from(n){if(!t.regex.test(n))return(0,e.Err)(TypeError(`${n} is invalid ipv6 value`));try{let{leftParts:r,rightParts:i,embeddedIpv4:a}=t.#e(n),o=r.map(e=>parseInt(e,16)),s=i.map(e=>parseInt(e,16)),c=8-(o.length+s.length+a.length);return(0,e.Ok)(new t([...o,...Array(c).fill(0),...s,...a]))}catch(t){return(0,e.Err)(t)}}static fromBuffer(n,r){try{let i=new DataView(n);if(r){let n=i.getBigUint64(0,!0);return(0,e.Ok)(new t(i.getBigUint64(8,!0)<<64n|n))}else{let n=i.getBigUint64(0,!1),r=i.getBigUint64(8,!1);return(0,e.Ok)(new t(n<<64n|r))}}catch(t){return(0,e.Err)(t)}}static#e(e){let n=e.split(`::`),r=n[0].split(`:`).filter(e=>e!==``),i=n.length>1?n[1].split(`:`).filter(e=>e!==``):[],a=[],o=i[i.length-1]??r[r.length-1];return o?.includes(`.`)&&(a=t.#t(o),i.length>0?i.pop():r.pop()),{leftParts:r,rightParts:i,embeddedIpv4:a}}static#t(e){let t=e.split(`.`).map(Number);return[t[0]<<8|t[1],t[2]<<8|t[3]]}static BITS=128;static LOCALHOST=new t(1n);static UNSPECIFIED=new t(0n);family=`ipv6`;#n;constructor(e){Array.isArray(e)?this.#n=this.#r(e):this.#n=e}isBenchmarking(){return this.#a(42540488320432167789079031612388147200n,48)}isDocumentation(){return this.#a(42540766411282592856903984951653826560n,32)||this.#a(85065399433376081038215121361612832768n,20)}isLoopback(){return this.#n===1n}isUnspecified(){return this.#n===0n}isMulticast(){return this.#n>>120n==255n}isMulticastInterfaceLocal(){return this.#a(338958331222012082418099330867817086976n,16)}isMulticastLinkLocal(){return this.#a(338963523518870617245727861364146307072n,16)}isMulticastRealmLocal(){return this.#a(338968715815729152073356391860475527168n,16)}isMulticastAdminLocal(){return this.#a(338973908112587686900984922356804747264n,16)}isMulticastSiteLocal(){return this.#a(338979100409446221728613452853133967360n,16)}isMulticastOrganizationLocal(){return this.#a(338994677300021826211499044342121627648n,16)}isMulticastGlobal(){return this.#a(339025831081173035177270227320096948224n,16)}isIpv4Mapped(){return this.#a(281470681743360n,96)}isUnicast(){return!this.isMulticast()}isUnicastLinkLocal(){return this.#a(338288524927261089654018896841347694592n,10)}isUnicastGlobal(){return this.isUnicast()&&!this.isLoopback()&&!this.isUnicastLinkLocal()&&!this.isUniqueLocal()&&!this.isUnspecified()&&!this.isDocumentation()}isGlobal(){return!this.isUnspecified()&&!this.isLoopback()&&!this.isIpv4Mapped()&&!this.isBenchmarking()&&!this.isDocumentation()&&!this.isUniqueLocal()&&!this.isUnicastLinkLocal()&&!this.isMulticast()}isUniqueLocal(){return this.#a(334965454937798799971759379190646833152n,7)}toIpv4(){if(this.isIpv4Mapped()||this.#a(0n,96)){let t=this.#i(this.#n);return(0,e.Some)(new n(t[6]>>8,t[6]&255,t[7]>>8,t[7]&255))}return(0,e.None)()}toIpv4Mapped(){if(this.isIpv4Mapped()){let t=this.#i(this.#n);return(0,e.Some)(new n(t[6]>>8,t[6]&255,t[7]>>8,t[7]&255))}return(0,e.None)()}toString(){let e=this.#i(this.#n),t=-1,n=0,r=-1,i=0;for(let a=0;a<e.length;a++)e[a]===0?(r===-1?(r=a,i=1):i++,i>n&&(n=i,t=r)):(r=-1,i=0);if(n<2)return e.map(e=>e.toString(16)).join(`:`);let a=e.slice(0,t).map(e=>e.toString(16)),o=e.slice(t+n).map(e=>e.toString(16));return`${a.join(`:`)}::${o.join(`:`)}`}toBuffer(e){let t=new ArrayBuffer(16),n=new DataView(t);return e?(n.setBigUint64(0,this.#n&18446744073709551615n,!0),n.setBigUint64(8,this.#n>>64n,!0)):(n.setBigUint64(0,this.#n>>64n,!1),n.setBigUint64(8,this.#n&18446744073709551615n,!1)),t}#r(e){let t=0n;for(let n of e){if(n<0||n>65535)throw Error(`IPv6 segment must be between 0 and 65535`);t=t<<16n|BigInt(n)}return t}#i(e){return[Number(e>>112n&65535n),Number(e>>96n&65535n),Number(e>>80n&65535n),Number(e>>64n&65535n),Number(e>>48n&65535n),Number(e>>32n&65535n),Number(e>>16n&65535n),Number(e&65535n)]}#a(e,t){if(t<0||t>128)throw Error(`Invalid prefix length`);if(t===0)return!0;let n=(1n<<128n)-1n,r=n<<BigInt(128-t)&n;return(this.#n&r)===(e&r)}},n=class n{static from(t){let r=t.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);if(!r)return(0,e.Err)(TypeError(`${t} is invalid ipv4 value`));let i=r.slice(1).map(Number);return i.some(e=>e>255)?(0,e.Err)(TypeError(`${t} is invalid ipv4 value`)):(0,e.Ok)(new n(i[0],i[1],i[2],i[3]))}static fromBuffer(t,r){try{return(0,e.Ok)(new n(new DataView(t).getUint32(0,r)))}catch(t){return(0,e.Err)(t)}}static BITS=32;static BROADCAST=new n(4294967295);static LOCALHOST=new n(2130706433);static UNSPECIFIED=new n(0);family=`ipv4`;#e;constructor(...e){e.length===1?this.#e=e[0]:this.#e=this.#t(e[0],e[1],e[2],e[3])}isBroadcast(){return this.#e===4294967295}isDocumentation(){return this.#r(3221225984,24)||this.#r(3325256704,24)||this.#r(3405803776,24)}isBenchmarking(){return this.#r(3323068416,15)}isGlobal(){return!(this.isUnspecified()||this.isPrivate()||this.isShared()||this.isLoopback()||this.isLinkLocal()||this.isDocumentation()||this.isBenchmarking()||this.isReserved()||this.isMulticast()||this.isBroadcast())}isLinkLocal(){return this.#r(2851995648,16)}isLoopback(){return this.#r(2130706432,8)}isMulticast(){return this.#r(3758096384,4)}isPrivate(){return this.#r(167772160,8)||this.#r(2886729728,12)||this.#r(3232235520,16)}isReserved(){return this.#r(4026531840,4)&&!this.isBroadcast()}isShared(){return this.#r(1681915904,10)}isUnspecified(){return this.#e===0}toIpv6(){return t.from(`::${this.toString()}`).unwrap()}toIpv6Mapped(){return t.from(`::ffff:${this.toString()}`).unwrap()}toString(){let[e,t,n,r]=this.#n(this.#e);return`${e}.${t}.${n}.${r}`}toBuffer(e){let t=new ArrayBuffer(4);return new DataView(t).setUint32(0,this.#e,e),t}#t(e,t,n,r){for(let i of[e,t,n,r])if(i<0||i>255)throw Error(`IPv4 octet must be between 0 and 255`);return(e<<24|t<<16|n<<8|r)>>>0}#n(e){return[e>>24&255,e>>16&255,e>>8&255,e&255]}#r(e,t){if(t<0||t>32)throw Error(`Invalid prefix length`);let n=t===0?0:-1<<32-t>>>0;return(this.#e&n)===(e&n)}};exports.Ipv4Addr=n,exports.Ipv6Addr=t;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@luolapeikko/result-option");var t=class t{static regex=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;static from(n){if(!t.regex.test(n))return(0,e.Err)(TypeError(`${n} is invalid ipv6 value`));try{let{leftParts:r,rightParts:i,embeddedIpv4:a}=t.#e(n),o=r.map(e=>parseInt(e,16)),s=i.map(e=>parseInt(e,16)),c=8-(o.length+s.length+a.length);return(0,e.Ok)(new t([...o,...Array(c).fill(0),...s,...a]))}catch(t){return(0,e.Err)(t)}}static fromBuffer(n,r){try{let i=new DataView(n);if(r){let n=i.getBigUint64(0,!0);return(0,e.Ok)(new t(i.getBigUint64(8,!0)<<64n|n))}else{let n=i.getBigUint64(0,!1),r=i.getBigUint64(8,!1);return(0,e.Ok)(new t(n<<64n|r))}}catch(t){return(0,e.Err)(t)}}static#e(e){let n=e.split(`::`),r=n[0].split(`:`).filter(e=>e!==``),i=n.length>1?n[1].split(`:`).filter(e=>e!==``):[],a=[],o=i[i.length-1]??r[r.length-1];return o?.includes(`.`)&&(a=t.#t(o),i.length>0?i.pop():r.pop()),{leftParts:r,rightParts:i,embeddedIpv4:a}}static#t(e){let t=e.split(`.`).map(Number);return[t[0]<<8|t[1],t[2]<<8|t[3]]}static BITS=128;static LOCALHOST=new t(1n);static UNSPECIFIED=new t(0n);family=`ipv6`;#n;constructor(e){Array.isArray(e)?this.#n=this.#r(e):this.#n=e}isBenchmarking(){return this.#a(42540488320432167789079031612388147200n,48)}isDocumentation(){return this.#a(42540766411282592856903984951653826560n,32)||this.#a(85065399433376081038215121361612832768n,20)}isLoopback(){return this.#n===1n}isUnspecified(){return this.#n===0n}isMulticast(){return this.#n>>120n==255n}isMulticastInterfaceLocal(){return this.#a(338958331222012082418099330867817086976n,16)}isMulticastLinkLocal(){return this.#a(338963523518870617245727861364146307072n,16)}isMulticastRealmLocal(){return this.#a(338968715815729152073356391860475527168n,16)}isMulticastAdminLocal(){return this.#a(338973908112587686900984922356804747264n,16)}isMulticastSiteLocal(){return this.#a(338979100409446221728613452853133967360n,16)}isMulticastOrganizationLocal(){return this.#a(338994677300021826211499044342121627648n,16)}isMulticastGlobal(){return this.#a(339025831081173035177270227320096948224n,16)}isIpv4Mapped(){return this.#a(281470681743360n,96)}isUnicast(){return!this.isMulticast()}isUnicastLinkLocal(){return this.#a(338288524927261089654018896841347694592n,10)}isUnicastGlobal(){return this.isUnicast()&&!this.isLoopback()&&!this.isUnicastLinkLocal()&&!this.isUniqueLocal()&&!this.isUnspecified()&&!this.isDocumentation()}isGlobal(){return!this.isUnspecified()&&!this.isLoopback()&&!this.isIpv4Mapped()&&!this.isBenchmarking()&&!this.isDocumentation()&&!this.isUniqueLocal()&&!this.isUnicastLinkLocal()&&!this.isMulticast()}isUniqueLocal(){return this.#a(334965454937798799971759379190646833152n,7)}toIpv4(){if(this.isIpv4Mapped()||this.#a(0n,96)){let t=this.#i(this.#n);return(0,e.Some)(new n(t[6]>>8,t[6]&255,t[7]>>8,t[7]&255))}return(0,e.None)()}toIpv4Mapped(){if(this.isIpv4Mapped()){let t=this.#i(this.#n);return(0,e.Some)(new n(t[6]>>8,t[6]&255,t[7]>>8,t[7]&255))}return(0,e.None)()}toString(){let e=this.#i(this.#n),t=-1,n=0,r=-1,i=0;for(let a=0;a<e.length;a++)e[a]===0?(r===-1?(r=a,i=1):i++,i>n&&(n=i,t=r)):(r=-1,i=0);if(n<2)return e.map(e=>e.toString(16)).join(`:`);let a=e.slice(0,t).map(e=>e.toString(16)),o=e.slice(t+n).map(e=>e.toString(16));return`${a.join(`:`)}::${o.join(`:`)}`}toBuffer(e){let t=new ArrayBuffer(16),n=new DataView(t);return e?(n.setBigUint64(0,this.#n&18446744073709551615n,!0),n.setBigUint64(8,this.#n>>64n,!0)):(n.setBigUint64(0,this.#n>>64n,!1),n.setBigUint64(8,this.#n&18446744073709551615n,!1)),t}equals(e){return`family`in e&&this.family===e.family&&this.#n===e.#n}#r(e){let t=0n;for(let n of e){if(n<0||n>65535)throw Error(`IPv6 segment must be between 0 and 65535`);t=t<<16n|BigInt(n)}return t}#i(e){return[Number(e>>112n&65535n),Number(e>>96n&65535n),Number(e>>80n&65535n),Number(e>>64n&65535n),Number(e>>48n&65535n),Number(e>>32n&65535n),Number(e>>16n&65535n),Number(e&65535n)]}#a(e,t){if(t<0||t>128)throw Error(`Invalid prefix length`);if(t===0)return!0;let n=(1n<<128n)-1n,r=n<<BigInt(128-t)&n;return(this.#n&r)===(e&r)}},n=class n{static from(t){let r=t.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);if(!r)return(0,e.Err)(TypeError(`${t} is invalid ipv4 value`));let i=r.slice(1).map(Number);return i.some(e=>e>255)?(0,e.Err)(TypeError(`${t} is invalid ipv4 value`)):(0,e.Ok)(new n(i[0],i[1],i[2],i[3]))}static fromBuffer(t,r){try{return(0,e.Ok)(new n(new DataView(t).getUint32(0,r)))}catch(t){return(0,e.Err)(t)}}static BITS=32;static BROADCAST=new n(4294967295);static LOCALHOST=new n(2130706433);static UNSPECIFIED=new n(0);family=`ipv4`;#e;constructor(...e){e.length===1?this.#e=e[0]:this.#e=this.#t(e[0],e[1],e[2],e[3])}isBroadcast(){return this.#e===4294967295}isDocumentation(){return this.#r(3221225984,24)||this.#r(3325256704,24)||this.#r(3405803776,24)}isBenchmarking(){return this.#r(3323068416,15)}isGlobal(){return!(this.isUnspecified()||this.isPrivate()||this.isShared()||this.isLoopback()||this.isLinkLocal()||this.isDocumentation()||this.isBenchmarking()||this.isReserved()||this.isMulticast()||this.isBroadcast())}isLinkLocal(){return this.#r(2851995648,16)}isLoopback(){return this.#r(2130706432,8)}isMulticast(){return this.#r(3758096384,4)}isPrivate(){return this.#r(167772160,8)||this.#r(2886729728,12)||this.#r(3232235520,16)}isReserved(){return this.#r(4026531840,4)&&!this.isBroadcast()}isShared(){return this.#r(1681915904,10)}isUnspecified(){return this.#e===0}toIpv6(){return t.from(`::${this.toString()}`).unwrap()}toIpv6Mapped(){return t.from(`::ffff:${this.toString()}`).unwrap()}toString(){let[e,t,n,r]=this.#n(this.#e);return`${e}.${t}.${n}.${r}`}toBuffer(e){let t=new ArrayBuffer(4);return new DataView(t).setUint32(0,this.#e,e),t}equals(e){return`family`in e&&this.family===e.family&&this.#e===e.#e}#t(e,t,n,r){for(let i of[e,t,n,r])if(i<0||i>255)throw Error(`IPv4 octet must be between 0 and 255`);return(e<<24|t<<16|n<<8|r)>>>0}#n(e){return[e>>24&255,e>>16&255,e>>8&255,e&255]}#r(e,t){if(t<0||t>32)throw Error(`Invalid prefix length`);let n=t===0?0:-1<<32-t>>>0;return(this.#e&n)===(e&n)}};exports.Ipv4Addr=n,exports.Ipv6Addr=t;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["#parseComponents","#parseEmbeddedIpv4","#integerAddress","#toInteger","#match","#fromInteger","#integerAddress","#toInteger","#match","#fromInteger"],"sources":["../src/Ipv6Addr.ts","../src/Ipv4Addr.ts"],"sourcesContent":["import {Err, type IOption, type IResult, None, Ok, Some} from '@luolapeikko/result-option';\nimport {Ipv4Addr} from './Ipv4Addr';\n\n/**\n * Represents an IPv6 address.\n * @example\n * const addr1 = Ipv6Addr.from('2001:db8::1').unwrap();\n * const addr2 = new Ipv6Addr([0x2001, 0xdb8, 0, 0, 0, 0, 0, 1]);\n * const addr3 = new Ipv6Addr(0x20010db8000000000000000000000001n);\n * @since v0.0.1\n */\nexport class Ipv6Addr {\n\tprivate static regex =\n\t\t/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;\n\n\t/**\n\t * Creates an IPv6 address from text.\n\t * @returns A successful result with an IPv6 address, or an error when the input is invalid.\n\t * @example\n\t * const addr = Ipv6Addr.from('2001:db8::1').unwrap();\n\t * @since v0.0.1\n\t */\n\tpublic static from(value: string): IResult<Ipv6Addr> {\n\t\tif (!Ipv6Addr.regex.test(value)) {\n\t\t\treturn Err(new TypeError(`${value} is invalid ipv6 value`));\n\t\t}\n\t\ttry {\n\t\t\tconst {leftParts, rightParts, embeddedIpv4} = Ipv6Addr.#parseComponents(value);\n\n\t\t\tconst leftSegs = leftParts.map((p) => parseInt(p, 16));\n\t\t\tconst rightSegs = rightParts.map((p) => parseInt(p, 16));\n\n\t\t\tconst missingLen = 8 - (leftSegs.length + rightSegs.length + embeddedIpv4.length);\n\t\t\tconst segments = [...leftSegs, ...Array(missingLen).fill(0), ...rightSegs, ...embeddedIpv4];\n\n\t\t\treturn Ok(new Ipv6Addr(segments as [number, number, number, number, number, number, number, number]));\n\t\t} catch (err) {\n\t\t\treturn Err(err);\n\t\t}\n\t}\n\n\t/**\n\t * Creates an IPv6 address from a 16-byte buffer.\n\t * @returns A successful result with an IPv6 address, or an error when the buffer cannot be read.\n\t * @since v0.0.1\n\t */\n\tpublic static fromBuffer(buffer: ArrayBuffer, littleEndian?: boolean): IResult<Ipv6Addr> {\n\t\ttry {\n\t\t\tconst view = new DataView(buffer);\n\t\t\tif (littleEndian) {\n\t\t\t\tconst low = view.getBigUint64(0, true);\n\t\t\t\tconst high = view.getBigUint64(8, true);\n\t\t\t\treturn Ok(new Ipv6Addr((high << 64n) | low));\n\t\t\t} else {\n\t\t\t\tconst high = view.getBigUint64(0, false);\n\t\t\t\tconst low = view.getBigUint64(8, false);\n\t\t\t\treturn Ok(new Ipv6Addr((high << 64n) | low));\n\t\t\t}\n\t\t} catch (err) {\n\t\t\treturn Err(err as Error);\n\t\t}\n\t}\n\n\tstatic #parseComponents(value: string) {\n\t\tconst components = value.split('::');\n\t\tconst leftParts = components[0].split(':').filter((x) => x !== '');\n\t\tconst rightParts = components.length > 1 ? components[1].split(':').filter((x) => x !== '') : [];\n\t\tlet embeddedIpv4: number[] = [];\n\t\tconst lastPart = rightParts[rightParts.length - 1] ?? leftParts[leftParts.length - 1];\n\t\tif (lastPart?.includes('.')) {\n\t\t\tembeddedIpv4 = Ipv6Addr.#parseEmbeddedIpv4(lastPart);\n\t\t\tif (rightParts.length > 0) {\n\t\t\t\trightParts.pop();\n\t\t\t} else {\n\t\t\t\tleftParts.pop();\n\t\t\t}\n\t\t}\n\t\treturn {leftParts, rightParts, embeddedIpv4};\n\t}\n\n\tstatic #parseEmbeddedIpv4(value: string): number[] {\n\t\tconst ipv4Octets = value.split('.').map(Number);\n\t\treturn [(ipv4Octets[0] << 8) | ipv4Octets[1], (ipv4Octets[2] << 8) | ipv4Octets[3]];\n\t}\n\n\t/**\n\t * The number of bits in an IPv6 address.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly BITS = 128;\n\n\t/**\n\t * The loopback address (`::1`).\n\t * @since v0.0.1\n\t */\n\tpublic static readonly LOCALHOST: Ipv6Addr = new Ipv6Addr(0x00000000000000000000000000000001n);\n\n\t/**\n\t * The unspecified address (`::`).\n\t * @since v0.0.1\n\t */\n\tpublic static readonly UNSPECIFIED: Ipv6Addr = new Ipv6Addr(0x00000000000000000000000000000000n);\n\n\t/**\n\t * The address family identifier for IPv6 addresses.\n\t * @since v0.0.1\n\t */\n\tpublic readonly family = 'ipv6';\n\n\t#integerAddress: bigint;\n\tpublic constructor(value: bigint);\n\tpublic constructor(segments: [number, number, number, number, number, number, number, number]);\n\tpublic constructor(valueOrSegments: [number, number, number, number, number, number, number, number] | bigint) {\n\t\tif (Array.isArray(valueOrSegments)) {\n\t\t\tthis.#integerAddress = this.#toInteger(valueOrSegments);\n\t\t} else {\n\t\t\tthis.#integerAddress = valueOrSegments;\n\t\t}\n\t}\n\n\t/**\n\t * Checks whether this address is in the benchmarking range.\n\t * @see https://tools.ietf.org/html/rfc5180 and https://www.rfc-editor.org/errata_search.php?eid=1752\n\t * @returns `true` when the address is in `2001:2::/48`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isBenchmarking(): boolean {\n\t\treturn this.#match(0x20010002000000000000000000000000n, 48);\n\t}\n\n\t/**\n\t * Checks whether this address is in a documentation-only range.\n\t * @see https://tools.ietf.org/html/rfc3849 and https://tools.ietf.org/html/rfc9637\n\t * @returns `true` for `2001:db8::/32` or `3fff::/20`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isDocumentation(): boolean {\n\t\treturn this.#match(0x20010db8000000000000000000000000n, 32) || this.#match(0x3fff0000000000000000000000000000n, 20);\n\t}\n\n\t/**\n\t * Checks whether this address is the loopback address.\n\t * @see https://tools.ietf.org/html/rfc4291#section-2.5.3\n\t * @returns `true` when the address is `::1`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isLoopback(): boolean {\n\t\treturn this.#integerAddress === 1n;\n\t}\n\n\t/**\n\t * Checks whether this address is the unspecified address.\n\t * @see https://tools.ietf.org/html/rfc4291\n\t * @returns `true` when the address is `::`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUnspecified(): boolean {\n\t\treturn this.#integerAddress === 0n;\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast address.\n\t * @see https://tools.ietf.org/html/rfc4291\n\t * @returns `true` when the address is in `ff00::/8`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isMulticast(): boolean {\n\t\treturn this.#integerAddress >> 120n === 0xffn;\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast interface-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff01::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastInterfaceLocal(): boolean {\n\t\treturn this.#match(0xff010000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast link-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff02::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastLinkLocal(): boolean {\n\t\treturn this.#match(0xff020000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast realm-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff03::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastRealmLocal(): boolean {\n\t\treturn this.#match(0xff030000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast admin-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff04::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastAdminLocal(): boolean {\n\t\treturn this.#match(0xff040000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast site-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff05::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastSiteLocal(): boolean {\n\t\treturn this.#match(0xff050000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast organization-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff08::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastOrganizationLocal(): boolean {\n\t\treturn this.#match(0xff080000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast global address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff0e::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastGlobal(): boolean {\n\t\treturn this.#match(0xff0e0000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is an IPv4-mapped IPv6 address.\n\t * @returns `true` when the address is in `::ffff:0:0/96`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isIpv4Mapped(): boolean {\n\t\treturn this.#match(0x00000000000000000000ffff00000000n, 96);\n\t}\n\n\t/**\n\t * Checks whether this address is a unicast address.\n\t * @see https://tools.ietf.org/html/rfc4291\n\t * @returns `true` when the address is not multicast, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUnicast(): boolean {\n\t\treturn !this.isMulticast();\n\t}\n\n\t/**\n\t * Checks whether this address is a link-local unicast address.\n\t * @see https://tools.ietf.org/html/rfc4291\n\t * @returns `true` when the address is in `fe80::/10`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUnicastLinkLocal(): boolean {\n\t\treturn this.#match(0xfe800000000000000000000000000000n, 10);\n\t}\n\n\t/**\n\t * Checks whether this address is a global unicast address.\n\t * @see https://tools.ietf.org/html/rfc4291#section-2.5.7\n\t * @returns `true` when the address is unicast and not loopback, link-local, private, unspecified, or documentation.\n\t * @since v0.0.1\n\t */\n\tpublic isUnicastGlobal(): boolean {\n\t\treturn this.isUnicast() && !this.isLoopback() && !this.isUnicastLinkLocal() && !this.isUniqueLocal() && !this.isUnspecified() && !this.isDocumentation();\n\t}\n\n\t/**\n\t * Checks whether this address appears globally reachable.\n\t * @see https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml\n\t * @returns `true` when the address is not in known non-global special ranges.\n\t * @since v0.0.1\n\t */\n\tpublic isGlobal(): boolean {\n\t\treturn (\n\t\t\t!this.isUnspecified() &&\n\t\t\t!this.isLoopback() &&\n\t\t\t!this.isIpv4Mapped() &&\n\t\t\t!this.isBenchmarking() &&\n\t\t\t!this.isDocumentation() &&\n\t\t\t!this.isUniqueLocal() &&\n\t\t\t!this.isUnicastLinkLocal() &&\n\t\t\t!this.isMulticast()\n\t\t);\n\t}\n\n\t/**\n\t * Checks whether this address is in the unique-local range.\n\t * @see https://tools.ietf.org/html/rfc4193\n\t * @returns `true` when the address is in `fc00::/7`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUniqueLocal(): boolean {\n\t\treturn this.#match(0xfc000000000000000000000000000000n, 7);\n\t}\n\n\t/**\n\t * Converts this address to IPv4 when compatible or mapped.\n\t * @returns An IPv4 address for `::a.b.c.d` or `::ffff:a.b.c.d`; otherwise `None`.\n\t * @since v0.0.1\n\t */\n\tpublic toIpv4(): IOption<Ipv4Addr> {\n\t\tif (this.isIpv4Mapped() || this.#match(0n, 96)) {\n\t\t\tconst segments = this.#fromInteger(this.#integerAddress);\n\t\t\treturn Some(new Ipv4Addr(segments[6] >> 8, segments[6] & 0xff, segments[7] >> 8, segments[7] & 0xff));\n\t\t}\n\t\treturn None();\n\t}\n\n\t/**\n\t * Converts this address to IPv4 only when it is IPv4-mapped.\n\t * @returns An IPv4 address for `::ffff:a.b.c.d`; otherwise `None`.\n\t * @since v0.0.1\n\t */\n\tpublic toIpv4Mapped(): IOption<Ipv4Addr> {\n\t\tif (this.isIpv4Mapped()) {\n\t\t\tconst segments = this.#fromInteger(this.#integerAddress);\n\t\t\treturn Some(new Ipv4Addr(segments[6] >> 8, segments[6] & 0xff, segments[7] >> 8, segments[7] & 0xff));\n\t\t}\n\t\treturn None();\n\t}\n\n\t/**\n\t * Formats this address as a compressed IPv6 string.\n\t * @returns The shortest standard IPv6 text form.\n\t * @since v0.0.1\n\t */\n\tpublic toString(): string {\n\t\tconst segments = this.#fromInteger(this.#integerAddress);\n\t\tlet maxZeroStart = -1;\n\t\tlet maxZeroLen = 0;\n\t\tlet currentZeroStart = -1;\n\t\tlet currentZeroLen = 0;\n\n\t\tfor (let i = 0; i < segments.length; i++) {\n\t\t\tif (segments[i] === 0) {\n\t\t\t\tif (currentZeroStart === -1) {\n\t\t\t\t\tcurrentZeroStart = i;\n\t\t\t\t\tcurrentZeroLen = 1;\n\t\t\t\t} else {\n\t\t\t\t\tcurrentZeroLen++;\n\t\t\t\t}\n\t\t\t\tif (currentZeroLen > maxZeroLen) {\n\t\t\t\t\tmaxZeroLen = currentZeroLen;\n\t\t\t\t\tmaxZeroStart = currentZeroStart;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcurrentZeroStart = -1;\n\t\t\t\tcurrentZeroLen = 0;\n\t\t\t}\n\t\t}\n\n\t\tif (maxZeroLen < 2) {\n\t\t\treturn segments.map((s) => s.toString(16)).join(':');\n\t\t}\n\n\t\tconst before = segments.slice(0, maxZeroStart).map((s) => s.toString(16));\n\t\tconst after = segments.slice(maxZeroStart + maxZeroLen).map((s) => s.toString(16));\n\n\t\treturn `${before.join(':')}::${after.join(':')}`;\n\t}\n\n\t/**\n\t * Encodes this address to a 16-byte buffer.\n\t * @param littleEndian Whether to use little-endian byte order. Defaults to `false`.\n\t * @returns An `ArrayBuffer` containing the IPv6 integer value.\n\t * @since v0.0.1\n\t */\n\tpublic toBuffer(littleEndian?: boolean): ArrayBuffer {\n\t\tconst buffer = new ArrayBuffer(16);\n\t\tconst view = new DataView(buffer);\n\t\tif (littleEndian) {\n\t\t\tview.setBigUint64(0, this.#integerAddress & 0xffffffffffffffffn, true);\n\t\t\tview.setBigUint64(8, this.#integerAddress >> 64n, true);\n\t\t} else {\n\t\t\tview.setBigUint64(0, this.#integerAddress >> 64n, false);\n\t\t\tview.setBigUint64(8, this.#integerAddress & 0xffffffffffffffffn, false);\n\t\t}\n\t\treturn buffer;\n\t}\n\n\t#toInteger(segments: [number, number, number, number, number, number, number, number]): bigint {\n\t\tlet result = 0n;\n\t\tfor (const segment of segments) {\n\t\t\tif (segment < 0 || segment > 0xffff) {\n\t\t\t\tthrow new Error('IPv6 segment must be between 0 and 65535');\n\t\t\t}\n\t\t\tresult = (result << 16n) | BigInt(segment);\n\t\t}\n\t\treturn result;\n\t}\n\n\t#fromInteger(integer: bigint): [number, number, number, number, number, number, number, number] {\n\t\treturn [\n\t\t\tNumber((integer >> 112n) & 0xffffn),\n\t\t\tNumber((integer >> 96n) & 0xffffn),\n\t\t\tNumber((integer >> 80n) & 0xffffn),\n\t\t\tNumber((integer >> 64n) & 0xffffn),\n\t\t\tNumber((integer >> 48n) & 0xffffn),\n\t\t\tNumber((integer >> 32n) & 0xffffn),\n\t\t\tNumber((integer >> 16n) & 0xffffn),\n\t\t\tNumber(integer & 0xffffn),\n\t\t];\n\t}\n\n\t#match(network: bigint, prefix: number): boolean {\n\t\tif (prefix < 0 || prefix > 128) {\n\t\t\tthrow new Error('Invalid prefix length');\n\t\t}\n\t\tif (prefix === 0) {\n\t\t\treturn true;\n\t\t}\n\t\tconst ALL_ONES = (1n << 128n) - 1n;\n\t\tconst mask = (ALL_ONES << BigInt(128 - prefix)) & ALL_ONES;\n\t\treturn (this.#integerAddress & mask) === (network & mask);\n\t}\n}\n","import {Err, type IResult, Ok} from '@luolapeikko/result-option';\nimport {Ipv6Addr} from './Ipv6Addr';\n\n/**\n * Represents an IPv4 address.\n * @example\n * const addr1 = Ipv4Addr.from('192.168.0.1').unwrap();\n * const addr2 = new Ipv4Addr(192, 168, 0, 1);\n * const addr3 = new Ipv4Addr(0xc0a80001);\n * @since v0.0.1\n */\nexport class Ipv4Addr {\n\t/**\n\t * Creates an IPv4 address from dotted-decimal text.\n\t * @returns A successful {@link IResult} with an IPv4 address, or an error when the input is invalid.\n\t * @since v0.0.1\n\t */\n\tpublic static from(value: string): IResult<Ipv4Addr, TypeError> {\n\t\tconst match = value.match(/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/);\n\t\tif (!match) {\n\t\t\treturn Err(new TypeError(`${value} is invalid ipv4 value`));\n\t\t}\n\t\tconst octets = match.slice(1).map(Number);\n\t\tif (octets.some((o) => o > 255)) {\n\t\t\treturn Err(new TypeError(`${value} is invalid ipv4 value`));\n\t\t}\n\t\treturn Ok(new Ipv4Addr(octets[0], octets[1], octets[2], octets[3]));\n\t}\n\n\t/**\n\t * Creates an IPv4 address from a 4-byte buffer.\n\t * @returns A successful {@link IResult} with an IPv4 address, or an error when the buffer cannot be read.\n\t * @since v0.0.1\n\t */\n\tpublic static fromBuffer(buffer: ArrayBuffer, littleEndian?: boolean): IResult<Ipv4Addr> {\n\t\ttry {\n\t\t\tconst view = new DataView(buffer);\n\t\t\treturn Ok(new Ipv4Addr(view.getUint32(0, littleEndian)));\n\t\t} catch (err) {\n\t\t\treturn Err(err);\n\t\t}\n\t}\n\n\t/**\n\t * The number of bits in an IPv4 address.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly BITS = 32;\n\n\t/**\n\t * The broadcast address `255.255.255.255`.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly BROADCAST: Ipv4Addr = new Ipv4Addr(0xffffffff);\n\n\t/**\n\t * The localhost address `127.0.0.1`.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly LOCALHOST: Ipv4Addr = new Ipv4Addr(0x7f000001);\n\n\t/**\n\t * The unspecified address `0.0.0.0`.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly UNSPECIFIED: Ipv4Addr = new Ipv4Addr(0x00000000);\n\n\t/**\n\t * The address family identifier for IPv4 addresses.\n\t * @since v0.0.1\n\t */\n\tpublic readonly family = 'ipv4';\n\n\t#integerAddress: number;\n\n\t/**\n\t * Creates a new IPv4 address from four octets.\n\t * @param num1 The first octet.\n\t * @param num2 The second octet.\n\t * @param num3 The third octet.\n\t * @param num4 The fourth octet.\n\t * @example\n\t * new Ipv4Addr(192, 168, 0, 1) // creates the address `192.168.0.1`\n\t */\n\tpublic constructor(num1: number, num2: number, num3: number, num4: number);\n\t/**\n\t * Creates a new IPv4 address from an integer value.\n\t * @param integerValue The integer representation of the IPv4 address.\n\t * @example\n\t * new Ipv4Addr(0xc0a80001) // creates the address `192.168.0.1` from the integer value `0xc0a80001`\n\t */\n\tpublic constructor(integerValue: number);\n\tpublic constructor(...args: [number] | [number, number, number, number]) {\n\t\tif (args.length === 1) {\n\t\t\tthis.#integerAddress = args[0];\n\t\t} else {\n\t\t\tthis.#integerAddress = this.#toInteger(args[0], args[1], args[2], args[3]);\n\t\t}\n\t}\n\n\t/**\n\t * Checks whether this address is the broadcast address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc919#section-7\n\t * @returns `true` when the address is `255.255.255.255`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isBroadcast(): boolean {\n\t\treturn this.#integerAddress === 0xffffffff;\n\t}\n\n\t/**\n\t * Checks whether this address is in a documentation-only range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc5737\n\t * @returns `true` for `192.0.2.0/24`, `198.51.100.0/24`, or `203.0.113.0/24`; otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isDocumentation(): boolean {\n\t\treturn (\n\t\t\tthis.#match(0xc0000200, 24) || // 192.0.2.0/24\n\t\t\tthis.#match(0xc6336400, 24) || // 198.51.100.0/24\n\t\t\tthis.#match(0xcb007100, 24) // 203.0.113.0/24\n\t\t);\n\t}\n\n\t/**\n\t * Checks whether this address is in the benchmarking range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc2544\n\t * @returns `true` when the address is in `198.18.0.0/15`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isBenchmarking(): boolean {\n\t\treturn this.#match(0xc6120000, 15);\n\t}\n\n\t/**\n\t * Checks whether this address is globally reachable.\n\t * @see https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml\n\t * @returns `true` when the address is not in any special non-global range.\n\t * @since v0.0.1\n\t */\n\tpublic isGlobal(): boolean {\n\t\treturn !(\n\t\t\tthis.isUnspecified() ||\n\t\t\tthis.isPrivate() ||\n\t\t\tthis.isShared() ||\n\t\t\tthis.isLoopback() ||\n\t\t\tthis.isLinkLocal() ||\n\t\t\tthis.isDocumentation() ||\n\t\t\tthis.isBenchmarking() ||\n\t\t\tthis.isReserved() ||\n\t\t\tthis.isMulticast() ||\n\t\t\tthis.isBroadcast()\n\t\t);\n\t}\n\n\t/**\n\t * Checks whether this address is link-local.\n\t * @see https://datatracker.ietf.org/doc/html/rfc3927\n\t * @returns `true` when the address is in `169.254.0.0/16`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isLinkLocal(): boolean {\n\t\treturn this.#match(0xa9fe0000, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a loopback address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc1122\n\t * @returns `true` when the address is in `127.0.0.0/8`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isLoopback(): boolean {\n\t\treturn this.#match(0x7f000000, 8);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc5771\n\t * @returns `true` when the address is in `224.0.0.0/4`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isMulticast(): boolean {\n\t\treturn this.#match(0xe0000000, 4);\n\t}\n\n\t/**\n\t * Checks whether this address is in a private-use range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc1918\n\t * @returns `true` for `10.0.0.0/8`, `172.16.0.0/12`, or `192.168.0.0/16`; otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isPrivate(): boolean {\n\t\treturn (\n\t\t\tthis.#match(0x0a000000, 8) || // 10.0.0.0/8\n\t\t\tthis.#match(0xac100000, 12) || // 172.16.0.0/12\n\t\t\tthis.#match(0xc0a80000, 16) // 192.168.0.0/16\n\t\t);\n\t}\n\n\t/**\n\t * Checks whether this address is in the reserved range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc1112\n\t * @returns `true` when the address is in `240.0.0.0/4` except the broadcast address.\n\t * @since v0.0.1\n\t */\n\tpublic isReserved(): boolean {\n\t\treturn this.#match(0xf0000000, 4) && !this.isBroadcast();\n\t}\n\n\t/**\n\t * Checks whether this address is in the shared Carrier-Grade NAT range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc6598\n\t * @returns `true` when the address is in `100.64.0.0/10`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isShared(): boolean {\n\t\treturn this.#match(0x64400000, 10);\n\t}\n\n\t/**\n\t * Checks whether this address is the unspecified address.\n\t * @returns `true` when the address is `0.0.0.0`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUnspecified(): boolean {\n\t\treturn this.#integerAddress === 0;\n\t}\n\n\t/**\n\t * Converts this address to an IPv4-compatible IPv6 address.\n\t * @returns An IPv6 address in the form `::a.b.c.d`.\n\t * @since v0.0.1\n\t */\n\tpublic toIpv6(): Ipv6Addr {\n\t\treturn Ipv6Addr.from(`::${this.toString()}`).unwrap();\n\t}\n\n\t/**\n\t * Converts this address to an IPv4-mapped IPv6 address.\n\t * @returns An IPv6 address in the form `::ffff:a.b.c.d`.\n\t * @since v0.0.1\n\t */\n\tpublic toIpv6Mapped(): Ipv6Addr {\n\t\treturn Ipv6Addr.from(`::ffff:${this.toString()}`).unwrap();\n\t}\n\n\t/**\n\t * Formats this address as dotted-decimal text.\n\t * @returns The IPv4 string representation, such as `192.168.0.1`.\n\t * @since v0.0.1\n\t */\n\tpublic toString(): string {\n\t\tconst [num1, num2, num3, num4] = this.#fromInteger(this.#integerAddress);\n\t\treturn `${num1}.${num2}.${num3}.${num4}`;\n\t}\n\n\t/**\n\t * Encodes this address to a 4-byte buffer.\n\t * @returns An `ArrayBuffer` containing the IPv4 integer value.\n\t * @since v0.0.1\n\t */\n\tpublic toBuffer(littleEndian?: boolean): ArrayBuffer {\n\t\tconst buffer = new ArrayBuffer(4);\n\t\tconst view = new DataView(buffer);\n\t\tview.setUint32(0, this.#integerAddress, littleEndian);\n\t\treturn buffer;\n\t}\n\n\t#toInteger(num1: number, num2: number, num3: number, num4: number): number {\n\t\tfor (const octet of [num1, num2, num3, num4]) {\n\t\t\tif (octet < 0 || octet > 255) {\n\t\t\t\tthrow new Error('IPv4 octet must be between 0 and 255');\n\t\t\t}\n\t\t}\n\t\treturn ((num1 << 24) | (num2 << 16) | (num3 << 8) | num4) >>> 0;\n\t}\n\n\t#fromInteger(integer: number): [number, number, number, number] {\n\t\tconst num1 = (integer >> 24) & 0xff;\n\t\tconst num2 = (integer >> 16) & 0xff;\n\t\tconst num3 = (integer >> 8) & 0xff;\n\t\tconst num4 = integer & 0xff;\n\t\treturn [num1, num2, num3, num4];\n\t}\n\n\t#match(network: number, prefix: number): boolean {\n\t\tif (prefix < 0 || prefix > 32) {\n\t\t\tthrow new Error('Invalid prefix length');\n\t\t}\n\t\tconst mask = prefix === 0 ? 0 : (~0 << (32 - prefix)) >>> 0;\n\t\treturn (this.#integerAddress & mask) === (network & mask);\n\t}\n}\n"],"mappings":"+GAWA,IAAa,EAAb,MAAa,CAAS,CACrB,OAAe,MACd,wpBASD,OAAc,KAAK,EAAkC,CACpD,GAAI,CAAC,EAAS,MAAM,KAAK,CAAK,EAC7B,OAAA,EAAA,EAAA,IAAA,CAAe,UAAU,GAAG,EAAM,uBAAuB,CAAC,EAE3D,GAAI,CACH,GAAM,CAAC,YAAW,aAAY,gBAAgB,EAASA,GAAiB,CAAK,EAEvE,EAAW,EAAU,IAAK,GAAM,SAAS,EAAG,EAAE,CAAC,EAC/C,EAAY,EAAW,IAAK,GAAM,SAAS,EAAG,EAAE,CAAC,EAEjD,EAAa,GAAK,EAAS,OAAS,EAAU,OAAS,EAAa,QAG1E,OAAA,EAAA,EAAA,GAAA,CAAU,IAAI,EAAS,CAFL,GAAG,EAAU,GAAG,MAAM,CAAU,CAAC,CAAC,KAAK,CAAC,EAAG,GAAG,EAAW,GAAG,CAEhD,CAAqE,CAAC,CACrG,OAAS,EAAK,CACb,OAAA,EAAA,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C1E,IAAK,IAAM,IAAS,CAAC,EAAM,EAAM,EAAM,CAAI,EAC1C,GAAI,EAAQ,GAAK,EAAQ,IACxB,MAAU,MAAM,sCAAsC,EAGxD,OAAS,GAAQ,GAAO,GAAQ,GAAO,GAAQ,EAAK,KAAU,CAC/D,CAEA,GAAa,EAAmD,CAK/D,MAAO,CAJO,GAAW,GAAM,IACjB,GAAW,GAAM,IACjB,GAAW,EAAK,IACjB,EAAU,GACO,CAC/B,CAEA,GAAO,EAAiB,EAAyB,CAChD,GAAI,EAAS,GAAK,EAAS,GAC1B,MAAU,MAAM,uBAAuB,EAExC,IAAM,EAAO,IAAW,EAAI,EAAK,IAAO,GAAK,IAAa,EAC1D,OAAQ,KAAKA,GAAkB,MAAW,EAAU,EACrD,CACD"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["#parseComponents","#parseEmbeddedIpv4","#integerAddress","#toInteger","#match","#fromInteger","#integerAddress","#toInteger","#match","#fromInteger"],"sources":["../src/Ipv6Addr.ts","../src/Ipv4Addr.ts"],"sourcesContent":["import {Err, type IOption, type IResult, None, Ok, Some} from '@luolapeikko/result-option';\nimport {Ipv4Addr} from './Ipv4Addr';\n\n/**\n * Represents an IPv6 address.\n * @example\n * const addr1 = Ipv6Addr.from('2001:db8::1').unwrap();\n * const addr2 = new Ipv6Addr([0x2001, 0xdb8, 0, 0, 0, 0, 0, 1]);\n * const addr3 = new Ipv6Addr(0x20010db8000000000000000000000001n);\n * @since v0.0.1\n */\nexport class Ipv6Addr {\n\tprivate static regex =\n\t\t/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;\n\n\t/**\n\t * Creates an IPv6 address from text.\n\t * @returns A successful result with an IPv6 address, or an error when the input is invalid.\n\t * @example\n\t * const addr = Ipv6Addr.from('2001:db8::1').unwrap();\n\t * @since v0.0.1\n\t */\n\tpublic static from(value: string): IResult<Ipv6Addr> {\n\t\tif (!Ipv6Addr.regex.test(value)) {\n\t\t\treturn Err(new TypeError(`${value} is invalid ipv6 value`));\n\t\t}\n\t\ttry {\n\t\t\tconst {leftParts, rightParts, embeddedIpv4} = Ipv6Addr.#parseComponents(value);\n\n\t\t\tconst leftSegs = leftParts.map((p) => parseInt(p, 16));\n\t\t\tconst rightSegs = rightParts.map((p) => parseInt(p, 16));\n\n\t\t\tconst missingLen = 8 - (leftSegs.length + rightSegs.length + embeddedIpv4.length);\n\t\t\tconst segments = [...leftSegs, ...Array(missingLen).fill(0), ...rightSegs, ...embeddedIpv4];\n\n\t\t\treturn Ok(new Ipv6Addr(segments as [number, number, number, number, number, number, number, number]));\n\t\t} catch (err) {\n\t\t\treturn Err(err);\n\t\t}\n\t}\n\n\t/**\n\t * Creates an IPv6 address from a 16-byte buffer.\n\t * @returns A successful result with an IPv6 address, or an error when the buffer cannot be read.\n\t * @since v0.0.1\n\t */\n\tpublic static fromBuffer(buffer: ArrayBuffer, littleEndian?: boolean): IResult<Ipv6Addr> {\n\t\ttry {\n\t\t\tconst view = new DataView(buffer);\n\t\t\tif (littleEndian) {\n\t\t\t\tconst low = view.getBigUint64(0, true);\n\t\t\t\tconst high = view.getBigUint64(8, true);\n\t\t\t\treturn Ok(new Ipv6Addr((high << 64n) | low));\n\t\t\t} else {\n\t\t\t\tconst high = view.getBigUint64(0, false);\n\t\t\t\tconst low = view.getBigUint64(8, false);\n\t\t\t\treturn Ok(new Ipv6Addr((high << 64n) | low));\n\t\t\t}\n\t\t} catch (err) {\n\t\t\treturn Err(err as Error);\n\t\t}\n\t}\n\n\tstatic #parseComponents(value: string) {\n\t\tconst components = value.split('::');\n\t\tconst leftParts = components[0].split(':').filter((x) => x !== '');\n\t\tconst rightParts = components.length > 1 ? components[1].split(':').filter((x) => x !== '') : [];\n\t\tlet embeddedIpv4: number[] = [];\n\t\tconst lastPart = rightParts[rightParts.length - 1] ?? leftParts[leftParts.length - 1];\n\t\tif (lastPart?.includes('.')) {\n\t\t\tembeddedIpv4 = Ipv6Addr.#parseEmbeddedIpv4(lastPart);\n\t\t\tif (rightParts.length > 0) {\n\t\t\t\trightParts.pop();\n\t\t\t} else {\n\t\t\t\tleftParts.pop();\n\t\t\t}\n\t\t}\n\t\treturn {leftParts, rightParts, embeddedIpv4};\n\t}\n\n\tstatic #parseEmbeddedIpv4(value: string): number[] {\n\t\tconst ipv4Octets = value.split('.').map(Number);\n\t\treturn [(ipv4Octets[0] << 8) | ipv4Octets[1], (ipv4Octets[2] << 8) | ipv4Octets[3]];\n\t}\n\n\t/**\n\t * The number of bits in an IPv6 address.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly BITS = 128;\n\n\t/**\n\t * The loopback address (`::1`).\n\t * @since v0.0.1\n\t */\n\tpublic static readonly LOCALHOST: Ipv6Addr = new Ipv6Addr(0x00000000000000000000000000000001n);\n\n\t/**\n\t * The unspecified address (`::`).\n\t * @since v0.0.1\n\t */\n\tpublic static readonly UNSPECIFIED: Ipv6Addr = new Ipv6Addr(0x00000000000000000000000000000000n);\n\n\t/**\n\t * The address family identifier for IPv6 addresses.\n\t * @since v0.0.1\n\t */\n\tpublic readonly family = 'ipv6';\n\n\t#integerAddress: bigint;\n\tpublic constructor(value: bigint);\n\tpublic constructor(segments: [number, number, number, number, number, number, number, number]);\n\tpublic constructor(valueOrSegments: [number, number, number, number, number, number, number, number] | bigint) {\n\t\tif (Array.isArray(valueOrSegments)) {\n\t\t\tthis.#integerAddress = this.#toInteger(valueOrSegments);\n\t\t} else {\n\t\t\tthis.#integerAddress = valueOrSegments;\n\t\t}\n\t}\n\n\t/**\n\t * Checks whether this address is in the benchmarking range.\n\t * @see https://tools.ietf.org/html/rfc5180 and https://www.rfc-editor.org/errata_search.php?eid=1752\n\t * @returns `true` when the address is in `2001:2::/48`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isBenchmarking(): boolean {\n\t\treturn this.#match(0x20010002000000000000000000000000n, 48);\n\t}\n\n\t/**\n\t * Checks whether this address is in a documentation-only range.\n\t * @see https://tools.ietf.org/html/rfc3849 and https://tools.ietf.org/html/rfc9637\n\t * @returns `true` for `2001:db8::/32` or `3fff::/20`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isDocumentation(): boolean {\n\t\treturn this.#match(0x20010db8000000000000000000000000n, 32) || this.#match(0x3fff0000000000000000000000000000n, 20);\n\t}\n\n\t/**\n\t * Checks whether this address is the loopback address.\n\t * @see https://tools.ietf.org/html/rfc4291#section-2.5.3\n\t * @returns `true` when the address is `::1`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isLoopback(): boolean {\n\t\treturn this.#integerAddress === 1n;\n\t}\n\n\t/**\n\t * Checks whether this address is the unspecified address.\n\t * @see https://tools.ietf.org/html/rfc4291\n\t * @returns `true` when the address is `::`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUnspecified(): boolean {\n\t\treturn this.#integerAddress === 0n;\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast address.\n\t * @see https://tools.ietf.org/html/rfc4291\n\t * @returns `true` when the address is in `ff00::/8`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isMulticast(): boolean {\n\t\treturn this.#integerAddress >> 120n === 0xffn;\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast interface-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff01::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastInterfaceLocal(): boolean {\n\t\treturn this.#match(0xff010000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast link-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff02::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastLinkLocal(): boolean {\n\t\treturn this.#match(0xff020000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast realm-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff03::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastRealmLocal(): boolean {\n\t\treturn this.#match(0xff030000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast admin-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff04::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastAdminLocal(): boolean {\n\t\treturn this.#match(0xff040000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast site-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff05::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastSiteLocal(): boolean {\n\t\treturn this.#match(0xff050000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast organization-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff08::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastOrganizationLocal(): boolean {\n\t\treturn this.#match(0xff080000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast global address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff0e::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastGlobal(): boolean {\n\t\treturn this.#match(0xff0e0000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is an IPv4-mapped IPv6 address.\n\t * @returns `true` when the address is in `::ffff:0:0/96`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isIpv4Mapped(): boolean {\n\t\treturn this.#match(0x00000000000000000000ffff00000000n, 96);\n\t}\n\n\t/**\n\t * Checks whether this address is a unicast address.\n\t * @see https://tools.ietf.org/html/rfc4291\n\t * @returns `true` when the address is not multicast, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUnicast(): boolean {\n\t\treturn !this.isMulticast();\n\t}\n\n\t/**\n\t * Checks whether this address is a link-local unicast address.\n\t * @see https://tools.ietf.org/html/rfc4291\n\t * @returns `true` when the address is in `fe80::/10`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUnicastLinkLocal(): boolean {\n\t\treturn this.#match(0xfe800000000000000000000000000000n, 10);\n\t}\n\n\t/**\n\t * Checks whether this address is a global unicast address.\n\t * @see https://tools.ietf.org/html/rfc4291#section-2.5.7\n\t * @returns `true` when the address is unicast and not loopback, link-local, private, unspecified, or documentation.\n\t * @since v0.0.1\n\t */\n\tpublic isUnicastGlobal(): boolean {\n\t\treturn this.isUnicast() && !this.isLoopback() && !this.isUnicastLinkLocal() && !this.isUniqueLocal() && !this.isUnspecified() && !this.isDocumentation();\n\t}\n\n\t/**\n\t * Checks whether this address appears globally reachable.\n\t * @see https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml\n\t * @returns `true` when the address is not in known non-global special ranges.\n\t * @since v0.0.1\n\t */\n\tpublic isGlobal(): boolean {\n\t\treturn (\n\t\t\t!this.isUnspecified() &&\n\t\t\t!this.isLoopback() &&\n\t\t\t!this.isIpv4Mapped() &&\n\t\t\t!this.isBenchmarking() &&\n\t\t\t!this.isDocumentation() &&\n\t\t\t!this.isUniqueLocal() &&\n\t\t\t!this.isUnicastLinkLocal() &&\n\t\t\t!this.isMulticast()\n\t\t);\n\t}\n\n\t/**\n\t * Checks whether this address is in the unique-local range.\n\t * @see https://tools.ietf.org/html/rfc4193\n\t * @returns `true` when the address is in `fc00::/7`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUniqueLocal(): boolean {\n\t\treturn this.#match(0xfc000000000000000000000000000000n, 7);\n\t}\n\n\t/**\n\t * Converts this address to IPv4 when compatible or mapped.\n\t * @returns An IPv4 address for `::a.b.c.d` or `::ffff:a.b.c.d`; otherwise `None`.\n\t * @since v0.0.1\n\t */\n\tpublic toIpv4(): IOption<Ipv4Addr> {\n\t\tif (this.isIpv4Mapped() || this.#match(0n, 96)) {\n\t\t\tconst segments = this.#fromInteger(this.#integerAddress);\n\t\t\treturn Some(new Ipv4Addr(segments[6] >> 8, segments[6] & 0xff, segments[7] >> 8, segments[7] & 0xff));\n\t\t}\n\t\treturn None();\n\t}\n\n\t/**\n\t * Converts this address to IPv4 only when it is IPv4-mapped.\n\t * @returns An IPv4 address for `::ffff:a.b.c.d`; otherwise `None`.\n\t * @since v0.0.1\n\t */\n\tpublic toIpv4Mapped(): IOption<Ipv4Addr> {\n\t\tif (this.isIpv4Mapped()) {\n\t\t\tconst segments = this.#fromInteger(this.#integerAddress);\n\t\t\treturn Some(new Ipv4Addr(segments[6] >> 8, segments[6] & 0xff, segments[7] >> 8, segments[7] & 0xff));\n\t\t}\n\t\treturn None();\n\t}\n\n\t/**\n\t * Formats this address as a compressed IPv6 string.\n\t * @returns The shortest standard IPv6 text form.\n\t * @since v0.0.1\n\t */\n\tpublic toString(): string {\n\t\tconst segments = this.#fromInteger(this.#integerAddress);\n\t\tlet maxZeroStart = -1;\n\t\tlet maxZeroLen = 0;\n\t\tlet currentZeroStart = -1;\n\t\tlet currentZeroLen = 0;\n\n\t\tfor (let i = 0; i < segments.length; i++) {\n\t\t\tif (segments[i] === 0) {\n\t\t\t\tif (currentZeroStart === -1) {\n\t\t\t\t\tcurrentZeroStart = i;\n\t\t\t\t\tcurrentZeroLen = 1;\n\t\t\t\t} else {\n\t\t\t\t\tcurrentZeroLen++;\n\t\t\t\t}\n\t\t\t\tif (currentZeroLen > maxZeroLen) {\n\t\t\t\t\tmaxZeroLen = currentZeroLen;\n\t\t\t\t\tmaxZeroStart = currentZeroStart;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcurrentZeroStart = -1;\n\t\t\t\tcurrentZeroLen = 0;\n\t\t\t}\n\t\t}\n\n\t\tif (maxZeroLen < 2) {\n\t\t\treturn segments.map((s) => s.toString(16)).join(':');\n\t\t}\n\n\t\tconst before = segments.slice(0, maxZeroStart).map((s) => s.toString(16));\n\t\tconst after = segments.slice(maxZeroStart + maxZeroLen).map((s) => s.toString(16));\n\n\t\treturn `${before.join(':')}::${after.join(':')}`;\n\t}\n\n\t/**\n\t * Encodes this address to a 16-byte buffer.\n\t * @param littleEndian Whether to use little-endian byte order. Defaults to `false`.\n\t * @returns An `ArrayBuffer` containing the IPv6 integer value.\n\t * @since v0.0.1\n\t */\n\tpublic toBuffer(littleEndian?: boolean): ArrayBuffer {\n\t\tconst buffer = new ArrayBuffer(16);\n\t\tconst view = new DataView(buffer);\n\t\tif (littleEndian) {\n\t\t\tview.setBigUint64(0, this.#integerAddress & 0xffffffffffffffffn, true);\n\t\t\tview.setBigUint64(8, this.#integerAddress >> 64n, true);\n\t\t} else {\n\t\t\tview.setBigUint64(0, this.#integerAddress >> 64n, false);\n\t\t\tview.setBigUint64(8, this.#integerAddress & 0xffffffffffffffffn, false);\n\t\t}\n\t\treturn buffer;\n\t}\n\n\t/**\n\t * Compares this IPv6 address with another for equality.\n\t * @param other instance of another IPv6 address to compare with.\n\t * @returns `true` if both addresses are equal, otherwise `false`.\n\t * @since v0.1.0\n\t */\n\tpublic equals(other: Ipv6Addr | Ipv4Addr | object): boolean {\n\t\treturn 'family' in other && this.family === other.family && this.#integerAddress === other.#integerAddress;\n\t}\n\n\t#toInteger(segments: [number, number, number, number, number, number, number, number]): bigint {\n\t\tlet result = 0n;\n\t\tfor (const segment of segments) {\n\t\t\tif (segment < 0 || segment > 0xffff) {\n\t\t\t\tthrow new Error('IPv6 segment must be between 0 and 65535');\n\t\t\t}\n\t\t\tresult = (result << 16n) | BigInt(segment);\n\t\t}\n\t\treturn result;\n\t}\n\n\t#fromInteger(integer: bigint): [number, number, number, number, number, number, number, number] {\n\t\treturn [\n\t\t\tNumber((integer >> 112n) & 0xffffn),\n\t\t\tNumber((integer >> 96n) & 0xffffn),\n\t\t\tNumber((integer >> 80n) & 0xffffn),\n\t\t\tNumber((integer >> 64n) & 0xffffn),\n\t\t\tNumber((integer >> 48n) & 0xffffn),\n\t\t\tNumber((integer >> 32n) & 0xffffn),\n\t\t\tNumber((integer >> 16n) & 0xffffn),\n\t\t\tNumber(integer & 0xffffn),\n\t\t];\n\t}\n\n\t#match(network: bigint, prefix: number): boolean {\n\t\tif (prefix < 0 || prefix > 128) {\n\t\t\tthrow new Error('Invalid prefix length');\n\t\t}\n\t\tif (prefix === 0) {\n\t\t\treturn true;\n\t\t}\n\t\tconst ALL_ONES = (1n << 128n) - 1n;\n\t\tconst mask = (ALL_ONES << BigInt(128 - prefix)) & ALL_ONES;\n\t\treturn (this.#integerAddress & mask) === (network & mask);\n\t}\n}\n","import {Err, type IResult, Ok} from '@luolapeikko/result-option';\nimport {Ipv6Addr} from './Ipv6Addr';\n\n/**\n * Represents an IPv4 address.\n * @example\n * const addr1 = Ipv4Addr.from('192.168.0.1').unwrap();\n * const addr2 = new Ipv4Addr(192, 168, 0, 1);\n * const addr3 = new Ipv4Addr(0xc0a80001);\n * @since v0.0.1\n */\nexport class Ipv4Addr {\n\t/**\n\t * Creates an IPv4 address from dotted-decimal text.\n\t * @returns A successful {@link IResult} with an IPv4 address, or an error when the input is invalid.\n\t * @since v0.0.1\n\t */\n\tpublic static from(value: string): IResult<Ipv4Addr, TypeError> {\n\t\tconst match = value.match(/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/);\n\t\tif (!match) {\n\t\t\treturn Err(new TypeError(`${value} is invalid ipv4 value`));\n\t\t}\n\t\tconst octets = match.slice(1).map(Number);\n\t\tif (octets.some((o) => o > 255)) {\n\t\t\treturn Err(new TypeError(`${value} is invalid ipv4 value`));\n\t\t}\n\t\treturn Ok(new Ipv4Addr(octets[0], octets[1], octets[2], octets[3]));\n\t}\n\n\t/**\n\t * Creates an IPv4 address from a 4-byte buffer.\n\t * @returns A successful {@link IResult} with an IPv4 address, or an error when the buffer cannot be read.\n\t * @since v0.0.1\n\t */\n\tpublic static fromBuffer(buffer: ArrayBuffer, littleEndian?: boolean): IResult<Ipv4Addr> {\n\t\ttry {\n\t\t\tconst view = new DataView(buffer);\n\t\t\treturn Ok(new Ipv4Addr(view.getUint32(0, littleEndian)));\n\t\t} catch (err) {\n\t\t\treturn Err(err);\n\t\t}\n\t}\n\n\t/**\n\t * The number of bits in an IPv4 address.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly BITS = 32;\n\n\t/**\n\t * The broadcast address `255.255.255.255`.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly BROADCAST: Ipv4Addr = new Ipv4Addr(0xffffffff);\n\n\t/**\n\t * The localhost address `127.0.0.1`.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly LOCALHOST: Ipv4Addr = new Ipv4Addr(0x7f000001);\n\n\t/**\n\t * The unspecified address `0.0.0.0`.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly UNSPECIFIED: Ipv4Addr = new Ipv4Addr(0x00000000);\n\n\t/**\n\t * The address family identifier for IPv4 addresses.\n\t * @since v0.0.1\n\t */\n\tpublic readonly family = 'ipv4';\n\n\t#integerAddress: number;\n\n\t/**\n\t * Creates a new IPv4 address from four octets.\n\t * @param num1 The first octet.\n\t * @param num2 The second octet.\n\t * @param num3 The third octet.\n\t * @param num4 The fourth octet.\n\t * @example\n\t * new Ipv4Addr(192, 168, 0, 1) // creates the address `192.168.0.1`\n\t */\n\tpublic constructor(num1: number, num2: number, num3: number, num4: number);\n\t/**\n\t * Creates a new IPv4 address from an integer value.\n\t * @param integerValue The integer representation of the IPv4 address.\n\t * @example\n\t * new Ipv4Addr(0xc0a80001) // creates the address `192.168.0.1` from the integer value `0xc0a80001`\n\t */\n\tpublic constructor(integerValue: number);\n\tpublic constructor(...args: [number] | [number, number, number, number]) {\n\t\tif (args.length === 1) {\n\t\t\tthis.#integerAddress = args[0];\n\t\t} else {\n\t\t\tthis.#integerAddress = this.#toInteger(args[0], args[1], args[2], args[3]);\n\t\t}\n\t}\n\n\t/**\n\t * Checks whether this address is the broadcast address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc919#section-7\n\t * @returns `true` when the address is `255.255.255.255`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isBroadcast(): boolean {\n\t\treturn this.#integerAddress === 0xffffffff;\n\t}\n\n\t/**\n\t * Checks whether this address is in a documentation-only range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc5737\n\t * @returns `true` for `192.0.2.0/24`, `198.51.100.0/24`, or `203.0.113.0/24`; otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isDocumentation(): boolean {\n\t\treturn (\n\t\t\tthis.#match(0xc0000200, 24) || // 192.0.2.0/24\n\t\t\tthis.#match(0xc6336400, 24) || // 198.51.100.0/24\n\t\t\tthis.#match(0xcb007100, 24) // 203.0.113.0/24\n\t\t);\n\t}\n\n\t/**\n\t * Checks whether this address is in the benchmarking range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc2544\n\t * @returns `true` when the address is in `198.18.0.0/15`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isBenchmarking(): boolean {\n\t\treturn this.#match(0xc6120000, 15);\n\t}\n\n\t/**\n\t * Checks whether this address is globally reachable.\n\t * @see https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml\n\t * @returns `true` when the address is not in any special non-global range.\n\t * @since v0.0.1\n\t */\n\tpublic isGlobal(): boolean {\n\t\treturn !(\n\t\t\tthis.isUnspecified() ||\n\t\t\tthis.isPrivate() ||\n\t\t\tthis.isShared() ||\n\t\t\tthis.isLoopback() ||\n\t\t\tthis.isLinkLocal() ||\n\t\t\tthis.isDocumentation() ||\n\t\t\tthis.isBenchmarking() ||\n\t\t\tthis.isReserved() ||\n\t\t\tthis.isMulticast() ||\n\t\t\tthis.isBroadcast()\n\t\t);\n\t}\n\n\t/**\n\t * Checks whether this address is link-local.\n\t * @see https://datatracker.ietf.org/doc/html/rfc3927\n\t * @returns `true` when the address is in `169.254.0.0/16`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isLinkLocal(): boolean {\n\t\treturn this.#match(0xa9fe0000, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a loopback address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc1122\n\t * @returns `true` when the address is in `127.0.0.0/8`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isLoopback(): boolean {\n\t\treturn this.#match(0x7f000000, 8);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc5771\n\t * @returns `true` when the address is in `224.0.0.0/4`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isMulticast(): boolean {\n\t\treturn this.#match(0xe0000000, 4);\n\t}\n\n\t/**\n\t * Checks whether this address is in a private-use range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc1918\n\t * @returns `true` for `10.0.0.0/8`, `172.16.0.0/12`, or `192.168.0.0/16`; otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isPrivate(): boolean {\n\t\treturn (\n\t\t\tthis.#match(0x0a000000, 8) || // 10.0.0.0/8\n\t\t\tthis.#match(0xac100000, 12) || // 172.16.0.0/12\n\t\t\tthis.#match(0xc0a80000, 16) // 192.168.0.0/16\n\t\t);\n\t}\n\n\t/**\n\t * Checks whether this address is in the reserved range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc1112\n\t * @returns `true` when the address is in `240.0.0.0/4` except the broadcast address.\n\t * @since v0.0.1\n\t */\n\tpublic isReserved(): boolean {\n\t\treturn this.#match(0xf0000000, 4) && !this.isBroadcast();\n\t}\n\n\t/**\n\t * Checks whether this address is in the shared Carrier-Grade NAT range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc6598\n\t * @returns `true` when the address is in `100.64.0.0/10`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isShared(): boolean {\n\t\treturn this.#match(0x64400000, 10);\n\t}\n\n\t/**\n\t * Checks whether this address is the unspecified address.\n\t * @returns `true` when the address is `0.0.0.0`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUnspecified(): boolean {\n\t\treturn this.#integerAddress === 0;\n\t}\n\n\t/**\n\t * Converts this address to an IPv4-compatible IPv6 address.\n\t * @returns An IPv6 address in the form `::a.b.c.d`.\n\t * @since v0.0.1\n\t */\n\tpublic toIpv6(): Ipv6Addr {\n\t\treturn Ipv6Addr.from(`::${this.toString()}`).unwrap();\n\t}\n\n\t/**\n\t * Converts this address to an IPv4-mapped IPv6 address.\n\t * @returns An IPv6 address in the form `::ffff:a.b.c.d`.\n\t * @since v0.0.1\n\t */\n\tpublic toIpv6Mapped(): Ipv6Addr {\n\t\treturn Ipv6Addr.from(`::ffff:${this.toString()}`).unwrap();\n\t}\n\n\t/**\n\t * Formats this address as dotted-decimal text.\n\t * @returns The IPv4 string representation, such as `192.168.0.1`.\n\t * @since v0.0.1\n\t */\n\tpublic toString(): string {\n\t\tconst [num1, num2, num3, num4] = this.#fromInteger(this.#integerAddress);\n\t\treturn `${num1}.${num2}.${num3}.${num4}`;\n\t}\n\n\t/**\n\t * Encodes this address to a 4-byte buffer.\n\t * @returns An `ArrayBuffer` containing the IPv4 integer value.\n\t * @since v0.0.1\n\t */\n\tpublic toBuffer(littleEndian?: boolean): ArrayBuffer {\n\t\tconst buffer = new ArrayBuffer(4);\n\t\tconst view = new DataView(buffer);\n\t\tview.setUint32(0, this.#integerAddress, littleEndian);\n\t\treturn buffer;\n\t}\n\n\t/**\n\t * Compares this IPv4 address with another for equality.\n\t * @param other instance of another IPv4 address to compare with.\n\t * @returns `true` if both addresses are equal, otherwise `false`.\n\t * @since v0.1.0\n\t */\n\tpublic equals(other: Ipv4Addr | Ipv6Addr | object): boolean {\n\t\treturn 'family' in other && this.family === other.family && this.#integerAddress === other.#integerAddress;\n\t}\n\n\t#toInteger(num1: number, num2: number, num3: number, num4: number): number {\n\t\tfor (const octet of [num1, num2, num3, num4]) {\n\t\t\tif (octet < 0 || octet > 255) {\n\t\t\t\tthrow new Error('IPv4 octet must be between 0 and 255');\n\t\t\t}\n\t\t}\n\t\treturn ((num1 << 24) | (num2 << 16) | (num3 << 8) | num4) >>> 0;\n\t}\n\n\t#fromInteger(integer: number): [number, number, number, number] {\n\t\tconst num1 = (integer >> 24) & 0xff;\n\t\tconst num2 = (integer >> 16) & 0xff;\n\t\tconst num3 = (integer >> 8) & 0xff;\n\t\tconst num4 = integer & 0xff;\n\t\treturn [num1, num2, num3, num4];\n\t}\n\n\t#match(network: number, prefix: number): boolean {\n\t\tif (prefix < 0 || prefix > 32) {\n\t\t\tthrow new Error('Invalid prefix length');\n\t\t}\n\t\tconst mask = prefix === 0 ? 0 : (~0 << (32 - prefix))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AuB,EAExC,IAAM,EAAO,IAAW,EAAI,EAAK,IAAO,GAAK,IAAa,EAC1D,OAAQ,KAAKA,GAAkB,MAAW,EAAU,EACrD,CACD"}
|
package/dist/index.d.cts
CHANGED
|
@@ -198,6 +198,13 @@ declare class Ipv6Addr {
|
|
|
198
198
|
* @since v0.0.1
|
|
199
199
|
*/
|
|
200
200
|
toBuffer(littleEndian?: boolean): ArrayBuffer;
|
|
201
|
+
/**
|
|
202
|
+
* Compares this IPv6 address with another for equality.
|
|
203
|
+
* @param other instance of another IPv6 address to compare with.
|
|
204
|
+
* @returns `true` if both addresses are equal, otherwise `false`.
|
|
205
|
+
* @since v0.1.0
|
|
206
|
+
*/
|
|
207
|
+
equals(other: Ipv6Addr | Ipv4Addr | object): boolean;
|
|
201
208
|
}
|
|
202
209
|
//#endregion
|
|
203
210
|
//#region src/Ipv4Addr.d.ts
|
|
@@ -365,6 +372,13 @@ declare class Ipv4Addr {
|
|
|
365
372
|
* @since v0.0.1
|
|
366
373
|
*/
|
|
367
374
|
toBuffer(littleEndian?: boolean): ArrayBuffer;
|
|
375
|
+
/**
|
|
376
|
+
* Compares this IPv4 address with another for equality.
|
|
377
|
+
* @param other instance of another IPv4 address to compare with.
|
|
378
|
+
* @returns `true` if both addresses are equal, otherwise `false`.
|
|
379
|
+
* @since v0.1.0
|
|
380
|
+
*/
|
|
381
|
+
equals(other: Ipv4Addr | Ipv6Addr | object): boolean;
|
|
368
382
|
}
|
|
369
383
|
//#endregion
|
|
370
384
|
export { Ipv4Addr, Ipv6Addr };
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/Ipv6Addr.ts","../src/Ipv4Addr.ts"],"mappings":";;;;AAWA;;;;;;;cAAa,QAAA;EAAA;iBACG,KAAA;;;;;;;;SAUD,IAAA,CAAK,KAAA,WAAgB,OAAA,CAAQ,QAAA
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":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AA,EAAW,QAAA;;;;;kBAMX,SAAA,EAAW,QAAA;;;;;kBAMX,WAAA,EAAa,QAAA;;;;;WAMpB,MAAA;;;;;;;;;;EAahB,WAAA,CAAmB,IAAA,UAAc,IAAA,UAAc,IAAA,UAAc,IAAA;;;;;;;EAO7D,WAAA,CAAmB,YAAA;;;;;;;EAenB,WAAA;;;;;ADqSgC;;EC3RhC,eAAA;;AAzGD;;;;;EAuHC,cAAA;;;;;;;EAUA,QAAA;;;;;;;EAqBA,WAAA;;;;;;;EAUA,UAAA;;;;;;;EAUA,WAAA;;;;;;;EAUA,SAAA;;;;;;;EAcA,UAAA;;;;;;;EAUA,QAAA;;;;;;EASA,aAAA;;;;;;EASA,MAAA,IAAiB,QAAA;;;;AAyCe;;EAhChC,YAAA,IAAuB,QAAA;;;;;;EASvB,QAAA;;;;;;EAUA,QAAA,CAAgB,YAAA,aAAyB,WAAA;;;;;;;EAazC,MAAA,CAAc,KAAA,EAAO,QAAA,GAAW,QAAA;AAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -198,6 +198,13 @@ declare class Ipv6Addr {
|
|
|
198
198
|
* @since v0.0.1
|
|
199
199
|
*/
|
|
200
200
|
toBuffer(littleEndian?: boolean): ArrayBuffer;
|
|
201
|
+
/**
|
|
202
|
+
* Compares this IPv6 address with another for equality.
|
|
203
|
+
* @param other instance of another IPv6 address to compare with.
|
|
204
|
+
* @returns `true` if both addresses are equal, otherwise `false`.
|
|
205
|
+
* @since v0.1.0
|
|
206
|
+
*/
|
|
207
|
+
equals(other: Ipv6Addr | Ipv4Addr | object): boolean;
|
|
201
208
|
}
|
|
202
209
|
//#endregion
|
|
203
210
|
//#region src/Ipv4Addr.d.ts
|
|
@@ -365,6 +372,13 @@ declare class Ipv4Addr {
|
|
|
365
372
|
* @since v0.0.1
|
|
366
373
|
*/
|
|
367
374
|
toBuffer(littleEndian?: boolean): ArrayBuffer;
|
|
375
|
+
/**
|
|
376
|
+
* Compares this IPv4 address with another for equality.
|
|
377
|
+
* @param other instance of another IPv4 address to compare with.
|
|
378
|
+
* @returns `true` if both addresses are equal, otherwise `false`.
|
|
379
|
+
* @since v0.1.0
|
|
380
|
+
*/
|
|
381
|
+
equals(other: Ipv4Addr | Ipv6Addr | object): boolean;
|
|
368
382
|
}
|
|
369
383
|
//#endregion
|
|
370
384
|
export { Ipv4Addr, Ipv6Addr };
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/Ipv6Addr.ts","../src/Ipv4Addr.ts"],"mappings":";;;;AAWA;;;;;;;cAAa,QAAA;EAAA;iBACG,KAAA;;;;;;;;SAUD,IAAA,CAAK,KAAA,WAAgB,OAAA,CAAQ,QAAA
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/Ipv6Addr.ts","../src/Ipv4Addr.ts"],"mappings":";;;;AAWA;;;;;;;cAAa,QAAA;EAAA;iBACG,KAAA;;;;;;;;SAUD,IAAA,CAAK,KAAA,WAAgB,OAAA,CAAQ,QAAA;EAyXX;;;;;EAAA,OAjWlB,UAAA,CAAW,MAAA,EAAQ,WAAA,EAAa,YAAA,aAAyB,OAAA,CAAQ,QAAA;;;;;kBA2CxD,IAAA;;;;;kBAMA,SAAA,EAAW,QAAA;;;;;kBAMX,WAAA,EAAa,QAAA;;;;;WAMpB,MAAA;EAGhB,WAAA,CAAmB,KAAA;EACnB,WAAA,CAAmB,QAAA;;;;;;;EAenB,cAAA;;;;;;;EAUA,eAAA;;;;;;;EAUA,UAAA;;;;;;;EAUA,aAAA;EAmPgC;;;;ACpYjC;;ED2JC,WAAA;;;;;;;EAUA,yBAAA;;;;;;;EAUA,oBAAA;ECwFgC;;;;;;ED9EhC,qBAAA;;;;;;;EAUA,qBAAA;;;;;;;EAUA,oBAAA;;;;;;;EAUA,4BAAA;;;;;;;EAUA,iBAAA;;;;;;EASA,YAAA;;;;;;;EAUA,SAAA;;;;;;ACmBgC;ED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";var i=class i{static regex=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;static from(t){if(!i.regex.test(t))return e(TypeError(`${t} is invalid ipv6 value`));try{let{leftParts:e,rightParts:r,embeddedIpv4:a}=i.#e(t),o=e.map(e=>parseInt(e,16)),s=r.map(e=>parseInt(e,16)),c=8-(o.length+s.length+a.length);return n(new i([...o,...Array(c).fill(0),...s,...a]))}catch(t){return e(t)}}static fromBuffer(t,r){try{let e=new DataView(t);if(r){let t=e.getBigUint64(0,!0);return n(new i(e.getBigUint64(8,!0)<<64n|t))}else{let t=e.getBigUint64(0,!1),r=e.getBigUint64(8,!1);return n(new i(t<<64n|r))}}catch(t){return e(t)}}static#e(e){let t=e.split(`::`),n=t[0].split(`:`).filter(e=>e!==``),r=t.length>1?t[1].split(`:`).filter(e=>e!==``):[],a=[],o=r[r.length-1]??n[n.length-1];return o?.includes(`.`)&&(a=i.#t(o),r.length>0?r.pop():n.pop()),{leftParts:n,rightParts:r,embeddedIpv4:a}}static#t(e){let t=e.split(`.`).map(Number);return[t[0]<<8|t[1],t[2]<<8|t[3]]}static BITS=128;static LOCALHOST=new i(1n);static UNSPECIFIED=new i(0n);family=`ipv6`;#n;constructor(e){Array.isArray(e)?this.#n=this.#r(e):this.#n=e}isBenchmarking(){return this.#a(42540488320432167789079031612388147200n,48)}isDocumentation(){return this.#a(42540766411282592856903984951653826560n,32)||this.#a(85065399433376081038215121361612832768n,20)}isLoopback(){return this.#n===1n}isUnspecified(){return this.#n===0n}isMulticast(){return this.#n>>120n==255n}isMulticastInterfaceLocal(){return this.#a(338958331222012082418099330867817086976n,16)}isMulticastLinkLocal(){return this.#a(338963523518870617245727861364146307072n,16)}isMulticastRealmLocal(){return this.#a(338968715815729152073356391860475527168n,16)}isMulticastAdminLocal(){return this.#a(338973908112587686900984922356804747264n,16)}isMulticastSiteLocal(){return this.#a(338979100409446221728613452853133967360n,16)}isMulticastOrganizationLocal(){return this.#a(338994677300021826211499044342121627648n,16)}isMulticastGlobal(){return this.#a(339025831081173035177270227320096948224n,16)}isIpv4Mapped(){return this.#a(281470681743360n,96)}isUnicast(){return!this.isMulticast()}isUnicastLinkLocal(){return this.#a(338288524927261089654018896841347694592n,10)}isUnicastGlobal(){return this.isUnicast()&&!this.isLoopback()&&!this.isUnicastLinkLocal()&&!this.isUniqueLocal()&&!this.isUnspecified()&&!this.isDocumentation()}isGlobal(){return!this.isUnspecified()&&!this.isLoopback()&&!this.isIpv4Mapped()&&!this.isBenchmarking()&&!this.isDocumentation()&&!this.isUniqueLocal()&&!this.isUnicastLinkLocal()&&!this.isMulticast()}isUniqueLocal(){return this.#a(334965454937798799971759379190646833152n,7)}toIpv4(){if(this.isIpv4Mapped()||this.#a(0n,96)){let e=this.#i(this.#n);return r(new a(e[6]>>8,e[6]&255,e[7]>>8,e[7]&255))}return t()}toIpv4Mapped(){if(this.isIpv4Mapped()){let e=this.#i(this.#n);return r(new a(e[6]>>8,e[6]&255,e[7]>>8,e[7]&255))}return t()}toString(){let e=this.#i(this.#n),t=-1,n=0,r=-1,i=0;for(let a=0;a<e.length;a++)e[a]===0?(r===-1?(r=a,i=1):i++,i>n&&(n=i,t=r)):(r=-1,i=0);if(n<2)return e.map(e=>e.toString(16)).join(`:`);let a=e.slice(0,t).map(e=>e.toString(16)),o=e.slice(t+n).map(e=>e.toString(16));return`${a.join(`:`)}::${o.join(`:`)}`}toBuffer(e){let t=new ArrayBuffer(16),n=new DataView(t);return e?(n.setBigUint64(0,this.#n&18446744073709551615n,!0),n.setBigUint64(8,this.#n>>64n,!0)):(n.setBigUint64(0,this.#n>>64n,!1),n.setBigUint64(8,this.#n&18446744073709551615n,!1)),t}#r(e){let t=0n;for(let n of e){if(n<0||n>65535)throw Error(`IPv6 segment must be between 0 and 65535`);t=t<<16n|BigInt(n)}return t}#i(e){return[Number(e>>112n&65535n),Number(e>>96n&65535n),Number(e>>80n&65535n),Number(e>>64n&65535n),Number(e>>48n&65535n),Number(e>>32n&65535n),Number(e>>16n&65535n),Number(e&65535n)]}#a(e,t){if(t<0||t>128)throw Error(`Invalid prefix length`);if(t===0)return!0;let n=(1n<<128n)-1n,r=n<<BigInt(128-t)&n;return(this.#n&r)===(e&r)}},a=class t{static from(r){let i=r.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);if(!i)return e(TypeError(`${r} is invalid ipv4 value`));let a=i.slice(1).map(Number);return a.some(e=>e>255)?e(TypeError(`${r} is invalid ipv4 value`)):n(new t(a[0],a[1],a[2],a[3]))}static fromBuffer(r,i){try{return n(new t(new DataView(r).getUint32(0,i)))}catch(t){return e(t)}}static BITS=32;static BROADCAST=new t(4294967295);static LOCALHOST=new t(2130706433);static UNSPECIFIED=new t(0);family=`ipv4`;#e;constructor(...e){e.length===1?this.#e=e[0]:this.#e=this.#t(e[0],e[1],e[2],e[3])}isBroadcast(){return this.#e===4294967295}isDocumentation(){return this.#r(3221225984,24)||this.#r(3325256704,24)||this.#r(3405803776,24)}isBenchmarking(){return this.#r(3323068416,15)}isGlobal(){return!(this.isUnspecified()||this.isPrivate()||this.isShared()||this.isLoopback()||this.isLinkLocal()||this.isDocumentation()||this.isBenchmarking()||this.isReserved()||this.isMulticast()||this.isBroadcast())}isLinkLocal(){return this.#r(2851995648,16)}isLoopback(){return this.#r(2130706432,8)}isMulticast(){return this.#r(3758096384,4)}isPrivate(){return this.#r(167772160,8)||this.#r(2886729728,12)||this.#r(3232235520,16)}isReserved(){return this.#r(4026531840,4)&&!this.isBroadcast()}isShared(){return this.#r(1681915904,10)}isUnspecified(){return this.#e===0}toIpv6(){return i.from(`::${this.toString()}`).unwrap()}toIpv6Mapped(){return i.from(`::ffff:${this.toString()}`).unwrap()}toString(){let[e,t,n,r]=this.#n(this.#e);return`${e}.${t}.${n}.${r}`}toBuffer(e){let t=new ArrayBuffer(4);return new DataView(t).setUint32(0,this.#e,e),t}#t(e,t,n,r){for(let i of[e,t,n,r])if(i<0||i>255)throw Error(`IPv4 octet must be between 0 and 255`);return(e<<24|t<<16|n<<8|r)>>>0}#n(e){return[e>>24&255,e>>16&255,e>>8&255,e&255]}#r(e,t){if(t<0||t>32)throw Error(`Invalid prefix length`);let n=t===0?0:-1<<32-t>>>0;return(this.#e&n)===(e&n)}};export{a as Ipv4Addr,i as Ipv6Addr};
|
|
1
|
+
import{Err as e,None as t,Ok as n,Some as r}from"@luolapeikko/result-option";var i=class i{static regex=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;static from(t){if(!i.regex.test(t))return e(TypeError(`${t} is invalid ipv6 value`));try{let{leftParts:e,rightParts:r,embeddedIpv4:a}=i.#e(t),o=e.map(e=>parseInt(e,16)),s=r.map(e=>parseInt(e,16)),c=8-(o.length+s.length+a.length);return n(new i([...o,...Array(c).fill(0),...s,...a]))}catch(t){return e(t)}}static fromBuffer(t,r){try{let e=new DataView(t);if(r){let t=e.getBigUint64(0,!0);return n(new i(e.getBigUint64(8,!0)<<64n|t))}else{let t=e.getBigUint64(0,!1),r=e.getBigUint64(8,!1);return n(new i(t<<64n|r))}}catch(t){return e(t)}}static#e(e){let t=e.split(`::`),n=t[0].split(`:`).filter(e=>e!==``),r=t.length>1?t[1].split(`:`).filter(e=>e!==``):[],a=[],o=r[r.length-1]??n[n.length-1];return o?.includes(`.`)&&(a=i.#t(o),r.length>0?r.pop():n.pop()),{leftParts:n,rightParts:r,embeddedIpv4:a}}static#t(e){let t=e.split(`.`).map(Number);return[t[0]<<8|t[1],t[2]<<8|t[3]]}static BITS=128;static LOCALHOST=new i(1n);static UNSPECIFIED=new i(0n);family=`ipv6`;#n;constructor(e){Array.isArray(e)?this.#n=this.#r(e):this.#n=e}isBenchmarking(){return this.#a(42540488320432167789079031612388147200n,48)}isDocumentation(){return this.#a(42540766411282592856903984951653826560n,32)||this.#a(85065399433376081038215121361612832768n,20)}isLoopback(){return this.#n===1n}isUnspecified(){return this.#n===0n}isMulticast(){return this.#n>>120n==255n}isMulticastInterfaceLocal(){return this.#a(338958331222012082418099330867817086976n,16)}isMulticastLinkLocal(){return this.#a(338963523518870617245727861364146307072n,16)}isMulticastRealmLocal(){return this.#a(338968715815729152073356391860475527168n,16)}isMulticastAdminLocal(){return this.#a(338973908112587686900984922356804747264n,16)}isMulticastSiteLocal(){return this.#a(338979100409446221728613452853133967360n,16)}isMulticastOrganizationLocal(){return this.#a(338994677300021826211499044342121627648n,16)}isMulticastGlobal(){return this.#a(339025831081173035177270227320096948224n,16)}isIpv4Mapped(){return this.#a(281470681743360n,96)}isUnicast(){return!this.isMulticast()}isUnicastLinkLocal(){return this.#a(338288524927261089654018896841347694592n,10)}isUnicastGlobal(){return this.isUnicast()&&!this.isLoopback()&&!this.isUnicastLinkLocal()&&!this.isUniqueLocal()&&!this.isUnspecified()&&!this.isDocumentation()}isGlobal(){return!this.isUnspecified()&&!this.isLoopback()&&!this.isIpv4Mapped()&&!this.isBenchmarking()&&!this.isDocumentation()&&!this.isUniqueLocal()&&!this.isUnicastLinkLocal()&&!this.isMulticast()}isUniqueLocal(){return this.#a(334965454937798799971759379190646833152n,7)}toIpv4(){if(this.isIpv4Mapped()||this.#a(0n,96)){let e=this.#i(this.#n);return r(new a(e[6]>>8,e[6]&255,e[7]>>8,e[7]&255))}return t()}toIpv4Mapped(){if(this.isIpv4Mapped()){let e=this.#i(this.#n);return r(new a(e[6]>>8,e[6]&255,e[7]>>8,e[7]&255))}return t()}toString(){let e=this.#i(this.#n),t=-1,n=0,r=-1,i=0;for(let a=0;a<e.length;a++)e[a]===0?(r===-1?(r=a,i=1):i++,i>n&&(n=i,t=r)):(r=-1,i=0);if(n<2)return e.map(e=>e.toString(16)).join(`:`);let a=e.slice(0,t).map(e=>e.toString(16)),o=e.slice(t+n).map(e=>e.toString(16));return`${a.join(`:`)}::${o.join(`:`)}`}toBuffer(e){let t=new ArrayBuffer(16),n=new DataView(t);return e?(n.setBigUint64(0,this.#n&18446744073709551615n,!0),n.setBigUint64(8,this.#n>>64n,!0)):(n.setBigUint64(0,this.#n>>64n,!1),n.setBigUint64(8,this.#n&18446744073709551615n,!1)),t}equals(e){return`family`in e&&this.family===e.family&&this.#n===e.#n}#r(e){let t=0n;for(let n of e){if(n<0||n>65535)throw Error(`IPv6 segment must be between 0 and 65535`);t=t<<16n|BigInt(n)}return t}#i(e){return[Number(e>>112n&65535n),Number(e>>96n&65535n),Number(e>>80n&65535n),Number(e>>64n&65535n),Number(e>>48n&65535n),Number(e>>32n&65535n),Number(e>>16n&65535n),Number(e&65535n)]}#a(e,t){if(t<0||t>128)throw Error(`Invalid prefix length`);if(t===0)return!0;let n=(1n<<128n)-1n,r=n<<BigInt(128-t)&n;return(this.#n&r)===(e&r)}},a=class t{static from(r){let i=r.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);if(!i)return e(TypeError(`${r} is invalid ipv4 value`));let a=i.slice(1).map(Number);return a.some(e=>e>255)?e(TypeError(`${r} is invalid ipv4 value`)):n(new t(a[0],a[1],a[2],a[3]))}static fromBuffer(r,i){try{return n(new t(new DataView(r).getUint32(0,i)))}catch(t){return e(t)}}static BITS=32;static BROADCAST=new t(4294967295);static LOCALHOST=new t(2130706433);static UNSPECIFIED=new t(0);family=`ipv4`;#e;constructor(...e){e.length===1?this.#e=e[0]:this.#e=this.#t(e[0],e[1],e[2],e[3])}isBroadcast(){return this.#e===4294967295}isDocumentation(){return this.#r(3221225984,24)||this.#r(3325256704,24)||this.#r(3405803776,24)}isBenchmarking(){return this.#r(3323068416,15)}isGlobal(){return!(this.isUnspecified()||this.isPrivate()||this.isShared()||this.isLoopback()||this.isLinkLocal()||this.isDocumentation()||this.isBenchmarking()||this.isReserved()||this.isMulticast()||this.isBroadcast())}isLinkLocal(){return this.#r(2851995648,16)}isLoopback(){return this.#r(2130706432,8)}isMulticast(){return this.#r(3758096384,4)}isPrivate(){return this.#r(167772160,8)||this.#r(2886729728,12)||this.#r(3232235520,16)}isReserved(){return this.#r(4026531840,4)&&!this.isBroadcast()}isShared(){return this.#r(1681915904,10)}isUnspecified(){return this.#e===0}toIpv6(){return i.from(`::${this.toString()}`).unwrap()}toIpv6Mapped(){return i.from(`::ffff:${this.toString()}`).unwrap()}toString(){let[e,t,n,r]=this.#n(this.#e);return`${e}.${t}.${n}.${r}`}toBuffer(e){let t=new ArrayBuffer(4);return new DataView(t).setUint32(0,this.#e,e),t}equals(e){return`family`in e&&this.family===e.family&&this.#e===e.#e}#t(e,t,n,r){for(let i of[e,t,n,r])if(i<0||i>255)throw Error(`IPv4 octet must be between 0 and 255`);return(e<<24|t<<16|n<<8|r)>>>0}#n(e){return[e>>24&255,e>>16&255,e>>8&255,e&255]}#r(e,t){if(t<0||t>32)throw Error(`Invalid prefix length`);let n=t===0?0:-1<<32-t>>>0;return(this.#e&n)===(e&n)}};export{a as Ipv4Addr,i as Ipv6Addr};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["#parseComponents","#parseEmbeddedIpv4","#integerAddress","#toInteger","#match","#fromInteger","#integerAddress","#toInteger","#match","#fromInteger"],"sources":["../src/Ipv6Addr.ts","../src/Ipv4Addr.ts"],"sourcesContent":["import {Err, type IOption, type IResult, None, Ok, Some} from '@luolapeikko/result-option';\nimport {Ipv4Addr} from './Ipv4Addr';\n\n/**\n * Represents an IPv6 address.\n * @example\n * const addr1 = Ipv6Addr.from('2001:db8::1').unwrap();\n * const addr2 = new Ipv6Addr([0x2001, 0xdb8, 0, 0, 0, 0, 0, 1]);\n * const addr3 = new Ipv6Addr(0x20010db8000000000000000000000001n);\n * @since v0.0.1\n */\nexport class Ipv6Addr {\n\tprivate static regex =\n\t\t/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;\n\n\t/**\n\t * Creates an IPv6 address from text.\n\t * @returns A successful result with an IPv6 address, or an error when the input is invalid.\n\t * @example\n\t * const addr = Ipv6Addr.from('2001:db8::1').unwrap();\n\t * @since v0.0.1\n\t */\n\tpublic static from(value: string): IResult<Ipv6Addr> {\n\t\tif (!Ipv6Addr.regex.test(value)) {\n\t\t\treturn Err(new TypeError(`${value} is invalid ipv6 value`));\n\t\t}\n\t\ttry {\n\t\t\tconst {leftParts, rightParts, embeddedIpv4} = Ipv6Addr.#parseComponents(value);\n\n\t\t\tconst leftSegs = leftParts.map((p) => parseInt(p, 16));\n\t\t\tconst rightSegs = rightParts.map((p) => parseInt(p, 16));\n\n\t\t\tconst missingLen = 8 - (leftSegs.length + rightSegs.length + embeddedIpv4.length);\n\t\t\tconst segments = [...leftSegs, ...Array(missingLen).fill(0), ...rightSegs, ...embeddedIpv4];\n\n\t\t\treturn Ok(new Ipv6Addr(segments as [number, number, number, number, number, number, number, number]));\n\t\t} catch (err) {\n\t\t\treturn Err(err);\n\t\t}\n\t}\n\n\t/**\n\t * Creates an IPv6 address from a 16-byte buffer.\n\t * @returns A successful result with an IPv6 address, or an error when the buffer cannot be read.\n\t * @since v0.0.1\n\t */\n\tpublic static fromBuffer(buffer: ArrayBuffer, littleEndian?: boolean): IResult<Ipv6Addr> {\n\t\ttry {\n\t\t\tconst view = new DataView(buffer);\n\t\t\tif (littleEndian) {\n\t\t\t\tconst low = view.getBigUint64(0, true);\n\t\t\t\tconst high = view.getBigUint64(8, true);\n\t\t\t\treturn Ok(new Ipv6Addr((high << 64n) | low));\n\t\t\t} else {\n\t\t\t\tconst high = view.getBigUint64(0, false);\n\t\t\t\tconst low = view.getBigUint64(8, false);\n\t\t\t\treturn Ok(new Ipv6Addr((high << 64n) | low));\n\t\t\t}\n\t\t} catch (err) {\n\t\t\treturn Err(err as Error);\n\t\t}\n\t}\n\n\tstatic #parseComponents(value: string) {\n\t\tconst components = value.split('::');\n\t\tconst leftParts = components[0].split(':').filter((x) => x !== '');\n\t\tconst rightParts = components.length > 1 ? components[1].split(':').filter((x) => x !== '') : [];\n\t\tlet embeddedIpv4: number[] = [];\n\t\tconst lastPart = rightParts[rightParts.length - 1] ?? leftParts[leftParts.length - 1];\n\t\tif (lastPart?.includes('.')) {\n\t\t\tembeddedIpv4 = Ipv6Addr.#parseEmbeddedIpv4(lastPart);\n\t\t\tif (rightParts.length > 0) {\n\t\t\t\trightParts.pop();\n\t\t\t} else {\n\t\t\t\tleftParts.pop();\n\t\t\t}\n\t\t}\n\t\treturn {leftParts, rightParts, embeddedIpv4};\n\t}\n\n\tstatic #parseEmbeddedIpv4(value: string): number[] {\n\t\tconst ipv4Octets = value.split('.').map(Number);\n\t\treturn [(ipv4Octets[0] << 8) | ipv4Octets[1], (ipv4Octets[2] << 8) | ipv4Octets[3]];\n\t}\n\n\t/**\n\t * The number of bits in an IPv6 address.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly BITS = 128;\n\n\t/**\n\t * The loopback address (`::1`).\n\t * @since v0.0.1\n\t */\n\tpublic static readonly LOCALHOST: Ipv6Addr = new Ipv6Addr(0x00000000000000000000000000000001n);\n\n\t/**\n\t * The unspecified address (`::`).\n\t * @since v0.0.1\n\t */\n\tpublic static readonly UNSPECIFIED: Ipv6Addr = new Ipv6Addr(0x00000000000000000000000000000000n);\n\n\t/**\n\t * The address family identifier for IPv6 addresses.\n\t * @since v0.0.1\n\t */\n\tpublic readonly family = 'ipv6';\n\n\t#integerAddress: bigint;\n\tpublic constructor(value: bigint);\n\tpublic constructor(segments: [number, number, number, number, number, number, number, number]);\n\tpublic constructor(valueOrSegments: [number, number, number, number, number, number, number, number] | bigint) {\n\t\tif (Array.isArray(valueOrSegments)) {\n\t\t\tthis.#integerAddress = this.#toInteger(valueOrSegments);\n\t\t} else {\n\t\t\tthis.#integerAddress = valueOrSegments;\n\t\t}\n\t}\n\n\t/**\n\t * Checks whether this address is in the benchmarking range.\n\t * @see https://tools.ietf.org/html/rfc5180 and https://www.rfc-editor.org/errata_search.php?eid=1752\n\t * @returns `true` when the address is in `2001:2::/48`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isBenchmarking(): boolean {\n\t\treturn this.#match(0x20010002000000000000000000000000n, 48);\n\t}\n\n\t/**\n\t * Checks whether this address is in a documentation-only range.\n\t * @see https://tools.ietf.org/html/rfc3849 and https://tools.ietf.org/html/rfc9637\n\t * @returns `true` for `2001:db8::/32` or `3fff::/20`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isDocumentation(): boolean {\n\t\treturn this.#match(0x20010db8000000000000000000000000n, 32) || this.#match(0x3fff0000000000000000000000000000n, 20);\n\t}\n\n\t/**\n\t * Checks whether this address is the loopback address.\n\t * @see https://tools.ietf.org/html/rfc4291#section-2.5.3\n\t * @returns `true` when the address is `::1`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isLoopback(): boolean {\n\t\treturn this.#integerAddress === 1n;\n\t}\n\n\t/**\n\t * Checks whether this address is the unspecified address.\n\t * @see https://tools.ietf.org/html/rfc4291\n\t * @returns `true` when the address is `::`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUnspecified(): boolean {\n\t\treturn this.#integerAddress === 0n;\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast address.\n\t * @see https://tools.ietf.org/html/rfc4291\n\t * @returns `true` when the address is in `ff00::/8`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isMulticast(): boolean {\n\t\treturn this.#integerAddress >> 120n === 0xffn;\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast interface-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff01::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastInterfaceLocal(): boolean {\n\t\treturn this.#match(0xff010000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast link-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff02::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastLinkLocal(): boolean {\n\t\treturn this.#match(0xff020000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast realm-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff03::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastRealmLocal(): boolean {\n\t\treturn this.#match(0xff030000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast admin-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff04::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastAdminLocal(): boolean {\n\t\treturn this.#match(0xff040000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast site-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff05::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastSiteLocal(): boolean {\n\t\treturn this.#match(0xff050000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast organization-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff08::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastOrganizationLocal(): boolean {\n\t\treturn this.#match(0xff080000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast global address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff0e::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastGlobal(): boolean {\n\t\treturn this.#match(0xff0e0000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is an IPv4-mapped IPv6 address.\n\t * @returns `true` when the address is in `::ffff:0:0/96`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isIpv4Mapped(): boolean {\n\t\treturn this.#match(0x00000000000000000000ffff00000000n, 96);\n\t}\n\n\t/**\n\t * Checks whether this address is a unicast address.\n\t * @see https://tools.ietf.org/html/rfc4291\n\t * @returns `true` when the address is not multicast, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUnicast(): boolean {\n\t\treturn !this.isMulticast();\n\t}\n\n\t/**\n\t * Checks whether this address is a link-local unicast address.\n\t * @see https://tools.ietf.org/html/rfc4291\n\t * @returns `true` when the address is in `fe80::/10`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUnicastLinkLocal(): boolean {\n\t\treturn this.#match(0xfe800000000000000000000000000000n, 10);\n\t}\n\n\t/**\n\t * Checks whether this address is a global unicast address.\n\t * @see https://tools.ietf.org/html/rfc4291#section-2.5.7\n\t * @returns `true` when the address is unicast and not loopback, link-local, private, unspecified, or documentation.\n\t * @since v0.0.1\n\t */\n\tpublic isUnicastGlobal(): boolean {\n\t\treturn this.isUnicast() && !this.isLoopback() && !this.isUnicastLinkLocal() && !this.isUniqueLocal() && !this.isUnspecified() && !this.isDocumentation();\n\t}\n\n\t/**\n\t * Checks whether this address appears globally reachable.\n\t * @see https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml\n\t * @returns `true` when the address is not in known non-global special ranges.\n\t * @since v0.0.1\n\t */\n\tpublic isGlobal(): boolean {\n\t\treturn (\n\t\t\t!this.isUnspecified() &&\n\t\t\t!this.isLoopback() &&\n\t\t\t!this.isIpv4Mapped() &&\n\t\t\t!this.isBenchmarking() &&\n\t\t\t!this.isDocumentation() &&\n\t\t\t!this.isUniqueLocal() &&\n\t\t\t!this.isUnicastLinkLocal() &&\n\t\t\t!this.isMulticast()\n\t\t);\n\t}\n\n\t/**\n\t * Checks whether this address is in the unique-local range.\n\t * @see https://tools.ietf.org/html/rfc4193\n\t * @returns `true` when the address is in `fc00::/7`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUniqueLocal(): boolean {\n\t\treturn this.#match(0xfc000000000000000000000000000000n, 7);\n\t}\n\n\t/**\n\t * Converts this address to IPv4 when compatible or mapped.\n\t * @returns An IPv4 address for `::a.b.c.d` or `::ffff:a.b.c.d`; otherwise `None`.\n\t * @since v0.0.1\n\t */\n\tpublic toIpv4(): IOption<Ipv4Addr> {\n\t\tif (this.isIpv4Mapped() || this.#match(0n, 96)) {\n\t\t\tconst segments = this.#fromInteger(this.#integerAddress);\n\t\t\treturn Some(new Ipv4Addr(segments[6] >> 8, segments[6] & 0xff, segments[7] >> 8, segments[7] & 0xff));\n\t\t}\n\t\treturn None();\n\t}\n\n\t/**\n\t * Converts this address to IPv4 only when it is IPv4-mapped.\n\t * @returns An IPv4 address for `::ffff:a.b.c.d`; otherwise `None`.\n\t * @since v0.0.1\n\t */\n\tpublic toIpv4Mapped(): IOption<Ipv4Addr> {\n\t\tif (this.isIpv4Mapped()) {\n\t\t\tconst segments = this.#fromInteger(this.#integerAddress);\n\t\t\treturn Some(new Ipv4Addr(segments[6] >> 8, segments[6] & 0xff, segments[7] >> 8, segments[7] & 0xff));\n\t\t}\n\t\treturn None();\n\t}\n\n\t/**\n\t * Formats this address as a compressed IPv6 string.\n\t * @returns The shortest standard IPv6 text form.\n\t * @since v0.0.1\n\t */\n\tpublic toString(): string {\n\t\tconst segments = this.#fromInteger(this.#integerAddress);\n\t\tlet maxZeroStart = -1;\n\t\tlet maxZeroLen = 0;\n\t\tlet currentZeroStart = -1;\n\t\tlet currentZeroLen = 0;\n\n\t\tfor (let i = 0; i < segments.length; i++) {\n\t\t\tif (segments[i] === 0) {\n\t\t\t\tif (currentZeroStart === -1) {\n\t\t\t\t\tcurrentZeroStart = i;\n\t\t\t\t\tcurrentZeroLen = 1;\n\t\t\t\t} else {\n\t\t\t\t\tcurrentZeroLen++;\n\t\t\t\t}\n\t\t\t\tif (currentZeroLen > maxZeroLen) {\n\t\t\t\t\tmaxZeroLen = currentZeroLen;\n\t\t\t\t\tmaxZeroStart = currentZeroStart;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcurrentZeroStart = -1;\n\t\t\t\tcurrentZeroLen = 0;\n\t\t\t}\n\t\t}\n\n\t\tif (maxZeroLen < 2) {\n\t\t\treturn segments.map((s) => s.toString(16)).join(':');\n\t\t}\n\n\t\tconst before = segments.slice(0, maxZeroStart).map((s) => s.toString(16));\n\t\tconst after = segments.slice(maxZeroStart + maxZeroLen).map((s) => s.toString(16));\n\n\t\treturn `${before.join(':')}::${after.join(':')}`;\n\t}\n\n\t/**\n\t * Encodes this address to a 16-byte buffer.\n\t * @param littleEndian Whether to use little-endian byte order. Defaults to `false`.\n\t * @returns An `ArrayBuffer` containing the IPv6 integer value.\n\t * @since v0.0.1\n\t */\n\tpublic toBuffer(littleEndian?: boolean): ArrayBuffer {\n\t\tconst buffer = new ArrayBuffer(16);\n\t\tconst view = new DataView(buffer);\n\t\tif (littleEndian) {\n\t\t\tview.setBigUint64(0, this.#integerAddress & 0xffffffffffffffffn, true);\n\t\t\tview.setBigUint64(8, this.#integerAddress >> 64n, true);\n\t\t} else {\n\t\t\tview.setBigUint64(0, this.#integerAddress >> 64n, false);\n\t\t\tview.setBigUint64(8, this.#integerAddress & 0xffffffffffffffffn, false);\n\t\t}\n\t\treturn buffer;\n\t}\n\n\t#toInteger(segments: [number, number, number, number, number, number, number, number]): bigint {\n\t\tlet result = 0n;\n\t\tfor (const segment of segments) {\n\t\t\tif (segment < 0 || segment > 0xffff) {\n\t\t\t\tthrow new Error('IPv6 segment must be between 0 and 65535');\n\t\t\t}\n\t\t\tresult = (result << 16n) | BigInt(segment);\n\t\t}\n\t\treturn result;\n\t}\n\n\t#fromInteger(integer: bigint): [number, number, number, number, number, number, number, number] {\n\t\treturn [\n\t\t\tNumber((integer >> 112n) & 0xffffn),\n\t\t\tNumber((integer >> 96n) & 0xffffn),\n\t\t\tNumber((integer >> 80n) & 0xffffn),\n\t\t\tNumber((integer >> 64n) & 0xffffn),\n\t\t\tNumber((integer >> 48n) & 0xffffn),\n\t\t\tNumber((integer >> 32n) & 0xffffn),\n\t\t\tNumber((integer >> 16n) & 0xffffn),\n\t\t\tNumber(integer & 0xffffn),\n\t\t];\n\t}\n\n\t#match(network: bigint, prefix: number): boolean {\n\t\tif (prefix < 0 || prefix > 128) {\n\t\t\tthrow new Error('Invalid prefix length');\n\t\t}\n\t\tif (prefix === 0) {\n\t\t\treturn true;\n\t\t}\n\t\tconst ALL_ONES = (1n << 128n) - 1n;\n\t\tconst mask = (ALL_ONES << BigInt(128 - prefix)) & ALL_ONES;\n\t\treturn (this.#integerAddress & mask) === (network & mask);\n\t}\n}\n","import {Err, type IResult, Ok} from '@luolapeikko/result-option';\nimport {Ipv6Addr} from './Ipv6Addr';\n\n/**\n * Represents an IPv4 address.\n * @example\n * const addr1 = Ipv4Addr.from('192.168.0.1').unwrap();\n * const addr2 = new Ipv4Addr(192, 168, 0, 1);\n * const addr3 = new Ipv4Addr(0xc0a80001);\n * @since v0.0.1\n */\nexport class Ipv4Addr {\n\t/**\n\t * Creates an IPv4 address from dotted-decimal text.\n\t * @returns A successful {@link IResult} with an IPv4 address, or an error when the input is invalid.\n\t * @since v0.0.1\n\t */\n\tpublic static from(value: string): IResult<Ipv4Addr, TypeError> {\n\t\tconst match = value.match(/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/);\n\t\tif (!match) {\n\t\t\treturn Err(new TypeError(`${value} is invalid ipv4 value`));\n\t\t}\n\t\tconst octets = match.slice(1).map(Number);\n\t\tif (octets.some((o) => o > 255)) {\n\t\t\treturn Err(new TypeError(`${value} is invalid ipv4 value`));\n\t\t}\n\t\treturn Ok(new Ipv4Addr(octets[0], octets[1], octets[2], octets[3]));\n\t}\n\n\t/**\n\t * Creates an IPv4 address from a 4-byte buffer.\n\t * @returns A successful {@link IResult} with an IPv4 address, or an error when the buffer cannot be read.\n\t * @since v0.0.1\n\t */\n\tpublic static fromBuffer(buffer: ArrayBuffer, littleEndian?: boolean): IResult<Ipv4Addr> {\n\t\ttry {\n\t\t\tconst view = new DataView(buffer);\n\t\t\treturn Ok(new Ipv4Addr(view.getUint32(0, littleEndian)));\n\t\t} catch (err) {\n\t\t\treturn Err(err);\n\t\t}\n\t}\n\n\t/**\n\t * The number of bits in an IPv4 address.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly BITS = 32;\n\n\t/**\n\t * The broadcast address `255.255.255.255`.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly BROADCAST: Ipv4Addr = new Ipv4Addr(0xffffffff);\n\n\t/**\n\t * The localhost address `127.0.0.1`.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly LOCALHOST: Ipv4Addr = new Ipv4Addr(0x7f000001);\n\n\t/**\n\t * The unspecified address `0.0.0.0`.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly UNSPECIFIED: Ipv4Addr = new Ipv4Addr(0x00000000);\n\n\t/**\n\t * The address family identifier for IPv4 addresses.\n\t * @since v0.0.1\n\t */\n\tpublic readonly family = 'ipv4';\n\n\t#integerAddress: number;\n\n\t/**\n\t * Creates a new IPv4 address from four octets.\n\t * @param num1 The first octet.\n\t * @param num2 The second octet.\n\t * @param num3 The third octet.\n\t * @param num4 The fourth octet.\n\t * @example\n\t * new Ipv4Addr(192, 168, 0, 1) // creates the address `192.168.0.1`\n\t */\n\tpublic constructor(num1: number, num2: number, num3: number, num4: number);\n\t/**\n\t * Creates a new IPv4 address from an integer value.\n\t * @param integerValue The integer representation of the IPv4 address.\n\t * @example\n\t * new Ipv4Addr(0xc0a80001) // creates the address `192.168.0.1` from the integer value `0xc0a80001`\n\t */\n\tpublic constructor(integerValue: number);\n\tpublic constructor(...args: [number] | [number, number, number, number]) {\n\t\tif (args.length === 1) {\n\t\t\tthis.#integerAddress = args[0];\n\t\t} else {\n\t\t\tthis.#integerAddress = this.#toInteger(args[0], args[1], args[2], args[3]);\n\t\t}\n\t}\n\n\t/**\n\t * Checks whether this address is the broadcast address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc919#section-7\n\t * @returns `true` when the address is `255.255.255.255`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isBroadcast(): boolean {\n\t\treturn this.#integerAddress === 0xffffffff;\n\t}\n\n\t/**\n\t * Checks whether this address is in a documentation-only range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc5737\n\t * @returns `true` for `192.0.2.0/24`, `198.51.100.0/24`, or `203.0.113.0/24`; otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isDocumentation(): boolean {\n\t\treturn (\n\t\t\tthis.#match(0xc0000200, 24) || // 192.0.2.0/24\n\t\t\tthis.#match(0xc6336400, 24) || // 198.51.100.0/24\n\t\t\tthis.#match(0xcb007100, 24) // 203.0.113.0/24\n\t\t);\n\t}\n\n\t/**\n\t * Checks whether this address is in the benchmarking range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc2544\n\t * @returns `true` when the address is in `198.18.0.0/15`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isBenchmarking(): boolean {\n\t\treturn this.#match(0xc6120000, 15);\n\t}\n\n\t/**\n\t * Checks whether this address is globally reachable.\n\t * @see https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml\n\t * @returns `true` when the address is not in any special non-global range.\n\t * @since v0.0.1\n\t */\n\tpublic isGlobal(): boolean {\n\t\treturn !(\n\t\t\tthis.isUnspecified() ||\n\t\t\tthis.isPrivate() ||\n\t\t\tthis.isShared() ||\n\t\t\tthis.isLoopback() ||\n\t\t\tthis.isLinkLocal() ||\n\t\t\tthis.isDocumentation() ||\n\t\t\tthis.isBenchmarking() ||\n\t\t\tthis.isReserved() ||\n\t\t\tthis.isMulticast() ||\n\t\t\tthis.isBroadcast()\n\t\t);\n\t}\n\n\t/**\n\t * Checks whether this address is link-local.\n\t * @see https://datatracker.ietf.org/doc/html/rfc3927\n\t * @returns `true` when the address is in `169.254.0.0/16`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isLinkLocal(): boolean {\n\t\treturn this.#match(0xa9fe0000, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a loopback address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc1122\n\t * @returns `true` when the address is in `127.0.0.0/8`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isLoopback(): boolean {\n\t\treturn this.#match(0x7f000000, 8);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc5771\n\t * @returns `true` when the address is in `224.0.0.0/4`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isMulticast(): boolean {\n\t\treturn this.#match(0xe0000000, 4);\n\t}\n\n\t/**\n\t * Checks whether this address is in a private-use range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc1918\n\t * @returns `true` for `10.0.0.0/8`, `172.16.0.0/12`, or `192.168.0.0/16`; otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isPrivate(): boolean {\n\t\treturn (\n\t\t\tthis.#match(0x0a000000, 8) || // 10.0.0.0/8\n\t\t\tthis.#match(0xac100000, 12) || // 172.16.0.0/12\n\t\t\tthis.#match(0xc0a80000, 16) // 192.168.0.0/16\n\t\t);\n\t}\n\n\t/**\n\t * Checks whether this address is in the reserved range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc1112\n\t * @returns `true` when the address is in `240.0.0.0/4` except the broadcast address.\n\t * @since v0.0.1\n\t */\n\tpublic isReserved(): boolean {\n\t\treturn this.#match(0xf0000000, 4) && !this.isBroadcast();\n\t}\n\n\t/**\n\t * Checks whether this address is in the shared Carrier-Grade NAT range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc6598\n\t * @returns `true` when the address is in `100.64.0.0/10`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isShared(): boolean {\n\t\treturn this.#match(0x64400000, 10);\n\t}\n\n\t/**\n\t * Checks whether this address is the unspecified address.\n\t * @returns `true` when the address is `0.0.0.0`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUnspecified(): boolean {\n\t\treturn this.#integerAddress === 0;\n\t}\n\n\t/**\n\t * Converts this address to an IPv4-compatible IPv6 address.\n\t * @returns An IPv6 address in the form `::a.b.c.d`.\n\t * @since v0.0.1\n\t */\n\tpublic toIpv6(): Ipv6Addr {\n\t\treturn Ipv6Addr.from(`::${this.toString()}`).unwrap();\n\t}\n\n\t/**\n\t * Converts this address to an IPv4-mapped IPv6 address.\n\t * @returns An IPv6 address in the form `::ffff:a.b.c.d`.\n\t * @since v0.0.1\n\t */\n\tpublic toIpv6Mapped(): Ipv6Addr {\n\t\treturn Ipv6Addr.from(`::ffff:${this.toString()}`).unwrap();\n\t}\n\n\t/**\n\t * Formats this address as dotted-decimal text.\n\t * @returns The IPv4 string representation, such as `192.168.0.1`.\n\t * @since v0.0.1\n\t */\n\tpublic toString(): string {\n\t\tconst [num1, num2, num3, num4] = this.#fromInteger(this.#integerAddress);\n\t\treturn `${num1}.${num2}.${num3}.${num4}`;\n\t}\n\n\t/**\n\t * Encodes this address to a 4-byte buffer.\n\t * @returns An `ArrayBuffer` containing the IPv4 integer value.\n\t * @since v0.0.1\n\t */\n\tpublic toBuffer(littleEndian?: boolean): ArrayBuffer {\n\t\tconst buffer = new ArrayBuffer(4);\n\t\tconst view = new DataView(buffer);\n\t\tview.setUint32(0, this.#integerAddress, littleEndian);\n\t\treturn buffer;\n\t}\n\n\t#toInteger(num1: number, num2: number, num3: number, num4: number): number {\n\t\tfor (const octet of [num1, num2, num3, num4]) {\n\t\t\tif (octet < 0 || octet > 255) {\n\t\t\t\tthrow new Error('IPv4 octet must be between 0 and 255');\n\t\t\t}\n\t\t}\n\t\treturn ((num1 << 24) | (num2 << 16) | (num3 << 8) | num4) >>> 0;\n\t}\n\n\t#fromInteger(integer: number): [number, number, number, number] {\n\t\tconst num1 = (integer >> 24) & 0xff;\n\t\tconst num2 = (integer >> 16) & 0xff;\n\t\tconst num3 = (integer >> 8) & 0xff;\n\t\tconst num4 = integer & 0xff;\n\t\treturn [num1, num2, num3, num4];\n\t}\n\n\t#match(network: number, prefix: number): boolean {\n\t\tif (prefix < 0 || prefix > 32) {\n\t\t\tthrow new Error('Invalid prefix length');\n\t\t}\n\t\tconst mask = prefix === 0 ? 0 : (~0 << (32 - prefix)) >>> 0;\n\t\treturn (this.#integerAddress & mask) === (network & mask);\n\t}\n}\n"],"mappings":"6EAWA,IAAa,EAAb,MAAa,CAAS,CACrB,OAAe,MACd,wpBASD,OAAc,KAAK,EAAkC,CACpD,GAAI,CAAC,EAA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vE,MAAO,GAAG,EAAK,GAAG,EAAK,GAAG,EAAK,GAAG,GACnC,CAOA,SAAgB,EAAqC,CACpD,IAAM,EAAS,IAAI,YAAY,CAAC,EAGhC,OADA,IADiB,SAAS,CACvB,CAAC,CAAC,UAAU,EAAG,KAAKA,GAAiB,CAAY,EAC7C,CACR,CAEA,GAAW,EAAc,EAAc,EAAc,EAAsB,CAC1E,IAAK,IAAM,IAAS,CAAC,EAAM,EAAM,EAAM,CAAI,EAC1C,GAAI,EAAQ,GAAK,EAAQ,IACxB,MAAU,MAAM,sCAAsC,EAGxD,OAAS,GAAQ,GAAO,GAAQ,GAAO,GAAQ,EAAK,KAAU,CAC/D,CAEA,GAAa,EAAmD,CAK/D,MAAO,CAJO,GAAW,GAAM,IACjB,GAAW,GAAM,IACjB,GAAW,EAAK,IACjB,EAAU,GACO,CAC/B,CAEA,GAAO,EAAiB,EAAyB,CAChD,GAAI,EAAS,GAAK,EAAS,GAC1B,MAAU,MAAM,uBAAuB,EAExC,IAAM,EAAO,IAAW,EAAI,EAAK,IAAO,GAAK,IAAa,EAC1D,OAAQ,KAAKA,GAAkB,MAAW,EAAU,EACrD,CACD"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["#parseComponents","#parseEmbeddedIpv4","#integerAddress","#toInteger","#match","#fromInteger","#integerAddress","#toInteger","#match","#fromInteger"],"sources":["../src/Ipv6Addr.ts","../src/Ipv4Addr.ts"],"sourcesContent":["import {Err, type IOption, type IResult, None, Ok, Some} from '@luolapeikko/result-option';\nimport {Ipv4Addr} from './Ipv4Addr';\n\n/**\n * Represents an IPv6 address.\n * @example\n * const addr1 = Ipv6Addr.from('2001:db8::1').unwrap();\n * const addr2 = new Ipv6Addr([0x2001, 0xdb8, 0, 0, 0, 0, 0, 1]);\n * const addr3 = new Ipv6Addr(0x20010db8000000000000000000000001n);\n * @since v0.0.1\n */\nexport class Ipv6Addr {\n\tprivate static regex =\n\t\t/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;\n\n\t/**\n\t * Creates an IPv6 address from text.\n\t * @returns A successful result with an IPv6 address, or an error when the input is invalid.\n\t * @example\n\t * const addr = Ipv6Addr.from('2001:db8::1').unwrap();\n\t * @since v0.0.1\n\t */\n\tpublic static from(value: string): IResult<Ipv6Addr> {\n\t\tif (!Ipv6Addr.regex.test(value)) {\n\t\t\treturn Err(new TypeError(`${value} is invalid ipv6 value`));\n\t\t}\n\t\ttry {\n\t\t\tconst {leftParts, rightParts, embeddedIpv4} = Ipv6Addr.#parseComponents(value);\n\n\t\t\tconst leftSegs = leftParts.map((p) => parseInt(p, 16));\n\t\t\tconst rightSegs = rightParts.map((p) => parseInt(p, 16));\n\n\t\t\tconst missingLen = 8 - (leftSegs.length + rightSegs.length + embeddedIpv4.length);\n\t\t\tconst segments = [...leftSegs, ...Array(missingLen).fill(0), ...rightSegs, ...embeddedIpv4];\n\n\t\t\treturn Ok(new Ipv6Addr(segments as [number, number, number, number, number, number, number, number]));\n\t\t} catch (err) {\n\t\t\treturn Err(err);\n\t\t}\n\t}\n\n\t/**\n\t * Creates an IPv6 address from a 16-byte buffer.\n\t * @returns A successful result with an IPv6 address, or an error when the buffer cannot be read.\n\t * @since v0.0.1\n\t */\n\tpublic static fromBuffer(buffer: ArrayBuffer, littleEndian?: boolean): IResult<Ipv6Addr> {\n\t\ttry {\n\t\t\tconst view = new DataView(buffer);\n\t\t\tif (littleEndian) {\n\t\t\t\tconst low = view.getBigUint64(0, true);\n\t\t\t\tconst high = view.getBigUint64(8, true);\n\t\t\t\treturn Ok(new Ipv6Addr((high << 64n) | low));\n\t\t\t} else {\n\t\t\t\tconst high = view.getBigUint64(0, false);\n\t\t\t\tconst low = view.getBigUint64(8, false);\n\t\t\t\treturn Ok(new Ipv6Addr((high << 64n) | low));\n\t\t\t}\n\t\t} catch (err) {\n\t\t\treturn Err(err as Error);\n\t\t}\n\t}\n\n\tstatic #parseComponents(value: string) {\n\t\tconst components = value.split('::');\n\t\tconst leftParts = components[0].split(':').filter((x) => x !== '');\n\t\tconst rightParts = components.length > 1 ? components[1].split(':').filter((x) => x !== '') : [];\n\t\tlet embeddedIpv4: number[] = [];\n\t\tconst lastPart = rightParts[rightParts.length - 1] ?? leftParts[leftParts.length - 1];\n\t\tif (lastPart?.includes('.')) {\n\t\t\tembeddedIpv4 = Ipv6Addr.#parseEmbeddedIpv4(lastPart);\n\t\t\tif (rightParts.length > 0) {\n\t\t\t\trightParts.pop();\n\t\t\t} else {\n\t\t\t\tleftParts.pop();\n\t\t\t}\n\t\t}\n\t\treturn {leftParts, rightParts, embeddedIpv4};\n\t}\n\n\tstatic #parseEmbeddedIpv4(value: string): number[] {\n\t\tconst ipv4Octets = value.split('.').map(Number);\n\t\treturn [(ipv4Octets[0] << 8) | ipv4Octets[1], (ipv4Octets[2] << 8) | ipv4Octets[3]];\n\t}\n\n\t/**\n\t * The number of bits in an IPv6 address.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly BITS = 128;\n\n\t/**\n\t * The loopback address (`::1`).\n\t * @since v0.0.1\n\t */\n\tpublic static readonly LOCALHOST: Ipv6Addr = new Ipv6Addr(0x00000000000000000000000000000001n);\n\n\t/**\n\t * The unspecified address (`::`).\n\t * @since v0.0.1\n\t */\n\tpublic static readonly UNSPECIFIED: Ipv6Addr = new Ipv6Addr(0x00000000000000000000000000000000n);\n\n\t/**\n\t * The address family identifier for IPv6 addresses.\n\t * @since v0.0.1\n\t */\n\tpublic readonly family = 'ipv6';\n\n\t#integerAddress: bigint;\n\tpublic constructor(value: bigint);\n\tpublic constructor(segments: [number, number, number, number, number, number, number, number]);\n\tpublic constructor(valueOrSegments: [number, number, number, number, number, number, number, number] | bigint) {\n\t\tif (Array.isArray(valueOrSegments)) {\n\t\t\tthis.#integerAddress = this.#toInteger(valueOrSegments);\n\t\t} else {\n\t\t\tthis.#integerAddress = valueOrSegments;\n\t\t}\n\t}\n\n\t/**\n\t * Checks whether this address is in the benchmarking range.\n\t * @see https://tools.ietf.org/html/rfc5180 and https://www.rfc-editor.org/errata_search.php?eid=1752\n\t * @returns `true` when the address is in `2001:2::/48`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isBenchmarking(): boolean {\n\t\treturn this.#match(0x20010002000000000000000000000000n, 48);\n\t}\n\n\t/**\n\t * Checks whether this address is in a documentation-only range.\n\t * @see https://tools.ietf.org/html/rfc3849 and https://tools.ietf.org/html/rfc9637\n\t * @returns `true` for `2001:db8::/32` or `3fff::/20`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isDocumentation(): boolean {\n\t\treturn this.#match(0x20010db8000000000000000000000000n, 32) || this.#match(0x3fff0000000000000000000000000000n, 20);\n\t}\n\n\t/**\n\t * Checks whether this address is the loopback address.\n\t * @see https://tools.ietf.org/html/rfc4291#section-2.5.3\n\t * @returns `true` when the address is `::1`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isLoopback(): boolean {\n\t\treturn this.#integerAddress === 1n;\n\t}\n\n\t/**\n\t * Checks whether this address is the unspecified address.\n\t * @see https://tools.ietf.org/html/rfc4291\n\t * @returns `true` when the address is `::`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUnspecified(): boolean {\n\t\treturn this.#integerAddress === 0n;\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast address.\n\t * @see https://tools.ietf.org/html/rfc4291\n\t * @returns `true` when the address is in `ff00::/8`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isMulticast(): boolean {\n\t\treturn this.#integerAddress >> 120n === 0xffn;\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast interface-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff01::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastInterfaceLocal(): boolean {\n\t\treturn this.#match(0xff010000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast link-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff02::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastLinkLocal(): boolean {\n\t\treturn this.#match(0xff020000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast realm-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff03::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastRealmLocal(): boolean {\n\t\treturn this.#match(0xff030000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast admin-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff04::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastAdminLocal(): boolean {\n\t\treturn this.#match(0xff040000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast site-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff05::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastSiteLocal(): boolean {\n\t\treturn this.#match(0xff050000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast organization-local address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff08::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastOrganizationLocal(): boolean {\n\t\treturn this.#match(0xff080000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast global address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc4291#section-2.7\n\t * @returns `true` when the address is in `ff0e::/16`, otherwise `false`.\n\t * @since v0.0.2\n\t */\n\tpublic isMulticastGlobal(): boolean {\n\t\treturn this.#match(0xff0e0000000000000000000000000000n, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is an IPv4-mapped IPv6 address.\n\t * @returns `true` when the address is in `::ffff:0:0/96`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isIpv4Mapped(): boolean {\n\t\treturn this.#match(0x00000000000000000000ffff00000000n, 96);\n\t}\n\n\t/**\n\t * Checks whether this address is a unicast address.\n\t * @see https://tools.ietf.org/html/rfc4291\n\t * @returns `true` when the address is not multicast, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUnicast(): boolean {\n\t\treturn !this.isMulticast();\n\t}\n\n\t/**\n\t * Checks whether this address is a link-local unicast address.\n\t * @see https://tools.ietf.org/html/rfc4291\n\t * @returns `true` when the address is in `fe80::/10`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUnicastLinkLocal(): boolean {\n\t\treturn this.#match(0xfe800000000000000000000000000000n, 10);\n\t}\n\n\t/**\n\t * Checks whether this address is a global unicast address.\n\t * @see https://tools.ietf.org/html/rfc4291#section-2.5.7\n\t * @returns `true` when the address is unicast and not loopback, link-local, private, unspecified, or documentation.\n\t * @since v0.0.1\n\t */\n\tpublic isUnicastGlobal(): boolean {\n\t\treturn this.isUnicast() && !this.isLoopback() && !this.isUnicastLinkLocal() && !this.isUniqueLocal() && !this.isUnspecified() && !this.isDocumentation();\n\t}\n\n\t/**\n\t * Checks whether this address appears globally reachable.\n\t * @see https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml\n\t * @returns `true` when the address is not in known non-global special ranges.\n\t * @since v0.0.1\n\t */\n\tpublic isGlobal(): boolean {\n\t\treturn (\n\t\t\t!this.isUnspecified() &&\n\t\t\t!this.isLoopback() &&\n\t\t\t!this.isIpv4Mapped() &&\n\t\t\t!this.isBenchmarking() &&\n\t\t\t!this.isDocumentation() &&\n\t\t\t!this.isUniqueLocal() &&\n\t\t\t!this.isUnicastLinkLocal() &&\n\t\t\t!this.isMulticast()\n\t\t);\n\t}\n\n\t/**\n\t * Checks whether this address is in the unique-local range.\n\t * @see https://tools.ietf.org/html/rfc4193\n\t * @returns `true` when the address is in `fc00::/7`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUniqueLocal(): boolean {\n\t\treturn this.#match(0xfc000000000000000000000000000000n, 7);\n\t}\n\n\t/**\n\t * Converts this address to IPv4 when compatible or mapped.\n\t * @returns An IPv4 address for `::a.b.c.d` or `::ffff:a.b.c.d`; otherwise `None`.\n\t * @since v0.0.1\n\t */\n\tpublic toIpv4(): IOption<Ipv4Addr> {\n\t\tif (this.isIpv4Mapped() || this.#match(0n, 96)) {\n\t\t\tconst segments = this.#fromInteger(this.#integerAddress);\n\t\t\treturn Some(new Ipv4Addr(segments[6] >> 8, segments[6] & 0xff, segments[7] >> 8, segments[7] & 0xff));\n\t\t}\n\t\treturn None();\n\t}\n\n\t/**\n\t * Converts this address to IPv4 only when it is IPv4-mapped.\n\t * @returns An IPv4 address for `::ffff:a.b.c.d`; otherwise `None`.\n\t * @since v0.0.1\n\t */\n\tpublic toIpv4Mapped(): IOption<Ipv4Addr> {\n\t\tif (this.isIpv4Mapped()) {\n\t\t\tconst segments = this.#fromInteger(this.#integerAddress);\n\t\t\treturn Some(new Ipv4Addr(segments[6] >> 8, segments[6] & 0xff, segments[7] >> 8, segments[7] & 0xff));\n\t\t}\n\t\treturn None();\n\t}\n\n\t/**\n\t * Formats this address as a compressed IPv6 string.\n\t * @returns The shortest standard IPv6 text form.\n\t * @since v0.0.1\n\t */\n\tpublic toString(): string {\n\t\tconst segments = this.#fromInteger(this.#integerAddress);\n\t\tlet maxZeroStart = -1;\n\t\tlet maxZeroLen = 0;\n\t\tlet currentZeroStart = -1;\n\t\tlet currentZeroLen = 0;\n\n\t\tfor (let i = 0; i < segments.length; i++) {\n\t\t\tif (segments[i] === 0) {\n\t\t\t\tif (currentZeroStart === -1) {\n\t\t\t\t\tcurrentZeroStart = i;\n\t\t\t\t\tcurrentZeroLen = 1;\n\t\t\t\t} else {\n\t\t\t\t\tcurrentZeroLen++;\n\t\t\t\t}\n\t\t\t\tif (currentZeroLen > maxZeroLen) {\n\t\t\t\t\tmaxZeroLen = currentZeroLen;\n\t\t\t\t\tmaxZeroStart = currentZeroStart;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcurrentZeroStart = -1;\n\t\t\t\tcurrentZeroLen = 0;\n\t\t\t}\n\t\t}\n\n\t\tif (maxZeroLen < 2) {\n\t\t\treturn segments.map((s) => s.toString(16)).join(':');\n\t\t}\n\n\t\tconst before = segments.slice(0, maxZeroStart).map((s) => s.toString(16));\n\t\tconst after = segments.slice(maxZeroStart + maxZeroLen).map((s) => s.toString(16));\n\n\t\treturn `${before.join(':')}::${after.join(':')}`;\n\t}\n\n\t/**\n\t * Encodes this address to a 16-byte buffer.\n\t * @param littleEndian Whether to use little-endian byte order. Defaults to `false`.\n\t * @returns An `ArrayBuffer` containing the IPv6 integer value.\n\t * @since v0.0.1\n\t */\n\tpublic toBuffer(littleEndian?: boolean): ArrayBuffer {\n\t\tconst buffer = new ArrayBuffer(16);\n\t\tconst view = new DataView(buffer);\n\t\tif (littleEndian) {\n\t\t\tview.setBigUint64(0, this.#integerAddress & 0xffffffffffffffffn, true);\n\t\t\tview.setBigUint64(8, this.#integerAddress >> 64n, true);\n\t\t} else {\n\t\t\tview.setBigUint64(0, this.#integerAddress >> 64n, false);\n\t\t\tview.setBigUint64(8, this.#integerAddress & 0xffffffffffffffffn, false);\n\t\t}\n\t\treturn buffer;\n\t}\n\n\t/**\n\t * Compares this IPv6 address with another for equality.\n\t * @param other instance of another IPv6 address to compare with.\n\t * @returns `true` if both addresses are equal, otherwise `false`.\n\t * @since v0.1.0\n\t */\n\tpublic equals(other: Ipv6Addr | Ipv4Addr | object): boolean {\n\t\treturn 'family' in other && this.family === other.family && this.#integerAddress === other.#integerAddress;\n\t}\n\n\t#toInteger(segments: [number, number, number, number, number, number, number, number]): bigint {\n\t\tlet result = 0n;\n\t\tfor (const segment of segments) {\n\t\t\tif (segment < 0 || segment > 0xffff) {\n\t\t\t\tthrow new Error('IPv6 segment must be between 0 and 65535');\n\t\t\t}\n\t\t\tresult = (result << 16n) | BigInt(segment);\n\t\t}\n\t\treturn result;\n\t}\n\n\t#fromInteger(integer: bigint): [number, number, number, number, number, number, number, number] {\n\t\treturn [\n\t\t\tNumber((integer >> 112n) & 0xffffn),\n\t\t\tNumber((integer >> 96n) & 0xffffn),\n\t\t\tNumber((integer >> 80n) & 0xffffn),\n\t\t\tNumber((integer >> 64n) & 0xffffn),\n\t\t\tNumber((integer >> 48n) & 0xffffn),\n\t\t\tNumber((integer >> 32n) & 0xffffn),\n\t\t\tNumber((integer >> 16n) & 0xffffn),\n\t\t\tNumber(integer & 0xffffn),\n\t\t];\n\t}\n\n\t#match(network: bigint, prefix: number): boolean {\n\t\tif (prefix < 0 || prefix > 128) {\n\t\t\tthrow new Error('Invalid prefix length');\n\t\t}\n\t\tif (prefix === 0) {\n\t\t\treturn true;\n\t\t}\n\t\tconst ALL_ONES = (1n << 128n) - 1n;\n\t\tconst mask = (ALL_ONES << BigInt(128 - prefix)) & ALL_ONES;\n\t\treturn (this.#integerAddress & mask) === (network & mask);\n\t}\n}\n","import {Err, type IResult, Ok} from '@luolapeikko/result-option';\nimport {Ipv6Addr} from './Ipv6Addr';\n\n/**\n * Represents an IPv4 address.\n * @example\n * const addr1 = Ipv4Addr.from('192.168.0.1').unwrap();\n * const addr2 = new Ipv4Addr(192, 168, 0, 1);\n * const addr3 = new Ipv4Addr(0xc0a80001);\n * @since v0.0.1\n */\nexport class Ipv4Addr {\n\t/**\n\t * Creates an IPv4 address from dotted-decimal text.\n\t * @returns A successful {@link IResult} with an IPv4 address, or an error when the input is invalid.\n\t * @since v0.0.1\n\t */\n\tpublic static from(value: string): IResult<Ipv4Addr, TypeError> {\n\t\tconst match = value.match(/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/);\n\t\tif (!match) {\n\t\t\treturn Err(new TypeError(`${value} is invalid ipv4 value`));\n\t\t}\n\t\tconst octets = match.slice(1).map(Number);\n\t\tif (octets.some((o) => o > 255)) {\n\t\t\treturn Err(new TypeError(`${value} is invalid ipv4 value`));\n\t\t}\n\t\treturn Ok(new Ipv4Addr(octets[0], octets[1], octets[2], octets[3]));\n\t}\n\n\t/**\n\t * Creates an IPv4 address from a 4-byte buffer.\n\t * @returns A successful {@link IResult} with an IPv4 address, or an error when the buffer cannot be read.\n\t * @since v0.0.1\n\t */\n\tpublic static fromBuffer(buffer: ArrayBuffer, littleEndian?: boolean): IResult<Ipv4Addr> {\n\t\ttry {\n\t\t\tconst view = new DataView(buffer);\n\t\t\treturn Ok(new Ipv4Addr(view.getUint32(0, littleEndian)));\n\t\t} catch (err) {\n\t\t\treturn Err(err);\n\t\t}\n\t}\n\n\t/**\n\t * The number of bits in an IPv4 address.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly BITS = 32;\n\n\t/**\n\t * The broadcast address `255.255.255.255`.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly BROADCAST: Ipv4Addr = new Ipv4Addr(0xffffffff);\n\n\t/**\n\t * The localhost address `127.0.0.1`.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly LOCALHOST: Ipv4Addr = new Ipv4Addr(0x7f000001);\n\n\t/**\n\t * The unspecified address `0.0.0.0`.\n\t * @since v0.0.1\n\t */\n\tpublic static readonly UNSPECIFIED: Ipv4Addr = new Ipv4Addr(0x00000000);\n\n\t/**\n\t * The address family identifier for IPv4 addresses.\n\t * @since v0.0.1\n\t */\n\tpublic readonly family = 'ipv4';\n\n\t#integerAddress: number;\n\n\t/**\n\t * Creates a new IPv4 address from four octets.\n\t * @param num1 The first octet.\n\t * @param num2 The second octet.\n\t * @param num3 The third octet.\n\t * @param num4 The fourth octet.\n\t * @example\n\t * new Ipv4Addr(192, 168, 0, 1) // creates the address `192.168.0.1`\n\t */\n\tpublic constructor(num1: number, num2: number, num3: number, num4: number);\n\t/**\n\t * Creates a new IPv4 address from an integer value.\n\t * @param integerValue The integer representation of the IPv4 address.\n\t * @example\n\t * new Ipv4Addr(0xc0a80001) // creates the address `192.168.0.1` from the integer value `0xc0a80001`\n\t */\n\tpublic constructor(integerValue: number);\n\tpublic constructor(...args: [number] | [number, number, number, number]) {\n\t\tif (args.length === 1) {\n\t\t\tthis.#integerAddress = args[0];\n\t\t} else {\n\t\t\tthis.#integerAddress = this.#toInteger(args[0], args[1], args[2], args[3]);\n\t\t}\n\t}\n\n\t/**\n\t * Checks whether this address is the broadcast address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc919#section-7\n\t * @returns `true` when the address is `255.255.255.255`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isBroadcast(): boolean {\n\t\treturn this.#integerAddress === 0xffffffff;\n\t}\n\n\t/**\n\t * Checks whether this address is in a documentation-only range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc5737\n\t * @returns `true` for `192.0.2.0/24`, `198.51.100.0/24`, or `203.0.113.0/24`; otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isDocumentation(): boolean {\n\t\treturn (\n\t\t\tthis.#match(0xc0000200, 24) || // 192.0.2.0/24\n\t\t\tthis.#match(0xc6336400, 24) || // 198.51.100.0/24\n\t\t\tthis.#match(0xcb007100, 24) // 203.0.113.0/24\n\t\t);\n\t}\n\n\t/**\n\t * Checks whether this address is in the benchmarking range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc2544\n\t * @returns `true` when the address is in `198.18.0.0/15`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isBenchmarking(): boolean {\n\t\treturn this.#match(0xc6120000, 15);\n\t}\n\n\t/**\n\t * Checks whether this address is globally reachable.\n\t * @see https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml\n\t * @returns `true` when the address is not in any special non-global range.\n\t * @since v0.0.1\n\t */\n\tpublic isGlobal(): boolean {\n\t\treturn !(\n\t\t\tthis.isUnspecified() ||\n\t\t\tthis.isPrivate() ||\n\t\t\tthis.isShared() ||\n\t\t\tthis.isLoopback() ||\n\t\t\tthis.isLinkLocal() ||\n\t\t\tthis.isDocumentation() ||\n\t\t\tthis.isBenchmarking() ||\n\t\t\tthis.isReserved() ||\n\t\t\tthis.isMulticast() ||\n\t\t\tthis.isBroadcast()\n\t\t);\n\t}\n\n\t/**\n\t * Checks whether this address is link-local.\n\t * @see https://datatracker.ietf.org/doc/html/rfc3927\n\t * @returns `true` when the address is in `169.254.0.0/16`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isLinkLocal(): boolean {\n\t\treturn this.#match(0xa9fe0000, 16);\n\t}\n\n\t/**\n\t * Checks whether this address is a loopback address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc1122\n\t * @returns `true` when the address is in `127.0.0.0/8`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isLoopback(): boolean {\n\t\treturn this.#match(0x7f000000, 8);\n\t}\n\n\t/**\n\t * Checks whether this address is a multicast address.\n\t * @see https://datatracker.ietf.org/doc/html/rfc5771\n\t * @returns `true` when the address is in `224.0.0.0/4`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isMulticast(): boolean {\n\t\treturn this.#match(0xe0000000, 4);\n\t}\n\n\t/**\n\t * Checks whether this address is in a private-use range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc1918\n\t * @returns `true` for `10.0.0.0/8`, `172.16.0.0/12`, or `192.168.0.0/16`; otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isPrivate(): boolean {\n\t\treturn (\n\t\t\tthis.#match(0x0a000000, 8) || // 10.0.0.0/8\n\t\t\tthis.#match(0xac100000, 12) || // 172.16.0.0/12\n\t\t\tthis.#match(0xc0a80000, 16) // 192.168.0.0/16\n\t\t);\n\t}\n\n\t/**\n\t * Checks whether this address is in the reserved range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc1112\n\t * @returns `true` when the address is in `240.0.0.0/4` except the broadcast address.\n\t * @since v0.0.1\n\t */\n\tpublic isReserved(): boolean {\n\t\treturn this.#match(0xf0000000, 4) && !this.isBroadcast();\n\t}\n\n\t/**\n\t * Checks whether this address is in the shared Carrier-Grade NAT range.\n\t * @see https://datatracker.ietf.org/doc/html/rfc6598\n\t * @returns `true` when the address is in `100.64.0.0/10`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isShared(): boolean {\n\t\treturn this.#match(0x64400000, 10);\n\t}\n\n\t/**\n\t * Checks whether this address is the unspecified address.\n\t * @returns `true` when the address is `0.0.0.0`, otherwise `false`.\n\t * @since v0.0.1\n\t */\n\tpublic isUnspecified(): boolean {\n\t\treturn this.#integerAddress === 0;\n\t}\n\n\t/**\n\t * Converts this address to an IPv4-compatible IPv6 address.\n\t * @returns An IPv6 address in the form `::a.b.c.d`.\n\t * @since v0.0.1\n\t */\n\tpublic toIpv6(): Ipv6Addr {\n\t\treturn Ipv6Addr.from(`::${this.toString()}`).unwrap();\n\t}\n\n\t/**\n\t * Converts this address to an IPv4-mapped IPv6 address.\n\t * @returns An IPv6 address in the form `::ffff:a.b.c.d`.\n\t * @since v0.0.1\n\t */\n\tpublic toIpv6Mapped(): Ipv6Addr {\n\t\treturn Ipv6Addr.from(`::ffff:${this.toString()}`).unwrap();\n\t}\n\n\t/**\n\t * Formats this address as dotted-decimal text.\n\t * @returns The IPv4 string representation, such as `192.168.0.1`.\n\t * @since v0.0.1\n\t */\n\tpublic toString(): string {\n\t\tconst [num1, num2, num3, num4] = this.#fromInteger(this.#integerAddress);\n\t\treturn `${num1}.${num2}.${num3}.${num4}`;\n\t}\n\n\t/**\n\t * Encodes this address to a 4-byte buffer.\n\t * @returns An `ArrayBuffer` containing the IPv4 integer value.\n\t * @since v0.0.1\n\t */\n\tpublic toBuffer(littleEndian?: boolean): ArrayBuffer {\n\t\tconst buffer = new ArrayBuffer(4);\n\t\tconst view = new DataView(buffer);\n\t\tview.setUint32(0, this.#integerAddress, littleEndian);\n\t\treturn buffer;\n\t}\n\n\t/**\n\t * Compares this IPv4 address with another for equality.\n\t * @param other instance of another IPv4 address to compare with.\n\t * @returns `true` if both addresses are equal, otherwise `false`.\n\t * @since v0.1.0\n\t */\n\tpublic equals(other: Ipv4Addr | Ipv6Addr | object): boolean {\n\t\treturn 'family' in other && this.family === other.family && this.#integerAddress === other.#integerAddress;\n\t}\n\n\t#toInteger(num1: number, num2: number, num3: number, num4: number): number {\n\t\tfor (const octet of [num1, num2, num3, num4]) {\n\t\t\tif (octet < 0 || octet > 255) {\n\t\t\t\tthrow new Error('IPv4 octet must be between 0 and 255');\n\t\t\t}\n\t\t}\n\t\treturn ((num1 << 24) | (num2 << 16) | (num3 << 8) | num4) >>> 0;\n\t}\n\n\t#fromInteger(integer: number): [number, number, number, number] {\n\t\tconst num1 = (integer >> 24) & 0xff;\n\t\tconst num2 = (integer >> 16) & 0xff;\n\t\tconst num3 = (integer >> 8) & 0xff;\n\t\tconst num4 = integer & 0xff;\n\t\treturn [num1, num2, num3, num4];\n\t}\n\n\t#match(network: number, prefix: number): boolean {\n\t\tif (prefix < 0 || prefix > 32) {\n\t\t\tthrow new Error('Invalid prefix length');\n\t\t}\n\t\tconst mask = prefix === 0 ? 0 : (~0 << (32 - prefix)) >>> 0;\n\t\treturn (this.#integerAddress & mask) === (network & mask);\n\t}\n}\n"],"mappings":"6EAWA,IAAa,EAAb,MAAa,CAAS,CACrB,OAAe,MACd,wpBASD,OAAc,KAAK,EAAkC,CACpD,GAAI,CAAC,EAAS,MAAM,KAAK,CAAK,EAC7B,OAAO,EAAQ,UAAU,GAAG,EAAM,uBAAuB,CAAC,EAE3D,GAAI,CACH,GAAM,CAAC,YAAW,aAAY,gBAAgB,EAASA,GAAiB,CAAK,EAEvE,EAAW,EAAU,IAAK,GAAM,SAAS,EAAG,EAAE,CAAC,EAC/C,EAAY,EAAW,IAAK,GAAM,SAAS,EAAG,EAAE,CAAC,EAEjD,EAAa,GAAK,EAAS,OAAS,EAAU,OAAS,EAAa,QAG1E,OAAO,EAAG,IAAI,EAAS,CAFL,GAAG,EAAU,GAAG,MAAM,CAAU,CAAC,CAAC,KAAK,CAAC,EAAG,GAAG,EAAW,GAAG,CAEhD,CAAqE,CAAC,CACrG,OAAS,EAAK,CACb,OAAO,EAAI,CAAG,CACf,CACD,CAOA,OAAc,WAAW,EAAqB,EAA2C,CACxF,GAAI,CACH,IAAM,EAAO,IAAI,SAAS,CAAM,EAChC,GAAI,EAAc,CACjB,IAAM,EAAM,EAAK,aAAa,EAAG,EAAI,EAErC,OAAO,EAAG,IAAI,EADD,EAAK,aAAa,EAAG,EACP,GAAK,IAAO,CAAG,CAAC,CAC5C,KAAO,CACN,IAAM,EAAO,EAAK,aAAa,EAAG,EAAK,EACjC,EAAM,EAAK,aAAa,EAAG,EAAK,EACtC,OAAO,EAAG,IAAI,EAAU,GAAQ,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