cidr-block
Advanced tools
| 'use strict'; | ||
| var ipv4 = require('./ipv4.cjs'); | ||
| var ipv6 = require('./ipv6.cjs'); | ||
| var ipv4Address = require('./ipv4-address.cjs'); | ||
| var ipv4Cidr = require('./ipv4-cidr.cjs'); | ||
| var ipv4Errors = require('./ipv4-errors.cjs'); | ||
| var ipv6Address = require('./ipv6-address.cjs'); | ||
| var ipv6Cidr = require('./ipv6-cidr.cjs'); | ||
| var ipv6Errors = require('./ipv6-errors.cjs'); | ||
| Object.defineProperty(exports, "ipv4", { | ||
| enumerable: true, | ||
| get: function () { return ipv4.ipv4; } | ||
| }); | ||
| Object.defineProperty(exports, "ipv6", { | ||
| enumerable: true, | ||
| get: function () { return ipv6.ipv6; } | ||
| }); | ||
| exports.Ipv4Address = ipv4Address.Ipv4Address; | ||
| exports.Ipv4Cidr = ipv4Cidr.Ipv4Cidr; | ||
| exports.InvalidIpv4AddressError = ipv4Errors.InvalidIpv4AddressError; | ||
| exports.InvalidIpv4CidrError = ipv4Errors.InvalidIpv4CidrError; | ||
| exports.InvalidIpv4CidrRangeError = ipv4Errors.InvalidIpv4CidrRangeError; | ||
| exports.Ipv6Address = ipv6Address.Ipv6Address; | ||
| exports.Ipv6Cidr = ipv6Cidr.Ipv6Cidr; | ||
| exports.InvalidIpv6AddressError = ipv6Errors.InvalidIpv6AddressError; | ||
| exports.InvalidIpv6CidrError = ipv6Errors.InvalidIpv6CidrError; | ||
| exports.InvalidIpv6CidrRangeError = ipv6Errors.InvalidIpv6CidrRangeError; | ||
| //# sourceMappingURL=index.cjs.map |
| {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} |
Sorry, the diff of this file is too big to display
| 'use strict'; | ||
| var tslib_es6_js = require('/Users/brandon/cidr-block/node_modules/tslib/tslib.es6.js'); | ||
| var ipv4 = require('./ipv4.cjs'); | ||
| var ipv4Errors = require('./ipv4-errors.cjs'); | ||
| var _Ipv4Address_octets; | ||
| /** | ||
| * Represents an IPv4 address with utility methods for manipulation and comparison. | ||
| * | ||
| * While you can instantiate this class directly, it is recommended to use the | ||
| * {@link ipv4.address} shorthand method from the `ipv4` namespace instead. | ||
| * | ||
| * @example Creating addresses (prefer the shorthand) | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * // Recommended: use the ipv4 namespace shorthand | ||
| * const addr1 = ipv4.address("192.168.1.1"); | ||
| * const addr2 = ipv4.address(3232235777); | ||
| * const addr3 = ipv4.address([192, 168, 1, 1]); | ||
| * ``` | ||
| * | ||
| * @example Converting between formats | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.toString(); // "192.168.1.1" | ||
| * addr.toNumber(); // 3232235777 | ||
| * addr.octets(); // [192, 168, 1, 1] | ||
| * addr.toBinaryString(); // "11000000.10101000.00000001.00000001" | ||
| * ``` | ||
| * | ||
| * @example Comparing addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.equals("192.168.1.1"); // true | ||
| * addr.isGreaterThan("192.168.1.0"); // true | ||
| * addr.isLessThan("192.168.1.2"); // true | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.nextAddress()?.toString(); // "192.168.1.2" | ||
| * addr.previousAddress()?.toString(); // "192.168.1.0" | ||
| * ``` | ||
| * | ||
| * @example Checking address types | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("127.0.0.1").isLoopbackAddress(); // true | ||
| * ipv4.address("10.0.0.1").isPrivateAddress(); // true | ||
| * ipv4.address("169.254.1.1").isLocalLinkAddress(); // true | ||
| * ipv4.address("224.0.0.1").isMulticastAddress(); // true | ||
| * ``` | ||
| */ | ||
| class Ipv4Address { | ||
| constructor(ip) { | ||
| _Ipv4Address_octets.set(this, void 0); | ||
| if (!ipv4.ipv4.isValidAddress(ip)) { | ||
| throw new ipv4Errors.InvalidIpv4AddressError(ip); | ||
| } | ||
| tslib_es6_js.__classPrivateFieldSet(this, _Ipv4Address_octets, ipv4.ipv4.parseOctets(ip), "f"); | ||
| } | ||
| /** | ||
| * Gets the octets of the IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.octets(); // [192, 168, 1, 1] | ||
| * ``` | ||
| * | ||
| * @returns An array of four numbers representing the octets of the IPv4 address. | ||
| */ | ||
| octets() { | ||
| return tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Address_octets, "f"); | ||
| } | ||
| /** | ||
| * Returns the string representation of the IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address([10, 0, 0, 1]); | ||
| * addr.toString(); // "10.0.0.1" | ||
| * ``` | ||
| * | ||
| * @returns The IPv4 address as a string in dotted-decimal notation (example: "192.187.0.1"). | ||
| */ | ||
| toString() { | ||
| return tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Address_octets, "f").join('.'); | ||
| } | ||
| /** | ||
| * Returns the binary string representation of the IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.toBinaryString(); // "11000000.10101000.00000001.00000001" | ||
| * ``` | ||
| * | ||
| * @returns The IPv4 address as a binary string in dotted-decimal notation (example: "11000000.10111011.00000000.00000001"). | ||
| */ | ||
| toBinaryString() { | ||
| return tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Address_octets, "f").map(octet => octet.toString(2).padStart(8, '0')).join('.'); | ||
| } | ||
| /** | ||
| * Converts the IPv4 address to its numeric representation. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.toNumber(); // 3232235777 | ||
| * ``` | ||
| * | ||
| * @returns The IPv4 address as a number. | ||
| */ | ||
| toNumber() { | ||
| return ((tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Address_octets, "f")[0] << 24) | (tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Address_octets, "f")[1] << 16) | (tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Address_octets, "f")[2] << 8) | tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Address_octets, "f")[3]); | ||
| } | ||
| /** | ||
| * Checks if there is a next sequential IPv4 address. | ||
| * This would only return false if the current address is the maximum possible value (255.255.255.255). | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("192.168.1.1").hasNextAddress(); // true | ||
| * ipv4.address("255.255.255.255").hasNextAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a next IPv4 address. | ||
| */ | ||
| hasNextAddress() { | ||
| return this.toNumber() < ipv4.ipv4.MAX_SIZE; | ||
| } | ||
| /** | ||
| * Gets the next sequential IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.nextAddress()?.toString(); // "192.168.1.2" | ||
| * | ||
| * const maxAddr = ipv4.address("255.255.255.255"); | ||
| * maxAddr.nextAddress(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The next IPv4 address, or undefined if the current address is the maximum possible value. | ||
| */ | ||
| nextAddress() { | ||
| const nextAddress = this.toNumber() + 1; | ||
| if (nextAddress > ipv4.ipv4.MAX_SIZE) { | ||
| return undefined; | ||
| } | ||
| return new Ipv4Address(nextAddress); | ||
| } | ||
| /** | ||
| * Checks if there is a previous sequential IPv4 address. | ||
| * This would only return false if the current address is the minimum possible value (0.0.0.0). | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("192.168.1.1").hasPreviousAddress(); // true | ||
| * ipv4.address("0.0.0.0").hasPreviousAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a previous IPv4 address. | ||
| */ | ||
| hasPreviousAddress() { | ||
| return this.toNumber() > ipv4.ipv4.MIN_SIZE; | ||
| } | ||
| /** | ||
| * Gets the previous sequential IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.previousAddress()?.toString(); // "192.168.1.0" | ||
| * | ||
| * const minAddr = ipv4.address("0.0.0.0"); | ||
| * minAddr.previousAddress(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The previous IPv4 address, or undefined if the current address is the minimum possible value. | ||
| */ | ||
| previousAddress() { | ||
| const prevAddress = this.toNumber() - 1; | ||
| if (prevAddress < ipv4.ipv4.MIN_SIZE) { | ||
| return undefined; | ||
| } | ||
| return new Ipv4Address(prevAddress); | ||
| } | ||
| /** | ||
| * Compares two IPv4 addresses for equality. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.equals("192.168.1.1"); // true | ||
| * addr.equals([192, 168, 1, 1]); // true | ||
| * addr.equals(ipv4.address("10.0.0.1")); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv4 address to compare with, which can be an Ipv4Address instance or literal value. | ||
| * @returns true if both IPv4 addresses are equal | ||
| */ | ||
| equals(otherAddress) { | ||
| if (otherAddress instanceof Ipv4Address) { | ||
| return this.toNumber() === otherAddress.toNumber(); | ||
| } | ||
| return this.toNumber() === new Ipv4Address(otherAddress).toNumber(); | ||
| } | ||
| /** | ||
| * Compares if this IPv4 address is greater than another IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.isGreaterThan("192.168.1.0"); // true | ||
| * addr.isGreaterThan("192.168.1.1"); // false | ||
| * addr.isGreaterThan("192.168.1.2"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv4 address to compare with, which can be an Ipv4Address instance or literal value. | ||
| * @returns true if this IPv4 address is greater than the other IPv4 address | ||
| */ | ||
| isGreaterThan(otherAddress) { | ||
| if (otherAddress instanceof Ipv4Address) { | ||
| return this.toNumber() > otherAddress.toNumber(); | ||
| } | ||
| return this.toNumber() > new Ipv4Address(otherAddress).toNumber(); | ||
| } | ||
| /** | ||
| * Compares if this IPv4 address is greater than or equal to another IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.isGreaterThanOrEqual("192.168.1.0"); // true | ||
| * addr.isGreaterThanOrEqual("192.168.1.1"); // true | ||
| * addr.isGreaterThanOrEqual("192.168.1.2"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv4 address to compare with, which can be an Ipv4Address instance or literal value. | ||
| * @returns true if this IPv4 address is greater than or equal to the other IPv4 address | ||
| */ | ||
| isGreaterThanOrEqual(otherAddress) { | ||
| if (otherAddress instanceof Ipv4Address) { | ||
| return this.toNumber() >= otherAddress.toNumber(); | ||
| } | ||
| return this.toNumber() >= new Ipv4Address(otherAddress).toNumber(); | ||
| } | ||
| /** | ||
| * Compares if this IPv4 address is less than another IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.isLessThan("192.168.1.2"); // true | ||
| * addr.isLessThan("192.168.1.1"); // false | ||
| * addr.isLessThan("192.168.1.0"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv4 address to compare with, which can be an Ipv4Address instance or literal value. | ||
| * @returns true if this IPv4 address is less than the other IPv4 address | ||
| */ | ||
| isLessThan(otherAddress) { | ||
| if (otherAddress instanceof Ipv4Address) { | ||
| return this.toNumber() < otherAddress.toNumber(); | ||
| } | ||
| return this.toNumber() < new Ipv4Address(otherAddress).toNumber(); | ||
| } | ||
| /** | ||
| * Compares if this IPv4 address is less than or equal to another IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.isLessThanOrEqual("192.168.1.2"); // true | ||
| * addr.isLessThanOrEqual("192.168.1.1"); // true | ||
| * addr.isLessThanOrEqual("192.168.1.0"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv4 address to compare with, which can be an Ipv4Address instance or literal value. | ||
| * @returns true if this IPv4 address is less than or equal to the other IPv4 address | ||
| */ | ||
| isLessThanOrEqual(otherAddress) { | ||
| if (otherAddress instanceof Ipv4Address) { | ||
| return this.toNumber() <= otherAddress.toNumber(); | ||
| } | ||
| return this.toNumber() <= new Ipv4Address(otherAddress).toNumber(); | ||
| } | ||
| /** | ||
| * Checks if the IPv4 address is a loopback address (in the CIDR of 127.0.0.0/8) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("127.0.0.1").isLoopbackAddress(); // true | ||
| * ipv4.address("127.255.0.1").isLoopbackAddress(); // true | ||
| * ipv4.address("192.168.1.1").isLoopbackAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv4 address is a loopback address (example: 127.0.0.1 is true) | ||
| */ | ||
| isLoopbackAddress() { | ||
| return tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Address_octets, "f")[0] === 127; | ||
| } | ||
| /** | ||
| * Checks if the IPv4 address is a private address. | ||
| * | ||
| * This is based on RFC 1918, which defines the following private address ranges: | ||
| * - 10.0.0.0/8 | ||
| * - 172.16.0.0/12 | ||
| * - 192.168.0.0/16 | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("10.0.0.1").isPrivateAddress(); // true | ||
| * ipv4.address("172.16.0.1").isPrivateAddress(); // true | ||
| * ipv4.address("192.168.1.1").isPrivateAddress(); // true | ||
| * ipv4.address("8.8.8.8").isPrivateAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv4 address is in any of the private address ranges. | ||
| */ | ||
| isPrivateAddress() { | ||
| const [o1, o2] = tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Address_octets, "f"); | ||
| return o1 === 10 || (o1 === 172 && o2 >= 16 && o2 <= 31) || (o1 === 192 && o2 === 168); | ||
| } | ||
| /** | ||
| * Checks if the IPv4 address is a local-link address (in the CIDR of 169.254.0.0/16). | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("169.254.1.1").isLocalLinkAddress(); // true | ||
| * ipv4.address("169.254.255.255").isLocalLinkAddress(); // true | ||
| * ipv4.address("192.168.1.1").isLocalLinkAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv4 address is a local-link address. | ||
| */ | ||
| isLocalLinkAddress() { | ||
| const [o1, o2] = tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Address_octets, "f"); | ||
| return o1 === 169 && o2 === 254; | ||
| } | ||
| /** | ||
| * Checks if the IPv4 address is a multicast address (between 224.0.0.0 to 239.255.255.255). | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("224.0.0.1").isMulticastAddress(); // true | ||
| * ipv4.address("239.255.255.255").isMulticastAddress(); // true | ||
| * ipv4.address("192.168.1.1").isMulticastAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv4 address is a multicast address. | ||
| */ | ||
| isMulticastAddress() { | ||
| const firstOctet = tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Address_octets, "f")[0]; | ||
| return firstOctet >= 224 && firstOctet <= 239; | ||
| } | ||
| } | ||
| _Ipv4Address_octets = new WeakMap(); | ||
| exports.Ipv4Address = Ipv4Address; | ||
| //# sourceMappingURL=ipv4-address.cjs.map |
| {"version":3,"file":"ipv4-address.cjs","sources":["../../../src/ipv4-address.ts"],"sourcesContent":[null],"names":["ipv4","InvalidIpv4AddressError","__classPrivateFieldSet","__classPrivateFieldGet"],"mappings":";;;;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDG;MACU,WAAW,CAAA;AAGtB,IAAA,WAAA,CAAY,EAAsB,EAAA;QAFlC,mBAAA,CAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA;QAGE,IAAI,CAACA,SAAI,CAAC,cAAc,CAAC,EAAE,CAAC,EAAE;AAC5B,YAAA,MAAM,IAAIC,kCAAuB,CAAC,EAAE,CAAC;QACvC;QACAC,mCAAA,CAAA,IAAI,uBAAWF,SAAI,CAAC,WAAW,CAAC,EAAE,CAAC,EAAA,GAAA,CAAA;IACrC;AAEA;;;;;;;;;;;;AAYG;IACI,MAAM,GAAA;QACX,OAAOG,mCAAA,CAAA,IAAI,EAAA,mBAAA,EAAA,GAAA,CAAQ;IACrB;AAEA;;;;;;;;;;;;AAYG;IACI,QAAQ,GAAA;QACb,OAAOA,mCAAA,CAAA,IAAI,EAAA,mBAAA,EAAA,GAAA,CAAQ,CAAC,IAAI,CAAC,GAAG,CAAsB;IACpD;AAEA;;;;;;;;;;;;AAYG;IACI,cAAc,GAAA;AACnB,QAAA,OAAOA,mCAAA,CAAA,IAAI,EAAA,mBAAA,EAAA,GAAA,CAAQ,CAAC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4.cjs'); | ||
| var ipv4Address = require('./ipv4-address.cjs'); | ||
| var ipv4Errors = require('./ipv4-errors.cjs'); | ||
| var _Ipv4Cidr_address, _Ipv4Cidr_range; | ||
| /** | ||
| * Represents an IPv4 CIDR block with utility methods for subnet operations. | ||
| * | ||
| * While you can instantiate this class directly, it is recommended to use the | ||
| * {@link ipv4.cidr} shorthand method from the `ipv4` namespace instead. | ||
| * | ||
| * @example Creating CIDR blocks (prefer the shorthand) | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * // Recommended: use the ipv4 namespace shorthand | ||
| * const cidr1 = ipv4.cidr("192.168.0.0/24"); | ||
| * const cidr2 = ipv4.cidr({ address: "10.0.0.0", range: 8 }); | ||
| * const cidr3 = ipv4.cidr([[172, 16, 0, 0], 12]); | ||
| * ``` | ||
| * | ||
| * @example Getting CIDR properties | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.baseAddress().toString(); // "192.168.0.0" | ||
| * cidr.range(); // 24 | ||
| * cidr.netmask().toString(); // "255.255.255.0" | ||
| * cidr.addressCount(); // 256 | ||
| * ``` | ||
| * | ||
| * @example Working with usable addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.getFirstUsableAddress()?.toString(); // "192.168.0.1" | ||
| * cidr.getLastUsableAddress()?.toString(); // "192.168.0.254" | ||
| * ``` | ||
| * | ||
| * @example Iterating over addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.1.0/30"); | ||
| * for (const addr of cidr.addresses()) { | ||
| * console.log(addr.toString()); | ||
| * } | ||
| * // "192.168.1.0", "192.168.1.1", "192.168.1.2", "192.168.1.3" | ||
| * ``` | ||
| * | ||
| * @example Checking containment and overlap | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.includes(ipv4.address("192.168.0.100")); // true | ||
| * cidr.includes(ipv4.address("192.168.1.1")); // false | ||
| * cidr.overlaps("192.168.0.0/25"); // true | ||
| * cidr.overlaps("10.0.0.0/8"); // false | ||
| * ``` | ||
| * | ||
| * @example Splitting into subranges | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * | ||
| * // Split into equal /26 subnets | ||
| * cidr.subnet(26).map(s => s.toString()); | ||
| * // ["192.168.0.0/26", "192.168.0.64/26", "192.168.0.128/26", "192.168.0.192/26"] | ||
| * | ||
| * // Split by specific ranges | ||
| * cidr.subnetBy([25, 26, 27, 27]).map(s => s.toString()); | ||
| * // ["192.168.0.0/25", "192.168.0.128/26", "192.168.0.192/27", "192.168.0.224/27"] | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential CIDRs | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.nextCIDR()?.toString(); // "192.168.1.0/24" | ||
| * cidr.previousCIDR()?.toString(); // "192.167.255.0/24" | ||
| * ``` | ||
| */ | ||
| class Ipv4Cidr { | ||
| constructor(address) { | ||
| _Ipv4Cidr_address.set(this, void 0); | ||
| _Ipv4Cidr_range.set(this, void 0); | ||
| if (!ipv4.ipv4.isValidCIDR(address)) { | ||
| throw new ipv4Errors.InvalidIpv4CidrError(address); | ||
| } | ||
| if (typeof address === 'string') { | ||
| const [ip, rangeStr] = address.split('/'); | ||
| tslib_es6_js.__classPrivateFieldSet(this, _Ipv4Cidr_address, new ipv4Address.Ipv4Address(ip), "f"); | ||
| tslib_es6_js.__classPrivateFieldSet(this, _Ipv4Cidr_range, parseInt(rangeStr, 10), "f"); | ||
| } | ||
| else if (Array.isArray(address)) { | ||
| tslib_es6_js.__classPrivateFieldSet(this, _Ipv4Cidr_address, new ipv4Address.Ipv4Address(address[0]), "f"); | ||
| tslib_es6_js.__classPrivateFieldSet(this, _Ipv4Cidr_range, address[1], "f"); | ||
| } | ||
| else if (typeof address === 'object' && address !== null) { | ||
| tslib_es6_js.__classPrivateFieldSet(this, _Ipv4Cidr_address, new ipv4Address.Ipv4Address(address.address), "f"); | ||
| tslib_es6_js.__classPrivateFieldSet(this, _Ipv4Cidr_range, address.range, "f"); | ||
| } | ||
| else { | ||
| throw new ipv4Errors.InvalidIpv4CidrError(address); | ||
| } | ||
| } | ||
| /** | ||
| * Gets the base IPv4 address of the CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.baseAddress().toString(); // "192.168.0.0" | ||
| * ``` | ||
| * | ||
| * @returns The base IPv4 address. | ||
| */ | ||
| baseAddress() { | ||
| return tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_address, "f"); | ||
| } | ||
| /** | ||
| * Gets the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.range(); // 24 | ||
| * ``` | ||
| * | ||
| * @returns The CIDR range as a number. | ||
| */ | ||
| range() { | ||
| return tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_range, "f"); | ||
| } | ||
| /** | ||
| * Calculates the netmask for the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.cidr("192.168.0.0/24").netmask().toString(); // "255.255.255.0" | ||
| * ipv4.cidr("10.0.0.0/8").netmask().toString(); // "255.0.0.0" | ||
| * ipv4.cidr("172.16.0.0/16").netmask().toString(); // "255.255.0.0" | ||
| * ``` | ||
| * | ||
| * @returns The netmask as an Ipv4Address. | ||
| */ | ||
| netmask() { | ||
| const maskNumber = tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_range, "f") === 0 ? 0 : (-1 << (32 - tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_range, "f"))) >>> 0; | ||
| return new ipv4Address.Ipv4Address(maskNumber); | ||
| } | ||
| /** | ||
| * Returns the string representation of the IPv4 CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr({ address: "10.0.0.0", range: 8 }); | ||
| * cidr.toString(); // "10.0.0.0/8" | ||
| * ``` | ||
| * | ||
| * @returns The IPv4 CIDR as a string (example: "192.0.0.0/24"). | ||
| */ | ||
| toString() { | ||
| return `${tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toString()}/${tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_range, "f")}`; | ||
| } | ||
| /** | ||
| * Gets the address and range parts of the IPv4 CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const [address, range] = ipv4.cidr("192.168.0.0/24").rangeParts(); | ||
| * address.toString(); // "192.168.0.0" | ||
| * range; // 24 | ||
| * ``` | ||
| * | ||
| * @returns A tuple containing the IPv4 address and the CIDR range. | ||
| */ | ||
| rangeParts() { | ||
| return [tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_address, "f"), tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_range, "f")]; | ||
| } | ||
| /** | ||
| * Calculates the total number of addresses in the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.cidr("192.168.0.0/24").addressCount(); // 256 | ||
| * ipv4.cidr("10.0.0.0/8").addressCount(); // 16777216 | ||
| * ipv4.cidr("192.168.1.0/32").addressCount(); // 1 | ||
| * ``` | ||
| * | ||
| * @returns The total number of addresses in the CIDR range. | ||
| */ | ||
| addressCount() { | ||
| return 2 ** (32 - tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_range, "f")); | ||
| } | ||
| /** | ||
| * Generates all IPv4 addresses within the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.1.0/30"); | ||
| * for (const addr of cidr.addresses()) { | ||
| * console.log(addr.toString()); | ||
| * } | ||
| * // Output: "192.168.1.0", "192.168.1.1", "192.168.1.2", "192.168.1.3" | ||
| * ``` | ||
| * | ||
| * @returns A generator that yields each IPv4 address in the CIDR range. | ||
| */ | ||
| *addresses() { | ||
| const baseNumber = tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber(); | ||
| const count = this.addressCount(); | ||
| for (let i = 0; i < count; i++) { | ||
| yield new ipv4Address.Ipv4Address(baseNumber + i); | ||
| } | ||
| } | ||
| /** | ||
| * Checks if this CIDR is equal to another CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.equals("192.168.0.0/24"); // true | ||
| * cidr.equals({ address: "192.168.0.0", range: 24 }); // true | ||
| * cidr.equals("10.0.0.0/8"); // false | ||
| * ``` | ||
| * | ||
| * @param other - The other IPv4 CIDR to compare with. | ||
| * @returns True if both CIDRs have the same base address and range; otherwise, false. | ||
| */ | ||
| equals(other) { | ||
| const otherCidr = other instanceof Ipv4Cidr ? other : new Ipv4Cidr(other); | ||
| return tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_address, "f").equals(tslib_es6_js.__classPrivateFieldGet(otherCidr, _Ipv4Cidr_address, "f")) && tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_range, "f") === tslib_es6_js.__classPrivateFieldGet(otherCidr, _Ipv4Cidr_range, "f"); | ||
| } | ||
| /** | ||
| * Checks if there is a next sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.cidr("192.168.0.0/24").hasNextCIDR(); // true | ||
| * ipv4.cidr("255.255.255.0/24").hasNextCIDR(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a next CIDR. | ||
| */ | ||
| hasNextCIDR() { | ||
| const nextBaseAddressNumber = tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber() + this.addressCount(); | ||
| return nextBaseAddressNumber <= ipv4.ipv4.MAX_SIZE; | ||
| } | ||
| /** | ||
| * Gets the next sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.nextCIDR()?.toString(); // "192.168.1.0/24" | ||
| * | ||
| * const lastCidr = ipv4.cidr("255.255.255.0/24"); | ||
| * lastCidr.nextCIDR(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The next CIDR, or undefined if there is no next CIDR. | ||
| */ | ||
| nextCIDR() { | ||
| const nextBaseAddressNumber = tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber() + this.addressCount(); | ||
| if (nextBaseAddressNumber > ipv4.ipv4.MAX_SIZE) { | ||
| return undefined; | ||
| } | ||
| return new Ipv4Cidr([nextBaseAddressNumber, tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_range, "f")]); | ||
| } | ||
| /** | ||
| * Checks if there is a previous sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.cidr("192.168.1.0/24").hasPreviousCIDR(); // true | ||
| * ipv4.cidr("0.0.0.0/24").hasPreviousCIDR(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a previous CIDR. | ||
| */ | ||
| hasPreviousCIDR() { | ||
| return tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber() >= this.addressCount(); | ||
| } | ||
| /** | ||
| * Gets the previous sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.1.0/24"); | ||
| * cidr.previousCIDR()?.toString(); // "192.168.0.0/24" | ||
| * | ||
| * const firstCidr = ipv4.cidr("0.0.0.0/24"); | ||
| * firstCidr.previousCIDR(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The previous CIDR, or undefined if there is no previous CIDR. | ||
| */ | ||
| previousCIDR() { | ||
| const prevBaseAddressNumber = tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber() - this.addressCount(); | ||
| if (prevBaseAddressNumber < ipv4.ipv4.MIN_SIZE) { | ||
| return undefined; | ||
| } | ||
| return new Ipv4Cidr([prevBaseAddressNumber, tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_range, "f")]); | ||
| } | ||
| /** | ||
| * Gets the first usable address in the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.getFirstUsableAddress()?.toString(); // "192.168.0.1" | ||
| * | ||
| * const hostCidr = ipv4.cidr("192.168.1.1/32"); | ||
| * hostCidr.getFirstUsableAddress(); // undefined (no usable addresses in /32) | ||
| * ``` | ||
| * | ||
| * @returns The first usable IPv4 address, or undefined if the range is /32. | ||
| */ | ||
| getFirstUsableAddress() { | ||
| if (tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_range, "f") === 32) { | ||
| return undefined; | ||
| } | ||
| const firstUsableNumber = tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber() + 1; | ||
| return new ipv4Address.Ipv4Address(firstUsableNumber); | ||
| } | ||
| /** | ||
| * Gets the last usable address in the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.getLastUsableAddress()?.toString(); // "192.168.0.254" | ||
| * | ||
| * const hostCidr = ipv4.cidr("192.168.1.1/32"); | ||
| * hostCidr.getLastUsableAddress(); // undefined (no usable addresses in /32) | ||
| * ``` | ||
| * | ||
| * @returns The last usable IPv4 address, or undefined if the range is /32. | ||
| */ | ||
| getLastUsableAddress() { | ||
| if (tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_range, "f") === 32) { | ||
| return undefined; | ||
| } | ||
| const lastUsableNumber = tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber() + this.addressCount() - 2; | ||
| return new ipv4Address.Ipv4Address(lastUsableNumber); | ||
| } | ||
| /** | ||
| * Checks if the given IPv4 address is within the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.includes(ipv4.address("192.168.0.100")); // true | ||
| * cidr.includes(ipv4.address("192.168.1.1")); // false | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv4 address to check. | ||
| * @returns True if the address is within the CIDR range; otherwise, false. | ||
| */ | ||
| includes(ip) { | ||
| const ipNumber = ip.toNumber(); | ||
| const baseNumber = tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber(); | ||
| const count = this.addressCount(); | ||
| return ipNumber >= baseNumber && ipNumber < baseNumber + count; | ||
| } | ||
| /** | ||
| * Checks if this CIDR overlaps with another CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.overlaps("192.168.0.0/25"); // true (subset) | ||
| * cidr.overlaps("192.168.0.128/25"); // true (partial overlap) | ||
| * cidr.overlaps("10.0.0.0/8"); // false (no overlap) | ||
| * ``` | ||
| * | ||
| * @param other - The other IPv4 CIDR to check for overlap. | ||
| * @returns True if the CIDRs overlap; otherwise, false. | ||
| */ | ||
| overlaps(other) { | ||
| const otherCidr = other instanceof Ipv4Cidr ? other : new Ipv4Cidr(other); | ||
| const thisBase = tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber(); | ||
| const thisCount = this.addressCount(); | ||
| const otherBase = tslib_es6_js.__classPrivateFieldGet(otherCidr, _Ipv4Cidr_address, "f").toNumber(); | ||
| const otherCount = otherCidr.addressCount(); | ||
| return thisBase < otherBase + otherCount && otherBase < thisBase + thisCount; | ||
| } | ||
| /** | ||
| * Splits the CIDR into smaller subranges of the specified new range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * const subnets = cidr.subnet(26); | ||
| * subnets.map(s => s.toString()); | ||
| * // ["192.168.0.0/26", "192.168.0.64/26", "192.168.0.128/26", "192.168.0.192/26"] | ||
| * ``` | ||
| * | ||
| * @param newRange - The new CIDR range for the subnets. | ||
| * @returns An array of Ipv4Cidr instances representing the subnets. | ||
| * @throws InvalidIpv4CidrRangeError if the new range is less than the current range or greater than the maximum range. | ||
| */ | ||
| subnet(newRange) { | ||
| if (newRange < tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_range, "f") || newRange > ipv4.ipv4.MAX_RANGE) { | ||
| throw new ipv4Errors.InvalidIpv4CidrRangeError(`New range ${newRange} must be between current range ${tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_range, "f")} and ${ipv4.ipv4.MAX_RANGE}`); | ||
| } | ||
| const subranges = []; | ||
| const totalSubnets = 2 ** (newRange - tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_range, "f")); | ||
| const baseNumber = tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber(); | ||
| const subnetSize = 2 ** (32 - newRange); | ||
| for (let i = 0; i < totalSubnets; i++) { | ||
| const subnetBaseNumber = baseNumber + i * subnetSize; | ||
| subranges.push(new Ipv4Cidr([subnetBaseNumber, newRange])); | ||
| } | ||
| return subranges; | ||
| } | ||
| /** | ||
| * Splits the CIDR into sequential subranges with the specified CIDR ranges. | ||
| * Each range in the input array creates a subrange starting where the previous one ended. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("10.0.0.0/16"); | ||
| * const subnets = cidr.subnetBy([24, 20, 24]); | ||
| * subnets.map(s => s.toString()); | ||
| * // ["10.0.0.0/24", "10.0.1.0/20", "10.0.17.0/24"] | ||
| * ``` | ||
| * | ||
| * @param ranges - An array of CIDR range values (e.g., [24, 20, 24]). | ||
| * @returns An array of Ipv4Cidr instances representing the subnets. | ||
| * @throws InvalidIpv4CidrRangeError if any range is less than the current range or greater than 32. | ||
| */ | ||
| subnetBy(ranges) { | ||
| const subranges = []; | ||
| let currentBase = tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber(); | ||
| const endAddress = currentBase + this.addressCount(); | ||
| for (const range of ranges) { | ||
| if (range < tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_range, "f") || range > ipv4.ipv4.MAX_RANGE) { | ||
| throw new ipv4Errors.InvalidIpv4CidrRangeError(`Range ${range} must be between current range ${tslib_es6_js.__classPrivateFieldGet(this, _Ipv4Cidr_range, "f")} and ${ipv4.ipv4.MAX_RANGE}`); | ||
| } | ||
| const subnetSize = 2 ** (32 - range); | ||
| if (currentBase + subnetSize > endAddress) { | ||
| throw new ipv4Errors.InvalidIpv4CidrRangeError(`Subrange /${range} at ${new ipv4Address.Ipv4Address(currentBase).toString()} exceeds the bounds of the parent CIDR`); | ||
| } | ||
| subranges.push(new Ipv4Cidr([currentBase, range])); | ||
| currentBase += subnetSize; | ||
| } | ||
| return subranges; | ||
| } | ||
| } | ||
| _Ipv4Cidr_address = new WeakMap(), _Ipv4Cidr_range = new WeakMap(); | ||
| exports.Ipv4Cidr = Ipv4Cidr; | ||
| //# sourceMappingURL=ipv4-cidr.cjs.map |
| {"version":3,"file":"ipv4-cidr.cjs","sources":["../../../src/ipv4-cidr.ts"],"sourcesContent":[null],"names":["ipv4","InvalidIpv4CidrError","__classPrivateFieldSet","Ipv4Address","__classPrivateFieldGet","InvalidIpv4CidrRangeError"],"mappings":";;;;;;;;AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFG;MACU,QAAQ,CAAA;AAInB,IAAA,WAAA,CAAY,OAAwB,EAAA;QAHpC,iBAAA,CAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA;QACA,eAAA,CAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA;QAGE,IAAI,CAACA,SAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE;AAC9B,YAAA,MAAM,IAAIC,+BAAoB,CAAC,OAAO,CAAC;QACzC;AACA,QAAA,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;AAC/B,YAAA,MAAM,CAAC,EAAE,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC;YACzCC,mCAAA,CAAA,IAAI,qBAAY,IAAIC,uBAAW,CAAC,EAAG,CAAC,MAAA;YACpCD,mCAAA,CAAA,IAAI,mBAAU,QAAQ,CAAC,QAAS,EAAE,EAAE,CAAC,EAAA,GAAA,CAAA;QACvC;AAAO,aAAA,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YACjCA,mCAAA,CAAA,IAAI,EAAA,iBAAA,EAAY,IAAIC,uBAAW,CAAC,OAAO,CAAC,CAAC,CAAC,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B,YAAA,IAAI,KAAK,GAAGA,mCAAA,CAAA,IAAI,EAAA,eAAA,EAAA,GAAA,CAAO,IAAI,KAAK,GAAGJ,SAAI,CAAC,SAAS,EAAE;AACjD,gBAAA,MAAM,IAAIK,oCAAyB,CACjC,CAAA,MAAA,EAAS,KAAK,CAAA,+BAAA,EAAkCD,mCAAA,CAAA,IAAI,EAAA,eAAA,EAAA,GAAA,CAAO,QAAQJ,SAAI,CAAC,SAAS,CAAA,CAAE,CACpF;YACH;YAEA,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC;AAEpC,YAAA,IAAI,WAAW,GAAG,UAAU,GAAG,UAAU,EAAE;AACzC,gBAAA,MAAM,IAAIK,oCAAyB,CACjC,CAAA,UAAA,EAAa,KAAK,OAAO,IAAIF,uBAAW,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAA,sCAAA,CAAwC,CACzG;YACH;AAEA,YAAA,SAAS,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;YAClD,WAAW,IAAI,UAAU;QAC3B;AAEA,QAAA,OAAO,SAAS;IAClB;AACD;;;;;"} |
| 'use strict'; | ||
| class InvalidIpv4AddressError extends Error { | ||
| constructor(invalidAddress) { | ||
| super(`${invalidAddress} is not a valid IPv4 address`); | ||
| this.name = 'InvalidIpv4AddressError'; | ||
| } | ||
| } | ||
| class InvalidIpv4CidrError extends Error { | ||
| constructor(invalidCidr) { | ||
| super(`${invalidCidr} is not a valid IPv4 CIDR range`); | ||
| this.name = 'InvalidIpv4CidrError'; | ||
| } | ||
| } | ||
| class InvalidIpv4CidrRangeError extends Error { | ||
| constructor() { | ||
| super(...arguments); | ||
| this.name = 'InvalidIpv4RangeError'; | ||
| } | ||
| } | ||
| exports.InvalidIpv4AddressError = InvalidIpv4AddressError; | ||
| exports.InvalidIpv4CidrError = InvalidIpv4CidrError; | ||
| exports.InvalidIpv4CidrRangeError = InvalidIpv4CidrRangeError; | ||
| //# sourceMappingURL=ipv4-errors.cjs.map |
| {"version":3,"file":"ipv4-errors.cjs","sources":["../../../src/ipv4-errors.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAM,MAAO,uBAAwB,SAAQ,KAAK,CAAA;AAGhD,IAAA,WAAA,CAAY,cAAuB,EAAA;AACjC,QAAA,KAAK,CAAC,CAAA,EAAG,cAAc,CAAA,4BAAA,CAA8B,CAAC;QAH/C,IAAA,CAAA,IAAI,GAAG,yBAAyB;IAIzC;AACD;AAEK,MAAO,oBAAqB,SAAQ,KAAK,CAAA;AAG7C,IAAA,WAAA,CAAY,WAAoB,EAAA;AAC9B,QAAA,KAAK,CAAC,CAAA,EAAG,WAAW,CAAA,+BAAA,CAAiC,CAAC;QAH/C,IAAA,CAAA,IAAI,GAAG,sBAAsB;IAItC;AACD;AAEK,MAAO,yBAA0B,SAAQ,KAAK,CAAA;AAApD,IAAA,WAAA,GAAA;;QACW,IAAA,CAAA,IAAI,GAAG,uBAAuB;IACzC;AAAC;;;;;;"} |
| 'use strict'; | ||
| var ipv4Address = require('./ipv4-address.cjs'); | ||
| var ipv4Cidr = require('./ipv4-cidr.cjs'); | ||
| var ipv4Errors = require('./ipv4-errors.cjs'); | ||
| exports.ipv4 = void 0; | ||
| (function (ipv4) { | ||
| /** | ||
| * The maximum possible value for an IPv4 address. | ||
| */ | ||
| ipv4.MAX_SIZE = 0xffffffff; | ||
| /** | ||
| * The minimum possible value for an IPv4 address. | ||
| */ | ||
| ipv4.MIN_SIZE = 0x00000000; | ||
| /** | ||
| * The maximum CIDR range for IPv4 addresses. | ||
| */ | ||
| ipv4.MAX_RANGE = 32; | ||
| /** | ||
| * The minimum CIDR range for IPv4 addresses. | ||
| */ | ||
| ipv4.MIN_RANGE = 0; | ||
| /** | ||
| * Creates a new Ipv4Address instance from the given literal. | ||
| * Valid formats include string, number, or octet array. | ||
| * | ||
| * @example Creating addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr1 = ipv4.address("192.168.1.1"); | ||
| * const addr2 = ipv4.address(3232235777); | ||
| * const addr3 = ipv4.address([192, 168, 1, 1]); | ||
| * ``` | ||
| * | ||
| * @example Converting between formats | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.toString(); // "192.168.1.1" | ||
| * addr.toNumber(); // 3232235777 | ||
| * addr.octets(); // [192, 168, 1, 1] | ||
| * addr.toBinaryString(); // "11000000.10101000.00000001.00000001" | ||
| * ``` | ||
| * | ||
| * @example Comparing addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.equals("192.168.1.1"); // true | ||
| * addr.isGreaterThan("192.168.1.0"); // true | ||
| * addr.isLessThan("192.168.1.2"); // true | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.nextAddress()?.toString(); // "192.168.1.2" | ||
| * addr.previousAddress()?.toString(); // "192.168.1.0" | ||
| * ``` | ||
| * | ||
| * @example Checking address types | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("127.0.0.1").isLoopbackAddress(); // true | ||
| * ipv4.address("10.0.0.1").isPrivateAddress(); // true | ||
| * ipv4.address("169.254.1.1").isLocalLinkAddress(); // true | ||
| * ipv4.address("224.0.0.1").isMulticastAddress(); // true | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv4 address in string, number, or octet array format. | ||
| * @returns A new Ipv4Address instance. | ||
| * @throws {InvalidIpv4AddressError} If the input is not a valid IPv4 address. | ||
| */ | ||
| function address(ip) { | ||
| return new ipv4Address.Ipv4Address(ip); | ||
| } | ||
| ipv4.address = address; | ||
| /** | ||
| * Creates a new Ipv4Cidr instance from the given literal. | ||
| * Valid formats include string, object, or tuple. | ||
| * | ||
| * @example Creating CIDR blocks | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr1 = ipv4.cidr("192.168.0.0/24"); | ||
| * const cidr2 = ipv4.cidr({ address: "10.0.0.0", range: 8 }); | ||
| * const cidr3 = ipv4.cidr([[172, 16, 0, 0], 12]); | ||
| * ``` | ||
| * | ||
| * @example Getting CIDR properties | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.baseAddress().toString(); // "192.168.0.0" | ||
| * cidr.range(); // 24 | ||
| * cidr.netmask().toString(); // "255.255.255.0" | ||
| * cidr.addressCount(); // 256 | ||
| * ``` | ||
| * | ||
| * @example Working with usable addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.getFirstUsableAddress()?.toString(); // "192.168.0.1" | ||
| * cidr.getLastUsableAddress()?.toString(); // "192.168.0.254" | ||
| * ``` | ||
| * | ||
| * @example Iterating over addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.1.0/30"); | ||
| * for (const addr of cidr.addresses()) { | ||
| * console.log(addr.toString()); | ||
| * } | ||
| * // "192.168.1.0", "192.168.1.1", "192.168.1.2", "192.168.1.3" | ||
| * ``` | ||
| * | ||
| * @example Checking containment and overlap | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.includes(ipv4.address("192.168.0.100")); // true | ||
| * cidr.includes(ipv4.address("192.168.1.1")); // false | ||
| * cidr.overlaps("192.168.0.0/25"); // true | ||
| * cidr.overlaps("10.0.0.0/8"); // false | ||
| * ``` | ||
| * | ||
| * @example Splitting into subranges | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * | ||
| * // Split into equal /26 subnets | ||
| * cidr.subnet(26).map(s => s.toString()); | ||
| * // ["192.168.0.0/26", "192.168.0.64/26", "192.168.0.128/26", "192.168.0.192/26"] | ||
| * | ||
| * // Split by specific ranges | ||
| * cidr.subnetBy([25, 26, 27, 27]).map(s => s.toString()); | ||
| * // ["192.168.0.0/25", "192.168.0.128/26", "192.168.0.192/27", "192.168.0.224/27"] | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential CIDRs | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.nextCIDR()?.toString(); // "192.168.1.0/24" | ||
| * cidr.previousCIDR()?.toString(); // "192.167.255.0/24" | ||
| * ``` | ||
| * | ||
| * @param cidr - The IPv4 CIDR in string, object, or tuple format. | ||
| * @returns A new Ipv4Cidr instance. | ||
| * @throws {InvalidIpv4CidrError} If the input is not a valid IPv4 CIDR. | ||
| */ | ||
| function cidr(cidr) { | ||
| return new ipv4Cidr.Ipv4Cidr(cidr); | ||
| } | ||
| ipv4.cidr = cidr; | ||
| /** | ||
| * Validates whether the given input is a valid IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.isValidAddress("192.168.1.1"); // true | ||
| * ipv4.isValidAddress("256.0.0.1"); // false (octet out of range) | ||
| * ipv4.isValidAddress(3232235777); // true | ||
| * ipv4.isValidAddress([192, 168, 1, 1]); // true | ||
| * ipv4.isValidAddress("invalid"); // false | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv4 address to validate, which can be in string, number, or octet array format. | ||
| * @returns True if the input is a valid IPv4 address; otherwise, false. | ||
| */ | ||
| function isValidAddress(ip) { | ||
| if (ip === null || ip === undefined) { | ||
| return false; | ||
| } | ||
| let octets = []; | ||
| if (typeof ip === 'string') { | ||
| octets = ip.split('.').map(Number); | ||
| } | ||
| else if (typeof ip === 'number') { | ||
| if (!Number.isFinite(ip) || ip < ipv4.MIN_SIZE || ip > ipv4.MAX_SIZE) { | ||
| return false; | ||
| } | ||
| octets = [(ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff]; | ||
| } | ||
| else if (Array.isArray(ip)) { | ||
| for (const element of ip) { | ||
| if (typeof element !== 'number') { | ||
| return false; | ||
| } | ||
| } | ||
| octets = ip; | ||
| } | ||
| else { | ||
| return false; | ||
| } | ||
| if (octets.length !== 4) { | ||
| return false; | ||
| } | ||
| for (const octet of octets) { | ||
| if (typeof octet !== 'number' || !Number.isInteger(octet) || octet < 0 || octet > 255) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| ipv4.isValidAddress = isValidAddress; | ||
| /** | ||
| * Validates whether the given input is a valid IPv4 CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.isValidCIDR("192.168.0.0/24"); // true | ||
| * ipv4.isValidCIDR("192.168.0.0/33"); // false (range out of bounds) | ||
| * ipv4.isValidCIDR({ address: "10.0.0.0", range: 8 }); // true | ||
| * ipv4.isValidCIDR([[172, 16, 0, 0], 12]); // true | ||
| * ipv4.isValidCIDR("invalid/24"); // false | ||
| * ``` | ||
| * | ||
| * @param cidr - The IPv4 CIDR to validate, which can be in string, object, or tuple format. | ||
| * @returns True if the input is a valid IPv4 CIDR; otherwise, false. | ||
| */ | ||
| function isValidCIDR(cidr) { | ||
| if (cidr === null || cidr === undefined) { | ||
| return false; | ||
| } | ||
| let address; | ||
| let range; | ||
| if (typeof cidr === 'string') { | ||
| const parts = cidr.split('/'); | ||
| if (parts.length !== 2) { | ||
| return false; | ||
| } | ||
| address = parts[0]; | ||
| range = parseInt(parts[1], 10); | ||
| } | ||
| else if (Array.isArray(cidr)) { | ||
| if (cidr.length !== 2) { | ||
| return false; | ||
| } | ||
| // Validate array element types at runtime | ||
| const [first, second] = cidr; | ||
| if (first === null || first === undefined) { | ||
| return false; | ||
| } | ||
| if (typeof second !== 'number') { | ||
| return false; | ||
| } | ||
| address = first; | ||
| range = second; | ||
| } | ||
| else if (typeof cidr === 'object') { | ||
| if (!('address' in cidr) || !('range' in cidr)) { | ||
| return false; | ||
| } | ||
| const { address: addr, range: r } = cidr; | ||
| if (addr === null || addr === undefined) { | ||
| return false; | ||
| } | ||
| if (typeof r !== 'number') { | ||
| return false; | ||
| } | ||
| address = addr; | ||
| range = r; | ||
| } | ||
| else { | ||
| return false; | ||
| } | ||
| if (address === undefined || !isValidAddress(address)) { | ||
| return false; | ||
| } | ||
| if (typeof range !== 'number' | ||
| || !Number.isInteger(range) | ||
| || range < ipv4.MIN_RANGE | ||
| || range > ipv4.MAX_RANGE) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| ipv4.isValidCIDR = isValidCIDR; | ||
| /** | ||
| * Parses the given IPv4 address into its octet representation. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.parseOctets("192.168.1.1"); // [192, 168, 1, 1] | ||
| * ipv4.parseOctets(3232235777); // [192, 168, 1, 1] | ||
| * ipv4.parseOctets([10, 0, 0, 1]); // [10, 0, 0, 1] | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv4 address to parse, which can be in string, number, or octet array format. | ||
| * @returns {Ipv4AddressOctets} An array of four numbers representing the octets of the IPv4 address. | ||
| * @throws {InvalidIpv4AddressError} If the input is not a valid IPv4 address. | ||
| */ | ||
| function parseOctets(ip) { | ||
| if (!isValidAddress(ip)) { | ||
| throw new ipv4Errors.InvalidIpv4AddressError(ip); | ||
| } | ||
| if (typeof ip === 'string') { | ||
| return ip.split('.').map(Number); | ||
| } | ||
| else if (typeof ip === 'number') { | ||
| return [ | ||
| (ip >> 24) & 0xff, | ||
| (ip >> 16) & 0xff, | ||
| (ip >> 8) & 0xff, | ||
| ip & 0xff, | ||
| ]; | ||
| } | ||
| else { | ||
| return ip; | ||
| } | ||
| } | ||
| ipv4.parseOctets = parseOctets; | ||
| })(exports.ipv4 || (exports.ipv4 = {})); | ||
| exports.Ipv4Address = ipv4Address.Ipv4Address; | ||
| exports.Ipv4Cidr = ipv4Cidr.Ipv4Cidr; | ||
| exports.InvalidIpv4AddressError = ipv4Errors.InvalidIpv4AddressError; | ||
| exports.InvalidIpv4CidrError = ipv4Errors.InvalidIpv4CidrError; | ||
| exports.InvalidIpv4CidrRangeError = ipv4Errors.InvalidIpv4CidrRangeError; | ||
| //# sourceMappingURL=ipv4.cjs.map |
| {"version":3,"file":"ipv4.cjs","sources":["../../../src/ipv4.ts"],"sourcesContent":[null],"names":["ipv4","Ipv4Address","Ipv4Cidr","InvalidIpv4AddressError"],"mappings":";;;;;;AAUiBA;AAAjB,CAAA,UAAiB,IAAI,EAAA;AACnB;;AAEG;IACU,IAAA,CAAA,QAAQ,GAAG,UAAU;AAElC;;AAEG;IACU,IAAA,CAAA,QAAQ,GAAG,UAAU;AAElC;;AAEG;IACU,IAAA,CAAA,SAAS,GAAG,EAAE;AAE3B;;AAEG;IACU,IAAA,CAAA,SAAS,GAAG,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDG;IACH,SAAgB,OAAO,CAAC,EAAsB,EAAA;AAC5C,QAAA,OAAO,IAAIC,uBAAW,CAAC,EAAE,CAAC;IAC5B;AAFgB,IAAA,IAAA,CAAA,OAAO,UAEtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFG;IACH,SAAgB,IAAI,CAAC,IAAqB,EAAA;AACxC,QAAA,OAAO,IAAIC,iBAAQ,CAAC,IAAI,CAAC;IAC3B;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AAI;AACjB,gBAAA,CAAC,EAAE,IAAI,CAAC,IAAI,IAAI;AAChB,gBAAA,EAAE,GAAG,IAAI;aACW;QACxB;aAAO;AACL,YAAA,OAAO,EAAuB;QAChC;IACF;AAhBgB,IAAA,IAAA,CAAA,WAAW,cAgB1B;AACH,CAAC,EAhVgBH,YAAI,KAAJA,YAAI,GAAA,EAAA,CAAA,CAAA;;;;;;;;"} |
| 'use strict'; | ||
| var tslib_es6_js = require('/Users/brandon/cidr-block/node_modules/tslib/tslib.es6.js'); | ||
| var ipv6 = require('./ipv6.cjs'); | ||
| var ipv6Errors = require('./ipv6-errors.cjs'); | ||
| var _Ipv6Address_hextets; | ||
| /** | ||
| * Represents an IPv6 address with utility methods for manipulation and comparison. | ||
| * | ||
| * While you can instantiate this class directly, it is recommended to use the | ||
| * {@link ipv6.address} shorthand method from the `ipv6` namespace instead. | ||
| * | ||
| * @example Creating addresses (prefer the shorthand) | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * // Recommended: use the ipv6 namespace shorthand | ||
| * const addr1 = ipv6.address("2001:db8::1"); | ||
| * const addr2 = ipv6.address(42540766411282592856903984951653826561n); | ||
| * const addr3 = ipv6.address([0x2001, 0xdb8, 0, 0, 0, 0, 0, 1]); | ||
| * ``` | ||
| * | ||
| * @example Converting between formats | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.toString(); // "2001:db8::1" (compressed) | ||
| * addr.toFullString(); // "2001:0db8:0000:0000:0000:0000:0000:0001" | ||
| * addr.toBigInt(); // 42540766411282592856903984951653826561n | ||
| * addr.hextets(); // [0x2001, 0xdb8, 0, 0, 0, 0, 0, 1] | ||
| * ``` | ||
| * | ||
| * @example Comparing addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.equals("2001:db8::1"); // true | ||
| * addr.isGreaterThan("2001:db8::0"); // true | ||
| * addr.isLessThan("2001:db8::2"); // true | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.nextAddress()?.toString(); // "2001:db8::2" | ||
| * addr.previousAddress()?.toString(); // "2001:db8::" | ||
| * ``` | ||
| * | ||
| * @example Checking address types | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("::1").isLoopbackAddress(); // true | ||
| * ipv6.address("fc00::1").isUniqueLocalAddress(); // true | ||
| * ipv6.address("fe80::1").isLinkLocalAddress(); // true | ||
| * ipv6.address("ff02::1").isMulticastAddress(); // true | ||
| * ``` | ||
| */ | ||
| class Ipv6Address { | ||
| constructor(ip) { | ||
| _Ipv6Address_hextets.set(this, void 0); | ||
| if (!ipv6.ipv6.isValidAddress(ip)) { | ||
| throw new ipv6Errors.InvalidIpv6AddressError(ip); | ||
| } | ||
| tslib_es6_js.__classPrivateFieldSet(this, _Ipv6Address_hextets, ipv6.ipv6.parseHextets(ip), "f"); | ||
| } | ||
| /** | ||
| * Gets the hextets of the IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.hextets(); // [0x2001, 0xdb8, 0, 0, 0, 0, 0, 1] | ||
| * ``` | ||
| * | ||
| * @returns An array of eight numbers representing the hextets of the IPv6 address. | ||
| */ | ||
| hextets() { | ||
| return tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Address_hextets, "f"); | ||
| } | ||
| /** | ||
| * Returns the full (expanded) string representation of the IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.toFullString(); // "2001:0db8:0000:0000:0000:0000:0000:0001" | ||
| * ``` | ||
| * | ||
| * @returns The IPv6 address as a full string with all hextets expanded. | ||
| */ | ||
| toFullString() { | ||
| return tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Address_hextets, "f").map(h => h.toString(16).padStart(4, '0')).join(':'); | ||
| } | ||
| /** | ||
| * Returns the compressed string representation of the IPv6 address. | ||
| * Uses :: notation for the longest run of consecutive zero hextets. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:0db8:0000:0000:0000:0000:0000:0001"); | ||
| * addr.toString(); // "2001:db8::1" | ||
| * ``` | ||
| * | ||
| * @returns The IPv6 address as a compressed string. | ||
| */ | ||
| toString() { | ||
| // Find the longest run of consecutive zeros | ||
| let longestStart = -1; | ||
| let longestLength = 0; | ||
| let currentStart = -1; | ||
| let currentLength = 0; | ||
| for (let i = 0; i < 8; i++) { | ||
| if (tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[i] === 0) { | ||
| if (currentStart === -1) { | ||
| currentStart = i; | ||
| currentLength = 1; | ||
| } | ||
| else { | ||
| currentLength++; | ||
| } | ||
| } | ||
| else { | ||
| if (currentLength > longestLength && currentLength > 1) { | ||
| longestStart = currentStart; | ||
| longestLength = currentLength; | ||
| } | ||
| currentStart = -1; | ||
| currentLength = 0; | ||
| } | ||
| } | ||
| // Check if the last run is the longest | ||
| if (currentLength > longestLength && currentLength > 1) { | ||
| longestStart = currentStart; | ||
| longestLength = currentLength; | ||
| } | ||
| // Build the compressed string | ||
| if (longestStart === -1) { | ||
| // No compression possible | ||
| return tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Address_hextets, "f").map(h => h.toString(16)).join(':'); | ||
| } | ||
| const before = tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Address_hextets, "f").slice(0, longestStart).map(h => h.toString(16)); | ||
| const after = tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Address_hextets, "f").slice(longestStart + longestLength).map(h => h.toString(16)); | ||
| if (before.length === 0 && after.length === 0) { | ||
| return '::'; | ||
| } | ||
| if (before.length === 0) { | ||
| return `::${after.join(':')}`; | ||
| } | ||
| if (after.length === 0) { | ||
| return `${before.join(':')}::`; | ||
| } | ||
| return `${before.join(':')}::${after.join(':')}`; | ||
| } | ||
| /** | ||
| * Returns the binary string representation of the IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("::1"); | ||
| * addr.toBinaryString(); | ||
| * // "0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000001" | ||
| * ``` | ||
| * | ||
| * @returns The IPv6 address as a binary string with colons separating hextets. | ||
| */ | ||
| toBinaryString() { | ||
| return tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Address_hextets, "f").map(h => h.toString(2).padStart(16, '0')).join(':'); | ||
| } | ||
| /** | ||
| * Converts the IPv6 address to its BigInt representation. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.toBigInt(); // 42540766411282592856903984951653826561n | ||
| * ``` | ||
| * | ||
| * @returns The IPv6 address as a BigInt. | ||
| */ | ||
| toBigInt() { | ||
| let result = 0n; | ||
| for (let i = 0; i < 8; i++) { | ||
| result = (result << 16n) | BigInt(tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[i]); | ||
| } | ||
| return result; | ||
| } | ||
| /** | ||
| * Checks if there is a next sequential IPv6 address. | ||
| * This would only return false if the current address is the maximum possible value. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("2001:db8::1").hasNextAddress(); // true | ||
| * ipv6.address("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff").hasNextAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a next IPv6 address. | ||
| */ | ||
| hasNextAddress() { | ||
| return this.toBigInt() < ipv6.ipv6.MAX_SIZE; | ||
| } | ||
| /** | ||
| * Gets the next sequential IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.nextAddress()?.toString(); // "2001:db8::2" | ||
| * | ||
| * const maxAddr = ipv6.address("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); | ||
| * maxAddr.nextAddress(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The next IPv6 address, or undefined if the current address is the maximum possible value. | ||
| */ | ||
| nextAddress() { | ||
| const nextAddress = this.toBigInt() + 1n; | ||
| if (nextAddress > ipv6.ipv6.MAX_SIZE) { | ||
| return undefined; | ||
| } | ||
| return new Ipv6Address(nextAddress); | ||
| } | ||
| /** | ||
| * Checks if there is a previous sequential IPv6 address. | ||
| * This would only return false if the current address is the minimum possible value (::). | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("2001:db8::1").hasPreviousAddress(); // true | ||
| * ipv6.address("::").hasPreviousAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a previous IPv6 address. | ||
| */ | ||
| hasPreviousAddress() { | ||
| return this.toBigInt() > ipv6.ipv6.MIN_SIZE; | ||
| } | ||
| /** | ||
| * Gets the previous sequential IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.previousAddress()?.toString(); // "2001:db8::" | ||
| * | ||
| * const minAddr = ipv6.address("::"); | ||
| * minAddr.previousAddress(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The previous IPv6 address, or undefined if the current address is the minimum possible value. | ||
| */ | ||
| previousAddress() { | ||
| const prevAddress = this.toBigInt() - 1n; | ||
| if (prevAddress < ipv6.ipv6.MIN_SIZE) { | ||
| return undefined; | ||
| } | ||
| return new Ipv6Address(prevAddress); | ||
| } | ||
| /** | ||
| * Compares two IPv6 addresses for equality. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.equals("2001:db8::1"); // true | ||
| * addr.equals("2001:0db8:0:0:0:0:0:1"); // true | ||
| * addr.equals(ipv6.address("2001:db8::2")); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv6 address to compare with, which can be an Ipv6Address instance or literal value. | ||
| * @returns true if both IPv6 addresses are equal | ||
| */ | ||
| equals(otherAddress) { | ||
| if (otherAddress instanceof Ipv6Address) { | ||
| return this.toBigInt() === otherAddress.toBigInt(); | ||
| } | ||
| return this.toBigInt() === new Ipv6Address(otherAddress).toBigInt(); | ||
| } | ||
| /** | ||
| * Compares if this IPv6 address is greater than another IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.isGreaterThan("2001:db8::"); // true | ||
| * addr.isGreaterThan("2001:db8::1"); // false | ||
| * addr.isGreaterThan("2001:db8::2"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv6 address to compare with, which can be an Ipv6Address instance or literal value. | ||
| * @returns true if this IPv6 address is greater than the other IPv6 address | ||
| */ | ||
| isGreaterThan(otherAddress) { | ||
| if (otherAddress instanceof Ipv6Address) { | ||
| return this.toBigInt() > otherAddress.toBigInt(); | ||
| } | ||
| return this.toBigInt() > new Ipv6Address(otherAddress).toBigInt(); | ||
| } | ||
| /** | ||
| * Compares if this IPv6 address is greater than or equal to another IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.isGreaterThanOrEqual("2001:db8::"); // true | ||
| * addr.isGreaterThanOrEqual("2001:db8::1"); // true | ||
| * addr.isGreaterThanOrEqual("2001:db8::2"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv6 address to compare with, which can be an Ipv6Address instance or literal value. | ||
| * @returns true if this IPv6 address is greater than or equal to the other IPv6 address | ||
| */ | ||
| isGreaterThanOrEqual(otherAddress) { | ||
| if (otherAddress instanceof Ipv6Address) { | ||
| return this.toBigInt() >= otherAddress.toBigInt(); | ||
| } | ||
| return this.toBigInt() >= new Ipv6Address(otherAddress).toBigInt(); | ||
| } | ||
| /** | ||
| * Compares if this IPv6 address is less than another IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.isLessThan("2001:db8::2"); // true | ||
| * addr.isLessThan("2001:db8::1"); // false | ||
| * addr.isLessThan("2001:db8::"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv6 address to compare with, which can be an Ipv6Address instance or literal value. | ||
| * @returns true if this IPv6 address is less than the other IPv6 address | ||
| */ | ||
| isLessThan(otherAddress) { | ||
| if (otherAddress instanceof Ipv6Address) { | ||
| return this.toBigInt() < otherAddress.toBigInt(); | ||
| } | ||
| return this.toBigInt() < new Ipv6Address(otherAddress).toBigInt(); | ||
| } | ||
| /** | ||
| * Compares if this IPv6 address is less than or equal to another IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.isLessThanOrEqual("2001:db8::2"); // true | ||
| * addr.isLessThanOrEqual("2001:db8::1"); // true | ||
| * addr.isLessThanOrEqual("2001:db8::"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv6 address to compare with, which can be an Ipv6Address instance or literal value. | ||
| * @returns true if this IPv6 address is less than or equal to the other IPv6 address | ||
| */ | ||
| isLessThanOrEqual(otherAddress) { | ||
| if (otherAddress instanceof Ipv6Address) { | ||
| return this.toBigInt() <= otherAddress.toBigInt(); | ||
| } | ||
| return this.toBigInt() <= new Ipv6Address(otherAddress).toBigInt(); | ||
| } | ||
| /** | ||
| * Checks if the IPv6 address is the loopback address (::1) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("::1").isLoopbackAddress(); // true | ||
| * ipv6.address("2001:db8::1").isLoopbackAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is the loopback address | ||
| */ | ||
| isLoopbackAddress() { | ||
| return this.toBigInt() === 1n; | ||
| } | ||
| /** | ||
| * Checks if the IPv6 address is the unspecified address (::) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("::").isUnspecifiedAddress(); // true | ||
| * ipv6.address("2001:db8::1").isUnspecifiedAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is the unspecified address | ||
| */ | ||
| isUnspecifiedAddress() { | ||
| return this.toBigInt() === 0n; | ||
| } | ||
| /** | ||
| * Checks if the IPv6 address is a unique local address (fc00::/7). | ||
| * These are the IPv6 equivalent of RFC 1918 private addresses. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("fc00::1").isUniqueLocalAddress(); // true | ||
| * ipv6.address("fd00::1").isUniqueLocalAddress(); // true | ||
| * ipv6.address("2001:db8::1").isUniqueLocalAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is a unique local address | ||
| */ | ||
| isUniqueLocalAddress() { | ||
| // fc00::/7 means first 7 bits are 1111110 | ||
| // This covers fc00::/8 and fd00::/8 | ||
| return (tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[0] & 0xfe00) === 0xfc00; | ||
| } | ||
| /** | ||
| * Checks if the IPv6 address is a link-local address (fe80::/10) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("fe80::1").isLinkLocalAddress(); // true | ||
| * ipv6.address("2001:db8::1").isLinkLocalAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is a link-local address | ||
| */ | ||
| isLinkLocalAddress() { | ||
| // fe80::/10 means first 10 bits are 1111111010 | ||
| return (tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[0] & 0xffc0) === 0xfe80; | ||
| } | ||
| /** | ||
| * Checks if the IPv6 address is a multicast address (ff00::/8) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("ff02::1").isMulticastAddress(); // true | ||
| * ipv6.address("2001:db8::1").isMulticastAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is a multicast address | ||
| */ | ||
| isMulticastAddress() { | ||
| return (tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[0] & 0xff00) === 0xff00; | ||
| } | ||
| /** | ||
| * Checks if the IPv6 address is an IPv4-mapped IPv6 address (::ffff:0:0/96) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("::ffff:192.168.1.1").isIPv4MappedAddress(); // true | ||
| * ipv6.address("::ffff:c0a8:0101").isIPv4MappedAddress(); // true | ||
| * ipv6.address("2001:db8::1").isIPv4MappedAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is an IPv4-mapped address | ||
| */ | ||
| isIPv4MappedAddress() { | ||
| // First 80 bits (5 hextets) must be 0, 6th hextet must be 0xffff | ||
| return (tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[0] === 0 | ||
| && tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[1] === 0 | ||
| && tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[2] === 0 | ||
| && tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[3] === 0 | ||
| && tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[4] === 0 | ||
| && tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[5] === 0xffff); | ||
| } | ||
| /** | ||
| * Checks if the IPv6 address is a documentation address (2001:db8::/32) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("2001:db8::1").isDocumentationAddress(); // true | ||
| * ipv6.address("2001:db8:1234::1").isDocumentationAddress(); // true | ||
| * ipv6.address("2001:470::1").isDocumentationAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is a documentation address | ||
| */ | ||
| isDocumentationAddress() { | ||
| return tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[0] === 0x2001 && tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[1] === 0x0db8; | ||
| } | ||
| } | ||
| _Ipv6Address_hextets = new WeakMap(); | ||
| exports.Ipv6Address = Ipv6Address; | ||
| //# sourceMappingURL=ipv6-address.cjs.map |
| {"version":3,"file":"ipv6-address.cjs","sources":["../../../src/ipv6-address.ts"],"sourcesContent":[null],"names":["ipv6","InvalidIpv6AddressError","__classPrivateFieldSet","__classPrivateFieldGet"],"mappings":";;;;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDG;MACU,WAAW,CAAA;AAGtB,IAAA,WAAA,CAAY,EAAsB,EAAA;QAFlC,oBAAA,CAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA;QAGE,IAAI,CAACA,SAAI,CAAC,cA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,CAAS,CAAC,CAAC,CAAC,KAAK;AACrB,eAAAA,mCAAA,CAAA,IAAI,EAAA,oBAAA,EAAA,GAAA,CAAS,CAAC,CAAC,CAAC,KAAK;AACrB,eAAAA,mCAAA,CAAA,IAAI,EAAA,oBAAA,EAAA,GAAA,CAAS,CAAC,CAAC,CAAC,KAAK;AACrB,eAAAA,mCAAA,CAAA,IAAI,EAAA,oBAAA,EAAA,GAAA,CAAS,CAAC,CAAC,CAAC,KAAK;eACrBA,mCAAA,CAAA,IAAI,4BAAS,CAAC,CAAC,CAAC,KAAK,MAAM;IAElC;AAEA;;;;;;;;;;;;;AAaG;IACI,sBAAsB,GAAA;AAC3B,QAAA,OAAOA,oCAAA,IAAI,EAAA,oBAAA,EAAA,GAAA,CAAS,CAAC,CAAC,CAAC,KAAK,MAAM,IAAIA,mCAAA,CAAA,IAAI,EAAA,oBAAA,EAAA,GAAA,CAAS,CAAC,CAAC,CAAC,KAAK,MAAM;IACnE;AACD;;;;;"} |
| 'use strict'; | ||
| var tslib_es6_js = require('/Users/brandon/cidr-block/node_modules/tslib/tslib.es6.js'); | ||
| var ipv6 = require('./ipv6.cjs'); | ||
| var ipv6Address = require('./ipv6-address.cjs'); | ||
| var ipv6Errors = require('./ipv6-errors.cjs'); | ||
| var _Ipv6Cidr_address, _Ipv6Cidr_range; | ||
| /** | ||
| * Represents an IPv6 CIDR block with utility methods for subnet operations. | ||
| * | ||
| * While you can instantiate this class directly, it is recommended to use the | ||
| * {@link ipv6.cidr} shorthand method from the `ipv6` namespace instead. | ||
| * | ||
| * @example Creating CIDR blocks (prefer the shorthand) | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * // Recommended: use the ipv6 namespace shorthand | ||
| * const cidr1 = ipv6.cidr("2001:db8::/32"); | ||
| * const cidr2 = ipv6.cidr({ address: "2001:db8::", range: 32 }); | ||
| * const cidr3 = ipv6.cidr(["2001:db8::", 32]); | ||
| * ``` | ||
| * | ||
| * @example Getting CIDR properties | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.baseAddress().toString(); // "2001:db8::" | ||
| * cidr.range(); // 32 | ||
| * cidr.netmask().toString(); // "ffff:ffff::" | ||
| * cidr.addressCount(); // 79228162514264337593543950336n | ||
| * ``` | ||
| * | ||
| * @example Working with usable addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/126"); | ||
| * cidr.getFirstUsableAddress()?.toString(); // "2001:db8::1" | ||
| * cidr.getLastUsableAddress()?.toString(); // "2001:db8::2" | ||
| * ``` | ||
| * | ||
| * @example Checking containment and overlap | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.includes(ipv6.address("2001:db8::1")); // true | ||
| * cidr.includes(ipv6.address("2001:db9::1")); // false | ||
| * cidr.overlaps("2001:db8::/48"); // true | ||
| * cidr.overlaps("2001:db9::/32"); // false | ||
| * ``` | ||
| * | ||
| * @example Splitting into subranges | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * | ||
| * // Split into equal /48 subnets | ||
| * cidr.subnet(34).map(s => s.toString()); | ||
| * // ["2001:db8::/34", "2001:db8:4000::/34", "2001:db8:8000::/34", "2001:db8:c000::/34"] | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential CIDRs | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.nextCIDR()?.toString(); // "2001:db9::/32" | ||
| * cidr.previousCIDR()?.toString(); // "2001:db7::/32" | ||
| * ``` | ||
| */ | ||
| class Ipv6Cidr { | ||
| constructor(address) { | ||
| _Ipv6Cidr_address.set(this, void 0); | ||
| _Ipv6Cidr_range.set(this, void 0); | ||
| if (!ipv6.ipv6.isValidCIDR(address)) { | ||
| throw new ipv6Errors.InvalidIpv6CidrError(address); | ||
| } | ||
| if (typeof address === 'string') { | ||
| const [ip, rangeStr] = address.split('/'); | ||
| tslib_es6_js.__classPrivateFieldSet(this, _Ipv6Cidr_address, new ipv6Address.Ipv6Address(ip), "f"); | ||
| tslib_es6_js.__classPrivateFieldSet(this, _Ipv6Cidr_range, Number.parseInt(rangeStr, 10), "f"); | ||
| } | ||
| else if (Array.isArray(address)) { | ||
| tslib_es6_js.__classPrivateFieldSet(this, _Ipv6Cidr_address, new ipv6Address.Ipv6Address(address[0]), "f"); | ||
| tslib_es6_js.__classPrivateFieldSet(this, _Ipv6Cidr_range, address[1], "f"); | ||
| } | ||
| else if (typeof address === 'object' && address !== null) { | ||
| tslib_es6_js.__classPrivateFieldSet(this, _Ipv6Cidr_address, new ipv6Address.Ipv6Address(address.address), "f"); | ||
| tslib_es6_js.__classPrivateFieldSet(this, _Ipv6Cidr_range, address.range, "f"); | ||
| } | ||
| else { | ||
| throw new ipv6Errors.InvalidIpv6CidrError(address); | ||
| } | ||
| } | ||
| /** | ||
| * Gets the base IPv6 address of the CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.baseAddress().toString(); // "2001:db8::" | ||
| * ``` | ||
| * | ||
| * @returns The base IPv6 address. | ||
| */ | ||
| baseAddress() { | ||
| return tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_address, "f"); | ||
| } | ||
| /** | ||
| * Gets the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.range(); // 32 | ||
| * ``` | ||
| * | ||
| * @returns The CIDR range as a number. | ||
| */ | ||
| range() { | ||
| return tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_range, "f"); | ||
| } | ||
| /** | ||
| * Calculates the netmask for the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.cidr("2001:db8::/32").netmask().toString(); // "ffff:ffff::" | ||
| * ipv6.cidr("2001:db8::/64").netmask().toString(); // "ffff:ffff:ffff:ffff::" | ||
| * ipv6.cidr("2001:db8::/128").netmask().toString(); // "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" | ||
| * ``` | ||
| * | ||
| * @returns The netmask as an Ipv6Address. | ||
| */ | ||
| netmask() { | ||
| if (tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_range, "f") === 0) { | ||
| return new ipv6Address.Ipv6Address(0n); | ||
| } | ||
| // Create a mask with `range` 1-bits followed by (128 - range) 0-bits | ||
| const mask = (1n << 128n) - (1n << BigInt(128 - tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_range, "f"))); | ||
| return new ipv6Address.Ipv6Address(mask); | ||
| } | ||
| /** | ||
| * Returns the string representation of the IPv6 CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr({ address: "2001:db8::", range: 32 }); | ||
| * cidr.toString(); // "2001:db8::/32" | ||
| * ``` | ||
| * | ||
| * @returns The IPv6 CIDR as a string (example: "2001:db8::/32"). | ||
| */ | ||
| toString() { | ||
| return `${tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toString()}/${tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_range, "f")}`; | ||
| } | ||
| /** | ||
| * Gets the address and range parts of the IPv6 CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const [address, range] = ipv6.cidr("2001:db8::/32").rangeParts(); | ||
| * address.toString(); // "2001:db8::" | ||
| * range; // 32 | ||
| * ``` | ||
| * | ||
| * @returns A tuple containing the IPv6 address and the CIDR range. | ||
| */ | ||
| rangeParts() { | ||
| return [tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_address, "f"), tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_range, "f")]; | ||
| } | ||
| /** | ||
| * Calculates the total number of addresses in the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.cidr("2001:db8::/64").addressCount(); // 18446744073709551616n | ||
| * ipv6.cidr("2001:db8::/128").addressCount(); // 1n | ||
| * ipv6.cidr("2001:db8::/126").addressCount(); // 4n | ||
| * ``` | ||
| * | ||
| * @returns The total number of addresses in the CIDR range as a BigInt. | ||
| */ | ||
| addressCount() { | ||
| return 1n << BigInt(128 - tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_range, "f")); | ||
| } | ||
| /** | ||
| * Generates IPv6 addresses within the CIDR range. | ||
| * Note: For large CIDR ranges, this may generate an extremely large number of addresses. | ||
| * Use with caution and consider using a limit parameter. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/126"); | ||
| * for (const addr of cidr.addresses()) { | ||
| * console.log(addr.toString()); | ||
| * } | ||
| * // Output: "2001:db8::", "2001:db8::1", "2001:db8::2", "2001:db8::3" | ||
| * ``` | ||
| * | ||
| * @param limit - Optional maximum number of addresses to generate (defaults to all addresses). | ||
| * @returns A generator that yields each IPv6 address in the CIDR range. | ||
| */ | ||
| *addresses(limit) { | ||
| const baseBigInt = tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt(); | ||
| const count = this.addressCount(); | ||
| const maxIterations = limit !== undefined && limit < count ? limit : count; | ||
| for (let i = 0n; i < maxIterations; i++) { | ||
| yield new ipv6Address.Ipv6Address(baseBigInt + i); | ||
| } | ||
| } | ||
| /** | ||
| * Checks if this CIDR is equal to another CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.equals("2001:db8::/32"); // true | ||
| * cidr.equals({ address: "2001:db8::", range: 32 }); // true | ||
| * cidr.equals("2001:db8::/48"); // false | ||
| * ``` | ||
| * | ||
| * @param other - The other IPv6 CIDR to compare with. | ||
| * @returns True if both CIDRs have the same base address and range; otherwise, false. | ||
| */ | ||
| equals(other) { | ||
| const otherCidr = other instanceof Ipv6Cidr ? other : new Ipv6Cidr(other); | ||
| return tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_address, "f").equals(tslib_es6_js.__classPrivateFieldGet(otherCidr, _Ipv6Cidr_address, "f")) && tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_range, "f") === tslib_es6_js.__classPrivateFieldGet(otherCidr, _Ipv6Cidr_range, "f"); | ||
| } | ||
| /** | ||
| * Checks if there is a next sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.cidr("2001:db8::/32").hasNextCIDR(); // true | ||
| * ipv6.cidr("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00/120").hasNextCIDR(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a next CIDR. | ||
| */ | ||
| hasNextCIDR() { | ||
| const nextBaseBigInt = tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt() + this.addressCount(); | ||
| return nextBaseBigInt <= ipv6.ipv6.MAX_SIZE; | ||
| } | ||
| /** | ||
| * Gets the next sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.nextCIDR()?.toString(); // "2001:db9::/32" | ||
| * ``` | ||
| * | ||
| * @returns The next CIDR, or undefined if there is no next CIDR. | ||
| */ | ||
| nextCIDR() { | ||
| const nextBaseBigInt = tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt() + this.addressCount(); | ||
| if (nextBaseBigInt > ipv6.ipv6.MAX_SIZE) { | ||
| return undefined; | ||
| } | ||
| return new Ipv6Cidr([nextBaseBigInt, tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_range, "f")]); | ||
| } | ||
| /** | ||
| * Checks if there is a previous sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.cidr("2001:db8::/32").hasPreviousCIDR(); // true | ||
| * ipv6.cidr("::/32").hasPreviousCIDR(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a previous CIDR. | ||
| */ | ||
| hasPreviousCIDR() { | ||
| return tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt() >= this.addressCount(); | ||
| } | ||
| /** | ||
| * Gets the previous sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.previousCIDR()?.toString(); // "2001:db7::/32" | ||
| * | ||
| * const firstCidr = ipv6.cidr("::/32"); | ||
| * firstCidr.previousCIDR(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The previous CIDR, or undefined if there is no previous CIDR. | ||
| */ | ||
| previousCIDR() { | ||
| const prevBaseBigInt = tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt() - this.addressCount(); | ||
| if (prevBaseBigInt < ipv6.ipv6.MIN_SIZE) { | ||
| return undefined; | ||
| } | ||
| return new Ipv6Cidr([prevBaseBigInt, tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_range, "f")]); | ||
| } | ||
| /** | ||
| * Gets the first usable address in the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/64"); | ||
| * cidr.getFirstUsableAddress()?.toString(); // "2001:db8::1" | ||
| * | ||
| * const hostCidr = ipv6.cidr("2001:db8::1/128"); | ||
| * hostCidr.getFirstUsableAddress(); // undefined (no usable addresses in /128) | ||
| * ``` | ||
| * | ||
| * @returns The first usable IPv6 address, or undefined if the range is /128. | ||
| */ | ||
| getFirstUsableAddress() { | ||
| if (tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_range, "f") === 128) { | ||
| return undefined; | ||
| } | ||
| const firstUsableBigInt = tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt() + 1n; | ||
| return new ipv6Address.Ipv6Address(firstUsableBigInt); | ||
| } | ||
| /** | ||
| * Gets the last usable address in the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/126"); | ||
| * cidr.getLastUsableAddress()?.toString(); // "2001:db8::2" | ||
| * | ||
| * const hostCidr = ipv6.cidr("2001:db8::1/128"); | ||
| * hostCidr.getLastUsableAddress(); // undefined (no usable addresses in /128) | ||
| * ``` | ||
| * | ||
| * @returns The last usable IPv6 address, or undefined if the range is /128. | ||
| */ | ||
| getLastUsableAddress() { | ||
| if (tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_range, "f") === 128) { | ||
| return undefined; | ||
| } | ||
| const lastUsableBigInt = tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt() + this.addressCount() - 2n; | ||
| return new ipv6Address.Ipv6Address(lastUsableBigInt); | ||
| } | ||
| /** | ||
| * Checks if the given IPv6 address is within the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.includes(ipv6.address("2001:db8::1")); // true | ||
| * cidr.includes(ipv6.address("2001:db9::1")); // false | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv6 address to check. | ||
| * @returns True if the address is within the CIDR range; otherwise, false. | ||
| */ | ||
| includes(ip) { | ||
| const ipBigInt = ip.toBigInt(); | ||
| const baseBigInt = tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt(); | ||
| const count = this.addressCount(); | ||
| return ipBigInt >= baseBigInt && ipBigInt < baseBigInt + count; | ||
| } | ||
| /** | ||
| * Checks if this CIDR overlaps with another CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.overlaps("2001:db8::/48"); // true (subset) | ||
| * cidr.overlaps("2001:db8:8000::/33"); // true (partial overlap) | ||
| * cidr.overlaps("2001:db9::/32"); // false (no overlap) | ||
| * ``` | ||
| * | ||
| * @param other - The other IPv6 CIDR to check for overlap. | ||
| * @returns True if the CIDRs overlap; otherwise, false. | ||
| */ | ||
| overlaps(other) { | ||
| const otherCidr = other instanceof Ipv6Cidr ? other : new Ipv6Cidr(other); | ||
| const thisBase = tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt(); | ||
| const thisCount = this.addressCount(); | ||
| const otherBase = tslib_es6_js.__classPrivateFieldGet(otherCidr, _Ipv6Cidr_address, "f").toBigInt(); | ||
| const otherCount = otherCidr.addressCount(); | ||
| return thisBase < otherBase + otherCount && otherBase < thisBase + thisCount; | ||
| } | ||
| /** | ||
| * Splits the CIDR into smaller subranges of the specified new range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * const subnets = cidr.subnet(34); | ||
| * subnets.map(s => s.toString()); | ||
| * // ["2001:db8::/34", "2001:db8:4000::/34", "2001:db8:8000::/34", "2001:db8:c000::/34"] | ||
| * ``` | ||
| * | ||
| * @param newRange - The new CIDR range for the subnets. | ||
| * @returns An array of Ipv6Cidr instances representing the subnets. | ||
| * @throws InvalidIpv6CidrRangeError if the new range is less than the current range or greater than the maximum range. | ||
| */ | ||
| subnet(newRange) { | ||
| if (newRange < tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_range, "f") || newRange > ipv6.ipv6.MAX_RANGE) { | ||
| throw new ipv6Errors.InvalidIpv6CidrRangeError(`New range ${newRange} must be between current range ${tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_range, "f")} and ${ipv6.ipv6.MAX_RANGE}`); | ||
| } | ||
| const subranges = []; | ||
| const totalSubnets = 1n << BigInt(newRange - tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_range, "f")); | ||
| const baseBigInt = tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt(); | ||
| const subnetSize = 1n << BigInt(128 - newRange); | ||
| for (let i = 0n; i < totalSubnets; i++) { | ||
| const subnetBaseBigInt = baseBigInt + i * subnetSize; | ||
| subranges.push(new Ipv6Cidr([subnetBaseBigInt, newRange])); | ||
| } | ||
| return subranges; | ||
| } | ||
| /** | ||
| * Splits the CIDR into sequential subranges with the specified CIDR ranges. | ||
| * Each range in the input array creates a subrange starting where the previous one ended. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * const subnets = cidr.subnetBy([48, 36, 48]); | ||
| * subnets.map(s => s.toString()); | ||
| * // ["2001:db8::/48", "2001:db8:1::/36", "2001:db8:1100::/48"] | ||
| * ``` | ||
| * | ||
| * @param ranges - An array of CIDR range values (e.g., [48, 36, 48]). | ||
| * @returns An array of Ipv6Cidr instances representing the subnets. | ||
| * @throws InvalidIpv6CidrRangeError if any range is less than the current range or greater than 128. | ||
| */ | ||
| subnetBy(ranges) { | ||
| const subranges = []; | ||
| let currentBase = tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt(); | ||
| const endAddress = currentBase + this.addressCount(); | ||
| for (const range of ranges) { | ||
| if (range < tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_range, "f") || range > ipv6.ipv6.MAX_RANGE) { | ||
| throw new ipv6Errors.InvalidIpv6CidrRangeError(`Range ${range} must be between current range ${tslib_es6_js.__classPrivateFieldGet(this, _Ipv6Cidr_range, "f")} and ${ipv6.ipv6.MAX_RANGE}`); | ||
| } | ||
| const subnetSize = 1n << BigInt(128 - range); | ||
| if (currentBase + subnetSize > endAddress) { | ||
| throw new ipv6Errors.InvalidIpv6CidrRangeError(`Subrange /${range} at ${new ipv6Address.Ipv6Address(currentBase).toString()} exceeds the bounds of the parent CIDR`); | ||
| } | ||
| subranges.push(new Ipv6Cidr([currentBase, range])); | ||
| currentBase += subnetSize; | ||
| } | ||
| return subranges; | ||
| } | ||
| } | ||
| _Ipv6Cidr_address = new WeakMap(), _Ipv6Cidr_range = new WeakMap(); | ||
| exports.Ipv6Cidr = Ipv6Cidr; | ||
| //# sourceMappingURL=ipv6-cidr.cjs.map |
| {"version":3,"file":"ipv6-cidr.cjs","sources":["../../../src/ipv6-cidr.ts"],"sourcesContent":[null],"names":["ipv6","InvalidIpv6CidrError","__classPrivateFieldSet","Ipv6Address","__classPrivateFieldGet","InvalidIpv6CidrRangeError"],"mappings":";;;;;;;;AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEG;MACU,QAAQ,CAAA;AAInB,IAAA,WAAA,CAAY,OAAwB,EAAA;QAHpC,iBAAA,CAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA;QACA,eAAA,CAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA;QAGE,IAAI,CAACA,SAA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AAM,IAAIK,oCAAyB,CACjC,CAAA,UAAA,EAAa,KAAK,OAAO,IAAIF,uBAAW,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAA,sCAAA,CAAwC,CACzG;YACH;AAEA,YAAA,SAAS,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;YAClD,WAAW,IAAI,UAAU;QAC3B;AAEA,QAAA,OAAO,SAAS;IAClB;AACD;;;;;"} |
| 'use strict'; | ||
| class InvalidIpv6AddressError extends Error { | ||
| constructor(invalidAddress) { | ||
| super(`${invalidAddress} is not a valid IPv6 address`); | ||
| this.name = 'InvalidIpv6AddressError'; | ||
| } | ||
| } | ||
| class InvalidIpv6CidrError extends Error { | ||
| constructor(invalidCidr) { | ||
| super(`${invalidCidr} is not a valid IPv6 CIDR range`); | ||
| this.name = 'InvalidIpv6CidrError'; | ||
| } | ||
| } | ||
| class InvalidIpv6CidrRangeError extends Error { | ||
| constructor() { | ||
| super(...arguments); | ||
| this.name = 'InvalidIpv6RangeError'; | ||
| } | ||
| } | ||
| exports.InvalidIpv6AddressError = InvalidIpv6AddressError; | ||
| exports.InvalidIpv6CidrError = InvalidIpv6CidrError; | ||
| exports.InvalidIpv6CidrRangeError = InvalidIpv6CidrRangeError; | ||
| //# sourceMappingURL=ipv6-errors.cjs.map |
| {"version":3,"file":"ipv6-errors.cjs","sources":["../../../src/ipv6-errors.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAM,MAAO,uBAAwB,SAAQ,KAAK,CAAA;AAGhD,IAAA,WAAA,CAAY,cAAuB,EAAA;AACjC,QAAA,KAAK,CAAC,CAAA,EAAG,cAAc,CAAA,4BAAA,CAA8B,CAAC;QAH/C,IAAA,CAAA,IAAI,GAAG,yBAAyB;IAIzC;AACD;AAEK,MAAO,oBAAqB,SAAQ,KAAK,CAAA;AAG7C,IAAA,WAAA,CAAY,WAAoB,EAAA;AAC9B,QAAA,KAAK,CAAC,CAAA,EAAG,WAAW,CAAA,+BAAA,CAAiC,CAAC;QAH/C,IAAA,CAAA,IAAI,GAAG,sBAAsB;IAItC;AACD;AAEK,MAAO,yBAA0B,SAAQ,KAAK,CAAA;AAApD,IAAA,WAAA,GAAA;;QACW,IAAA,CAAA,IAAI,GAAG,uBAAuB;IACzC;AAAC;;;;;;"} |
| 'use strict'; | ||
| var ipv6Address = require('./ipv6-address.cjs'); | ||
| var ipv6Cidr = require('./ipv6-cidr.cjs'); | ||
| var ipv6Errors = require('./ipv6-errors.cjs'); | ||
| exports.ipv6 = void 0; | ||
| (function (ipv6) { | ||
| /** | ||
| * The maximum possible value for an IPv6 address. | ||
| */ | ||
| ipv6.MAX_SIZE = (1n << 128n) - 1n; | ||
| /** | ||
| * The minimum possible value for an IPv6 address. | ||
| */ | ||
| ipv6.MIN_SIZE = 0n; | ||
| /** | ||
| * The maximum CIDR range for IPv6 addresses. | ||
| */ | ||
| ipv6.MAX_RANGE = 128; | ||
| /** | ||
| * The minimum CIDR range for IPv6 addresses. | ||
| */ | ||
| ipv6.MIN_RANGE = 0; | ||
| /** | ||
| * Creates a new Ipv6Address instance from the given literal. | ||
| * Valid formats include string (with :: compression support), bigint, or hextets array. | ||
| * | ||
| * @example Creating addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr1 = ipv6.address("2001:db8::1"); | ||
| * const addr2 = ipv6.address(42540766411282592856903984951653826561n); | ||
| * const addr3 = ipv6.address([0x2001, 0xdb8, 0, 0, 0, 0, 0, 1]); | ||
| * ``` | ||
| * | ||
| * @example Converting between formats | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.toString(); // "2001:db8::1" (compressed) | ||
| * addr.toFullString(); // "2001:0db8:0000:0000:0000:0000:0000:0001" | ||
| * addr.toBigInt(); // 42540766411282592856903984951653826561n | ||
| * addr.hextets(); // [0x2001, 0xdb8, 0, 0, 0, 0, 0, 1] | ||
| * ``` | ||
| * | ||
| * @example Comparing addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.equals("2001:db8::1"); // true | ||
| * addr.isGreaterThan("2001:db8::"); // true | ||
| * addr.isLessThan("2001:db8::2"); // true | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.nextAddress()?.toString(); // "2001:db8::2" | ||
| * addr.previousAddress()?.toString(); // "2001:db8::" | ||
| * ``` | ||
| * | ||
| * @example Checking address types | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("::1").isLoopbackAddress(); // true | ||
| * ipv6.address("fc00::1").isUniqueLocalAddress(); // true | ||
| * ipv6.address("fe80::1").isLinkLocalAddress(); // true | ||
| * ipv6.address("ff02::1").isMulticastAddress(); // true | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv6 address in string, bigint, or hextets array format. | ||
| * @returns A new Ipv6Address instance. | ||
| * @throws {InvalidIpv6AddressError} If the input is not a valid IPv6 address. | ||
| */ | ||
| function address(ip) { | ||
| return new ipv6Address.Ipv6Address(ip); | ||
| } | ||
| ipv6.address = address; | ||
| /** | ||
| * Creates a new Ipv6Cidr instance from the given literal. | ||
| * Valid formats include string, object, or tuple. | ||
| * | ||
| * @example Creating CIDR blocks | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr1 = ipv6.cidr("2001:db8::/32"); | ||
| * const cidr2 = ipv6.cidr({ address: "2001:db8::", range: 32 }); | ||
| * const cidr3 = ipv6.cidr(["2001:db8::", 32]); | ||
| * ``` | ||
| * | ||
| * @example Getting CIDR properties | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.baseAddress().toString(); // "2001:db8::" | ||
| * cidr.range(); // 32 | ||
| * cidr.netmask().toString(); // "ffff:ffff::" | ||
| * cidr.addressCount(); // 79228162514264337593543950336n | ||
| * ``` | ||
| * | ||
| * @example Working with usable addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/126"); | ||
| * cidr.getFirstUsableAddress()?.toString(); // "2001:db8::1" | ||
| * cidr.getLastUsableAddress()?.toString(); // "2001:db8::2" | ||
| * ``` | ||
| * | ||
| * @example Checking containment and overlap | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.includes(ipv6.address("2001:db8::1")); // true | ||
| * cidr.includes(ipv6.address("2001:db9::1")); // false | ||
| * cidr.overlaps("2001:db8::/48"); // true | ||
| * cidr.overlaps("2001:db9::/32"); // false | ||
| * ``` | ||
| * | ||
| * @example Splitting into subranges | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * | ||
| * // Split into equal /34 subnets | ||
| * cidr.subnet(34).map(s => s.toString()); | ||
| * // ["2001:db8::/34", "2001:db8:4000::/34", "2001:db8:8000::/34", "2001:db8:c000::/34"] | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential CIDRs | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.nextCIDR()?.toString(); // "2001:db9::/32" | ||
| * cidr.previousCIDR()?.toString(); // "2001:db7::/32" | ||
| * ``` | ||
| * | ||
| * @param cidr - The IPv6 CIDR in string, object, or tuple format. | ||
| * @returns A new Ipv6Cidr instance. | ||
| * @throws {InvalidIpv6CidrError} If the input is not a valid IPv6 CIDR. | ||
| */ | ||
| function cidr(cidr) { | ||
| return new ipv6Cidr.Ipv6Cidr(cidr); | ||
| } | ||
| ipv6.cidr = cidr; | ||
| /** | ||
| * Validates whether the given input is a valid IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.isValidAddress("2001:db8::1"); // true | ||
| * ipv6.isValidAddress("::"); // true | ||
| * ipv6.isValidAddress("::1"); // true | ||
| * ipv6.isValidAddress("gggg::1"); // false (invalid hex) | ||
| * ipv6.isValidAddress("2001:db8"); // false (incomplete) | ||
| * ipv6.isValidAddress([0x2001, 0xdb8, 0, 0, 0, 0, 0, 1]); // true | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv6 address to validate, which can be in string, bigint, or hextets array format. | ||
| * @returns True if the input is a valid IPv6 address; otherwise, false. | ||
| */ | ||
| function isValidAddress(ip) { | ||
| if (ip === null || ip === undefined) { | ||
| return false; | ||
| } | ||
| if (typeof ip === 'bigint') { | ||
| return ip >= ipv6.MIN_SIZE && ip <= ipv6.MAX_SIZE; | ||
| } | ||
| if (Array.isArray(ip)) { | ||
| if (ip.length !== 8) { | ||
| return false; | ||
| } | ||
| for (const element of ip) { | ||
| if (typeof element !== 'number' | ||
| || !Number.isInteger(element) | ||
| || element < 0 | ||
| || element > 0xffff) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| if (typeof ip !== 'string') { | ||
| return false; | ||
| } | ||
| // Handle IPv4-mapped IPv6 addresses (::ffff:192.168.1.1) | ||
| const ipv4MappedMatch = ip.match(/^(::ffff:)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/i); | ||
| if (ipv4MappedMatch) { | ||
| const ipv4Part = ipv4MappedMatch[2]; | ||
| const octets = ipv4Part.split('.').map(Number); | ||
| if (octets.length !== 4) | ||
| return false; | ||
| for (const octet of octets) { | ||
| if (octet < 0 || octet > 255) | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| // Check for multiple :: which is invalid | ||
| const doubleColonCount = (ip.match(/::/g) || []).length; | ||
| if (doubleColonCount > 1) { | ||
| return false; | ||
| } | ||
| // Handle :: expansion | ||
| let expandedIp = ip; | ||
| if (ip.includes('::')) { | ||
| const parts = ip.split('::'); | ||
| const leftParts = parts[0] ? parts[0].split(':') : []; | ||
| const rightParts = parts[1] ? parts[1].split(':') : []; | ||
| const missingCount = 8 - leftParts.length - rightParts.length; | ||
| if (missingCount < 0) { | ||
| return false; | ||
| } | ||
| const middleParts = Array(missingCount).fill('0'); | ||
| expandedIp = [...leftParts, ...middleParts, ...rightParts].join(':'); | ||
| } | ||
| const hextets = expandedIp.split(':'); | ||
| if (hextets.length !== 8) { | ||
| return false; | ||
| } | ||
| for (const hextet of hextets) { | ||
| if (hextet === '' || hextet.length > 4) { | ||
| return false; | ||
| } | ||
| if (!/^[0-9a-fA-F]+$/.test(hextet)) { | ||
| return false; | ||
| } | ||
| const value = Number.parseInt(hextet, 16); | ||
| if (value < 0 || value > 0xffff) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| ipv6.isValidAddress = isValidAddress; | ||
| /** | ||
| * Validates whether the given input is a valid IPv6 CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.isValidCIDR("2001:db8::/32"); // true | ||
| * ipv6.isValidCIDR("2001:db8::/129"); // false (range out of bounds) | ||
| * ipv6.isValidCIDR({ address: "2001:db8::", range: 32 }); // true | ||
| * ipv6.isValidCIDR(["2001:db8::", 32]); // true | ||
| * ipv6.isValidCIDR("invalid/32"); // false | ||
| * ``` | ||
| * | ||
| * @param cidr - The IPv6 CIDR to validate, which can be in string, object, or tuple format. | ||
| * @returns True if the input is a valid IPv6 CIDR; otherwise, false. | ||
| */ | ||
| function isValidCIDR(cidr) { | ||
| if (cidr === null || cidr === undefined) { | ||
| return false; | ||
| } | ||
| let address; | ||
| let range; | ||
| if (typeof cidr === 'string') { | ||
| const parts = cidr.split('/'); | ||
| if (parts.length !== 2) { | ||
| return false; | ||
| } | ||
| address = parts[0]; | ||
| range = Number.parseInt(parts[1], 10); | ||
| } | ||
| else if (Array.isArray(cidr)) { | ||
| if (cidr.length !== 2) { | ||
| return false; | ||
| } | ||
| const [first, second] = cidr; | ||
| if (first === null || first === undefined) { | ||
| return false; | ||
| } | ||
| if (typeof second !== 'number') { | ||
| return false; | ||
| } | ||
| address = first; | ||
| range = second; | ||
| } | ||
| else if (typeof cidr === 'object') { | ||
| if (!('address' in cidr) || !('range' in cidr)) { | ||
| return false; | ||
| } | ||
| const { address: addr, range: r } = cidr; | ||
| if (addr === null || addr === undefined) { | ||
| return false; | ||
| } | ||
| if (typeof r !== 'number') { | ||
| return false; | ||
| } | ||
| address = addr; | ||
| range = r; | ||
| } | ||
| else { | ||
| return false; | ||
| } | ||
| if (address === undefined || !isValidAddress(address)) { | ||
| return false; | ||
| } | ||
| if (typeof range !== 'number' | ||
| || !Number.isInteger(range) | ||
| || range < ipv6.MIN_RANGE | ||
| || range > ipv6.MAX_RANGE) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| ipv6.isValidCIDR = isValidCIDR; | ||
| /** | ||
| * Parses the given IPv6 address into its hextets representation. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.parseHextets("2001:db8::1"); // [0x2001, 0xdb8, 0, 0, 0, 0, 0, 1] | ||
| * ipv6.parseHextets("::"); // [0, 0, 0, 0, 0, 0, 0, 0] | ||
| * ipv6.parseHextets(42540766411282592856903984951653826561n); // [0x2001, 0xdb8, 0, 0, 0, 0, 0, 1] | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv6 address to parse, which can be in string, bigint, or hextets array format. | ||
| * @returns {Ipv6AddressHextets} An array of eight numbers representing the hextets of the IPv6 address. | ||
| * @throws {InvalidIpv6AddressError} If the input is not a valid IPv6 address. | ||
| */ | ||
| function parseHextets(ip) { | ||
| if (!isValidAddress(ip)) { | ||
| throw new ipv6Errors.InvalidIpv6AddressError(ip); | ||
| } | ||
| if (typeof ip === 'bigint') { | ||
| const hextets = []; | ||
| let value = ip; | ||
| for (let i = 0; i < 8; i++) { | ||
| hextets.unshift(Number(value & 0xffffn)); | ||
| value = value >> 16n; | ||
| } | ||
| return hextets; | ||
| } | ||
| if (Array.isArray(ip)) { | ||
| return ip; | ||
| } | ||
| // Handle IPv4-mapped IPv6 addresses | ||
| const ipv4MappedMatch = ip.match(/^(::ffff:)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/i); | ||
| if (ipv4MappedMatch) { | ||
| const ipv4Part = ipv4MappedMatch[2]; | ||
| const octets = ipv4Part.split('.').map(Number); | ||
| return [ | ||
| 0, | ||
| 0, | ||
| 0, | ||
| 0, | ||
| 0, | ||
| 0xffff, | ||
| (octets[0] << 8) | octets[1], | ||
| (octets[2] << 8) | octets[3], | ||
| ]; | ||
| } | ||
| // Handle :: expansion | ||
| let expandedIp = ip; | ||
| if (ip.includes('::')) { | ||
| const parts = ip.split('::'); | ||
| const leftParts = parts[0] ? parts[0].split(':') : []; | ||
| const rightParts = parts[1] ? parts[1].split(':') : []; | ||
| const missingCount = 8 - leftParts.length - rightParts.length; | ||
| const middleParts = Array(missingCount).fill('0'); | ||
| expandedIp = [...leftParts, ...middleParts, ...rightParts].join(':'); | ||
| } | ||
| return expandedIp.split(':').map(h => Number.parseInt(h, 16)); | ||
| } | ||
| ipv6.parseHextets = parseHextets; | ||
| })(exports.ipv6 || (exports.ipv6 = {})); | ||
| exports.Ipv6Address = ipv6Address.Ipv6Address; | ||
| exports.Ipv6Cidr = ipv6Cidr.Ipv6Cidr; | ||
| exports.InvalidIpv6AddressError = ipv6Errors.InvalidIpv6AddressError; | ||
| exports.InvalidIpv6CidrError = ipv6Errors.InvalidIpv6CidrError; | ||
| exports.InvalidIpv6CidrRangeError = ipv6Errors.InvalidIpv6CidrRangeError; | ||
| //# sourceMapp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,CAAuB;IACrF;AAjDgB,IAAA,IAAA,CAAA,YAAY,eAiD3B;AACH,CAAC,EAnZgBH,YAAI,KAAJA,YAAI,GAAA,EAAA,CAAA,CAAA;;;;;;;;"} |
| export * from './ipv4'; | ||
| export * from './ipv6'; | ||
| //# sourceMappingURL=index.d.ts.map |
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,QAAQ,CAAA"} |
| export { ipv4 } from './ipv4.js'; | ||
| export { ipv6 } from './ipv6.js'; | ||
| export { Ipv4Address } from './ipv4-address.js'; | ||
| export { Ipv4Cidr } from './ipv4-cidr.js'; | ||
| export { InvalidIpv4AddressError, InvalidIpv4CidrError, InvalidIpv4CidrRangeError } from './ipv4-errors.js'; | ||
| export { Ipv6Address } from './ipv6-address.js'; | ||
| export { Ipv6Cidr } from './ipv6-cidr.js'; | ||
| export { InvalidIpv6AddressError, InvalidIpv6CidrError, InvalidIpv6CidrRangeError } from './ipv6-errors.js'; | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"} |
| import type { Ipv4AddressLiteral, Ipv4AddressOctets, Ipv4AddressString } from './ipv4-types'; | ||
| /** | ||
| * Represents an IPv4 address with utility methods for manipulation and comparison. | ||
| * | ||
| * While you can instantiate this class directly, it is recommended to use the | ||
| * {@link ipv4.address} shorthand method from the `ipv4` namespace instead. | ||
| * | ||
| * @example Creating addresses (prefer the shorthand) | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * // Recommended: use the ipv4 namespace shorthand | ||
| * const addr1 = ipv4.address("192.168.1.1"); | ||
| * const addr2 = ipv4.address(3232235777); | ||
| * const addr3 = ipv4.address([192, 168, 1, 1]); | ||
| * ``` | ||
| * | ||
| * @example Converting between formats | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.toString(); // "192.168.1.1" | ||
| * addr.toNumber(); // 3232235777 | ||
| * addr.octets(); // [192, 168, 1, 1] | ||
| * addr.toBinaryString(); // "11000000.10101000.00000001.00000001" | ||
| * ``` | ||
| * | ||
| * @example Comparing addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.equals("192.168.1.1"); // true | ||
| * addr.isGreaterThan("192.168.1.0"); // true | ||
| * addr.isLessThan("192.168.1.2"); // true | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.nextAddress()?.toString(); // "192.168.1.2" | ||
| * addr.previousAddress()?.toString(); // "192.168.1.0" | ||
| * ``` | ||
| * | ||
| * @example Checking address types | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("127.0.0.1").isLoopbackAddress(); // true | ||
| * ipv4.address("10.0.0.1").isPrivateAddress(); // true | ||
| * ipv4.address("169.254.1.1").isLocalLinkAddress(); // true | ||
| * ipv4.address("224.0.0.1").isMulticastAddress(); // true | ||
| * ``` | ||
| */ | ||
| export declare class Ipv4Address { | ||
| #private; | ||
| constructor(ip: Ipv4AddressLiteral); | ||
| /** | ||
| * Gets the octets of the IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.octets(); // [192, 168, 1, 1] | ||
| * ``` | ||
| * | ||
| * @returns An array of four numbers representing the octets of the IPv4 address. | ||
| */ | ||
| octets(): Ipv4AddressOctets; | ||
| /** | ||
| * Returns the string representation of the IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address([10, 0, 0, 1]); | ||
| * addr.toString(); // "10.0.0.1" | ||
| * ``` | ||
| * | ||
| * @returns The IPv4 address as a string in dotted-decimal notation (example: "192.187.0.1"). | ||
| */ | ||
| toString(): Ipv4AddressString; | ||
| /** | ||
| * Returns the binary string representation of the IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.toBinaryString(); // "11000000.10101000.00000001.00000001" | ||
| * ``` | ||
| * | ||
| * @returns The IPv4 address as a binary string in dotted-decimal notation (example: "11000000.10111011.00000000.00000001"). | ||
| */ | ||
| toBinaryString(): string; | ||
| /** | ||
| * Converts the IPv4 address to its numeric representation. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.toNumber(); // 3232235777 | ||
| * ``` | ||
| * | ||
| * @returns The IPv4 address as a number. | ||
| */ | ||
| toNumber(): number; | ||
| /** | ||
| * Checks if there is a next sequential IPv4 address. | ||
| * This would only return false if the current address is the maximum possible value (255.255.255.255). | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("192.168.1.1").hasNextAddress(); // true | ||
| * ipv4.address("255.255.255.255").hasNextAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a next IPv4 address. | ||
| */ | ||
| hasNextAddress(): boolean; | ||
| /** | ||
| * Gets the next sequential IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.nextAddress()?.toString(); // "192.168.1.2" | ||
| * | ||
| * const maxAddr = ipv4.address("255.255.255.255"); | ||
| * maxAddr.nextAddress(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The next IPv4 address, or undefined if the current address is the maximum possible value. | ||
| */ | ||
| nextAddress(): Ipv4Address | undefined; | ||
| /** | ||
| * Checks if there is a previous sequential IPv4 address. | ||
| * This would only return false if the current address is the minimum possible value (0.0.0.0). | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("192.168.1.1").hasPreviousAddress(); // true | ||
| * ipv4.address("0.0.0.0").hasPreviousAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a previous IPv4 address. | ||
| */ | ||
| hasPreviousAddress(): boolean; | ||
| /** | ||
| * Gets the previous sequential IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.previousAddress()?.toString(); // "192.168.1.0" | ||
| * | ||
| * const minAddr = ipv4.address("0.0.0.0"); | ||
| * minAddr.previousAddress(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The previous IPv4 address, or undefined if the current address is the minimum possible value. | ||
| */ | ||
| previousAddress(): Ipv4Address | undefined; | ||
| /** | ||
| * Compares two IPv4 addresses for equality. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.equals("192.168.1.1"); // true | ||
| * addr.equals([192, 168, 1, 1]); // true | ||
| * addr.equals(ipv4.address("10.0.0.1")); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv4 address to compare with, which can be an Ipv4Address instance or literal value. | ||
| * @returns true if both IPv4 addresses are equal | ||
| */ | ||
| equals(otherAddress: Ipv4Address | Ipv4AddressLiteral): boolean; | ||
| /** | ||
| * Compares if this IPv4 address is greater than another IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.isGreaterThan("192.168.1.0"); // true | ||
| * addr.isGreaterThan("192.168.1.1"); // false | ||
| * addr.isGreaterThan("192.168.1.2"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv4 address to compare with, which can be an Ipv4Address instance or literal value. | ||
| * @returns true if this IPv4 address is greater than the other IPv4 address | ||
| */ | ||
| isGreaterThan(otherAddress: Ipv4Address | Ipv4AddressLiteral): boolean; | ||
| /** | ||
| * Compares if this IPv4 address is greater than or equal to another IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.isGreaterThanOrEqual("192.168.1.0"); // true | ||
| * addr.isGreaterThanOrEqual("192.168.1.1"); // true | ||
| * addr.isGreaterThanOrEqual("192.168.1.2"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv4 address to compare with, which can be an Ipv4Address instance or literal value. | ||
| * @returns true if this IPv4 address is greater than or equal to the other IPv4 address | ||
| */ | ||
| isGreaterThanOrEqual(otherAddress: Ipv4Address | Ipv4AddressLiteral): boolean; | ||
| /** | ||
| * Compares if this IPv4 address is less than another IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.isLessThan("192.168.1.2"); // true | ||
| * addr.isLessThan("192.168.1.1"); // false | ||
| * addr.isLessThan("192.168.1.0"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv4 address to compare with, which can be an Ipv4Address instance or literal value. | ||
| * @returns true if this IPv4 address is less than the other IPv4 address | ||
| */ | ||
| isLessThan(otherAddress: Ipv4Address | Ipv4AddressLiteral): boolean; | ||
| /** | ||
| * Compares if this IPv4 address is less than or equal to another IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.isLessThanOrEqual("192.168.1.2"); // true | ||
| * addr.isLessThanOrEqual("192.168.1.1"); // true | ||
| * addr.isLessThanOrEqual("192.168.1.0"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv4 address to compare with, which can be an Ipv4Address instance or literal value. | ||
| * @returns true if this IPv4 address is less than or equal to the other IPv4 address | ||
| */ | ||
| isLessThanOrEqual(otherAddress: Ipv4Address | Ipv4AddressLiteral): boolean; | ||
| /** | ||
| * Checks if the IPv4 address is a loopback address (in the CIDR of 127.0.0.0/8) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("127.0.0.1").isLoopbackAddress(); // true | ||
| * ipv4.address("127.255.0.1").isLoopbackAddress(); // true | ||
| * ipv4.address("192.168.1.1").isLoopbackAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv4 address is a loopback address (example: 127.0.0.1 is true) | ||
| */ | ||
| isLoopbackAddress(): boolean; | ||
| /** | ||
| * Checks if the IPv4 address is a private address. | ||
| * | ||
| * This is based on RFC 1918, which defines the following private address ranges: | ||
| * - 10.0.0.0/8 | ||
| * - 172.16.0.0/12 | ||
| * - 192.168.0.0/16 | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("10.0.0.1").isPrivateAddress(); // true | ||
| * ipv4.address("172.16.0.1").isPrivateAddress(); // true | ||
| * ipv4.address("192.168.1.1").isPrivateAddress(); // true | ||
| * ipv4.address("8.8.8.8").isPrivateAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv4 address is in any of the private address ranges. | ||
| */ | ||
| isPrivateAddress(): boolean; | ||
| /** | ||
| * Checks if the IPv4 address is a local-link address (in the CIDR of 169.254.0.0/16). | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("169.254.1.1").isLocalLinkAddress(); // true | ||
| * ipv4.address("169.254.255.255").isLocalLinkAddress(); // true | ||
| * ipv4.address("192.168.1.1").isLocalLinkAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv4 address is a local-link address. | ||
| */ | ||
| isLocalLinkAddress(): boolean; | ||
| /** | ||
| * Checks if the IPv4 address is a multicast address (between 224.0.0.0 to 239.255.255.255). | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("224.0.0.1").isMulticastAddress(); // true | ||
| * ipv4.address("239.255.255.255").isMulticastAddress(); // true | ||
| * ipv4.address("192.168.1.1").isMulticastAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv4 address is a multicast address. | ||
| */ | ||
| isMulticastAddress(): boolean; | ||
| } | ||
| //# sourceMappingURL=ipv4-address.d.ts.map |
| {"version":3,"file":"ipv4-address.d.ts","sourceRoot":"","sources":["../../src/ipv4-address.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAI5F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,qBAAa,WAAW;;gBAGV,EAAE,EAAE,kBAAkB;IAOlC;;;;;;;;;;;;OAYG;IACI,MAAM,IAAI,iBAAiB;IAIlC;;;;;;;;;;;;OAYG;IACI,QAAQ,IAAI,iBAAiB;IAIpC;;;;;;;;;;;;OAYG;IACI,cAAc,IAAI,MAAM;IAI/B;;;;;;;;;;;;OAYG;IACI,QAAQ,IAAI,MAAM;IAMzB;;;;;;;;;;;;;OAaG;IACI,cAAc,IAAI,OAAO;IAIhC;;;;;;;;;;;;;;;OAeG;IACI,WAAW,IAAI,WAAW,GAAG,SAAS;IAQ7C;;;;;;;;;;;;;OAaG;IACI,kBAAkB,IAAI,OAAO;IAIpC;;;;;;;;;;;;;;;OAeG;IACI,eAAe,IAAI,WAAW,GAAG,SAAS;IAQjD;;;;;;;;;;;;;;;OAeG;IACI,MAAM,CAAC,YAAY,EAAE,WAAW,GAAG,kBAAkB,GAAG,OAAO;IAOtE;;;;;;;;;;;;;;;OAeG;IACI,aAAa,CAAC,YAAY,EAAE,WAAW,GAAG,kBAAkB,GAAG,OAAO;IAO7E;;;;;;;;;;;;;;;OAeG;IACI,oBAAoB,CAAC,YAAY,EAAE,WAAW,GAAG,kBAAkB,GAAG,OAAO;IAOpF;;;;;;;;;;;;;;;OAeG;IACI,UAAU,CAAC,YAAY,EAAE,WAAW,GAAG,kBAAkB,GAAG,OAAO;IAO1E;;;;;;;;;;;;;;;OAeG;IACI,iBAAiB,CAAC,YAAY,EAAE,WAAW,GAAG,kBAAkB,GAAG,OAAO;IAOjF;;;;;;;;;;;;;OAaG;IACI,iBAAiB,IAAI,OAAO;IAInC;;;;;;;;;;;;;;;;;;;OAmBG;IACI,gBAAgB,IAAI,OAAO;IAMlC;;;;;;;;;;;;;OAaG;IACI,kBAAkB,IAAI,OAAO;IAMpC;;;;;;;;;;;;;OAaG;IACI,kBAAkB,IAAI,OAAO;CAIrC"} |
| import { __classPrivateFieldSet, __classPrivateFieldGet } from '/Users/brandon/cidr-block/node_modules/tslib/tslib.es6.js'; | ||
| import { ipv4 } from './ipv4.js'; | ||
| import { InvalidIpv4AddressError } from './ipv4-errors.js'; | ||
| var _Ipv4Address_octets; | ||
| /** | ||
| * Represents an IPv4 address with utility methods for manipulation and comparison. | ||
| * | ||
| * While you can instantiate this class directly, it is recommended to use the | ||
| * {@link ipv4.address} shorthand method from the `ipv4` namespace instead. | ||
| * | ||
| * @example Creating addresses (prefer the shorthand) | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * // Recommended: use the ipv4 namespace shorthand | ||
| * const addr1 = ipv4.address("192.168.1.1"); | ||
| * const addr2 = ipv4.address(3232235777); | ||
| * const addr3 = ipv4.address([192, 168, 1, 1]); | ||
| * ``` | ||
| * | ||
| * @example Converting between formats | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.toString(); // "192.168.1.1" | ||
| * addr.toNumber(); // 3232235777 | ||
| * addr.octets(); // [192, 168, 1, 1] | ||
| * addr.toBinaryString(); // "11000000.10101000.00000001.00000001" | ||
| * ``` | ||
| * | ||
| * @example Comparing addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.equals("192.168.1.1"); // true | ||
| * addr.isGreaterThan("192.168.1.0"); // true | ||
| * addr.isLessThan("192.168.1.2"); // true | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.nextAddress()?.toString(); // "192.168.1.2" | ||
| * addr.previousAddress()?.toString(); // "192.168.1.0" | ||
| * ``` | ||
| * | ||
| * @example Checking address types | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("127.0.0.1").isLoopbackAddress(); // true | ||
| * ipv4.address("10.0.0.1").isPrivateAddress(); // true | ||
| * ipv4.address("169.254.1.1").isLocalLinkAddress(); // true | ||
| * ipv4.address("224.0.0.1").isMulticastAddress(); // true | ||
| * ``` | ||
| */ | ||
| class Ipv4Address { | ||
| constructor(ip) { | ||
| _Ipv4Address_octets.set(this, void 0); | ||
| if (!ipv4.isValidAddress(ip)) { | ||
| throw new InvalidIpv4AddressError(ip); | ||
| } | ||
| __classPrivateFieldSet(this, _Ipv4Address_octets, ipv4.parseOctets(ip), "f"); | ||
| } | ||
| /** | ||
| * Gets the octets of the IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.octets(); // [192, 168, 1, 1] | ||
| * ``` | ||
| * | ||
| * @returns An array of four numbers representing the octets of the IPv4 address. | ||
| */ | ||
| octets() { | ||
| return __classPrivateFieldGet(this, _Ipv4Address_octets, "f"); | ||
| } | ||
| /** | ||
| * Returns the string representation of the IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address([10, 0, 0, 1]); | ||
| * addr.toString(); // "10.0.0.1" | ||
| * ``` | ||
| * | ||
| * @returns The IPv4 address as a string in dotted-decimal notation (example: "192.187.0.1"). | ||
| */ | ||
| toString() { | ||
| return __classPrivateFieldGet(this, _Ipv4Address_octets, "f").join('.'); | ||
| } | ||
| /** | ||
| * Returns the binary string representation of the IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.toBinaryString(); // "11000000.10101000.00000001.00000001" | ||
| * ``` | ||
| * | ||
| * @returns The IPv4 address as a binary string in dotted-decimal notation (example: "11000000.10111011.00000000.00000001"). | ||
| */ | ||
| toBinaryString() { | ||
| return __classPrivateFieldGet(this, _Ipv4Address_octets, "f").map(octet => octet.toString(2).padStart(8, '0')).join('.'); | ||
| } | ||
| /** | ||
| * Converts the IPv4 address to its numeric representation. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.toNumber(); // 3232235777 | ||
| * ``` | ||
| * | ||
| * @returns The IPv4 address as a number. | ||
| */ | ||
| toNumber() { | ||
| return ((__classPrivateFieldGet(this, _Ipv4Address_octets, "f")[0] << 24) | (__classPrivateFieldGet(this, _Ipv4Address_octets, "f")[1] << 16) | (__classPrivateFieldGet(this, _Ipv4Address_octets, "f")[2] << 8) | __classPrivateFieldGet(this, _Ipv4Address_octets, "f")[3]); | ||
| } | ||
| /** | ||
| * Checks if there is a next sequential IPv4 address. | ||
| * This would only return false if the current address is the maximum possible value (255.255.255.255). | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("192.168.1.1").hasNextAddress(); // true | ||
| * ipv4.address("255.255.255.255").hasNextAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a next IPv4 address. | ||
| */ | ||
| hasNextAddress() { | ||
| return this.toNumber() < ipv4.MAX_SIZE; | ||
| } | ||
| /** | ||
| * Gets the next sequential IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.nextAddress()?.toString(); // "192.168.1.2" | ||
| * | ||
| * const maxAddr = ipv4.address("255.255.255.255"); | ||
| * maxAddr.nextAddress(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The next IPv4 address, or undefined if the current address is the maximum possible value. | ||
| */ | ||
| nextAddress() { | ||
| const nextAddress = this.toNumber() + 1; | ||
| if (nextAddress > ipv4.MAX_SIZE) { | ||
| return undefined; | ||
| } | ||
| return new Ipv4Address(nextAddress); | ||
| } | ||
| /** | ||
| * Checks if there is a previous sequential IPv4 address. | ||
| * This would only return false if the current address is the minimum possible value (0.0.0.0). | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("192.168.1.1").hasPreviousAddress(); // true | ||
| * ipv4.address("0.0.0.0").hasPreviousAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a previous IPv4 address. | ||
| */ | ||
| hasPreviousAddress() { | ||
| return this.toNumber() > ipv4.MIN_SIZE; | ||
| } | ||
| /** | ||
| * Gets the previous sequential IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.previousAddress()?.toString(); // "192.168.1.0" | ||
| * | ||
| * const minAddr = ipv4.address("0.0.0.0"); | ||
| * minAddr.previousAddress(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The previous IPv4 address, or undefined if the current address is the minimum possible value. | ||
| */ | ||
| previousAddress() { | ||
| const prevAddress = this.toNumber() - 1; | ||
| if (prevAddress < ipv4.MIN_SIZE) { | ||
| return undefined; | ||
| } | ||
| return new Ipv4Address(prevAddress); | ||
| } | ||
| /** | ||
| * Compares two IPv4 addresses for equality. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.equals("192.168.1.1"); // true | ||
| * addr.equals([192, 168, 1, 1]); // true | ||
| * addr.equals(ipv4.address("10.0.0.1")); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv4 address to compare with, which can be an Ipv4Address instance or literal value. | ||
| * @returns true if both IPv4 addresses are equal | ||
| */ | ||
| equals(otherAddress) { | ||
| if (otherAddress instanceof Ipv4Address) { | ||
| return this.toNumber() === otherAddress.toNumber(); | ||
| } | ||
| return this.toNumber() === new Ipv4Address(otherAddress).toNumber(); | ||
| } | ||
| /** | ||
| * Compares if this IPv4 address is greater than another IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.isGreaterThan("192.168.1.0"); // true | ||
| * addr.isGreaterThan("192.168.1.1"); // false | ||
| * addr.isGreaterThan("192.168.1.2"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv4 address to compare with, which can be an Ipv4Address instance or literal value. | ||
| * @returns true if this IPv4 address is greater than the other IPv4 address | ||
| */ | ||
| isGreaterThan(otherAddress) { | ||
| if (otherAddress instanceof Ipv4Address) { | ||
| return this.toNumber() > otherAddress.toNumber(); | ||
| } | ||
| return this.toNumber() > new Ipv4Address(otherAddress).toNumber(); | ||
| } | ||
| /** | ||
| * Compares if this IPv4 address is greater than or equal to another IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.isGreaterThanOrEqual("192.168.1.0"); // true | ||
| * addr.isGreaterThanOrEqual("192.168.1.1"); // true | ||
| * addr.isGreaterThanOrEqual("192.168.1.2"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv4 address to compare with, which can be an Ipv4Address instance or literal value. | ||
| * @returns true if this IPv4 address is greater than or equal to the other IPv4 address | ||
| */ | ||
| isGreaterThanOrEqual(otherAddress) { | ||
| if (otherAddress instanceof Ipv4Address) { | ||
| return this.toNumber() >= otherAddress.toNumber(); | ||
| } | ||
| return this.toNumber() >= new Ipv4Address(otherAddress).toNumber(); | ||
| } | ||
| /** | ||
| * Compares if this IPv4 address is less than another IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.isLessThan("192.168.1.2"); // true | ||
| * addr.isLessThan("192.168.1.1"); // false | ||
| * addr.isLessThan("192.168.1.0"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv4 address to compare with, which can be an Ipv4Address instance or literal value. | ||
| * @returns true if this IPv4 address is less than the other IPv4 address | ||
| */ | ||
| isLessThan(otherAddress) { | ||
| if (otherAddress instanceof Ipv4Address) { | ||
| return this.toNumber() < otherAddress.toNumber(); | ||
| } | ||
| return this.toNumber() < new Ipv4Address(otherAddress).toNumber(); | ||
| } | ||
| /** | ||
| * Compares if this IPv4 address is less than or equal to another IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.isLessThanOrEqual("192.168.1.2"); // true | ||
| * addr.isLessThanOrEqual("192.168.1.1"); // true | ||
| * addr.isLessThanOrEqual("192.168.1.0"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv4 address to compare with, which can be an Ipv4Address instance or literal value. | ||
| * @returns true if this IPv4 address is less than or equal to the other IPv4 address | ||
| */ | ||
| isLessThanOrEqual(otherAddress) { | ||
| if (otherAddress instanceof Ipv4Address) { | ||
| return this.toNumber() <= otherAddress.toNumber(); | ||
| } | ||
| return this.toNumber() <= new Ipv4Address(otherAddress).toNumber(); | ||
| } | ||
| /** | ||
| * Checks if the IPv4 address is a loopback address (in the CIDR of 127.0.0.0/8) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("127.0.0.1").isLoopbackAddress(); // true | ||
| * ipv4.address("127.255.0.1").isLoopbackAddress(); // true | ||
| * ipv4.address("192.168.1.1").isLoopbackAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv4 address is a loopback address (example: 127.0.0.1 is true) | ||
| */ | ||
| isLoopbackAddress() { | ||
| return __classPrivateFieldGet(this, _Ipv4Address_octets, "f")[0] === 127; | ||
| } | ||
| /** | ||
| * Checks if the IPv4 address is a private address. | ||
| * | ||
| * This is based on RFC 1918, which defines the following private address ranges: | ||
| * - 10.0.0.0/8 | ||
| * - 172.16.0.0/12 | ||
| * - 192.168.0.0/16 | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("10.0.0.1").isPrivateAddress(); // true | ||
| * ipv4.address("172.16.0.1").isPrivateAddress(); // true | ||
| * ipv4.address("192.168.1.1").isPrivateAddress(); // true | ||
| * ipv4.address("8.8.8.8").isPrivateAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv4 address is in any of the private address ranges. | ||
| */ | ||
| isPrivateAddress() { | ||
| const [o1, o2] = __classPrivateFieldGet(this, _Ipv4Address_octets, "f"); | ||
| return o1 === 10 || (o1 === 172 && o2 >= 16 && o2 <= 31) || (o1 === 192 && o2 === 168); | ||
| } | ||
| /** | ||
| * Checks if the IPv4 address is a local-link address (in the CIDR of 169.254.0.0/16). | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("169.254.1.1").isLocalLinkAddress(); // true | ||
| * ipv4.address("169.254.255.255").isLocalLinkAddress(); // true | ||
| * ipv4.address("192.168.1.1").isLocalLinkAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv4 address is a local-link address. | ||
| */ | ||
| isLocalLinkAddress() { | ||
| const [o1, o2] = __classPrivateFieldGet(this, _Ipv4Address_octets, "f"); | ||
| return o1 === 169 && o2 === 254; | ||
| } | ||
| /** | ||
| * Checks if the IPv4 address is a multicast address (between 224.0.0.0 to 239.255.255.255). | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("224.0.0.1").isMulticastAddress(); // true | ||
| * ipv4.address("239.255.255.255").isMulticastAddress(); // true | ||
| * ipv4.address("192.168.1.1").isMulticastAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv4 address is a multicast address. | ||
| */ | ||
| isMulticastAddress() { | ||
| const firstOctet = __classPrivateFieldGet(this, _Ipv4Address_octets, "f")[0]; | ||
| return firstOctet >= 224 && firstOctet <= 239; | ||
| } | ||
| } | ||
| _Ipv4Address_octets = new WeakMap(); | ||
| export { Ipv4Address }; | ||
| //# sourceMappingURL=ipv4-address.js.map |
| {"version":3,"file":"ipv4-address.js","sources":["../../../src/ipv4-address.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDG;MACU,WAAW,CAAA;AAGtB,IAAA,WAAA,CAAY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AK,EAAE,KAAK,GAAG,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG,CAAC;IACxF;AAEA;;;;;;;;;;;;;AAaG;IACI,kBAAkB,GAAA;QACvB,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,sBAAA,CAAA,IAAI,EAAA,mBAAA,EAAA,GAAA,CAAQ;AAE7B,QAAA,OAAO,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG;IACjC;AAEA;;;;;;;;;;;;;AAaG;IACI,kBAAkB,GAAA;QACvB,MAAM,UAAU,GAAG,sBAAA,CAAA,IAAI,2BAAQ,CAAC,CAAC,CAAC;AAClC,QAAA,OAAO,UAAU,IAAI,GAAG,IAAI,UAAU,IAAI,GAAG;IAC/C;AACD;;;;;"} |
| import { Ipv4Address } from './ipv4-address'; | ||
| import type { Ipv4CidrLiteral, Ipv4CidrString } from './ipv4-types'; | ||
| /** | ||
| * Represents an IPv4 CIDR block with utility methods for subnet operations. | ||
| * | ||
| * While you can instantiate this class directly, it is recommended to use the | ||
| * {@link ipv4.cidr} shorthand method from the `ipv4` namespace instead. | ||
| * | ||
| * @example Creating CIDR blocks (prefer the shorthand) | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * // Recommended: use the ipv4 namespace shorthand | ||
| * const cidr1 = ipv4.cidr("192.168.0.0/24"); | ||
| * const cidr2 = ipv4.cidr({ address: "10.0.0.0", range: 8 }); | ||
| * const cidr3 = ipv4.cidr([[172, 16, 0, 0], 12]); | ||
| * ``` | ||
| * | ||
| * @example Getting CIDR properties | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.baseAddress().toString(); // "192.168.0.0" | ||
| * cidr.range(); // 24 | ||
| * cidr.netmask().toString(); // "255.255.255.0" | ||
| * cidr.addressCount(); // 256 | ||
| * ``` | ||
| * | ||
| * @example Working with usable addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.getFirstUsableAddress()?.toString(); // "192.168.0.1" | ||
| * cidr.getLastUsableAddress()?.toString(); // "192.168.0.254" | ||
| * ``` | ||
| * | ||
| * @example Iterating over addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.1.0/30"); | ||
| * for (const addr of cidr.addresses()) { | ||
| * console.log(addr.toString()); | ||
| * } | ||
| * // "192.168.1.0", "192.168.1.1", "192.168.1.2", "192.168.1.3" | ||
| * ``` | ||
| * | ||
| * @example Checking containment and overlap | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.includes(ipv4.address("192.168.0.100")); // true | ||
| * cidr.includes(ipv4.address("192.168.1.1")); // false | ||
| * cidr.overlaps("192.168.0.0/25"); // true | ||
| * cidr.overlaps("10.0.0.0/8"); // false | ||
| * ``` | ||
| * | ||
| * @example Splitting into subranges | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * | ||
| * // Split into equal /26 subnets | ||
| * cidr.subnet(26).map(s => s.toString()); | ||
| * // ["192.168.0.0/26", "192.168.0.64/26", "192.168.0.128/26", "192.168.0.192/26"] | ||
| * | ||
| * // Split by specific ranges | ||
| * cidr.subnetBy([25, 26, 27, 27]).map(s => s.toString()); | ||
| * // ["192.168.0.0/25", "192.168.0.128/26", "192.168.0.192/27", "192.168.0.224/27"] | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential CIDRs | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.nextCIDR()?.toString(); // "192.168.1.0/24" | ||
| * cidr.previousCIDR()?.toString(); // "192.167.255.0/24" | ||
| * ``` | ||
| */ | ||
| export declare class Ipv4Cidr { | ||
| #private; | ||
| constructor(address: Ipv4CidrLiteral); | ||
| /** | ||
| * Gets the base IPv4 address of the CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.baseAddress().toString(); // "192.168.0.0" | ||
| * ``` | ||
| * | ||
| * @returns The base IPv4 address. | ||
| */ | ||
| baseAddress(): Ipv4Address; | ||
| /** | ||
| * Gets the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.range(); // 24 | ||
| * ``` | ||
| * | ||
| * @returns The CIDR range as a number. | ||
| */ | ||
| range(): number; | ||
| /** | ||
| * Calculates the netmask for the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.cidr("192.168.0.0/24").netmask().toString(); // "255.255.255.0" | ||
| * ipv4.cidr("10.0.0.0/8").netmask().toString(); // "255.0.0.0" | ||
| * ipv4.cidr("172.16.0.0/16").netmask().toString(); // "255.255.0.0" | ||
| * ``` | ||
| * | ||
| * @returns The netmask as an Ipv4Address. | ||
| */ | ||
| netmask(): Ipv4Address; | ||
| /** | ||
| * Returns the string representation of the IPv4 CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr({ address: "10.0.0.0", range: 8 }); | ||
| * cidr.toString(); // "10.0.0.0/8" | ||
| * ``` | ||
| * | ||
| * @returns The IPv4 CIDR as a string (example: "192.0.0.0/24"). | ||
| */ | ||
| toString(): Ipv4CidrString; | ||
| /** | ||
| * Gets the address and range parts of the IPv4 CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const [address, range] = ipv4.cidr("192.168.0.0/24").rangeParts(); | ||
| * address.toString(); // "192.168.0.0" | ||
| * range; // 24 | ||
| * ``` | ||
| * | ||
| * @returns A tuple containing the IPv4 address and the CIDR range. | ||
| */ | ||
| rangeParts(): [Ipv4Address, number]; | ||
| /** | ||
| * Calculates the total number of addresses in the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.cidr("192.168.0.0/24").addressCount(); // 256 | ||
| * ipv4.cidr("10.0.0.0/8").addressCount(); // 16777216 | ||
| * ipv4.cidr("192.168.1.0/32").addressCount(); // 1 | ||
| * ``` | ||
| * | ||
| * @returns The total number of addresses in the CIDR range. | ||
| */ | ||
| addressCount(): number; | ||
| /** | ||
| * Generates all IPv4 addresses within the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.1.0/30"); | ||
| * for (const addr of cidr.addresses()) { | ||
| * console.log(addr.toString()); | ||
| * } | ||
| * // Output: "192.168.1.0", "192.168.1.1", "192.168.1.2", "192.168.1.3" | ||
| * ``` | ||
| * | ||
| * @returns A generator that yields each IPv4 address in the CIDR range. | ||
| */ | ||
| addresses(): Generator<Ipv4Address>; | ||
| /** | ||
| * Checks if this CIDR is equal to another CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.equals("192.168.0.0/24"); // true | ||
| * cidr.equals({ address: "192.168.0.0", range: 24 }); // true | ||
| * cidr.equals("10.0.0.0/8"); // false | ||
| * ``` | ||
| * | ||
| * @param other - The other IPv4 CIDR to compare with. | ||
| * @returns True if both CIDRs have the same base address and range; otherwise, false. | ||
| */ | ||
| equals(other: Ipv4Cidr | Ipv4CidrLiteral): boolean; | ||
| /** | ||
| * Checks if there is a next sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.cidr("192.168.0.0/24").hasNextCIDR(); // true | ||
| * ipv4.cidr("255.255.255.0/24").hasNextCIDR(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a next CIDR. | ||
| */ | ||
| hasNextCIDR(): boolean; | ||
| /** | ||
| * Gets the next sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.nextCIDR()?.toString(); // "192.168.1.0/24" | ||
| * | ||
| * const lastCidr = ipv4.cidr("255.255.255.0/24"); | ||
| * lastCidr.nextCIDR(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The next CIDR, or undefined if there is no next CIDR. | ||
| */ | ||
| nextCIDR(): Ipv4Cidr | undefined; | ||
| /** | ||
| * Checks if there is a previous sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.cidr("192.168.1.0/24").hasPreviousCIDR(); // true | ||
| * ipv4.cidr("0.0.0.0/24").hasPreviousCIDR(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a previous CIDR. | ||
| */ | ||
| hasPreviousCIDR(): boolean; | ||
| /** | ||
| * Gets the previous sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.1.0/24"); | ||
| * cidr.previousCIDR()?.toString(); // "192.168.0.0/24" | ||
| * | ||
| * const firstCidr = ipv4.cidr("0.0.0.0/24"); | ||
| * firstCidr.previousCIDR(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The previous CIDR, or undefined if there is no previous CIDR. | ||
| */ | ||
| previousCIDR(): Ipv4Cidr | undefined; | ||
| /** | ||
| * Gets the first usable address in the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.getFirstUsableAddress()?.toString(); // "192.168.0.1" | ||
| * | ||
| * const hostCidr = ipv4.cidr("192.168.1.1/32"); | ||
| * hostCidr.getFirstUsableAddress(); // undefined (no usable addresses in /32) | ||
| * ``` | ||
| * | ||
| * @returns The first usable IPv4 address, or undefined if the range is /32. | ||
| */ | ||
| getFirstUsableAddress(): Ipv4Address | undefined; | ||
| /** | ||
| * Gets the last usable address in the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.getLastUsableAddress()?.toString(); // "192.168.0.254" | ||
| * | ||
| * const hostCidr = ipv4.cidr("192.168.1.1/32"); | ||
| * hostCidr.getLastUsableAddress(); // undefined (no usable addresses in /32) | ||
| * ``` | ||
| * | ||
| * @returns The last usable IPv4 address, or undefined if the range is /32. | ||
| */ | ||
| getLastUsableAddress(): Ipv4Address | undefined; | ||
| /** | ||
| * Checks if the given IPv4 address is within the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.includes(ipv4.address("192.168.0.100")); // true | ||
| * cidr.includes(ipv4.address("192.168.1.1")); // false | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv4 address to check. | ||
| * @returns True if the address is within the CIDR range; otherwise, false. | ||
| */ | ||
| includes(ip: Ipv4Address): boolean; | ||
| /** | ||
| * Checks if this CIDR overlaps with another CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.overlaps("192.168.0.0/25"); // true (subset) | ||
| * cidr.overlaps("192.168.0.128/25"); // true (partial overlap) | ||
| * cidr.overlaps("10.0.0.0/8"); // false (no overlap) | ||
| * ``` | ||
| * | ||
| * @param other - The other IPv4 CIDR to check for overlap. | ||
| * @returns True if the CIDRs overlap; otherwise, false. | ||
| */ | ||
| overlaps(other: Ipv4Cidr | Ipv4CidrLiteral): boolean; | ||
| /** | ||
| * Splits the CIDR into smaller subranges of the specified new range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * const subnets = cidr.subnet(26); | ||
| * subnets.map(s => s.toString()); | ||
| * // ["192.168.0.0/26", "192.168.0.64/26", "192.168.0.128/26", "192.168.0.192/26"] | ||
| * ``` | ||
| * | ||
| * @param newRange - The new CIDR range for the subnets. | ||
| * @returns An array of Ipv4Cidr instances representing the subnets. | ||
| * @throws InvalidIpv4CidrRangeError if the new range is less than the current range or greater than the maximum range. | ||
| */ | ||
| subnet(newRange: number): Ipv4Cidr[]; | ||
| /** | ||
| * Splits the CIDR into sequential subranges with the specified CIDR ranges. | ||
| * Each range in the input array creates a subrange starting where the previous one ended. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("10.0.0.0/16"); | ||
| * const subnets = cidr.subnetBy([24, 20, 24]); | ||
| * subnets.map(s => s.toString()); | ||
| * // ["10.0.0.0/24", "10.0.1.0/20", "10.0.17.0/24"] | ||
| * ``` | ||
| * | ||
| * @param ranges - An array of CIDR range values (e.g., [24, 20, 24]). | ||
| * @returns An array of Ipv4Cidr instances representing the subnets. | ||
| * @throws InvalidIpv4CidrRangeError if any range is less than the current range or greater than 32. | ||
| */ | ||
| subnetBy(ranges: number[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G;IACI,oBAAoB,IAAI,WAAW,GAAG,SAAS;IAQtD;;;;;;;;;;;;;;OAcG;IACI,QAAQ,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO;IAOzC;;;;;;;;;;;;;;;OAeG;IACI,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,eAAe,GAAG,OAAO;IAS3D;;;;;;;;;;;;;;;;OAgBG;IACI,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,EAAE;IAoB3C;;;;;;;;;;;;;;;;;OAiBG;IACI,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE;CA0B9C"} |
| import { __classPrivateFieldSet, __classPrivateFieldGet } from '/Users/brandon/cidr-block/node_modules/tslib/tslib.es6.js'; | ||
| import { ipv4 } from './ipv4.js'; | ||
| import { Ipv4Address } from './ipv4-address.js'; | ||
| import { InvalidIpv4CidrError, InvalidIpv4CidrRangeError } from './ipv4-errors.js'; | ||
| var _Ipv4Cidr_address, _Ipv4Cidr_range; | ||
| /** | ||
| * Represents an IPv4 CIDR block with utility methods for subnet operations. | ||
| * | ||
| * While you can instantiate this class directly, it is recommended to use the | ||
| * {@link ipv4.cidr} shorthand method from the `ipv4` namespace instead. | ||
| * | ||
| * @example Creating CIDR blocks (prefer the shorthand) | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * // Recommended: use the ipv4 namespace shorthand | ||
| * const cidr1 = ipv4.cidr("192.168.0.0/24"); | ||
| * const cidr2 = ipv4.cidr({ address: "10.0.0.0", range: 8 }); | ||
| * const cidr3 = ipv4.cidr([[172, 16, 0, 0], 12]); | ||
| * ``` | ||
| * | ||
| * @example Getting CIDR properties | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.baseAddress().toString(); // "192.168.0.0" | ||
| * cidr.range(); // 24 | ||
| * cidr.netmask().toString(); // "255.255.255.0" | ||
| * cidr.addressCount(); // 256 | ||
| * ``` | ||
| * | ||
| * @example Working with usable addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.getFirstUsableAddress()?.toString(); // "192.168.0.1" | ||
| * cidr.getLastUsableAddress()?.toString(); // "192.168.0.254" | ||
| * ``` | ||
| * | ||
| * @example Iterating over addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.1.0/30"); | ||
| * for (const addr of cidr.addresses()) { | ||
| * console.log(addr.toString()); | ||
| * } | ||
| * // "192.168.1.0", "192.168.1.1", "192.168.1.2", "192.168.1.3" | ||
| * ``` | ||
| * | ||
| * @example Checking containment and overlap | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.includes(ipv4.address("192.168.0.100")); // true | ||
| * cidr.includes(ipv4.address("192.168.1.1")); // false | ||
| * cidr.overlaps("192.168.0.0/25"); // true | ||
| * cidr.overlaps("10.0.0.0/8"); // false | ||
| * ``` | ||
| * | ||
| * @example Splitting into subranges | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * | ||
| * // Split into equal /26 subnets | ||
| * cidr.subnet(26).map(s => s.toString()); | ||
| * // ["192.168.0.0/26", "192.168.0.64/26", "192.168.0.128/26", "192.168.0.192/26"] | ||
| * | ||
| * // Split by specific ranges | ||
| * cidr.subnetBy([25, 26, 27, 27]).map(s => s.toString()); | ||
| * // ["192.168.0.0/25", "192.168.0.128/26", "192.168.0.192/27", "192.168.0.224/27"] | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential CIDRs | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.nextCIDR()?.toString(); // "192.168.1.0/24" | ||
| * cidr.previousCIDR()?.toString(); // "192.167.255.0/24" | ||
| * ``` | ||
| */ | ||
| class Ipv4Cidr { | ||
| constructor(address) { | ||
| _Ipv4Cidr_address.set(this, void 0); | ||
| _Ipv4Cidr_range.set(this, void 0); | ||
| if (!ipv4.isValidCIDR(address)) { | ||
| throw new InvalidIpv4CidrError(address); | ||
| } | ||
| if (typeof address === 'string') { | ||
| const [ip, rangeStr] = address.split('/'); | ||
| __classPrivateFieldSet(this, _Ipv4Cidr_address, new Ipv4Address(ip), "f"); | ||
| __classPrivateFieldSet(this, _Ipv4Cidr_range, parseInt(rangeStr, 10), "f"); | ||
| } | ||
| else if (Array.isArray(address)) { | ||
| __classPrivateFieldSet(this, _Ipv4Cidr_address, new Ipv4Address(address[0]), "f"); | ||
| __classPrivateFieldSet(this, _Ipv4Cidr_range, address[1], "f"); | ||
| } | ||
| else if (typeof address === 'object' && address !== null) { | ||
| __classPrivateFieldSet(this, _Ipv4Cidr_address, new Ipv4Address(address.address), "f"); | ||
| __classPrivateFieldSet(this, _Ipv4Cidr_range, address.range, "f"); | ||
| } | ||
| else { | ||
| throw new InvalidIpv4CidrError(address); | ||
| } | ||
| } | ||
| /** | ||
| * Gets the base IPv4 address of the CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.baseAddress().toString(); // "192.168.0.0" | ||
| * ``` | ||
| * | ||
| * @returns The base IPv4 address. | ||
| */ | ||
| baseAddress() { | ||
| return __classPrivateFieldGet(this, _Ipv4Cidr_address, "f"); | ||
| } | ||
| /** | ||
| * Gets the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.range(); // 24 | ||
| * ``` | ||
| * | ||
| * @returns The CIDR range as a number. | ||
| */ | ||
| range() { | ||
| return __classPrivateFieldGet(this, _Ipv4Cidr_range, "f"); | ||
| } | ||
| /** | ||
| * Calculates the netmask for the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.cidr("192.168.0.0/24").netmask().toString(); // "255.255.255.0" | ||
| * ipv4.cidr("10.0.0.0/8").netmask().toString(); // "255.0.0.0" | ||
| * ipv4.cidr("172.16.0.0/16").netmask().toString(); // "255.255.0.0" | ||
| * ``` | ||
| * | ||
| * @returns The netmask as an Ipv4Address. | ||
| */ | ||
| netmask() { | ||
| const maskNumber = __classPrivateFieldGet(this, _Ipv4Cidr_range, "f") === 0 ? 0 : (-1 << (32 - __classPrivateFieldGet(this, _Ipv4Cidr_range, "f"))) >>> 0; | ||
| return new Ipv4Address(maskNumber); | ||
| } | ||
| /** | ||
| * Returns the string representation of the IPv4 CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr({ address: "10.0.0.0", range: 8 }); | ||
| * cidr.toString(); // "10.0.0.0/8" | ||
| * ``` | ||
| * | ||
| * @returns The IPv4 CIDR as a string (example: "192.0.0.0/24"). | ||
| */ | ||
| toString() { | ||
| return `${__classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toString()}/${__classPrivateFieldGet(this, _Ipv4Cidr_range, "f")}`; | ||
| } | ||
| /** | ||
| * Gets the address and range parts of the IPv4 CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const [address, range] = ipv4.cidr("192.168.0.0/24").rangeParts(); | ||
| * address.toString(); // "192.168.0.0" | ||
| * range; // 24 | ||
| * ``` | ||
| * | ||
| * @returns A tuple containing the IPv4 address and the CIDR range. | ||
| */ | ||
| rangeParts() { | ||
| return [__classPrivateFieldGet(this, _Ipv4Cidr_address, "f"), __classPrivateFieldGet(this, _Ipv4Cidr_range, "f")]; | ||
| } | ||
| /** | ||
| * Calculates the total number of addresses in the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.cidr("192.168.0.0/24").addressCount(); // 256 | ||
| * ipv4.cidr("10.0.0.0/8").addressCount(); // 16777216 | ||
| * ipv4.cidr("192.168.1.0/32").addressCount(); // 1 | ||
| * ``` | ||
| * | ||
| * @returns The total number of addresses in the CIDR range. | ||
| */ | ||
| addressCount() { | ||
| return 2 ** (32 - __classPrivateFieldGet(this, _Ipv4Cidr_range, "f")); | ||
| } | ||
| /** | ||
| * Generates all IPv4 addresses within the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.1.0/30"); | ||
| * for (const addr of cidr.addresses()) { | ||
| * console.log(addr.toString()); | ||
| * } | ||
| * // Output: "192.168.1.0", "192.168.1.1", "192.168.1.2", "192.168.1.3" | ||
| * ``` | ||
| * | ||
| * @returns A generator that yields each IPv4 address in the CIDR range. | ||
| */ | ||
| *addresses() { | ||
| const baseNumber = __classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber(); | ||
| const count = this.addressCount(); | ||
| for (let i = 0; i < count; i++) { | ||
| yield new Ipv4Address(baseNumber + i); | ||
| } | ||
| } | ||
| /** | ||
| * Checks if this CIDR is equal to another CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.equals("192.168.0.0/24"); // true | ||
| * cidr.equals({ address: "192.168.0.0", range: 24 }); // true | ||
| * cidr.equals("10.0.0.0/8"); // false | ||
| * ``` | ||
| * | ||
| * @param other - The other IPv4 CIDR to compare with. | ||
| * @returns True if both CIDRs have the same base address and range; otherwise, false. | ||
| */ | ||
| equals(other) { | ||
| const otherCidr = other instanceof Ipv4Cidr ? other : new Ipv4Cidr(other); | ||
| return __classPrivateFieldGet(this, _Ipv4Cidr_address, "f").equals(__classPrivateFieldGet(otherCidr, _Ipv4Cidr_address, "f")) && __classPrivateFieldGet(this, _Ipv4Cidr_range, "f") === __classPrivateFieldGet(otherCidr, _Ipv4Cidr_range, "f"); | ||
| } | ||
| /** | ||
| * Checks if there is a next sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.cidr("192.168.0.0/24").hasNextCIDR(); // true | ||
| * ipv4.cidr("255.255.255.0/24").hasNextCIDR(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a next CIDR. | ||
| */ | ||
| hasNextCIDR() { | ||
| const nextBaseAddressNumber = __classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber() + this.addressCount(); | ||
| return nextBaseAddressNumber <= ipv4.MAX_SIZE; | ||
| } | ||
| /** | ||
| * Gets the next sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.nextCIDR()?.toString(); // "192.168.1.0/24" | ||
| * | ||
| * const lastCidr = ipv4.cidr("255.255.255.0/24"); | ||
| * lastCidr.nextCIDR(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The next CIDR, or undefined if there is no next CIDR. | ||
| */ | ||
| nextCIDR() { | ||
| const nextBaseAddressNumber = __classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber() + this.addressCount(); | ||
| if (nextBaseAddressNumber > ipv4.MAX_SIZE) { | ||
| return undefined; | ||
| } | ||
| return new Ipv4Cidr([nextBaseAddressNumber, __classPrivateFieldGet(this, _Ipv4Cidr_range, "f")]); | ||
| } | ||
| /** | ||
| * Checks if there is a previous sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.cidr("192.168.1.0/24").hasPreviousCIDR(); // true | ||
| * ipv4.cidr("0.0.0.0/24").hasPreviousCIDR(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a previous CIDR. | ||
| */ | ||
| hasPreviousCIDR() { | ||
| return __classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber() >= this.addressCount(); | ||
| } | ||
| /** | ||
| * Gets the previous sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.1.0/24"); | ||
| * cidr.previousCIDR()?.toString(); // "192.168.0.0/24" | ||
| * | ||
| * const firstCidr = ipv4.cidr("0.0.0.0/24"); | ||
| * firstCidr.previousCIDR(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The previous CIDR, or undefined if there is no previous CIDR. | ||
| */ | ||
| previousCIDR() { | ||
| const prevBaseAddressNumber = __classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber() - this.addressCount(); | ||
| if (prevBaseAddressNumber < ipv4.MIN_SIZE) { | ||
| return undefined; | ||
| } | ||
| return new Ipv4Cidr([prevBaseAddressNumber, __classPrivateFieldGet(this, _Ipv4Cidr_range, "f")]); | ||
| } | ||
| /** | ||
| * Gets the first usable address in the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.getFirstUsableAddress()?.toString(); // "192.168.0.1" | ||
| * | ||
| * const hostCidr = ipv4.cidr("192.168.1.1/32"); | ||
| * hostCidr.getFirstUsableAddress(); // undefined (no usable addresses in /32) | ||
| * ``` | ||
| * | ||
| * @returns The first usable IPv4 address, or undefined if the range is /32. | ||
| */ | ||
| getFirstUsableAddress() { | ||
| if (__classPrivateFieldGet(this, _Ipv4Cidr_range, "f") === 32) { | ||
| return undefined; | ||
| } | ||
| const firstUsableNumber = __classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber() + 1; | ||
| return new Ipv4Address(firstUsableNumber); | ||
| } | ||
| /** | ||
| * Gets the last usable address in the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.getLastUsableAddress()?.toString(); // "192.168.0.254" | ||
| * | ||
| * const hostCidr = ipv4.cidr("192.168.1.1/32"); | ||
| * hostCidr.getLastUsableAddress(); // undefined (no usable addresses in /32) | ||
| * ``` | ||
| * | ||
| * @returns The last usable IPv4 address, or undefined if the range is /32. | ||
| */ | ||
| getLastUsableAddress() { | ||
| if (__classPrivateFieldGet(this, _Ipv4Cidr_range, "f") === 32) { | ||
| return undefined; | ||
| } | ||
| const lastUsableNumber = __classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber() + this.addressCount() - 2; | ||
| return new Ipv4Address(lastUsableNumber); | ||
| } | ||
| /** | ||
| * Checks if the given IPv4 address is within the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.includes(ipv4.address("192.168.0.100")); // true | ||
| * cidr.includes(ipv4.address("192.168.1.1")); // false | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv4 address to check. | ||
| * @returns True if the address is within the CIDR range; otherwise, false. | ||
| */ | ||
| includes(ip) { | ||
| const ipNumber = ip.toNumber(); | ||
| const baseNumber = __classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber(); | ||
| const count = this.addressCount(); | ||
| return ipNumber >= baseNumber && ipNumber < baseNumber + count; | ||
| } | ||
| /** | ||
| * Checks if this CIDR overlaps with another CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.overlaps("192.168.0.0/25"); // true (subset) | ||
| * cidr.overlaps("192.168.0.128/25"); // true (partial overlap) | ||
| * cidr.overlaps("10.0.0.0/8"); // false (no overlap) | ||
| * ``` | ||
| * | ||
| * @param other - The other IPv4 CIDR to check for overlap. | ||
| * @returns True if the CIDRs overlap; otherwise, false. | ||
| */ | ||
| overlaps(other) { | ||
| const otherCidr = other instanceof Ipv4Cidr ? other : new Ipv4Cidr(other); | ||
| const thisBase = __classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber(); | ||
| const thisCount = this.addressCount(); | ||
| const otherBase = __classPrivateFieldGet(otherCidr, _Ipv4Cidr_address, "f").toNumber(); | ||
| const otherCount = otherCidr.addressCount(); | ||
| return thisBase < otherBase + otherCount && otherBase < thisBase + thisCount; | ||
| } | ||
| /** | ||
| * Splits the CIDR into smaller subranges of the specified new range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * const subnets = cidr.subnet(26); | ||
| * subnets.map(s => s.toString()); | ||
| * // ["192.168.0.0/26", "192.168.0.64/26", "192.168.0.128/26", "192.168.0.192/26"] | ||
| * ``` | ||
| * | ||
| * @param newRange - The new CIDR range for the subnets. | ||
| * @returns An array of Ipv4Cidr instances representing the subnets. | ||
| * @throws InvalidIpv4CidrRangeError if the new range is less than the current range or greater than the maximum range. | ||
| */ | ||
| subnet(newRange) { | ||
| if (newRange < __classPrivateFieldGet(this, _Ipv4Cidr_range, "f") || newRange > ipv4.MAX_RANGE) { | ||
| throw new InvalidIpv4CidrRangeError(`New range ${newRange} must be between current range ${__classPrivateFieldGet(this, _Ipv4Cidr_range, "f")} and ${ipv4.MAX_RANGE}`); | ||
| } | ||
| const subranges = []; | ||
| const totalSubnets = 2 ** (newRange - __classPrivateFieldGet(this, _Ipv4Cidr_range, "f")); | ||
| const baseNumber = __classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber(); | ||
| const subnetSize = 2 ** (32 - newRange); | ||
| for (let i = 0; i < totalSubnets; i++) { | ||
| const subnetBaseNumber = baseNumber + i * subnetSize; | ||
| subranges.push(new Ipv4Cidr([subnetBaseNumber, newRange])); | ||
| } | ||
| return subranges; | ||
| } | ||
| /** | ||
| * Splits the CIDR into sequential subranges with the specified CIDR ranges. | ||
| * Each range in the input array creates a subrange starting where the previous one ended. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("10.0.0.0/16"); | ||
| * const subnets = cidr.subnetBy([24, 20, 24]); | ||
| * subnets.map(s => s.toString()); | ||
| * // ["10.0.0.0/24", "10.0.1.0/20", "10.0.17.0/24"] | ||
| * ``` | ||
| * | ||
| * @param ranges - An array of CIDR range values (e.g., [24, 20, 24]). | ||
| * @returns An array of Ipv4Cidr instances representing the subnets. | ||
| * @throws InvalidIpv4CidrRangeError if any range is less than the current range or greater than 32. | ||
| */ | ||
| subnetBy(ranges) { | ||
| const subranges = []; | ||
| let currentBase = __classPrivateFieldGet(this, _Ipv4Cidr_address, "f").toNumber(); | ||
| const endAddress = currentBase + this.addressCount(); | ||
| for (const range of ranges) { | ||
| if (range < __classPrivateFieldGet(this, _Ipv4Cidr_range, "f") || range > ipv4.MAX_RANGE) { | ||
| throw new InvalidIpv4CidrRangeError(`Range ${range} must be between current range ${__classPrivateFieldGet(this, _Ipv4Cidr_range, "f")} and ${ipv4.MAX_RANGE}`); | ||
| } | ||
| const subnetSize = 2 ** (32 - range); | ||
| if (currentBase + subnetSize > endAddress) { | ||
| throw new InvalidIpv4CidrRangeError(`Subrange /${range} at ${new Ipv4Address(currentBase).toString()} exceeds the bounds of the parent CIDR`); | ||
| } | ||
| subranges.push(new Ipv4Cidr([currentBase, range])); | ||
| currentBase += subnetSize; | ||
| } | ||
| return subranges; | ||
| } | ||
| } | ||
| _Ipv4Cidr_address = new WeakMap(), _Ipv4Cidr_range = new WeakMap(); | ||
| export { Ipv4Cidr }; | ||
| //# sourceMappingURL=ipv4-cidr.js.map |
| {"version":3,"file":"ipv4-cidr.js","sources":["../../../src/ipv4-cidr.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFG;MACU,QAAQ,CAAA;AAInB,IAAA,WAAA,CAAY,OAAwB,EAAA;QAHpC,iBAAA,CAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA;QACA,eAAA,CAAA,GAAA,CAAA,IAAA,EAAA,MAAA,CAAA;QAGE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE;AAC9B,YAAA,MAAM,IAAI,oBAAoB,CAAC,OAAO,CAAC;QACzC;AACA,QAAA,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;AAC/B,YAAA,MAAM,CAAC,EAAE,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC;YACzC,sBAAA,CAAA,IAAI,qBAAY,IAAI,WAAW,CAAC,EAAG,CAAC,MAAA;YACpC,sBAAA,CAAA,IAAI,mBAAU,QAAQ,CAAC,QAAS,EAAE,EAAE,CAAC,EAAA,GAAA,CAAA;QACvC;AAAO,aAAA,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YACjC,sBAAA,CAAA,IAAI,EAAA,iBAAA,EAAY,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAA,GAAA,CAAA;AAC3C,YAAA,sBAAA,CAAA,IAAI,EAAA,eAAA,EAAU,OAAO,CAAC,CAAC,CAAC,MAAA;QAC1B;aAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,EAAE;YAC1D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,CAAO,QAAQ,IAAI,CAAC,SAAS,CAAA,CAAE,CACpF;YACH;YAEA,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC;AAEpC,YAAA,IAAI,WAAW,GAAG,UAAU,GAAG,UAAU,EAAE;AACzC,gBAAA,MAAM,IAAI,yBAAyB,CACjC,CAAA,UAAA,EAAa,KAAK,OAAO,IAAI,WAAW,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAA,sCAAA,CAAwC,CACzG;YACH;AAEA,YAAA,SAAS,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;YAClD,WAAW,IAAI,UAAU;QAC3B;AAEA,QAAA,OAAO,SAAS;IAClB;AACD;;;;;"} |
| export declare class InvalidIpv4AddressError extends Error { | ||
| name: string; | ||
| constructor(invalidAddress: unknown); | ||
| } | ||
| export declare class InvalidIpv4CidrError extends Error { | ||
| name: string; | ||
| constructor(invalidCidr: unknown); | ||
| } | ||
| export declare class InvalidIpv4CidrRangeError extends Error { | ||
| name: string; | ||
| } | ||
| //# sourceMappingURL=ipv4-errors.d.ts.map |
| {"version":3,"file":"ipv4-errors.d.ts","sourceRoot":"","sources":["../../src/ipv4-errors.ts"],"names":[],"mappings":"AAAA,qBAAa,uBAAwB,SAAQ,KAAK;IACvC,IAAI,SAA4B;gBAE7B,cAAc,EAAE,OAAO;CAGpC;AAED,qBAAa,oBAAqB,SAAQ,KAAK;IACpC,IAAI,SAAyB;gBAE1B,WAAW,EAAE,OAAO;CAGjC;AAED,qBAAa,yBAA0B,SAAQ,KAAK;IACzC,IAAI,SAA0B;CACxC"} |
| class InvalidIpv4AddressError extends Error { | ||
| constructor(invalidAddress) { | ||
| super(`${invalidAddress} is not a valid IPv4 address`); | ||
| this.name = 'InvalidIpv4AddressError'; | ||
| } | ||
| } | ||
| class InvalidIpv4CidrError extends Error { | ||
| constructor(invalidCidr) { | ||
| super(`${invalidCidr} is not a valid IPv4 CIDR range`); | ||
| this.name = 'InvalidIpv4CidrError'; | ||
| } | ||
| } | ||
| class InvalidIpv4CidrRangeError extends Error { | ||
| constructor() { | ||
| super(...arguments); | ||
| this.name = 'InvalidIpv4RangeError'; | ||
| } | ||
| } | ||
| export { InvalidIpv4AddressError, InvalidIpv4CidrError, InvalidIpv4CidrRangeError }; | ||
| //# sourceMappingURL=ipv4-errors.js.map |
| {"version":3,"file":"ipv4-errors.js","sources":["../../../src/ipv4-errors.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAM,MAAO,uBAAwB,SAAQ,KAAK,CAAA;AAGhD,IAAA,WAAA,CAAY,cAAuB,EAAA;AACjC,QAAA,KAAK,CAAC,CAAA,EAAG,cAAc,CAAA,4BAAA,CAA8B,CAAC;QAH/C,IAAA,CAAA,IAAI,GAAG,yBAAyB;IAIzC;AACD;AAEK,MAAO,oBAAqB,SAAQ,KAAK,CAAA;AAG7C,IAAA,WAAA,CAAY,WAAoB,EAAA;AAC9B,QAAA,KAAK,CAAC,CAAA,EAAG,WAAW,CAAA,+BAAA,CAAiC,CAAC;QAH/C,IAAA,CAAA,IAAI,GAAG,sBAAsB;IAItC;AACD;AAEK,MAAO,yBAA0B,SAAQ,KAAK,CAAA;AAApD,IAAA,WAAA,GAAA;;QACW,IAAA,CAAA,IAAI,GAAG,uBAAuB;IACzC;AAAC;;;;"} |
| /** | ||
| * Represents an IPv4 address from a 'literal' value. | ||
| * Examples: | ||
| * - String: "10.0.0.0" | ||
| * - Number: 167772160 | ||
| * - Octet Array: [10, 0, 0, 0] | ||
| */ | ||
| export type Ipv4AddressLiteral = string | number | number[]; | ||
| /** | ||
| * Represents an IPv4 address in string format (uses stricter typescript type). | ||
| */ | ||
| export type Ipv4AddressString = `${number}.${number}.${number}.${number}`; | ||
| /** | ||
| * Represents an IPv4 address as an array of four octets. | ||
| */ | ||
| export type Ipv4AddressOctets = [number, number, number, number]; | ||
| /** | ||
| * Represents an IPv4 CIDR from a 'literal' value. | ||
| * Examples: | ||
| * - String: "10.0.0.0/24" | ||
| * - Object: { address: "10.0.0.0", range: 24 } | ||
| * - Tuple: [[10, 0, 0, 0], 24] | ||
| */ | ||
| export type Ipv4CidrLiteral = string | { | ||
| address: Ipv4AddressLiteral; | ||
| range: number; | ||
| } | [Ipv4AddressLiteral, number]; | ||
| /** | ||
| * Represents an IPv4 CIDR in string format (uses stricter typescript type). | ||
| */ | ||
| export type Ipv4CidrString = `${number}.${number}.${number}.${number}/${number}`; | ||
| //# sourceMappingURL=ipv4-types.d.ts.map |
| {"version":3,"file":"ipv4-types.d.ts","sourceRoot":"","sources":["../../src/ipv4-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;AAE3D;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,GAAG,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE,CAAA;AAEzE;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAEhE;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GACvB,MAAM,GACN;IAAE,OAAO,EAAE,kBAAkB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC9C,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAA;AAEhC;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,GAAG,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE,CAAA"} |
| import type { Ipv4AddressLiteral, Ipv4AddressOctets, Ipv4CidrLiteral } from './ipv4-types'; | ||
| import { Ipv4Address } from './ipv4-address'; | ||
| import { Ipv4Cidr } from './ipv4-cidr'; | ||
| export * from './ipv4-address'; | ||
| export * from './ipv4-cidr'; | ||
| export * from './ipv4-types'; | ||
| export * from './ipv4-errors'; | ||
| export declare namespace ipv4 { | ||
| /** | ||
| * The maximum possible value for an IPv4 address. | ||
| */ | ||
| const MAX_SIZE = 4294967295; | ||
| /** | ||
| * The minimum possible value for an IPv4 address. | ||
| */ | ||
| const MIN_SIZE = 0; | ||
| /** | ||
| * The maximum CIDR range for IPv4 addresses. | ||
| */ | ||
| const MAX_RANGE = 32; | ||
| /** | ||
| * The minimum CIDR range for IPv4 addresses. | ||
| */ | ||
| const MIN_RANGE = 0; | ||
| /** | ||
| * Creates a new Ipv4Address instance from the given literal. | ||
| * Valid formats include string, number, or octet array. | ||
| * | ||
| * @example Creating addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr1 = ipv4.address("192.168.1.1"); | ||
| * const addr2 = ipv4.address(3232235777); | ||
| * const addr3 = ipv4.address([192, 168, 1, 1]); | ||
| * ``` | ||
| * | ||
| * @example Converting between formats | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.toString(); // "192.168.1.1" | ||
| * addr.toNumber(); // 3232235777 | ||
| * addr.octets(); // [192, 168, 1, 1] | ||
| * addr.toBinaryString(); // "11000000.10101000.00000001.00000001" | ||
| * ``` | ||
| * | ||
| * @example Comparing addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.equals("192.168.1.1"); // true | ||
| * addr.isGreaterThan("192.168.1.0"); // true | ||
| * addr.isLessThan("192.168.1.2"); // true | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.nextAddress()?.toString(); // "192.168.1.2" | ||
| * addr.previousAddress()?.toString(); // "192.168.1.0" | ||
| * ``` | ||
| * | ||
| * @example Checking address types | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("127.0.0.1").isLoopbackAddress(); // true | ||
| * ipv4.address("10.0.0.1").isPrivateAddress(); // true | ||
| * ipv4.address("169.254.1.1").isLocalLinkAddress(); // true | ||
| * ipv4.address("224.0.0.1").isMulticastAddress(); // true | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv4 address in string, number, or octet array format. | ||
| * @returns A new Ipv4Address instance. | ||
| * @throws {InvalidIpv4AddressError} If the input is not a valid IPv4 address. | ||
| */ | ||
| function address(ip: Ipv4AddressLiteral): Ipv4Address; | ||
| /** | ||
| * Creates a new Ipv4Cidr instance from the given literal. | ||
| * Valid formats include string, object, or tuple. | ||
| * | ||
| * @example Creating CIDR blocks | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr1 = ipv4.cidr("192.168.0.0/24"); | ||
| * const cidr2 = ipv4.cidr({ address: "10.0.0.0", range: 8 }); | ||
| * const cidr3 = ipv4.cidr([[172, 16, 0, 0], 12]); | ||
| * ``` | ||
| * | ||
| * @example Getting CIDR properties | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.baseAddress().toString(); // "192.168.0.0" | ||
| * cidr.range(); // 24 | ||
| * cidr.netmask().toString(); // "255.255.255.0" | ||
| * cidr.addressCount(); // 256 | ||
| * ``` | ||
| * | ||
| * @example Working with usable addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.getFirstUsableAddress()?.toString(); // "192.168.0.1" | ||
| * cidr.getLastUsableAddress()?.toString(); // "192.168.0.254" | ||
| * ``` | ||
| * | ||
| * @example Iterating over addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.1.0/30"); | ||
| * for (const addr of cidr.addresses()) { | ||
| * console.log(addr.toString()); | ||
| * } | ||
| * // "192.168.1.0", "192.168.1.1", "192.168.1.2", "192.168.1.3" | ||
| * ``` | ||
| * | ||
| * @example Checking containment and overlap | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.includes(ipv4.address("192.168.0.100")); // true | ||
| * cidr.includes(ipv4.address("192.168.1.1")); // false | ||
| * cidr.overlaps("192.168.0.0/25"); // true | ||
| * cidr.overlaps("10.0.0.0/8"); // false | ||
| * ``` | ||
| * | ||
| * @example Splitting into subranges | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * | ||
| * // Split into equal /26 subnets | ||
| * cidr.subnet(26).map(s => s.toString()); | ||
| * // ["192.168.0.0/26", "192.168.0.64/26", "192.168.0.128/26", "192.168.0.192/26"] | ||
| * | ||
| * // Split by specific ranges | ||
| * cidr.subnetBy([25, 26, 27, 27]).map(s => s.toString()); | ||
| * // ["192.168.0.0/25", "192.168.0.128/26", "192.168.0.192/27", "192.168.0.224/27"] | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential CIDRs | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.nextCIDR()?.toString(); // "192.168.1.0/24" | ||
| * cidr.previousCIDR()?.toString(); // "192.167.255.0/24" | ||
| * ``` | ||
| * | ||
| * @param cidr - The IPv4 CIDR in string, object, or tuple format. | ||
| * @returns A new Ipv4Cidr instance. | ||
| * @throws {InvalidIpv4CidrError} If the input is not a valid IPv4 CIDR. | ||
| */ | ||
| function cidr(cidr: Ipv4CidrLiteral): Ipv4Cidr; | ||
| /** | ||
| * Validates whether the given input is a valid IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.isValidAddress("192.168.1.1"); // true | ||
| * ipv4.isValidAddress("256.0.0.1"); // false (octet out of range) | ||
| * ipv4.isValidAddress(3232235777); // true | ||
| * ipv4.isValidAddress([192, 168, 1, 1]); // true | ||
| * ipv4.isValidAddress("invalid"); // false | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv4 address to validate, which can be in string, number, or octet array format. | ||
| * @returns True if the input is a valid IPv4 address; otherwise, false. | ||
| */ | ||
| function isValidAddress(ip: Ipv4AddressLiteral): boolean; | ||
| /** | ||
| * Validates whether the given input is a valid IPv4 CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.isValidCIDR("192.168.0.0/24"); // true | ||
| * ipv4.isValidCIDR("192.168.0.0/33"); // false (range out of bounds) | ||
| * ipv4.isValidCIDR({ address: "10.0.0.0", range: 8 }); // true | ||
| * ipv4.isValidCIDR([[172, 16, 0, 0], 12]); // true | ||
| * ipv4.isValidCIDR("invalid/24"); // false | ||
| * ``` | ||
| * | ||
| * @param cidr - The IPv4 CIDR to validate, which can be in string, object, or tuple format. | ||
| * @returns True if the input is a valid IPv4 CIDR; otherwise, false. | ||
| */ | ||
| function isValidCIDR(cidr: Ipv4CidrLiteral): boolean; | ||
| /** | ||
| * Parses the given IPv4 address into its octet representation. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.parseOctets("192.168.1.1"); // [192, 168, 1, 1] | ||
| * ipv4.parseOctets(3232235777); // [192, 168, 1, 1] | ||
| * ipv4.parseOctets([10, 0, 0, 1]); // [10, 0, 0, 1] | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv4 address to parse, which can be in string, number, or octet array format. | ||
| * @returns {Ipv4AddressOctets} An array of four numbers representing the octets of the IPv4 address. | ||
| * @throws {InvalidIpv4AddressError} If the input is not a valid IPv4 address. | ||
| */ | ||
| function parseOctets(ip: Ipv4A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339
| import { Ipv4Address } from './ipv4-address.js'; | ||
| import { Ipv4Cidr } from './ipv4-cidr.js'; | ||
| import { InvalidIpv4AddressError } from './ipv4-errors.js'; | ||
| export { InvalidIpv4CidrError, InvalidIpv4CidrRangeError } from './ipv4-errors.js'; | ||
| var ipv4; | ||
| (function (ipv4) { | ||
| /** | ||
| * The maximum possible value for an IPv4 address. | ||
| */ | ||
| ipv4.MAX_SIZE = 0xffffffff; | ||
| /** | ||
| * The minimum possible value for an IPv4 address. | ||
| */ | ||
| ipv4.MIN_SIZE = 0x00000000; | ||
| /** | ||
| * The maximum CIDR range for IPv4 addresses. | ||
| */ | ||
| ipv4.MAX_RANGE = 32; | ||
| /** | ||
| * The minimum CIDR range for IPv4 addresses. | ||
| */ | ||
| ipv4.MIN_RANGE = 0; | ||
| /** | ||
| * Creates a new Ipv4Address instance from the given literal. | ||
| * Valid formats include string, number, or octet array. | ||
| * | ||
| * @example Creating addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr1 = ipv4.address("192.168.1.1"); | ||
| * const addr2 = ipv4.address(3232235777); | ||
| * const addr3 = ipv4.address([192, 168, 1, 1]); | ||
| * ``` | ||
| * | ||
| * @example Converting between formats | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.toString(); // "192.168.1.1" | ||
| * addr.toNumber(); // 3232235777 | ||
| * addr.octets(); // [192, 168, 1, 1] | ||
| * addr.toBinaryString(); // "11000000.10101000.00000001.00000001" | ||
| * ``` | ||
| * | ||
| * @example Comparing addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.equals("192.168.1.1"); // true | ||
| * addr.isGreaterThan("192.168.1.0"); // true | ||
| * addr.isLessThan("192.168.1.2"); // true | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv4.address("192.168.1.1"); | ||
| * addr.nextAddress()?.toString(); // "192.168.1.2" | ||
| * addr.previousAddress()?.toString(); // "192.168.1.0" | ||
| * ``` | ||
| * | ||
| * @example Checking address types | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.address("127.0.0.1").isLoopbackAddress(); // true | ||
| * ipv4.address("10.0.0.1").isPrivateAddress(); // true | ||
| * ipv4.address("169.254.1.1").isLocalLinkAddress(); // true | ||
| * ipv4.address("224.0.0.1").isMulticastAddress(); // true | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv4 address in string, number, or octet array format. | ||
| * @returns A new Ipv4Address instance. | ||
| * @throws {InvalidIpv4AddressError} If the input is not a valid IPv4 address. | ||
| */ | ||
| function address(ip) { | ||
| return new Ipv4Address(ip); | ||
| } | ||
| ipv4.address = address; | ||
| /** | ||
| * Creates a new Ipv4Cidr instance from the given literal. | ||
| * Valid formats include string, object, or tuple. | ||
| * | ||
| * @example Creating CIDR blocks | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr1 = ipv4.cidr("192.168.0.0/24"); | ||
| * const cidr2 = ipv4.cidr({ address: "10.0.0.0", range: 8 }); | ||
| * const cidr3 = ipv4.cidr([[172, 16, 0, 0], 12]); | ||
| * ``` | ||
| * | ||
| * @example Getting CIDR properties | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.baseAddress().toString(); // "192.168.0.0" | ||
| * cidr.range(); // 24 | ||
| * cidr.netmask().toString(); // "255.255.255.0" | ||
| * cidr.addressCount(); // 256 | ||
| * ``` | ||
| * | ||
| * @example Working with usable addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.getFirstUsableAddress()?.toString(); // "192.168.0.1" | ||
| * cidr.getLastUsableAddress()?.toString(); // "192.168.0.254" | ||
| * ``` | ||
| * | ||
| * @example Iterating over addresses | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.1.0/30"); | ||
| * for (const addr of cidr.addresses()) { | ||
| * console.log(addr.toString()); | ||
| * } | ||
| * // "192.168.1.0", "192.168.1.1", "192.168.1.2", "192.168.1.3" | ||
| * ``` | ||
| * | ||
| * @example Checking containment and overlap | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.includes(ipv4.address("192.168.0.100")); // true | ||
| * cidr.includes(ipv4.address("192.168.1.1")); // false | ||
| * cidr.overlaps("192.168.0.0/25"); // true | ||
| * cidr.overlaps("10.0.0.0/8"); // false | ||
| * ``` | ||
| * | ||
| * @example Splitting into subranges | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * | ||
| * // Split into equal /26 subnets | ||
| * cidr.subnet(26).map(s => s.toString()); | ||
| * // ["192.168.0.0/26", "192.168.0.64/26", "192.168.0.128/26", "192.168.0.192/26"] | ||
| * | ||
| * // Split by specific ranges | ||
| * cidr.subnetBy([25, 26, 27, 27]).map(s => s.toString()); | ||
| * // ["192.168.0.0/25", "192.168.0.128/26", "192.168.0.192/27", "192.168.0.224/27"] | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential CIDRs | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv4.cidr("192.168.0.0/24"); | ||
| * cidr.nextCIDR()?.toString(); // "192.168.1.0/24" | ||
| * cidr.previousCIDR()?.toString(); // "192.167.255.0/24" | ||
| * ``` | ||
| * | ||
| * @param cidr - The IPv4 CIDR in string, object, or tuple format. | ||
| * @returns A new Ipv4Cidr instance. | ||
| * @throws {InvalidIpv4CidrError} If the input is not a valid IPv4 CIDR. | ||
| */ | ||
| function cidr(cidr) { | ||
| return new Ipv4Cidr(cidr); | ||
| } | ||
| ipv4.cidr = cidr; | ||
| /** | ||
| * Validates whether the given input is a valid IPv4 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.isValidAddress("192.168.1.1"); // true | ||
| * ipv4.isValidAddress("256.0.0.1"); // false (octet out of range) | ||
| * ipv4.isValidAddress(3232235777); // true | ||
| * ipv4.isValidAddress([192, 168, 1, 1]); // true | ||
| * ipv4.isValidAddress("invalid"); // false | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv4 address to validate, which can be in string, number, or octet array format. | ||
| * @returns True if the input is a valid IPv4 address; otherwise, false. | ||
| */ | ||
| function isValidAddress(ip) { | ||
| if (ip === null || ip === undefined) { | ||
| return false; | ||
| } | ||
| let octets = []; | ||
| if (typeof ip === 'string') { | ||
| octets = ip.split('.').map(Number); | ||
| } | ||
| else if (typeof ip === 'number') { | ||
| if (!Number.isFinite(ip) || ip < ipv4.MIN_SIZE || ip > ipv4.MAX_SIZE) { | ||
| return false; | ||
| } | ||
| octets = [(ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff]; | ||
| } | ||
| else if (Array.isArray(ip)) { | ||
| for (const element of ip) { | ||
| if (typeof element !== 'number') { | ||
| return false; | ||
| } | ||
| } | ||
| octets = ip; | ||
| } | ||
| else { | ||
| return false; | ||
| } | ||
| if (octets.length !== 4) { | ||
| return false; | ||
| } | ||
| for (const octet of octets) { | ||
| if (typeof octet !== 'number' || !Number.isInteger(octet) || octet < 0 || octet > 255) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| ipv4.isValidAddress = isValidAddress; | ||
| /** | ||
| * Validates whether the given input is a valid IPv4 CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.isValidCIDR("192.168.0.0/24"); // true | ||
| * ipv4.isValidCIDR("192.168.0.0/33"); // false (range out of bounds) | ||
| * ipv4.isValidCIDR({ address: "10.0.0.0", range: 8 }); // true | ||
| * ipv4.isValidCIDR([[172, 16, 0, 0], 12]); // true | ||
| * ipv4.isValidCIDR("invalid/24"); // false | ||
| * ``` | ||
| * | ||
| * @param cidr - The IPv4 CIDR to validate, which can be in string, object, or tuple format. | ||
| * @returns True if the input is a valid IPv4 CIDR; otherwise, false. | ||
| */ | ||
| function isValidCIDR(cidr) { | ||
| if (cidr === null || cidr === undefined) { | ||
| return false; | ||
| } | ||
| let address; | ||
| let range; | ||
| if (typeof cidr === 'string') { | ||
| const parts = cidr.split('/'); | ||
| if (parts.length !== 2) { | ||
| return false; | ||
| } | ||
| address = parts[0]; | ||
| range = parseInt(parts[1], 10); | ||
| } | ||
| else if (Array.isArray(cidr)) { | ||
| if (cidr.length !== 2) { | ||
| return false; | ||
| } | ||
| // Validate array element types at runtime | ||
| const [first, second] = cidr; | ||
| if (first === null || first === undefined) { | ||
| return false; | ||
| } | ||
| if (typeof second !== 'number') { | ||
| return false; | ||
| } | ||
| address = first; | ||
| range = second; | ||
| } | ||
| else if (typeof cidr === 'object') { | ||
| if (!('address' in cidr) || !('range' in cidr)) { | ||
| return false; | ||
| } | ||
| const { address: addr, range: r } = cidr; | ||
| if (addr === null || addr === undefined) { | ||
| return false; | ||
| } | ||
| if (typeof r !== 'number') { | ||
| return false; | ||
| } | ||
| address = addr; | ||
| range = r; | ||
| } | ||
| else { | ||
| return false; | ||
| } | ||
| if (address === undefined || !isValidAddress(address)) { | ||
| return false; | ||
| } | ||
| if (typeof range !== 'number' | ||
| || !Number.isInteger(range) | ||
| || range < ipv4.MIN_RANGE | ||
| || range > ipv4.MAX_RANGE) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| ipv4.isValidCIDR = isValidCIDR; | ||
| /** | ||
| * Parses the given IPv4 address into its octet representation. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv4 } from 'cidr-block'; | ||
| * | ||
| * ipv4.parseOctets("192.168.1.1"); // [192, 168, 1, 1] | ||
| * ipv4.parseOctets(3232235777); // [192, 168, 1, 1] | ||
| * ipv4.parseOctets([10, 0, 0, 1]); // [10, 0, 0, 1] | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv4 address to parse, which can be in string, number, or octet array format. | ||
| * @returns {Ipv4AddressOctets} An array of four numbers representing the octets of the IPv4 address. | ||
| * @throws {InvalidIpv4AddressError} If the input is not a valid IPv4 address. | ||
| */ | ||
| function parseOctets(ip) { | ||
| if (!isValidAddress(ip)) { | ||
| throw new InvalidIpv4AddressError(ip); | ||
| } | ||
| if (typeof ip === 'string') { | ||
| return ip.split('.').map(Number); | ||
| } | ||
| else if (typeof ip === 'number') { | ||
| return [ | ||
| (ip >> 24) & 0xff, | ||
| (ip >> 16) & 0xff, | ||
| (ip >> 8) & 0xff, | ||
| ip & 0xff, | ||
| ]; | ||
| } | ||
| else { | ||
| return ip; | ||
| } | ||
| } | ||
| ipv4.parseOctets = parseOctets; | ||
| })(ipv4 || (ipv4 = {})); | ||
| export { InvalidIpv4AddressError, Ipv4Address, Ipv4Cidr, ipv4 }; | ||
| //# sourceMappingURL=ipv4.js.map |
| {"version":3,"file":"ipv4.js","sources":["../../../src/ipv4.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAUM,IAAW;AAAjB,CAAA,UAAiB,IAAI,EAAA;AACnB;;AAEG;IACU,IAAA,CAAA,QAAQ,GAAG,UAAU;AAElC;;AAEG;IACU,IAAA,CAAA,QAAQ,GAAG,UAAU;AAElC;;AAEG;IACU,IAAA,CAAA,SAAS,GAAG,EAAE;AAE3B;;AAEG;IACU,IAAA,CAAA,SAAS,GAAG,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAw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AAA,MAAM,IAAI,uBAAuB,CAAC,EAAE,CAAC;QACvC;AACA,QAAA,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE;YAC1B,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAsB;QACvD;AAAO,aAAA,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE;YACjC,OAAO;AACL,gBAAA,CAAC,EAAE,IAAI,EAAE,IAAI,IAAI;AACjB,gBAAA,CAAC,EAAE,IAAI,EAAE,IAAI,IAAI;AACjB,gBAAA,CAAC,EAAE,IAAI,CAAC,IAAI,IAAI;AAChB,gBAAA,EAAE,GAAG,IAAI;aACW;QACxB;aAAO;AACL,YAAA,OAAO,EAAuB;QAChC;IACF;AAhBgB,IAAA,IAAA,CAAA,WAAW,cAgB1B;AACH,CAAC,EAhVgB,IAAI,KAAJ,IAAI,GAAA,EAAA,CAAA,CAAA;;;;"} |
| import type { Ipv6AddressLiteral, Ipv6AddressHextets } from './ipv6-types'; | ||
| /** | ||
| * Represents an IPv6 address with utility methods for manipulation and comparison. | ||
| * | ||
| * While you can instantiate this class directly, it is recommended to use the | ||
| * {@link ipv6.address} shorthand method from the `ipv6` namespace instead. | ||
| * | ||
| * @example Creating addresses (prefer the shorthand) | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * // Recommended: use the ipv6 namespace shorthand | ||
| * const addr1 = ipv6.address("2001:db8::1"); | ||
| * const addr2 = ipv6.address(42540766411282592856903984951653826561n); | ||
| * const addr3 = ipv6.address([0x2001, 0xdb8, 0, 0, 0, 0, 0, 1]); | ||
| * ``` | ||
| * | ||
| * @example Converting between formats | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.toString(); // "2001:db8::1" (compressed) | ||
| * addr.toFullString(); // "2001:0db8:0000:0000:0000:0000:0000:0001" | ||
| * addr.toBigInt(); // 42540766411282592856903984951653826561n | ||
| * addr.hextets(); // [0x2001, 0xdb8, 0, 0, 0, 0, 0, 1] | ||
| * ``` | ||
| * | ||
| * @example Comparing addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.equals("2001:db8::1"); // true | ||
| * addr.isGreaterThan("2001:db8::0"); // true | ||
| * addr.isLessThan("2001:db8::2"); // true | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.nextAddress()?.toString(); // "2001:db8::2" | ||
| * addr.previousAddress()?.toString(); // "2001:db8::" | ||
| * ``` | ||
| * | ||
| * @example Checking address types | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("::1").isLoopbackAddress(); // true | ||
| * ipv6.address("fc00::1").isUniqueLocalAddress(); // true | ||
| * ipv6.address("fe80::1").isLinkLocalAddress(); // true | ||
| * ipv6.address("ff02::1").isMulticastAddress(); // true | ||
| * ``` | ||
| */ | ||
| export declare class Ipv6Address { | ||
| #private; | ||
| constructor(ip: Ipv6AddressLiteral); | ||
| /** | ||
| * Gets the hextets of the IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.hextets(); // [0x2001, 0xdb8, 0, 0, 0, 0, 0, 1] | ||
| * ``` | ||
| * | ||
| * @returns An array of eight numbers representing the hextets of the IPv6 address. | ||
| */ | ||
| hextets(): Ipv6AddressHextets; | ||
| /** | ||
| * Returns the full (expanded) string representation of the IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.toFullString(); // "2001:0db8:0000:0000:0000:0000:0000:0001" | ||
| * ``` | ||
| * | ||
| * @returns The IPv6 address as a full string with all hextets expanded. | ||
| */ | ||
| toFullString(): string; | ||
| /** | ||
| * Returns the compressed string representation of the IPv6 address. | ||
| * Uses :: notation for the longest run of consecutive zero hextets. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:0db8:0000:0000:0000:0000:0000:0001"); | ||
| * addr.toString(); // "2001:db8::1" | ||
| * ``` | ||
| * | ||
| * @returns The IPv6 address as a compressed string. | ||
| */ | ||
| toString(): string; | ||
| /** | ||
| * Returns the binary string representation of the IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("::1"); | ||
| * addr.toBinaryString(); | ||
| * // "0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000001" | ||
| * ``` | ||
| * | ||
| * @returns The IPv6 address as a binary string with colons separating hextets. | ||
| */ | ||
| toBinaryString(): string; | ||
| /** | ||
| * Converts the IPv6 address to its BigInt representation. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.toBigInt(); // 42540766411282592856903984951653826561n | ||
| * ``` | ||
| * | ||
| * @returns The IPv6 address as a BigInt. | ||
| */ | ||
| toBigInt(): bigint; | ||
| /** | ||
| * Checks if there is a next sequential IPv6 address. | ||
| * This would only return false if the current address is the maximum possible value. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("2001:db8::1").hasNextAddress(); // true | ||
| * ipv6.address("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff").hasNextAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a next IPv6 address. | ||
| */ | ||
| hasNextAddress(): boolean; | ||
| /** | ||
| * Gets the next sequential IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.nextAddress()?.toString(); // "2001:db8::2" | ||
| * | ||
| * const maxAddr = ipv6.address("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); | ||
| * maxAddr.nextAddress(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The next IPv6 address, or undefined if the current address is the maximum possible value. | ||
| */ | ||
| nextAddress(): Ipv6Address | undefined; | ||
| /** | ||
| * Checks if there is a previous sequential IPv6 address. | ||
| * This would only return false if the current address is the minimum possible value (::). | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("2001:db8::1").hasPreviousAddress(); // true | ||
| * ipv6.address("::").hasPreviousAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a previous IPv6 address. | ||
| */ | ||
| hasPreviousAddress(): boolean; | ||
| /** | ||
| * Gets the previous sequential IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.previousAddress()?.toString(); // "2001:db8::" | ||
| * | ||
| * const minAddr = ipv6.address("::"); | ||
| * minAddr.previousAddress(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The previous IPv6 address, or undefined if the current address is the minimum possible value. | ||
| */ | ||
| previousAddress(): Ipv6Address | undefined; | ||
| /** | ||
| * Compares two IPv6 addresses for equality. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.equals("2001:db8::1"); // true | ||
| * addr.equals("2001:0db8:0:0:0:0:0:1"); // true | ||
| * addr.equals(ipv6.address("2001:db8::2")); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv6 address to compare with, which can be an Ipv6Address instance or literal value. | ||
| * @returns true if both IPv6 addresses are equal | ||
| */ | ||
| equals(otherAddress: Ipv6Address | Ipv6AddressLiteral): boolean; | ||
| /** | ||
| * Compares if this IPv6 address is greater than another IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.isGreaterThan("2001:db8::"); // true | ||
| * addr.isGreaterThan("2001:db8::1"); // false | ||
| * addr.isGreaterThan("2001:db8::2"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv6 address to compare with, which can be an Ipv6Address instance or literal value. | ||
| * @returns true if this IPv6 address is greater than the other IPv6 address | ||
| */ | ||
| isGreaterThan(otherAddress: Ipv6Address | Ipv6AddressLiteral): boolean; | ||
| /** | ||
| * Compares if this IPv6 address is greater than or equal to another IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.isGreaterThanOrEqual("2001:db8::"); // true | ||
| * addr.isGreaterThanOrEqual("2001:db8::1"); // true | ||
| * addr.isGreaterThanOrEqual("2001:db8::2"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv6 address to compare with, which can be an Ipv6Address instance or literal value. | ||
| * @returns true if this IPv6 address is greater than or equal to the other IPv6 address | ||
| */ | ||
| isGreaterThanOrEqual(otherAddress: Ipv6Address | Ipv6AddressLiteral): boolean; | ||
| /** | ||
| * Compares if this IPv6 address is less than another IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.isLessThan("2001:db8::2"); // true | ||
| * addr.isLessThan("2001:db8::1"); // false | ||
| * addr.isLessThan("2001:db8::"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv6 address to compare with, which can be an Ipv6Address instance or literal value. | ||
| * @returns true if this IPv6 address is less than the other IPv6 address | ||
| */ | ||
| isLessThan(otherAddress: Ipv6Address | Ipv6AddressLiteral): boolean; | ||
| /** | ||
| * Compares if this IPv6 address is less than or equal to another IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.isLessThanOrEqual("2001:db8::2"); // true | ||
| * addr.isLessThanOrEqual("2001:db8::1"); // true | ||
| * addr.isLessThanOrEqual("2001:db8::"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv6 address to compare with, which can be an Ipv6Address instance or literal value. | ||
| * @returns true if this IPv6 address is less than or equal to the other IPv6 address | ||
| */ | ||
| isLessThanOrEqual(otherAddress: Ipv6Address | Ipv6AddressLiteral): boolean; | ||
| /** | ||
| * Checks if the IPv6 address is the loopback address (::1) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("::1").isLoopbackAddress(); // true | ||
| * ipv6.address("2001:db8::1").isLoopbackAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is the loopback address | ||
| */ | ||
| isLoopbackAddress(): boolean; | ||
| /** | ||
| * Checks if the IPv6 address is the unspecified address (::) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("::").isUnspecifiedAddress(); // true | ||
| * ipv6.address("2001:db8::1").isUnspecifiedAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is the unspecified address | ||
| */ | ||
| isUnspecifiedAddress(): boolean; | ||
| /** | ||
| * Checks if the IPv6 address is a unique local address (fc00::/7). | ||
| * These are the IPv6 equivalent of RFC 1918 private addresses. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("fc00::1").isUniqueLocalAddress(); // true | ||
| * ipv6.address("fd00::1").isUniqueLocalAddress(); // true | ||
| * ipv6.address("2001:db8::1").isUniqueLocalAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is a unique local address | ||
| */ | ||
| isUniqueLocalAddress(): boolean; | ||
| /** | ||
| * Checks if the IPv6 address is a link-local address (fe80::/10) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("fe80::1").isLinkLocalAddress(); // true | ||
| * ipv6.address("2001:db8::1").isLinkLocalAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is a link-local address | ||
| */ | ||
| isLinkLocalAddress(): boolean; | ||
| /** | ||
| * Checks if the IPv6 address is a multicast address (ff00::/8) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("ff02::1").isMulticastAddress(); // true | ||
| * ipv6.address("2001:db8::1").isMulticastAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is a multicast address | ||
| */ | ||
| isMulticastAddress(): boolean; | ||
| /** | ||
| * Checks if the IPv6 address is an IPv4-mapped IPv6 address (::ffff:0:0/96) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("::ffff:192.168.1.1").isIPv4MappedAddress(); // true | ||
| * ipv6.address("::ffff:c0a8:0101").isIPv4MappedAddress(); // true | ||
| * ipv6.address("2001:db8::1").isIPv4MappedAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is an IPv4-mapped address | ||
| */ | ||
| isIPv4MappedAddress(): boolean; | ||
| /** | ||
| * Checks if the IPv6 address is a documentation address (2001:db8::/32) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("2001:db8::1").isDocumentationAddress(); // true | ||
| * ipv6.address("2001:db8:1234::1").isDocumentationAddress(); // true | ||
| * ipv6.address("2001:470::1").isDocumentationAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is a documentation address | ||
| */ | ||
| isDocumentationAddress(): boolean; | ||
| } | ||
| //# sourceMappingURL=ipv6-address.d.ts.map |
| {"version":3,"file":"ipv6-address.d.ts","sourceRoot":"","sources":["../../src/ipv6-address.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAI1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,qBAAa,WAAW;;gBAGV,EAAE,EAAE,kBAAkB;IAOlC;;;;;;;;;;;;OAYG;IACI,OAAO,IAAI,kBAAkB;IAIpC;;;;;;;;;;;;OAYG;IACI,YAAY,IAAI,MAAM;IAI7B;;;;;;;;;;;;;OAaG;IACI,QAAQ,IAAI,MAAM;IAoDzB;;;;;;;;;;;;;OAaG;IACI,cAAc,IAAI,MAAM;IAI/B;;;;;;;;;;;;OAYG;IACI,QAAQ,IAAI,MAAM;IAQzB;;;;;;;;;;;;;OAaG;IACI,cAAc,IAAI,OAAO;IAIhC;;;;;;;;;;;;;;;OAeG;IACI,WAAW,IAAI,WAAW,GAAG,SAAS;IAQ7C;;;;;;;;;;;;;OAaG;IACI,kBAAkB,IAAI,OAAO;IAIpC;;;;;;;;;;;;;;;OAeG;IACI,eAAe,IAAI,WAAW,GAAG,SAAS;IAQjD;;;;;;;;;;;;;;;OAeG;IACI,MAAM,CAAC,YAAY,EAAE,WAAW,GAAG,kBAAkB,GAAG,OAAO;IAOtE;;;;;;;;;;;;;;;OAeG;IACI,aAAa,CAAC,YAAY,EAAE,WAAW,GAAG,kBAAkB,GAAG,OAAO;IAO7E;;;;;;;;;;;;;;;OAeG;IACI,oBAAoB,CAAC,YAAY,EAAE,WAAW,GAAG,kBAAkB,GAAG,OAAO;IAOpF;;;;;;;;;;;;;;;OAeG;IACI,UAAU,CAAC,YAAY,EAAE,WAAW,GAAG,kBAAkB,GAAG,OAAO;IAO1E;;;;;;;;;;;;;;;OAeG;IACI,iBAAiB,CAAC,YAAY,EAAE,WAAW,GAAG,kBAAkB,GAAG,OAAO;IAOjF;;;;;;;;;;;;OAYG;IACI,iBAAiB,IAAI,OAAO;IAInC;;;;;;;;;;;;OAYG;IACI,oBAAoB,IAAI,OAAO;IAItC;;;;;;;;;;;;;;OAcG;IACI,oBAAoB,IAAI,OAAO;IAMtC;;;;;;;;;;;;OAYG;IACI,kBAAkB,IAAI,OAAO;IAKpC;;;;;;;;;;;;OAYG;IACI,kBAAkB,IAAI,OAAO;IAIpC;;;;;;;;;;;;;OAaG;IACI,mBAAmB,IAAI,OAAO;IAYrC;;;;;;;;;;;;;OAaG;IACI,sBAAsB,IAAI,OAAO;CAGzC"} |
| import { __classPrivateFieldSet, __classPrivateFieldGet } from '/Users/brandon/cidr-block/node_modules/tslib/tslib.es6.js'; | ||
| import { ipv6 } from './ipv6.js'; | ||
| import { InvalidIpv6AddressError } from './ipv6-errors.js'; | ||
| var _Ipv6Address_hextets; | ||
| /** | ||
| * Represents an IPv6 address with utility methods for manipulation and comparison. | ||
| * | ||
| * While you can instantiate this class directly, it is recommended to use the | ||
| * {@link ipv6.address} shorthand method from the `ipv6` namespace instead. | ||
| * | ||
| * @example Creating addresses (prefer the shorthand) | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * // Recommended: use the ipv6 namespace shorthand | ||
| * const addr1 = ipv6.address("2001:db8::1"); | ||
| * const addr2 = ipv6.address(42540766411282592856903984951653826561n); | ||
| * const addr3 = ipv6.address([0x2001, 0xdb8, 0, 0, 0, 0, 0, 1]); | ||
| * ``` | ||
| * | ||
| * @example Converting between formats | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.toString(); // "2001:db8::1" (compressed) | ||
| * addr.toFullString(); // "2001:0db8:0000:0000:0000:0000:0000:0001" | ||
| * addr.toBigInt(); // 42540766411282592856903984951653826561n | ||
| * addr.hextets(); // [0x2001, 0xdb8, 0, 0, 0, 0, 0, 1] | ||
| * ``` | ||
| * | ||
| * @example Comparing addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.equals("2001:db8::1"); // true | ||
| * addr.isGreaterThan("2001:db8::0"); // true | ||
| * addr.isLessThan("2001:db8::2"); // true | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.nextAddress()?.toString(); // "2001:db8::2" | ||
| * addr.previousAddress()?.toString(); // "2001:db8::" | ||
| * ``` | ||
| * | ||
| * @example Checking address types | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("::1").isLoopbackAddress(); // true | ||
| * ipv6.address("fc00::1").isUniqueLocalAddress(); // true | ||
| * ipv6.address("fe80::1").isLinkLocalAddress(); // true | ||
| * ipv6.address("ff02::1").isMulticastAddress(); // true | ||
| * ``` | ||
| */ | ||
| class Ipv6Address { | ||
| constructor(ip) { | ||
| _Ipv6Address_hextets.set(this, void 0); | ||
| if (!ipv6.isValidAddress(ip)) { | ||
| throw new InvalidIpv6AddressError(ip); | ||
| } | ||
| __classPrivateFieldSet(this, _Ipv6Address_hextets, ipv6.parseHextets(ip), "f"); | ||
| } | ||
| /** | ||
| * Gets the hextets of the IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.hextets(); // [0x2001, 0xdb8, 0, 0, 0, 0, 0, 1] | ||
| * ``` | ||
| * | ||
| * @returns An array of eight numbers representing the hextets of the IPv6 address. | ||
| */ | ||
| hextets() { | ||
| return __classPrivateFieldGet(this, _Ipv6Address_hextets, "f"); | ||
| } | ||
| /** | ||
| * Returns the full (expanded) string representation of the IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.toFullString(); // "2001:0db8:0000:0000:0000:0000:0000:0001" | ||
| * ``` | ||
| * | ||
| * @returns The IPv6 address as a full string with all hextets expanded. | ||
| */ | ||
| toFullString() { | ||
| return __classPrivateFieldGet(this, _Ipv6Address_hextets, "f").map(h => h.toString(16).padStart(4, '0')).join(':'); | ||
| } | ||
| /** | ||
| * Returns the compressed string representation of the IPv6 address. | ||
| * Uses :: notation for the longest run of consecutive zero hextets. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:0db8:0000:0000:0000:0000:0000:0001"); | ||
| * addr.toString(); // "2001:db8::1" | ||
| * ``` | ||
| * | ||
| * @returns The IPv6 address as a compressed string. | ||
| */ | ||
| toString() { | ||
| // Find the longest run of consecutive zeros | ||
| let longestStart = -1; | ||
| let longestLength = 0; | ||
| let currentStart = -1; | ||
| let currentLength = 0; | ||
| for (let i = 0; i < 8; i++) { | ||
| if (__classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[i] === 0) { | ||
| if (currentStart === -1) { | ||
| currentStart = i; | ||
| currentLength = 1; | ||
| } | ||
| else { | ||
| currentLength++; | ||
| } | ||
| } | ||
| else { | ||
| if (currentLength > longestLength && currentLength > 1) { | ||
| longestStart = currentStart; | ||
| longestLength = currentLength; | ||
| } | ||
| currentStart = -1; | ||
| currentLength = 0; | ||
| } | ||
| } | ||
| // Check if the last run is the longest | ||
| if (currentLength > longestLength && currentLength > 1) { | ||
| longestStart = currentStart; | ||
| longestLength = currentLength; | ||
| } | ||
| // Build the compressed string | ||
| if (longestStart === -1) { | ||
| // No compression possible | ||
| return __classPrivateFieldGet(this, _Ipv6Address_hextets, "f").map(h => h.toString(16)).join(':'); | ||
| } | ||
| const before = __classPrivateFieldGet(this, _Ipv6Address_hextets, "f").slice(0, longestStart).map(h => h.toString(16)); | ||
| const after = __classPrivateFieldGet(this, _Ipv6Address_hextets, "f").slice(longestStart + longestLength).map(h => h.toString(16)); | ||
| if (before.length === 0 && after.length === 0) { | ||
| return '::'; | ||
| } | ||
| if (before.length === 0) { | ||
| return `::${after.join(':')}`; | ||
| } | ||
| if (after.length === 0) { | ||
| return `${before.join(':')}::`; | ||
| } | ||
| return `${before.join(':')}::${after.join(':')}`; | ||
| } | ||
| /** | ||
| * Returns the binary string representation of the IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("::1"); | ||
| * addr.toBinaryString(); | ||
| * // "0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000001" | ||
| * ``` | ||
| * | ||
| * @returns The IPv6 address as a binary string with colons separating hextets. | ||
| */ | ||
| toBinaryString() { | ||
| return __classPrivateFieldGet(this, _Ipv6Address_hextets, "f").map(h => h.toString(2).padStart(16, '0')).join(':'); | ||
| } | ||
| /** | ||
| * Converts the IPv6 address to its BigInt representation. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.toBigInt(); // 42540766411282592856903984951653826561n | ||
| * ``` | ||
| * | ||
| * @returns The IPv6 address as a BigInt. | ||
| */ | ||
| toBigInt() { | ||
| let result = 0n; | ||
| for (let i = 0; i < 8; i++) { | ||
| result = (result << 16n) | BigInt(__classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[i]); | ||
| } | ||
| return result; | ||
| } | ||
| /** | ||
| * Checks if there is a next sequential IPv6 address. | ||
| * This would only return false if the current address is the maximum possible value. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("2001:db8::1").hasNextAddress(); // true | ||
| * ipv6.address("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff").hasNextAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a next IPv6 address. | ||
| */ | ||
| hasNextAddress() { | ||
| return this.toBigInt() < ipv6.MAX_SIZE; | ||
| } | ||
| /** | ||
| * Gets the next sequential IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.nextAddress()?.toString(); // "2001:db8::2" | ||
| * | ||
| * const maxAddr = ipv6.address("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); | ||
| * maxAddr.nextAddress(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The next IPv6 address, or undefined if the current address is the maximum possible value. | ||
| */ | ||
| nextAddress() { | ||
| const nextAddress = this.toBigInt() + 1n; | ||
| if (nextAddress > ipv6.MAX_SIZE) { | ||
| return undefined; | ||
| } | ||
| return new Ipv6Address(nextAddress); | ||
| } | ||
| /** | ||
| * Checks if there is a previous sequential IPv6 address. | ||
| * This would only return false if the current address is the minimum possible value (::). | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("2001:db8::1").hasPreviousAddress(); // true | ||
| * ipv6.address("::").hasPreviousAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a previous IPv6 address. | ||
| */ | ||
| hasPreviousAddress() { | ||
| return this.toBigInt() > ipv6.MIN_SIZE; | ||
| } | ||
| /** | ||
| * Gets the previous sequential IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.previousAddress()?.toString(); // "2001:db8::" | ||
| * | ||
| * const minAddr = ipv6.address("::"); | ||
| * minAddr.previousAddress(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The previous IPv6 address, or undefined if the current address is the minimum possible value. | ||
| */ | ||
| previousAddress() { | ||
| const prevAddress = this.toBigInt() - 1n; | ||
| if (prevAddress < ipv6.MIN_SIZE) { | ||
| return undefined; | ||
| } | ||
| return new Ipv6Address(prevAddress); | ||
| } | ||
| /** | ||
| * Compares two IPv6 addresses for equality. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.equals("2001:db8::1"); // true | ||
| * addr.equals("2001:0db8:0:0:0:0:0:1"); // true | ||
| * addr.equals(ipv6.address("2001:db8::2")); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv6 address to compare with, which can be an Ipv6Address instance or literal value. | ||
| * @returns true if both IPv6 addresses are equal | ||
| */ | ||
| equals(otherAddress) { | ||
| if (otherAddress instanceof Ipv6Address) { | ||
| return this.toBigInt() === otherAddress.toBigInt(); | ||
| } | ||
| return this.toBigInt() === new Ipv6Address(otherAddress).toBigInt(); | ||
| } | ||
| /** | ||
| * Compares if this IPv6 address is greater than another IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.isGreaterThan("2001:db8::"); // true | ||
| * addr.isGreaterThan("2001:db8::1"); // false | ||
| * addr.isGreaterThan("2001:db8::2"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv6 address to compare with, which can be an Ipv6Address instance or literal value. | ||
| * @returns true if this IPv6 address is greater than the other IPv6 address | ||
| */ | ||
| isGreaterThan(otherAddress) { | ||
| if (otherAddress instanceof Ipv6Address) { | ||
| return this.toBigInt() > otherAddress.toBigInt(); | ||
| } | ||
| return this.toBigInt() > new Ipv6Address(otherAddress).toBigInt(); | ||
| } | ||
| /** | ||
| * Compares if this IPv6 address is greater than or equal to another IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.isGreaterThanOrEqual("2001:db8::"); // true | ||
| * addr.isGreaterThanOrEqual("2001:db8::1"); // true | ||
| * addr.isGreaterThanOrEqual("2001:db8::2"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv6 address to compare with, which can be an Ipv6Address instance or literal value. | ||
| * @returns true if this IPv6 address is greater than or equal to the other IPv6 address | ||
| */ | ||
| isGreaterThanOrEqual(otherAddress) { | ||
| if (otherAddress instanceof Ipv6Address) { | ||
| return this.toBigInt() >= otherAddress.toBigInt(); | ||
| } | ||
| return this.toBigInt() >= new Ipv6Address(otherAddress).toBigInt(); | ||
| } | ||
| /** | ||
| * Compares if this IPv6 address is less than another IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.isLessThan("2001:db8::2"); // true | ||
| * addr.isLessThan("2001:db8::1"); // false | ||
| * addr.isLessThan("2001:db8::"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv6 address to compare with, which can be an Ipv6Address instance or literal value. | ||
| * @returns true if this IPv6 address is less than the other IPv6 address | ||
| */ | ||
| isLessThan(otherAddress) { | ||
| if (otherAddress instanceof Ipv6Address) { | ||
| return this.toBigInt() < otherAddress.toBigInt(); | ||
| } | ||
| return this.toBigInt() < new Ipv6Address(otherAddress).toBigInt(); | ||
| } | ||
| /** | ||
| * Compares if this IPv6 address is less than or equal to another IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.isLessThanOrEqual("2001:db8::2"); // true | ||
| * addr.isLessThanOrEqual("2001:db8::1"); // true | ||
| * addr.isLessThanOrEqual("2001:db8::"); // false | ||
| * ``` | ||
| * | ||
| * @param otherAddress - The other IPv6 address to compare with, which can be an Ipv6Address instance or literal value. | ||
| * @returns true if this IPv6 address is less than or equal to the other IPv6 address | ||
| */ | ||
| isLessThanOrEqual(otherAddress) { | ||
| if (otherAddress instanceof Ipv6Address) { | ||
| return this.toBigInt() <= otherAddress.toBigInt(); | ||
| } | ||
| return this.toBigInt() <= new Ipv6Address(otherAddress).toBigInt(); | ||
| } | ||
| /** | ||
| * Checks if the IPv6 address is the loopback address (::1) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("::1").isLoopbackAddress(); // true | ||
| * ipv6.address("2001:db8::1").isLoopbackAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is the loopback address | ||
| */ | ||
| isLoopbackAddress() { | ||
| return this.toBigInt() === 1n; | ||
| } | ||
| /** | ||
| * Checks if the IPv6 address is the unspecified address (::) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("::").isUnspecifiedAddress(); // true | ||
| * ipv6.address("2001:db8::1").isUnspecifiedAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is the unspecified address | ||
| */ | ||
| isUnspecifiedAddress() { | ||
| return this.toBigInt() === 0n; | ||
| } | ||
| /** | ||
| * Checks if the IPv6 address is a unique local address (fc00::/7). | ||
| * These are the IPv6 equivalent of RFC 1918 private addresses. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("fc00::1").isUniqueLocalAddress(); // true | ||
| * ipv6.address("fd00::1").isUniqueLocalAddress(); // true | ||
| * ipv6.address("2001:db8::1").isUniqueLocalAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is a unique local address | ||
| */ | ||
| isUniqueLocalAddress() { | ||
| // fc00::/7 means first 7 bits are 1111110 | ||
| // This covers fc00::/8 and fd00::/8 | ||
| return (__classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[0] & 0xfe00) === 0xfc00; | ||
| } | ||
| /** | ||
| * Checks if the IPv6 address is a link-local address (fe80::/10) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("fe80::1").isLinkLocalAddress(); // true | ||
| * ipv6.address("2001:db8::1").isLinkLocalAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is a link-local address | ||
| */ | ||
| isLinkLocalAddress() { | ||
| // fe80::/10 means first 10 bits are 1111111010 | ||
| return (__classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[0] & 0xffc0) === 0xfe80; | ||
| } | ||
| /** | ||
| * Checks if the IPv6 address is a multicast address (ff00::/8) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("ff02::1").isMulticastAddress(); // true | ||
| * ipv6.address("2001:db8::1").isMulticastAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is a multicast address | ||
| */ | ||
| isMulticastAddress() { | ||
| return (__classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[0] & 0xff00) === 0xff00; | ||
| } | ||
| /** | ||
| * Checks if the IPv6 address is an IPv4-mapped IPv6 address (::ffff:0:0/96) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("::ffff:192.168.1.1").isIPv4MappedAddress(); // true | ||
| * ipv6.address("::ffff:c0a8:0101").isIPv4MappedAddress(); // true | ||
| * ipv6.address("2001:db8::1").isIPv4MappedAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is an IPv4-mapped address | ||
| */ | ||
| isIPv4MappedAddress() { | ||
| // First 80 bits (5 hextets) must be 0, 6th hextet must be 0xffff | ||
| return (__classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[0] === 0 | ||
| && __classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[1] === 0 | ||
| && __classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[2] === 0 | ||
| && __classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[3] === 0 | ||
| && __classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[4] === 0 | ||
| && __classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[5] === 0xffff); | ||
| } | ||
| /** | ||
| * Checks if the IPv6 address is a documentation address (2001:db8::/32) | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("2001:db8::1").isDocumentationAddress(); // true | ||
| * ipv6.address("2001:db8:1234::1").isDocumentationAddress(); // true | ||
| * ipv6.address("2001:470::1").isDocumentationAddress(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if the IPv6 address is a documentation address | ||
| */ | ||
| isDocumentationAddress() { | ||
| return __classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[0] === 0x2001 && __classPrivateFieldGet(this, _Ipv6Address_hextets, "f")[1] === 0x0db8; | ||
| } | ||
| } | ||
| _Ipv6Address_hextets = new WeakMap(); | ||
| export { Ipv6Address }; | ||
| //# sourceMappingURL=ipv6-address.js.map |
| {"version":3,"file":"ipv6-address.js","sources":["../../../src/ipv6-address.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDG;MACU,WAAW,CAAA;AAGtB,IAAA,WAAA,CAAY,EAAsB,EAAA;QAFlC,oBAAA,CAAA,GAA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A,sBAAA,CAAA,IAAI,EAAA,oBAAA,EAAA,GAAA,CAAS,CAAC,CAAC,CAAC,KAAK;AACrB,eAAA,sBAAA,CAAA,IAAI,EAAA,oBAAA,EAAA,GAAA,CAAS,CAAC,CAAC,CAAC,KAAK;AACrB,eAAA,sBAAA,CAAA,IAAI,EAAA,oBAAA,EAAA,GAAA,CAAS,CAAC,CAAC,CAAC,KAAK;AACrB,eAAA,sBAAA,CAAA,IAAI,EAAA,oBAAA,EAAA,GAAA,CAAS,CAAC,CAAC,CAAC,KAAK;eACrB,sBAAA,CAAA,IAAI,4BAAS,CAAC,CAAC,CAAC,KAAK,MAAM;IAElC;AAEA;;;;;;;;;;;;;AAaG;IACI,sBAAsB,GAAA;AAC3B,QAAA,OAAO,uBAAA,IAAI,EAAA,oBAAA,EAAA,GAAA,CAAS,CAAC,CAAC,CAAC,KAAK,MAAM,IAAI,sBAAA,CAAA,IAAI,EAAA,oBAAA,EAAA,GAAA,CAAS,CAAC,CAAC,CAAC,KAAK,MAAM;IACnE;AACD;;;;;"} |
| import { Ipv6Address } from './ipv6-address'; | ||
| import type { Ipv6CidrLiteral } from './ipv6-types'; | ||
| /** | ||
| * Represents an IPv6 CIDR block with utility methods for subnet operations. | ||
| * | ||
| * While you can instantiate this class directly, it is recommended to use the | ||
| * {@link ipv6.cidr} shorthand method from the `ipv6` namespace instead. | ||
| * | ||
| * @example Creating CIDR blocks (prefer the shorthand) | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * // Recommended: use the ipv6 namespace shorthand | ||
| * const cidr1 = ipv6.cidr("2001:db8::/32"); | ||
| * const cidr2 = ipv6.cidr({ address: "2001:db8::", range: 32 }); | ||
| * const cidr3 = ipv6.cidr(["2001:db8::", 32]); | ||
| * ``` | ||
| * | ||
| * @example Getting CIDR properties | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.baseAddress().toString(); // "2001:db8::" | ||
| * cidr.range(); // 32 | ||
| * cidr.netmask().toString(); // "ffff:ffff::" | ||
| * cidr.addressCount(); // 79228162514264337593543950336n | ||
| * ``` | ||
| * | ||
| * @example Working with usable addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/126"); | ||
| * cidr.getFirstUsableAddress()?.toString(); // "2001:db8::1" | ||
| * cidr.getLastUsableAddress()?.toString(); // "2001:db8::2" | ||
| * ``` | ||
| * | ||
| * @example Checking containment and overlap | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.includes(ipv6.address("2001:db8::1")); // true | ||
| * cidr.includes(ipv6.address("2001:db9::1")); // false | ||
| * cidr.overlaps("2001:db8::/48"); // true | ||
| * cidr.overlaps("2001:db9::/32"); // false | ||
| * ``` | ||
| * | ||
| * @example Splitting into subranges | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * | ||
| * // Split into equal /48 subnets | ||
| * cidr.subnet(34).map(s => s.toString()); | ||
| * // ["2001:db8::/34", "2001:db8:4000::/34", "2001:db8:8000::/34", "2001:db8:c000::/34"] | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential CIDRs | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.nextCIDR()?.toString(); // "2001:db9::/32" | ||
| * cidr.previousCIDR()?.toString(); // "2001:db7::/32" | ||
| * ``` | ||
| */ | ||
| export declare class Ipv6Cidr { | ||
| #private; | ||
| constructor(address: Ipv6CidrLiteral); | ||
| /** | ||
| * Gets the base IPv6 address of the CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.baseAddress().toString(); // "2001:db8::" | ||
| * ``` | ||
| * | ||
| * @returns The base IPv6 address. | ||
| */ | ||
| baseAddress(): Ipv6Address; | ||
| /** | ||
| * Gets the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.range(); // 32 | ||
| * ``` | ||
| * | ||
| * @returns The CIDR range as a number. | ||
| */ | ||
| range(): number; | ||
| /** | ||
| * Calculates the netmask for the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.cidr("2001:db8::/32").netmask().toString(); // "ffff:ffff::" | ||
| * ipv6.cidr("2001:db8::/64").netmask().toString(); // "ffff:ffff:ffff:ffff::" | ||
| * ipv6.cidr("2001:db8::/128").netmask().toString(); // "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" | ||
| * ``` | ||
| * | ||
| * @returns The netmask as an Ipv6Address. | ||
| */ | ||
| netmask(): Ipv6Address; | ||
| /** | ||
| * Returns the string representation of the IPv6 CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr({ address: "2001:db8::", range: 32 }); | ||
| * cidr.toString(); // "2001:db8::/32" | ||
| * ``` | ||
| * | ||
| * @returns The IPv6 CIDR as a string (example: "2001:db8::/32"). | ||
| */ | ||
| toString(): string; | ||
| /** | ||
| * Gets the address and range parts of the IPv6 CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const [address, range] = ipv6.cidr("2001:db8::/32").rangeParts(); | ||
| * address.toString(); // "2001:db8::" | ||
| * range; // 32 | ||
| * ``` | ||
| * | ||
| * @returns A tuple containing the IPv6 address and the CIDR range. | ||
| */ | ||
| rangeParts(): [Ipv6Address, number]; | ||
| /** | ||
| * Calculates the total number of addresses in the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.cidr("2001:db8::/64").addressCount(); // 18446744073709551616n | ||
| * ipv6.cidr("2001:db8::/128").addressCount(); // 1n | ||
| * ipv6.cidr("2001:db8::/126").addressCount(); // 4n | ||
| * ``` | ||
| * | ||
| * @returns The total number of addresses in the CIDR range as a BigInt. | ||
| */ | ||
| addressCount(): bigint; | ||
| /** | ||
| * Generates IPv6 addresses within the CIDR range. | ||
| * Note: For large CIDR ranges, this may generate an extremely large number of addresses. | ||
| * Use with caution and consider using a limit parameter. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/126"); | ||
| * for (const addr of cidr.addresses()) { | ||
| * console.log(addr.toString()); | ||
| * } | ||
| * // Output: "2001:db8::", "2001:db8::1", "2001:db8::2", "2001:db8::3" | ||
| * ``` | ||
| * | ||
| * @param limit - Optional maximum number of addresses to generate (defaults to all addresses). | ||
| * @returns A generator that yields each IPv6 address in the CIDR range. | ||
| */ | ||
| addresses(limit?: bigint): Generator<Ipv6Address>; | ||
| /** | ||
| * Checks if this CIDR is equal to another CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.equals("2001:db8::/32"); // true | ||
| * cidr.equals({ address: "2001:db8::", range: 32 }); // true | ||
| * cidr.equals("2001:db8::/48"); // false | ||
| * ``` | ||
| * | ||
| * @param other - The other IPv6 CIDR to compare with. | ||
| * @returns True if both CIDRs have the same base address and range; otherwise, false. | ||
| */ | ||
| equals(other: Ipv6Cidr | Ipv6CidrLiteral): boolean; | ||
| /** | ||
| * Checks if there is a next sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.cidr("2001:db8::/32").hasNextCIDR(); // true | ||
| * ipv6.cidr("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00/120").hasNextCIDR(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a next CIDR. | ||
| */ | ||
| hasNextCIDR(): boolean; | ||
| /** | ||
| * Gets the next sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.nextCIDR()?.toString(); // "2001:db9::/32" | ||
| * ``` | ||
| * | ||
| * @returns The next CIDR, or undefined if there is no next CIDR. | ||
| */ | ||
| nextCIDR(): Ipv6Cidr | undefined; | ||
| /** | ||
| * Checks if there is a previous sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.cidr("2001:db8::/32").hasPreviousCIDR(); // true | ||
| * ipv6.cidr("::/32").hasPreviousCIDR(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a previous CIDR. | ||
| */ | ||
| hasPreviousCIDR(): boolean; | ||
| /** | ||
| * Gets the previous sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.previousCIDR()?.toString(); // "2001:db7::/32" | ||
| * | ||
| * const firstCidr = ipv6.cidr("::/32"); | ||
| * firstCidr.previousCIDR(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The previous CIDR, or undefined if there is no previous CIDR. | ||
| */ | ||
| previousCIDR(): Ipv6Cidr | undefined; | ||
| /** | ||
| * Gets the first usable address in the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/64"); | ||
| * cidr.getFirstUsableAddress()?.toString(); // "2001:db8::1" | ||
| * | ||
| * const hostCidr = ipv6.cidr("2001:db8::1/128"); | ||
| * hostCidr.getFirstUsableAddress(); // undefined (no usable addresses in /128) | ||
| * ``` | ||
| * | ||
| * @returns The first usable IPv6 address, or undefined if the range is /128. | ||
| */ | ||
| getFirstUsableAddress(): Ipv6Address | undefined; | ||
| /** | ||
| * Gets the last usable address in the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/126"); | ||
| * cidr.getLastUsableAddress()?.toString(); // "2001:db8::2" | ||
| * | ||
| * const hostCidr = ipv6.cidr("2001:db8::1/128"); | ||
| * hostCidr.getLastUsableAddress(); // undefined (no usable addresses in /128) | ||
| * ``` | ||
| * | ||
| * @returns The last usable IPv6 address, or undefined if the range is /128. | ||
| */ | ||
| getLastUsableAddress(): Ipv6Address | undefined; | ||
| /** | ||
| * Checks if the given IPv6 address is within the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.includes(ipv6.address("2001:db8::1")); // true | ||
| * cidr.includes(ipv6.address("2001:db9::1")); // false | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv6 address to check. | ||
| * @returns True if the address is within the CIDR range; otherwise, false. | ||
| */ | ||
| includes(ip: Ipv6Address): boolean; | ||
| /** | ||
| * Checks if this CIDR overlaps with another CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.overlaps("2001:db8::/48"); // true (subset) | ||
| * cidr.overlaps("2001:db8:8000::/33"); // true (partial overlap) | ||
| * cidr.overlaps("2001:db9::/32"); // false (no overlap) | ||
| * ``` | ||
| * | ||
| * @param other - The other IPv6 CIDR to check for overlap. | ||
| * @returns True if the CIDRs overlap; otherwise, false. | ||
| */ | ||
| overlaps(other: Ipv6Cidr | Ipv6CidrLiteral): boolean; | ||
| /** | ||
| * Splits the CIDR into smaller subranges of the specified new range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * const subnets = cidr.subnet(34); | ||
| * subnets.map(s => s.toString()); | ||
| * // ["2001:db8::/34", "2001:db8:4000::/34", "2001:db8:8000::/34", "2001:db8:c000::/34"] | ||
| * ``` | ||
| * | ||
| * @param newRange - The new CIDR range for the subnets. | ||
| * @returns An array of Ipv6Cidr instances representing the subnets. | ||
| * @throws InvalidIpv6CidrRangeError if the new range is less than the current range or greater than the maximum range. | ||
| */ | ||
| subnet(newRange: number): Ipv6Cidr[]; | ||
| /** | ||
| * Splits the CIDR into sequential subranges with the specified CIDR ranges. | ||
| * Each range in the input array creates a subrange starting where the previous one ended. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * const subnets = cidr.subnetBy([48, 36, 48]); | ||
| * subnets.map(s => s.toString()); | ||
| * // ["2001:db8::/48", "2001:db8:1::/36", "2001:db8:1100::/48"] | ||
| * ``` | ||
| * | ||
| * @param ranges - An array of CIDR range values (e.g., [48, 36, 48]). | ||
| * @returns An array of Ipv6Cidr instances representing the subnets. | ||
| * @throws InvalidIpv6CidrRangeError if any range is less than the current range or greater than 128. | ||
| */ | ||
| subnetBy(ranges: number[]): Ipv6Cidr[]; | ||
| } | ||
| //# sourceMappingURL=ipv6-cidr.d.ts.map |
| {"version":3,"file":"ipv6-cidr.d.ts","sourceRoot":"","sources":["../../src/ipv6-cidr.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,O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,OAAO;IAS3D;;;;;;;;;;;;;;;;OAgBG;IACI,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,EAAE;IAoB3C;;;;;;;;;;;;;;;;;OAiBG;IACI,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE;CA0B9C"} |
| import { __classPrivateFieldSet, __classPrivateFieldGet } from '/Users/brandon/cidr-block/node_modules/tslib/tslib.es6.js'; | ||
| import { ipv6 } from './ipv6.js'; | ||
| import { Ipv6Address } from './ipv6-address.js'; | ||
| import { InvalidIpv6CidrError, InvalidIpv6CidrRangeError } from './ipv6-errors.js'; | ||
| var _Ipv6Cidr_address, _Ipv6Cidr_range; | ||
| /** | ||
| * Represents an IPv6 CIDR block with utility methods for subnet operations. | ||
| * | ||
| * While you can instantiate this class directly, it is recommended to use the | ||
| * {@link ipv6.cidr} shorthand method from the `ipv6` namespace instead. | ||
| * | ||
| * @example Creating CIDR blocks (prefer the shorthand) | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * // Recommended: use the ipv6 namespace shorthand | ||
| * const cidr1 = ipv6.cidr("2001:db8::/32"); | ||
| * const cidr2 = ipv6.cidr({ address: "2001:db8::", range: 32 }); | ||
| * const cidr3 = ipv6.cidr(["2001:db8::", 32]); | ||
| * ``` | ||
| * | ||
| * @example Getting CIDR properties | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.baseAddress().toString(); // "2001:db8::" | ||
| * cidr.range(); // 32 | ||
| * cidr.netmask().toString(); // "ffff:ffff::" | ||
| * cidr.addressCount(); // 79228162514264337593543950336n | ||
| * ``` | ||
| * | ||
| * @example Working with usable addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/126"); | ||
| * cidr.getFirstUsableAddress()?.toString(); // "2001:db8::1" | ||
| * cidr.getLastUsableAddress()?.toString(); // "2001:db8::2" | ||
| * ``` | ||
| * | ||
| * @example Checking containment and overlap | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.includes(ipv6.address("2001:db8::1")); // true | ||
| * cidr.includes(ipv6.address("2001:db9::1")); // false | ||
| * cidr.overlaps("2001:db8::/48"); // true | ||
| * cidr.overlaps("2001:db9::/32"); // false | ||
| * ``` | ||
| * | ||
| * @example Splitting into subranges | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * | ||
| * // Split into equal /48 subnets | ||
| * cidr.subnet(34).map(s => s.toString()); | ||
| * // ["2001:db8::/34", "2001:db8:4000::/34", "2001:db8:8000::/34", "2001:db8:c000::/34"] | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential CIDRs | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.nextCIDR()?.toString(); // "2001:db9::/32" | ||
| * cidr.previousCIDR()?.toString(); // "2001:db7::/32" | ||
| * ``` | ||
| */ | ||
| class Ipv6Cidr { | ||
| constructor(address) { | ||
| _Ipv6Cidr_address.set(this, void 0); | ||
| _Ipv6Cidr_range.set(this, void 0); | ||
| if (!ipv6.isValidCIDR(address)) { | ||
| throw new InvalidIpv6CidrError(address); | ||
| } | ||
| if (typeof address === 'string') { | ||
| const [ip, rangeStr] = address.split('/'); | ||
| __classPrivateFieldSet(this, _Ipv6Cidr_address, new Ipv6Address(ip), "f"); | ||
| __classPrivateFieldSet(this, _Ipv6Cidr_range, Number.parseInt(rangeStr, 10), "f"); | ||
| } | ||
| else if (Array.isArray(address)) { | ||
| __classPrivateFieldSet(this, _Ipv6Cidr_address, new Ipv6Address(address[0]), "f"); | ||
| __classPrivateFieldSet(this, _Ipv6Cidr_range, address[1], "f"); | ||
| } | ||
| else if (typeof address === 'object' && address !== null) { | ||
| __classPrivateFieldSet(this, _Ipv6Cidr_address, new Ipv6Address(address.address), "f"); | ||
| __classPrivateFieldSet(this, _Ipv6Cidr_range, address.range, "f"); | ||
| } | ||
| else { | ||
| throw new InvalidIpv6CidrError(address); | ||
| } | ||
| } | ||
| /** | ||
| * Gets the base IPv6 address of the CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.baseAddress().toString(); // "2001:db8::" | ||
| * ``` | ||
| * | ||
| * @returns The base IPv6 address. | ||
| */ | ||
| baseAddress() { | ||
| return __classPrivateFieldGet(this, _Ipv6Cidr_address, "f"); | ||
| } | ||
| /** | ||
| * Gets the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.range(); // 32 | ||
| * ``` | ||
| * | ||
| * @returns The CIDR range as a number. | ||
| */ | ||
| range() { | ||
| return __classPrivateFieldGet(this, _Ipv6Cidr_range, "f"); | ||
| } | ||
| /** | ||
| * Calculates the netmask for the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.cidr("2001:db8::/32").netmask().toString(); // "ffff:ffff::" | ||
| * ipv6.cidr("2001:db8::/64").netmask().toString(); // "ffff:ffff:ffff:ffff::" | ||
| * ipv6.cidr("2001:db8::/128").netmask().toString(); // "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" | ||
| * ``` | ||
| * | ||
| * @returns The netmask as an Ipv6Address. | ||
| */ | ||
| netmask() { | ||
| if (__classPrivateFieldGet(this, _Ipv6Cidr_range, "f") === 0) { | ||
| return new Ipv6Address(0n); | ||
| } | ||
| // Create a mask with `range` 1-bits followed by (128 - range) 0-bits | ||
| const mask = (1n << 128n) - (1n << BigInt(128 - __classPrivateFieldGet(this, _Ipv6Cidr_range, "f"))); | ||
| return new Ipv6Address(mask); | ||
| } | ||
| /** | ||
| * Returns the string representation of the IPv6 CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr({ address: "2001:db8::", range: 32 }); | ||
| * cidr.toString(); // "2001:db8::/32" | ||
| * ``` | ||
| * | ||
| * @returns The IPv6 CIDR as a string (example: "2001:db8::/32"). | ||
| */ | ||
| toString() { | ||
| return `${__classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toString()}/${__classPrivateFieldGet(this, _Ipv6Cidr_range, "f")}`; | ||
| } | ||
| /** | ||
| * Gets the address and range parts of the IPv6 CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const [address, range] = ipv6.cidr("2001:db8::/32").rangeParts(); | ||
| * address.toString(); // "2001:db8::" | ||
| * range; // 32 | ||
| * ``` | ||
| * | ||
| * @returns A tuple containing the IPv6 address and the CIDR range. | ||
| */ | ||
| rangeParts() { | ||
| return [__classPrivateFieldGet(this, _Ipv6Cidr_address, "f"), __classPrivateFieldGet(this, _Ipv6Cidr_range, "f")]; | ||
| } | ||
| /** | ||
| * Calculates the total number of addresses in the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.cidr("2001:db8::/64").addressCount(); // 18446744073709551616n | ||
| * ipv6.cidr("2001:db8::/128").addressCount(); // 1n | ||
| * ipv6.cidr("2001:db8::/126").addressCount(); // 4n | ||
| * ``` | ||
| * | ||
| * @returns The total number of addresses in the CIDR range as a BigInt. | ||
| */ | ||
| addressCount() { | ||
| return 1n << BigInt(128 - __classPrivateFieldGet(this, _Ipv6Cidr_range, "f")); | ||
| } | ||
| /** | ||
| * Generates IPv6 addresses within the CIDR range. | ||
| * Note: For large CIDR ranges, this may generate an extremely large number of addresses. | ||
| * Use with caution and consider using a limit parameter. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/126"); | ||
| * for (const addr of cidr.addresses()) { | ||
| * console.log(addr.toString()); | ||
| * } | ||
| * // Output: "2001:db8::", "2001:db8::1", "2001:db8::2", "2001:db8::3" | ||
| * ``` | ||
| * | ||
| * @param limit - Optional maximum number of addresses to generate (defaults to all addresses). | ||
| * @returns A generator that yields each IPv6 address in the CIDR range. | ||
| */ | ||
| *addresses(limit) { | ||
| const baseBigInt = __classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt(); | ||
| const count = this.addressCount(); | ||
| const maxIterations = limit !== undefined && limit < count ? limit : count; | ||
| for (let i = 0n; i < maxIterations; i++) { | ||
| yield new Ipv6Address(baseBigInt + i); | ||
| } | ||
| } | ||
| /** | ||
| * Checks if this CIDR is equal to another CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.equals("2001:db8::/32"); // true | ||
| * cidr.equals({ address: "2001:db8::", range: 32 }); // true | ||
| * cidr.equals("2001:db8::/48"); // false | ||
| * ``` | ||
| * | ||
| * @param other - The other IPv6 CIDR to compare with. | ||
| * @returns True if both CIDRs have the same base address and range; otherwise, false. | ||
| */ | ||
| equals(other) { | ||
| const otherCidr = other instanceof Ipv6Cidr ? other : new Ipv6Cidr(other); | ||
| return __classPrivateFieldGet(this, _Ipv6Cidr_address, "f").equals(__classPrivateFieldGet(otherCidr, _Ipv6Cidr_address, "f")) && __classPrivateFieldGet(this, _Ipv6Cidr_range, "f") === __classPrivateFieldGet(otherCidr, _Ipv6Cidr_range, "f"); | ||
| } | ||
| /** | ||
| * Checks if there is a next sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.cidr("2001:db8::/32").hasNextCIDR(); // true | ||
| * ipv6.cidr("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00/120").hasNextCIDR(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a next CIDR. | ||
| */ | ||
| hasNextCIDR() { | ||
| const nextBaseBigInt = __classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt() + this.addressCount(); | ||
| return nextBaseBigInt <= ipv6.MAX_SIZE; | ||
| } | ||
| /** | ||
| * Gets the next sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.nextCIDR()?.toString(); // "2001:db9::/32" | ||
| * ``` | ||
| * | ||
| * @returns The next CIDR, or undefined if there is no next CIDR. | ||
| */ | ||
| nextCIDR() { | ||
| const nextBaseBigInt = __classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt() + this.addressCount(); | ||
| if (nextBaseBigInt > ipv6.MAX_SIZE) { | ||
| return undefined; | ||
| } | ||
| return new Ipv6Cidr([nextBaseBigInt, __classPrivateFieldGet(this, _Ipv6Cidr_range, "f")]); | ||
| } | ||
| /** | ||
| * Checks if there is a previous sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.cidr("2001:db8::/32").hasPreviousCIDR(); // true | ||
| * ipv6.cidr("::/32").hasPreviousCIDR(); // false | ||
| * ``` | ||
| * | ||
| * @returns true if there is a previous CIDR. | ||
| */ | ||
| hasPreviousCIDR() { | ||
| return __classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt() >= this.addressCount(); | ||
| } | ||
| /** | ||
| * Gets the previous sequential CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.previousCIDR()?.toString(); // "2001:db7::/32" | ||
| * | ||
| * const firstCidr = ipv6.cidr("::/32"); | ||
| * firstCidr.previousCIDR(); // undefined | ||
| * ``` | ||
| * | ||
| * @returns The previous CIDR, or undefined if there is no previous CIDR. | ||
| */ | ||
| previousCIDR() { | ||
| const prevBaseBigInt = __classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt() - this.addressCount(); | ||
| if (prevBaseBigInt < ipv6.MIN_SIZE) { | ||
| return undefined; | ||
| } | ||
| return new Ipv6Cidr([prevBaseBigInt, __classPrivateFieldGet(this, _Ipv6Cidr_range, "f")]); | ||
| } | ||
| /** | ||
| * Gets the first usable address in the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/64"); | ||
| * cidr.getFirstUsableAddress()?.toString(); // "2001:db8::1" | ||
| * | ||
| * const hostCidr = ipv6.cidr("2001:db8::1/128"); | ||
| * hostCidr.getFirstUsableAddress(); // undefined (no usable addresses in /128) | ||
| * ``` | ||
| * | ||
| * @returns The first usable IPv6 address, or undefined if the range is /128. | ||
| */ | ||
| getFirstUsableAddress() { | ||
| if (__classPrivateFieldGet(this, _Ipv6Cidr_range, "f") === 128) { | ||
| return undefined; | ||
| } | ||
| const firstUsableBigInt = __classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt() + 1n; | ||
| return new Ipv6Address(firstUsableBigInt); | ||
| } | ||
| /** | ||
| * Gets the last usable address in the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/126"); | ||
| * cidr.getLastUsableAddress()?.toString(); // "2001:db8::2" | ||
| * | ||
| * const hostCidr = ipv6.cidr("2001:db8::1/128"); | ||
| * hostCidr.getLastUsableAddress(); // undefined (no usable addresses in /128) | ||
| * ``` | ||
| * | ||
| * @returns The last usable IPv6 address, or undefined if the range is /128. | ||
| */ | ||
| getLastUsableAddress() { | ||
| if (__classPrivateFieldGet(this, _Ipv6Cidr_range, "f") === 128) { | ||
| return undefined; | ||
| } | ||
| const lastUsableBigInt = __classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt() + this.addressCount() - 2n; | ||
| return new Ipv6Address(lastUsableBigInt); | ||
| } | ||
| /** | ||
| * Checks if the given IPv6 address is within the CIDR range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.includes(ipv6.address("2001:db8::1")); // true | ||
| * cidr.includes(ipv6.address("2001:db9::1")); // false | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv6 address to check. | ||
| * @returns True if the address is within the CIDR range; otherwise, false. | ||
| */ | ||
| includes(ip) { | ||
| const ipBigInt = ip.toBigInt(); | ||
| const baseBigInt = __classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt(); | ||
| const count = this.addressCount(); | ||
| return ipBigInt >= baseBigInt && ipBigInt < baseBigInt + count; | ||
| } | ||
| /** | ||
| * Checks if this CIDR overlaps with another CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.overlaps("2001:db8::/48"); // true (subset) | ||
| * cidr.overlaps("2001:db8:8000::/33"); // true (partial overlap) | ||
| * cidr.overlaps("2001:db9::/32"); // false (no overlap) | ||
| * ``` | ||
| * | ||
| * @param other - The other IPv6 CIDR to check for overlap. | ||
| * @returns True if the CIDRs overlap; otherwise, false. | ||
| */ | ||
| overlaps(other) { | ||
| const otherCidr = other instanceof Ipv6Cidr ? other : new Ipv6Cidr(other); | ||
| const thisBase = __classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt(); | ||
| const thisCount = this.addressCount(); | ||
| const otherBase = __classPrivateFieldGet(otherCidr, _Ipv6Cidr_address, "f").toBigInt(); | ||
| const otherCount = otherCidr.addressCount(); | ||
| return thisBase < otherBase + otherCount && otherBase < thisBase + thisCount; | ||
| } | ||
| /** | ||
| * Splits the CIDR into smaller subranges of the specified new range. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * const subnets = cidr.subnet(34); | ||
| * subnets.map(s => s.toString()); | ||
| * // ["2001:db8::/34", "2001:db8:4000::/34", "2001:db8:8000::/34", "2001:db8:c000::/34"] | ||
| * ``` | ||
| * | ||
| * @param newRange - The new CIDR range for the subnets. | ||
| * @returns An array of Ipv6Cidr instances representing the subnets. | ||
| * @throws InvalidIpv6CidrRangeError if the new range is less than the current range or greater than the maximum range. | ||
| */ | ||
| subnet(newRange) { | ||
| if (newRange < __classPrivateFieldGet(this, _Ipv6Cidr_range, "f") || newRange > ipv6.MAX_RANGE) { | ||
| throw new InvalidIpv6CidrRangeError(`New range ${newRange} must be between current range ${__classPrivateFieldGet(this, _Ipv6Cidr_range, "f")} and ${ipv6.MAX_RANGE}`); | ||
| } | ||
| const subranges = []; | ||
| const totalSubnets = 1n << BigInt(newRange - __classPrivateFieldGet(this, _Ipv6Cidr_range, "f")); | ||
| const baseBigInt = __classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt(); | ||
| const subnetSize = 1n << BigInt(128 - newRange); | ||
| for (let i = 0n; i < totalSubnets; i++) { | ||
| const subnetBaseBigInt = baseBigInt + i * subnetSize; | ||
| subranges.push(new Ipv6Cidr([subnetBaseBigInt, newRange])); | ||
| } | ||
| return subranges; | ||
| } | ||
| /** | ||
| * Splits the CIDR into sequential subranges with the specified CIDR ranges. | ||
| * Each range in the input array creates a subrange starting where the previous one ended. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * const subnets = cidr.subnetBy([48, 36, 48]); | ||
| * subnets.map(s => s.toString()); | ||
| * // ["2001:db8::/48", "2001:db8:1::/36", "2001:db8:1100::/48"] | ||
| * ``` | ||
| * | ||
| * @param ranges - An array of CIDR range values (e.g., [48, 36, 48]). | ||
| * @returns An array of Ipv6Cidr instances representing the subnets. | ||
| * @throws InvalidIpv6CidrRangeError if any range is less than the current range or greater than 128. | ||
| */ | ||
| subnetBy(ranges) { | ||
| const subranges = []; | ||
| let currentBase = __classPrivateFieldGet(this, _Ipv6Cidr_address, "f").toBigInt(); | ||
| const endAddress = currentBase + this.addressCount(); | ||
| for (const range of ranges) { | ||
| if (range < __classPrivateFieldGet(this, _Ipv6Cidr_range, "f") || range > ipv6.MAX_RANGE) { | ||
| throw new InvalidIpv6CidrRangeError(`Range ${range} must be between current range ${__classPrivateFieldGet(this, _Ipv6Cidr_range, "f")} and ${ipv6.MAX_RANGE}`); | ||
| } | ||
| const subnetSize = 1n << BigInt(128 - range); | ||
| if (currentBase + subnetSize > endAddress) { | ||
| throw new InvalidIpv6CidrRangeError(`Subrange /${range} at ${new Ipv6Address(currentBase).toString()} exceeds the bounds of the parent CIDR`); | ||
| } | ||
| subranges.push(new Ipv6Cidr([currentBase, range])); | ||
| currentBase += subnetSize; | ||
| } | ||
| return subranges; | ||
| } | ||
| } | ||
| _Ipv6Cidr_address = new WeakMap(), _Ipv6Cidr_range = new WeakMap(); | ||
| export { Ipv6Cidr }; | ||
| //# sourceMappingURL=ipv6-cidr.js.map |
| {"version":3,"file":"ipv6-cidr.js","sources":["../../../src/ipv6-cidr.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEG;MACU,QAAQ,CAAA;AAInB,IAAA,WAAA,CAAY,OA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C,YAAA,IAAI,WAAW,GAAG,UAAU,GAAG,UAAU,EAAE;AACzC,gBAAA,MAAM,IAAI,yBAAyB,CACjC,CAAA,UAAA,EAAa,KAAK,OAAO,IAAI,WAAW,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAA,sCAAA,CAAwC,CACzG;YACH;AAEA,YAAA,SAAS,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;YAClD,WAAW,IAAI,UAAU;QAC3B;AAEA,QAAA,OAAO,SAAS;IAClB;AACD;;;;;"} |
| export declare class InvalidIpv6AddressError extends Error { | ||
| name: string; | ||
| constructor(invalidAddress: unknown); | ||
| } | ||
| export declare class InvalidIpv6CidrError extends Error { | ||
| name: string; | ||
| constructor(invalidCidr: unknown); | ||
| } | ||
| export declare class InvalidIpv6CidrRangeError extends Error { | ||
| name: string; | ||
| } | ||
| //# sourceMappingURL=ipv6-errors.d.ts.map |
| {"version":3,"file":"ipv6-errors.d.ts","sourceRoot":"","sources":["../../src/ipv6-errors.ts"],"names":[],"mappings":"AAAA,qBAAa,uBAAwB,SAAQ,KAAK;IACvC,IAAI,SAA4B;gBAE7B,cAAc,EAAE,OAAO;CAGpC;AAED,qBAAa,oBAAqB,SAAQ,KAAK;IACpC,IAAI,SAAyB;gBAE1B,WAAW,EAAE,OAAO;CAGjC;AAED,qBAAa,yBAA0B,SAAQ,KAAK;IACzC,IAAI,SAA0B;CACxC"} |
| class InvalidIpv6AddressError extends Error { | ||
| constructor(invalidAddress) { | ||
| super(`${invalidAddress} is not a valid IPv6 address`); | ||
| this.name = 'InvalidIpv6AddressError'; | ||
| } | ||
| } | ||
| class InvalidIpv6CidrError extends Error { | ||
| constructor(invalidCidr) { | ||
| super(`${invalidCidr} is not a valid IPv6 CIDR range`); | ||
| this.name = 'InvalidIpv6CidrError'; | ||
| } | ||
| } | ||
| class InvalidIpv6CidrRangeError extends Error { | ||
| constructor() { | ||
| super(...arguments); | ||
| this.name = 'InvalidIpv6RangeError'; | ||
| } | ||
| } | ||
| export { InvalidIpv6AddressError, InvalidIpv6CidrError, InvalidIpv6CidrRangeError }; | ||
| //# sourceMappingURL=ipv6-errors.js.map |
| {"version":3,"file":"ipv6-errors.js","sources":["../../../src/ipv6-errors.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAM,MAAO,uBAAwB,SAAQ,KAAK,CAAA;AAGhD,IAAA,WAAA,CAAY,cAAuB,EAAA;AACjC,QAAA,KAAK,CAAC,CAAA,EAAG,cAAc,CAAA,4BAAA,CAA8B,CAAC;QAH/C,IAAA,CAAA,IAAI,GAAG,yBAAyB;IAIzC;AACD;AAEK,MAAO,oBAAqB,SAAQ,KAAK,CAAA;AAG7C,IAAA,WAAA,CAAY,WAAoB,EAAA;AAC9B,QAAA,KAAK,CAAC,CAAA,EAAG,WAAW,CAAA,+BAAA,CAAiC,CAAC;QAH/C,IAAA,CAAA,IAAI,GAAG,sBAAsB;IAItC;AACD;AAEK,MAAO,yBAA0B,SAAQ,KAAK,CAAA;AAApD,IAAA,WAAA,GAAA;;QACW,IAAA,CAAA,IAAI,GAAG,uBAAuB;IACzC;AAAC;;;;"} |
| /** | ||
| * Represents an IPv6 address from a 'literal' value. | ||
| * Examples: | ||
| * - String: "2001:db8::1" | ||
| * - BigInt: 42540766411282592856903984951653826561n | ||
| * - Hextets Array: [0x2001, 0xdb8, 0, 0, 0, 0, 0, 1] | ||
| */ | ||
| export type Ipv6AddressLiteral = string | bigint | number[]; | ||
| /** | ||
| * Represents an IPv6 address as an array of eight 16-bit hextets. | ||
| */ | ||
| export type Ipv6AddressHextets = [number, number, number, number, number, number, number, number]; | ||
| /** | ||
| * Represents an IPv6 CIDR from a 'literal' value. | ||
| * Examples: | ||
| * - String: "2001:db8::/32" | ||
| * - Object: { address: "2001:db8::", range: 32 } | ||
| * - Tuple: ["2001:db8::", 32] | ||
| */ | ||
| export type Ipv6CidrLiteral = string | { | ||
| address: Ipv6AddressLiteral; | ||
| range: number; | ||
| } | [Ipv6AddressLiteral, number]; | ||
| //# sourceMappingURL=ipv6-types.d.ts.map |
| {"version":3,"file":"ipv6-types.d.ts","sourceRoot":"","sources":["../../src/ipv6-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;AAE3D;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAEjG;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GACvB,MAAM,GACN;IAAE,OAAO,EAAE,kBAAkB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC9C,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAA"} |
| import type { Ipv6AddressLiteral, Ipv6AddressHextets, Ipv6CidrLiteral } from './ipv6-types'; | ||
| import { Ipv6Address } from './ipv6-address'; | ||
| import { Ipv6Cidr } from './ipv6-cidr'; | ||
| export * from './ipv6-address'; | ||
| export * from './ipv6-cidr'; | ||
| export * from './ipv6-types'; | ||
| export * from './ipv6-errors'; | ||
| export declare namespace ipv6 { | ||
| /** | ||
| * The maximum possible value for an IPv6 address. | ||
| */ | ||
| const MAX_SIZE: bigint; | ||
| /** | ||
| * The minimum possible value for an IPv6 address. | ||
| */ | ||
| const MIN_SIZE = 0n; | ||
| /** | ||
| * The maximum CIDR range for IPv6 addresses. | ||
| */ | ||
| const MAX_RANGE = 128; | ||
| /** | ||
| * The minimum CIDR range for IPv6 addresses. | ||
| */ | ||
| const MIN_RANGE = 0; | ||
| /** | ||
| * Creates a new Ipv6Address instance from the given literal. | ||
| * Valid formats include string (with :: compression support), bigint, or hextets array. | ||
| * | ||
| * @example Creating addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr1 = ipv6.address("2001:db8::1"); | ||
| * const addr2 = ipv6.address(42540766411282592856903984951653826561n); | ||
| * const addr3 = ipv6.address([0x2001, 0xdb8, 0, 0, 0, 0, 0, 1]); | ||
| * ``` | ||
| * | ||
| * @example Converting between formats | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.toString(); // "2001:db8::1" (compressed) | ||
| * addr.toFullString(); // "2001:0db8:0000:0000:0000:0000:0000:0001" | ||
| * addr.toBigInt(); // 42540766411282592856903984951653826561n | ||
| * addr.hextets(); // [0x2001, 0xdb8, 0, 0, 0, 0, 0, 1] | ||
| * ``` | ||
| * | ||
| * @example Comparing addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.equals("2001:db8::1"); // true | ||
| * addr.isGreaterThan("2001:db8::"); // true | ||
| * addr.isLessThan("2001:db8::2"); // true | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.nextAddress()?.toString(); // "2001:db8::2" | ||
| * addr.previousAddress()?.toString(); // "2001:db8::" | ||
| * ``` | ||
| * | ||
| * @example Checking address types | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("::1").isLoopbackAddress(); // true | ||
| * ipv6.address("fc00::1").isUniqueLocalAddress(); // true | ||
| * ipv6.address("fe80::1").isLinkLocalAddress(); // true | ||
| * ipv6.address("ff02::1").isMulticastAddress(); // true | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv6 address in string, bigint, or hextets array format. | ||
| * @returns A new Ipv6Address instance. | ||
| * @throws {InvalidIpv6AddressError} If the input is not a valid IPv6 address. | ||
| */ | ||
| function address(ip: Ipv6AddressLiteral): Ipv6Address; | ||
| /** | ||
| * Creates a new Ipv6Cidr instance from the given literal. | ||
| * Valid formats include string, object, or tuple. | ||
| * | ||
| * @example Creating CIDR blocks | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr1 = ipv6.cidr("2001:db8::/32"); | ||
| * const cidr2 = ipv6.cidr({ address: "2001:db8::", range: 32 }); | ||
| * const cidr3 = ipv6.cidr(["2001:db8::", 32]); | ||
| * ``` | ||
| * | ||
| * @example Getting CIDR properties | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.baseAddress().toString(); // "2001:db8::" | ||
| * cidr.range(); // 32 | ||
| * cidr.netmask().toString(); // "ffff:ffff::" | ||
| * cidr.addressCount(); // 79228162514264337593543950336n | ||
| * ``` | ||
| * | ||
| * @example Working with usable addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/126"); | ||
| * cidr.getFirstUsableAddress()?.toString(); // "2001:db8::1" | ||
| * cidr.getLastUsableAddress()?.toString(); // "2001:db8::2" | ||
| * ``` | ||
| * | ||
| * @example Checking containment and overlap | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.includes(ipv6.address("2001:db8::1")); // true | ||
| * cidr.includes(ipv6.address("2001:db9::1")); // false | ||
| * cidr.overlaps("2001:db8::/48"); // true | ||
| * cidr.overlaps("2001:db9::/32"); // false | ||
| * ``` | ||
| * | ||
| * @example Splitting into subranges | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * | ||
| * // Split into equal /34 subnets | ||
| * cidr.subnet(34).map(s => s.toString()); | ||
| * // ["2001:db8::/34", "2001:db8:4000::/34", "2001:db8:8000::/34", "2001:db8:c000::/34"] | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential CIDRs | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.nextCIDR()?.toString(); // "2001:db9::/32" | ||
| * cidr.previousCIDR()?.toString(); // "2001:db7::/32" | ||
| * ``` | ||
| * | ||
| * @param cidr - The IPv6 CIDR in string, object, or tuple format. | ||
| * @returns A new Ipv6Cidr instance. | ||
| * @throws {InvalidIpv6CidrError} If the input is not a valid IPv6 CIDR. | ||
| */ | ||
| function cidr(cidr: Ipv6CidrLiteral): Ipv6Cidr; | ||
| /** | ||
| * Validates whether the given input is a valid IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.isValidAddress("2001:db8::1"); // true | ||
| * ipv6.isValidAddress("::"); // true | ||
| * ipv6.isValidAddress("::1"); // true | ||
| * ipv6.isValidAddress("gggg::1"); // false (invalid hex) | ||
| * ipv6.isValidAddress("2001:db8"); // false (incomplete) | ||
| * ipv6.isValidAddress([0x2001, 0xdb8, 0, 0, 0, 0, 0, 1]); // true | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv6 address to validate, which can be in string, bigint, or hextets array format. | ||
| * @returns True if the input is a valid IPv6 address; otherwise, false. | ||
| */ | ||
| function isValidAddress(ip: Ipv6AddressLiteral): boolean; | ||
| /** | ||
| * Validates whether the given input is a valid IPv6 CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.isValidCIDR("2001:db8::/32"); // true | ||
| * ipv6.isValidCIDR("2001:db8::/129"); // false (range out of bounds) | ||
| * ipv6.isValidCIDR({ address: "2001:db8::", range: 32 }); // true | ||
| * ipv6.isValidCIDR(["2001:db8::", 32]); // true | ||
| * ipv6.isValidCIDR("invalid/32"); // false | ||
| * ``` | ||
| * | ||
| * @param cidr - The IPv6 CIDR to validate, which can be in string, object, or tuple format. | ||
| * @returns True if the input is a valid IPv6 CIDR; otherwise, false. | ||
| */ | ||
| function isValidCIDR(cidr: Ipv6CidrLiteral): boolean; | ||
| /** | ||
| * Parses the given IPv6 address into its hextets representation. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.parseHextets("2001:db8::1"); // [0x2001, 0xdb8, 0, 0, 0, 0, 0, 1] | ||
| * ipv6.parseHextets("::"); // [0, 0, 0, 0, 0, 0, 0, 0] | ||
| * ipv6.parseHextets(42540766411282592856903984951653826561n); // [0x2001, 0xdb8, 0, 0, 0, 0, 0, 1] | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv6 address to parse, which can be in string, bigint, or hextets array format. | ||
| * @returns {Ipv6AddressHextets} An array of eight numbers representing the hextets of the IPv6 address. | ||
| * @throws {InvalidIpv6AddressError} If the input is not a valid IPv6 address. | ||
| */ | ||
| function parseHextets(ip: Ipv6AddressLiteral): Ipv6AddressHextets; | ||
| } | ||
| //# sourceMappingURL=ipv6.d.ts.map |
| {"version":3,"file":"ipv6.d.ts","sourceRoot":"","sources":["../../src/ipv6.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC3F,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAGtC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAE7B,yBAAiB,IAAI,CAAC;IACpB;;OAEG;IACI,MAAM,QAAQ,QAAoB,CAAA;IAEzC;;OAEG;IACI,MAAM,QAAQ,KAAK,CAAA;IAE1B;;OAEG;IACI,MAAM,SAAS,MAAM,CAAA;IAE5B;;OAEG;IACI,MAAM,SAAS,IAAI,CAAA;IAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwDG;IACH,SAAgB,OAAO,CAAC,EAAE,EAAE,kBAAkB,GAAG,WAAW,CAE3D;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmEG;IACH,SAAgB,IAAI,CAAC,IAAI,EAAE,eAAe,GAAG,QAAQ,CAEpD;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,SAAgB,cAAc,CAAC,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAqF9D;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,SAAgB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CA2D1D;IAED;;;;;;;;;;;;;;;OAeG;IACH,SAAgB,YAAY,CAAC,EAAE,EAAE,kBAAkB,GAAG,kBAAkB,CAiDvE;CACF"} |
+387
| import { Ipv6Address } from './ipv6-address.js'; | ||
| import { Ipv6Cidr } from './ipv6-cidr.js'; | ||
| import { InvalidIpv6AddressError } from './ipv6-errors.js'; | ||
| export { InvalidIpv6CidrError, InvalidIpv6CidrRangeError } from './ipv6-errors.js'; | ||
| var ipv6; | ||
| (function (ipv6) { | ||
| /** | ||
| * The maximum possible value for an IPv6 address. | ||
| */ | ||
| ipv6.MAX_SIZE = (1n << 128n) - 1n; | ||
| /** | ||
| * The minimum possible value for an IPv6 address. | ||
| */ | ||
| ipv6.MIN_SIZE = 0n; | ||
| /** | ||
| * The maximum CIDR range for IPv6 addresses. | ||
| */ | ||
| ipv6.MAX_RANGE = 128; | ||
| /** | ||
| * The minimum CIDR range for IPv6 addresses. | ||
| */ | ||
| ipv6.MIN_RANGE = 0; | ||
| /** | ||
| * Creates a new Ipv6Address instance from the given literal. | ||
| * Valid formats include string (with :: compression support), bigint, or hextets array. | ||
| * | ||
| * @example Creating addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr1 = ipv6.address("2001:db8::1"); | ||
| * const addr2 = ipv6.address(42540766411282592856903984951653826561n); | ||
| * const addr3 = ipv6.address([0x2001, 0xdb8, 0, 0, 0, 0, 0, 1]); | ||
| * ``` | ||
| * | ||
| * @example Converting between formats | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.toString(); // "2001:db8::1" (compressed) | ||
| * addr.toFullString(); // "2001:0db8:0000:0000:0000:0000:0000:0001" | ||
| * addr.toBigInt(); // 42540766411282592856903984951653826561n | ||
| * addr.hextets(); // [0x2001, 0xdb8, 0, 0, 0, 0, 0, 1] | ||
| * ``` | ||
| * | ||
| * @example Comparing addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.equals("2001:db8::1"); // true | ||
| * addr.isGreaterThan("2001:db8::"); // true | ||
| * addr.isLessThan("2001:db8::2"); // true | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const addr = ipv6.address("2001:db8::1"); | ||
| * addr.nextAddress()?.toString(); // "2001:db8::2" | ||
| * addr.previousAddress()?.toString(); // "2001:db8::" | ||
| * ``` | ||
| * | ||
| * @example Checking address types | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.address("::1").isLoopbackAddress(); // true | ||
| * ipv6.address("fc00::1").isUniqueLocalAddress(); // true | ||
| * ipv6.address("fe80::1").isLinkLocalAddress(); // true | ||
| * ipv6.address("ff02::1").isMulticastAddress(); // true | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv6 address in string, bigint, or hextets array format. | ||
| * @returns A new Ipv6Address instance. | ||
| * @throws {InvalidIpv6AddressError} If the input is not a valid IPv6 address. | ||
| */ | ||
| function address(ip) { | ||
| return new Ipv6Address(ip); | ||
| } | ||
| ipv6.address = address; | ||
| /** | ||
| * Creates a new Ipv6Cidr instance from the given literal. | ||
| * Valid formats include string, object, or tuple. | ||
| * | ||
| * @example Creating CIDR blocks | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr1 = ipv6.cidr("2001:db8::/32"); | ||
| * const cidr2 = ipv6.cidr({ address: "2001:db8::", range: 32 }); | ||
| * const cidr3 = ipv6.cidr(["2001:db8::", 32]); | ||
| * ``` | ||
| * | ||
| * @example Getting CIDR properties | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.baseAddress().toString(); // "2001:db8::" | ||
| * cidr.range(); // 32 | ||
| * cidr.netmask().toString(); // "ffff:ffff::" | ||
| * cidr.addressCount(); // 79228162514264337593543950336n | ||
| * ``` | ||
| * | ||
| * @example Working with usable addresses | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/126"); | ||
| * cidr.getFirstUsableAddress()?.toString(); // "2001:db8::1" | ||
| * cidr.getLastUsableAddress()?.toString(); // "2001:db8::2" | ||
| * ``` | ||
| * | ||
| * @example Checking containment and overlap | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.includes(ipv6.address("2001:db8::1")); // true | ||
| * cidr.includes(ipv6.address("2001:db9::1")); // false | ||
| * cidr.overlaps("2001:db8::/48"); // true | ||
| * cidr.overlaps("2001:db9::/32"); // false | ||
| * ``` | ||
| * | ||
| * @example Splitting into subranges | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * | ||
| * // Split into equal /34 subnets | ||
| * cidr.subnet(34).map(s => s.toString()); | ||
| * // ["2001:db8::/34", "2001:db8:4000::/34", "2001:db8:8000::/34", "2001:db8:c000::/34"] | ||
| * ``` | ||
| * | ||
| * @example Navigating sequential CIDRs | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * const cidr = ipv6.cidr("2001:db8::/32"); | ||
| * cidr.nextCIDR()?.toString(); // "2001:db9::/32" | ||
| * cidr.previousCIDR()?.toString(); // "2001:db7::/32" | ||
| * ``` | ||
| * | ||
| * @param cidr - The IPv6 CIDR in string, object, or tuple format. | ||
| * @returns A new Ipv6Cidr instance. | ||
| * @throws {InvalidIpv6CidrError} If the input is not a valid IPv6 CIDR. | ||
| */ | ||
| function cidr(cidr) { | ||
| return new Ipv6Cidr(cidr); | ||
| } | ||
| ipv6.cidr = cidr; | ||
| /** | ||
| * Validates whether the given input is a valid IPv6 address. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.isValidAddress("2001:db8::1"); // true | ||
| * ipv6.isValidAddress("::"); // true | ||
| * ipv6.isValidAddress("::1"); // true | ||
| * ipv6.isValidAddress("gggg::1"); // false (invalid hex) | ||
| * ipv6.isValidAddress("2001:db8"); // false (incomplete) | ||
| * ipv6.isValidAddress([0x2001, 0xdb8, 0, 0, 0, 0, 0, 1]); // true | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv6 address to validate, which can be in string, bigint, or hextets array format. | ||
| * @returns True if the input is a valid IPv6 address; otherwise, false. | ||
| */ | ||
| function isValidAddress(ip) { | ||
| if (ip === null || ip === undefined) { | ||
| return false; | ||
| } | ||
| if (typeof ip === 'bigint') { | ||
| return ip >= ipv6.MIN_SIZE && ip <= ipv6.MAX_SIZE; | ||
| } | ||
| if (Array.isArray(ip)) { | ||
| if (ip.length !== 8) { | ||
| return false; | ||
| } | ||
| for (const element of ip) { | ||
| if (typeof element !== 'number' | ||
| || !Number.isInteger(element) | ||
| || element < 0 | ||
| || element > 0xffff) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| if (typeof ip !== 'string') { | ||
| return false; | ||
| } | ||
| // Handle IPv4-mapped IPv6 addresses (::ffff:192.168.1.1) | ||
| const ipv4MappedMatch = ip.match(/^(::ffff:)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/i); | ||
| if (ipv4MappedMatch) { | ||
| const ipv4Part = ipv4MappedMatch[2]; | ||
| const octets = ipv4Part.split('.').map(Number); | ||
| if (octets.length !== 4) | ||
| return false; | ||
| for (const octet of octets) { | ||
| if (octet < 0 || octet > 255) | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| // Check for multiple :: which is invalid | ||
| const doubleColonCount = (ip.match(/::/g) || []).length; | ||
| if (doubleColonCount > 1) { | ||
| return false; | ||
| } | ||
| // Handle :: expansion | ||
| let expandedIp = ip; | ||
| if (ip.includes('::')) { | ||
| const parts = ip.split('::'); | ||
| const leftParts = parts[0] ? parts[0].split(':') : []; | ||
| const rightParts = parts[1] ? parts[1].split(':') : []; | ||
| const missingCount = 8 - leftParts.length - rightParts.length; | ||
| if (missingCount < 0) { | ||
| return false; | ||
| } | ||
| const middleParts = Array(missingCount).fill('0'); | ||
| expandedIp = [...leftParts, ...middleParts, ...rightParts].join(':'); | ||
| } | ||
| const hextets = expandedIp.split(':'); | ||
| if (hextets.length !== 8) { | ||
| return false; | ||
| } | ||
| for (const hextet of hextets) { | ||
| if (hextet === '' || hextet.length > 4) { | ||
| return false; | ||
| } | ||
| if (!/^[0-9a-fA-F]+$/.test(hextet)) { | ||
| return false; | ||
| } | ||
| const value = Number.parseInt(hextet, 16); | ||
| if (value < 0 || value > 0xffff) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| ipv6.isValidAddress = isValidAddress; | ||
| /** | ||
| * Validates whether the given input is a valid IPv6 CIDR. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.isValidCIDR("2001:db8::/32"); // true | ||
| * ipv6.isValidCIDR("2001:db8::/129"); // false (range out of bounds) | ||
| * ipv6.isValidCIDR({ address: "2001:db8::", range: 32 }); // true | ||
| * ipv6.isValidCIDR(["2001:db8::", 32]); // true | ||
| * ipv6.isValidCIDR("invalid/32"); // false | ||
| * ``` | ||
| * | ||
| * @param cidr - The IPv6 CIDR to validate, which can be in string, object, or tuple format. | ||
| * @returns True if the input is a valid IPv6 CIDR; otherwise, false. | ||
| */ | ||
| function isValidCIDR(cidr) { | ||
| if (cidr === null || cidr === undefined) { | ||
| return false; | ||
| } | ||
| let address; | ||
| let range; | ||
| if (typeof cidr === 'string') { | ||
| const parts = cidr.split('/'); | ||
| if (parts.length !== 2) { | ||
| return false; | ||
| } | ||
| address = parts[0]; | ||
| range = Number.parseInt(parts[1], 10); | ||
| } | ||
| else if (Array.isArray(cidr)) { | ||
| if (cidr.length !== 2) { | ||
| return false; | ||
| } | ||
| const [first, second] = cidr; | ||
| if (first === null || first === undefined) { | ||
| return false; | ||
| } | ||
| if (typeof second !== 'number') { | ||
| return false; | ||
| } | ||
| address = first; | ||
| range = second; | ||
| } | ||
| else if (typeof cidr === 'object') { | ||
| if (!('address' in cidr) || !('range' in cidr)) { | ||
| return false; | ||
| } | ||
| const { address: addr, range: r } = cidr; | ||
| if (addr === null || addr === undefined) { | ||
| return false; | ||
| } | ||
| if (typeof r !== 'number') { | ||
| return false; | ||
| } | ||
| address = addr; | ||
| range = r; | ||
| } | ||
| else { | ||
| return false; | ||
| } | ||
| if (address === undefined || !isValidAddress(address)) { | ||
| return false; | ||
| } | ||
| if (typeof range !== 'number' | ||
| || !Number.isInteger(range) | ||
| || range < ipv6.MIN_RANGE | ||
| || range > ipv6.MAX_RANGE) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| ipv6.isValidCIDR = isValidCIDR; | ||
| /** | ||
| * Parses the given IPv6 address into its hextets representation. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { ipv6 } from 'cidr-block'; | ||
| * | ||
| * ipv6.parseHextets("2001:db8::1"); // [0x2001, 0xdb8, 0, 0, 0, 0, 0, 1] | ||
| * ipv6.parseHextets("::"); // [0, 0, 0, 0, 0, 0, 0, 0] | ||
| * ipv6.parseHextets(42540766411282592856903984951653826561n); // [0x2001, 0xdb8, 0, 0, 0, 0, 0, 1] | ||
| * ``` | ||
| * | ||
| * @param ip - The IPv6 address to parse, which can be in string, bigint, or hextets array format. | ||
| * @returns {Ipv6AddressHextets} An array of eight numbers representing the hextets of the IPv6 address. | ||
| * @throws {InvalidIpv6AddressError} If the input is not a valid IPv6 address. | ||
| */ | ||
| function parseHextets(ip) { | ||
| if (!isValidAddress(ip)) { | ||
| throw new InvalidIpv6AddressError(ip); | ||
| } | ||
| if (typeof ip === 'bigint') { | ||
| const hextets = []; | ||
| let value = ip; | ||
| for (let i = 0; i < 8; i++) { | ||
| hextets.unshift(Number(value & 0xffffn)); | ||
| value = value >> 16n; | ||
| } | ||
| return hextets; | ||
| } | ||
| if (Array.isArray(ip)) { | ||
| return ip; | ||
| } | ||
| // Handle IPv4-mapped IPv6 addresses | ||
| const ipv4MappedMatch = ip.match(/^(::ffff:)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/i); | ||
| if (ipv4MappedMatch) { | ||
| const ipv4Part = ipv4MappedMatch[2]; | ||
| const octets = ipv4Part.split('.').map(Number); | ||
| return [ | ||
| 0, | ||
| 0, | ||
| 0, | ||
| 0, | ||
| 0, | ||
| 0xffff, | ||
| (octets[0] << 8) | octets[1], | ||
| (octets[2] << 8) | octets[3], | ||
| ]; | ||
| } | ||
| // Handle :: expansion | ||
| let expandedIp = ip; | ||
| if (ip.includes('::')) { | ||
| const parts = ip.split('::'); | ||
| const leftParts = parts[0] ? parts[0].split(':') : []; | ||
| const rightParts = parts[1] ? parts[1].split(':') : []; | ||
| const missingCount = 8 - leftParts.length - rightParts.length; | ||
| const middleParts = Array(missingCount).fill('0'); | ||
| expandedIp = [...leftParts, ...middleParts, ...rightParts].join(':'); | ||
| } | ||
| return expandedIp.split(':').map(h => Number.parseInt(h, 16)); | ||
| } | ||
| ipv6.parseHextets = parseHextets; | ||
| })(ipv6 || (ipv6 = {})); | ||
| export { InvalidIpv6AddressError, Ipv6Address, Ipv6Cidr, ipv6 }; | ||
| //# sourceMappingURL=ipv6.js.map |
| {"version":3,"file":"ipv6.js","sources":["../../../src/ipv6.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAUM,IAAW;AAAjB,CAAA,UAAiB,IAAI,EAAA;AACnB;;AAEG;IACU,IAAA,CAAA,QAAQ,GAAG,CAAC,EAAE,IAAI,IAAI,IAAI,EAAE;AAEzC;;AAEG;IACU,IAAA,CAAA,QAAQ,GAAG,EAAE;AAE1B;;AAEG;IACU,IAAA,CAAA,SAAS,GAAG,GAAG;AAE5B;;AAEG;IACU,IAAA,CAAA,SAAS,GAAG,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDG;IACH,SAAgB,OAAO,CAAC,EAAsB,EAAA;AAC5C,QAAA,OAAO,IAAI,WAAW,CAAC,EAAE,CAAC;IAC5B;AAFgB,IAAA,IAAA,CAAA,OAAO,UAEtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEG;IACH,SAAgB,IAAI,CAAC,IAAqB,EAAA;AACxC,QAAA,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC;IAC3B;AAFgB,IAAA,IAAA,CAAA,IAAI,OAEnB;AAED;;;;;;;;;;;;;;;;;AAiBG;IACH,SAAgB,cAAc,CAAC,EAAsB,EAAA;QACnD,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,SAAS,EAAE;AACnC,YAAA,OAAO,KAAK;QACd;AAEA,QAAA,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE;YAC1B,O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,CAAC,IAAI,CAAC,GAAG,CAAC;QACtE;QAEA,OAAO,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAuB;IACrF;AAjDgB,IAAA,IAAA,CAAA,YAAY,eAiD3B;AACH,CAAC,EAnZgB,IAAI,KAAJ,IAAI,GAAA,EAAA,CAAA,CAAA;;;;"} |
+41
-78
| { | ||
| "name": "cidr-block", | ||
| "description": "ipv4 and ipv6 address and cidr range utilities", | ||
| "version": "1.3.2", | ||
| "description": "IPv4 and IPv6 address and cidr range utilities", | ||
| "version": "2.0.0", | ||
| "license": "MIT", | ||
@@ -15,24 +15,33 @@ "author": "Brandon Burrus <brandon@burrus.io>", | ||
| }, | ||
| "main": "build/index.js", | ||
| "module": "build/index.esm.js", | ||
| "types": "build/index.d.ts", | ||
| "type": "module", | ||
| "main": "./dist/cjs/index.cjs", | ||
| "module": "./dist/esm/index.js", | ||
| "types": "./dist/esm/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "import": { | ||
| "types": "./dist/esm/index.d.ts", | ||
| "default": "./dist/esm/index.js" | ||
| }, | ||
| "require": { | ||
| "types": "./dist/cjs/index.d.cts", | ||
| "default": "./dist/cjs/index.cjs" | ||
| } | ||
| } | ||
| }, | ||
| "files": [ | ||
| "build" | ||
| "dist" | ||
| ], | ||
| "sideEffects": false, | ||
| "engines": { | ||
| "node": ">=16" | ||
| }, | ||
| "scripts": { | ||
| "prebuild": "rimraf dist", | ||
| "build": "rollup -c", | ||
| "build:watch": "rollup -cw", | ||
| "predocs": "rimraf docs", | ||
| "docs": "typedoc src/index.ts", | ||
| "lint": "eslint . --ext .ts", | ||
| "lint:fix": "eslint . --fix --ext .ts", | ||
| "format": "prettier --check **/*.ts", | ||
| "format:fix": "prettier --write **/*.ts", | ||
| "prebuild": "rimraf build", | ||
| "test": "jest", | ||
| "test:ci": "jest --verbose", | ||
| "test:cov": "jest --coverage", | ||
| "test:verbose": "jest --verbose", | ||
| "test:watch": "jest --watch", | ||
| "test:ui": "majestic" | ||
| "docgen": "typedoc", | ||
| "lint": "biome check", | ||
| "lint:fix": "biome check --fix", | ||
| "format": "biome format", | ||
| "format:fix": "biome format --fix" | ||
| }, | ||
@@ -54,62 +63,16 @@ "keywords": [ | ||
| "devDependencies": { | ||
| "@rollup/plugin-typescript": "^8.2.5", | ||
| "@types/jest": "^27.0.2", | ||
| "@types/node": "^16.10.3", | ||
| "@typescript-eslint/eslint-plugin": "^4.33.0", | ||
| "@typescript-eslint/parser": "^4.33.0", | ||
| "eslint": "^7.32.0", | ||
| "eslint-config-prettier": "^8.3.0", | ||
| "jest": "^27.2.5", | ||
| "majestic": "^1.8.1", | ||
| "prettier": "^2.4.1", | ||
| "rimraf": "^3.0.2", | ||
| "rollup": "^2.58.0", | ||
| "ts-jest": "^27.0.5", | ||
| "typedoc": "^0.22.5", | ||
| "typescript": "^4.4.3" | ||
| "@biomejs/biome": "^2.3.7", | ||
| "@rollup/plugin-node-resolve": "^16.0.3", | ||
| "@rollup/plugin-typescript": "^12.3.0", | ||
| "rimraf": "^6.1.2", | ||
| "rollup": "^4.53.3", | ||
| "rollup-plugin-dts": "^6.2.3", | ||
| "tslib": "^2.8.1", | ||
| "typedoc-github-theme": "^0.3.1", | ||
| "typescript": "^5.9.3", | ||
| "vitest": "^4.0.13" | ||
| }, | ||
| "jest": { | ||
| "preset": "ts-jest", | ||
| "testEnvironment": "node", | ||
| "transform": { | ||
| "^.+\\.ts$": "ts-jest" | ||
| }, | ||
| "collectCoverageFrom": [ | ||
| "<rootDir>/src/**/*" | ||
| ], | ||
| "coverageThreshold": { | ||
| "global": { | ||
| "branches": 100, | ||
| "functions": 100, | ||
| "lines": 100 | ||
| } | ||
| } | ||
| }, | ||
| "eslintConfig": { | ||
| "root": true, | ||
| "parser": "@typescript-eslint/parser", | ||
| "plugins": [ | ||
| "@typescript-eslint" | ||
| ], | ||
| "extends": [ | ||
| "eslint:recommended", | ||
| "plugin:@typescript-eslint/recommended" | ||
| ], | ||
| "rules": { | ||
| "@typescript-eslint/no-non-null-assertion": "off", | ||
| "prefer-const": "off" | ||
| } | ||
| }, | ||
| "prettier": { | ||
| "arrowParens": "avoid", | ||
| "bracketSameLine": true, | ||
| "bracketSpacing": true, | ||
| "jsxSingleQuote": true, | ||
| "printWidth": 100, | ||
| "quoteProps": "as-needed", | ||
| "semi": false, | ||
| "singleQuote": true, | ||
| "useTabs": false, | ||
| "trailingComma": "none" | ||
| "dependencies": { | ||
| "typedoc": "^0.28.14" | ||
| } | ||
| } |
+659
-34
@@ -1,9 +0,5 @@ | ||
| # cidr-block | ||
| IPv4 and IPv6 address and CIDR range utilities for JavaScript and TypeScript. | ||
| ipv4 and ipv6 address and cidr range utilities | ||
| ## Installation | ||
| To install npm package, run the following in your project: | ||
| ```bash | ||
@@ -13,57 +9,686 @@ npm install cidr-block | ||
| or if you're using yarn instead of npm | ||
| ## Features | ||
| ```bash | ||
| yarn add cidr-block | ||
| - Full IPv4 and IPv6 address support | ||
| - CIDR block creation and manipulation | ||
| - Address validation and parsing | ||
| - Network calculations (netmask, address count, usable addresses) | ||
| - Subnetting operations | ||
| - Address type detection (private, loopback, multicast, etc.) | ||
| - Full TypeScript support with comprehensive type definitions | ||
| - Zero dependencies | ||
| - Works with ESM and CommonJS | ||
| ## Quick Start | ||
| ```typescript | ||
| import { ipv4, ipv6 } from 'cidr-block'; | ||
| // Create and work with IPv4 addresses | ||
| const addr = ipv4.address('192.168.1.1'); | ||
| console.log(addr.isPrivateAddress()); // true | ||
| // Create and work with CIDR blocks | ||
| const cidr = ipv4.cidr('10.0.0.0/16'); | ||
| console.log(cidr.addressCount()); // 65536 | ||
| // IPv6 works the same way | ||
| const v6addr = ipv6.address('2001:db8::1'); | ||
| console.log(v6addr.toString()); // "2001:db8::1" | ||
| ``` | ||
| The package is written completely in TypeScript and exports all of it's types automatically, | ||
| meaning you don't need to install any additional `@types` typings. | ||
| ## API Reference | ||
| ## Getting Started | ||
| ### IPv4 | ||
| Start by defining a cidr range | ||
| #### Creating Addresses | ||
| ```typescript | ||
| import { ipv4 as ip } from 'cidr-block' | ||
| import { ipv4 } from 'cidr-block'; | ||
| const myCidr = ip.cidr('10.0.0.0/24') | ||
| // From string | ||
| const addr1 = ipv4.address('192.168.1.1'); | ||
| // From number | ||
| const addr2 = ipv4.address(3232235777); | ||
| // From octet array | ||
| const addr3 = ipv4.address([192, 168, 1, 1]); | ||
| ``` | ||
| To get the next logical cidr block | ||
| #### Address Validation | ||
| ```typescript | ||
| console.log(myCidr.nextBlock().toString()) // 10.0.1.0/24 | ||
| import { ipv4 } from 'cidr-block'; | ||
| ipv4.isValidAddress('192.168.1.1'); // true | ||
| ipv4.isValidAddress('256.1.1.1'); // false | ||
| ipv4.isValidAddress([10, 0, 0, 1]); // true | ||
| ipv4.isValidAddress(4294967295); // true (255.255.255.255) | ||
| ipv4.isValidAddress(4294967296); // false (exceeds max) | ||
| ``` | ||
| All `cidr-block` functions and methods are immutable, meaning a new instance will always be | ||
| returned instead of trying to modify the current value. | ||
| #### Address Conversion | ||
| Once you have a cidr, you have access to all of it's related utilities: | ||
| ```typescript | ||
| import { ipv4 } from 'cidr-block'; | ||
| const addr = ipv4.address('192.168.1.1'); | ||
| addr.toString(); // "192.168.1.1" | ||
| addr.toNumber(); // 3232235777 | ||
| addr.octets(); // [192, 168, 1, 1] | ||
| addr.toBinaryString(); // "11000000.10101000.00000001.00000001" | ||
| ``` | ||
| #### Address Type Detection | ||
| ```typescript | ||
| myCidr.netmask // 255.255.255.0 | ||
| myCidr.firstUsableIp // 10.0.0.0 (remember that methods act immutable, so this is still at 10.0.0.0) | ||
| myCidr.lastUsableIp // 10.0.0.254 | ||
| myCidr.includes(ip.address('10.0.0.128')) // true | ||
| import { ipv4 } from 'cidr-block'; | ||
| // Private addresses (RFC 1918) | ||
| ipv4.address('10.0.0.1').isPrivateAddress(); // true | ||
| ipv4.address('172.16.0.1').isPrivateAddress(); // true | ||
| ipv4.address('192.168.0.1').isPrivateAddress(); // true | ||
| ipv4.address('8.8.8.8').isPrivateAddress(); // false | ||
| // Loopback addresses | ||
| ipv4.address('127.0.0.1').isLoopbackAddress(); // true | ||
| ipv4.address('127.255.255.255').isLoopbackAddress(); // true | ||
| // Link-local addresses | ||
| ipv4.address('169.254.1.1').isLocalLinkAddress(); // true | ||
| // Multicast addresses | ||
| ipv4.address('224.0.0.1').isMulticastAddress(); // true | ||
| ipv4.address('239.255.255.255').isMulticastAddress(); // true | ||
| ``` | ||
| ## Documentation and API Reference | ||
| #### Address Comparison | ||
| The full documentation and API reference can be found at https://cidr-block.com | ||
| ```typescript | ||
| import { ipv4 } from 'cidr-block'; | ||
| ## FAQ | ||
| const addr1 = ipv4.address('192.168.1.1'); | ||
| const addr2 = ipv4.address('192.168.1.2'); | ||
| Q: Why are the imports in all the example code like that? | ||
| addr1.equals('192.168.1.1'); // true | ||
| addr1.equals(addr2); // false | ||
| addr1.isLessThan(addr2); // true | ||
| addr1.isGreaterThan(addr2); // false | ||
| addr1.isLessThanOrEqual(addr2); // true | ||
| addr1.isGreaterThanOrEqual(addr2); // false | ||
| ``` | ||
| A: The imports in all example code are formatted as the following: | ||
| #### Address Navigation | ||
| ```typescript | ||
| // esm | ||
| import { ipv4 as ip } from 'cidr-block' | ||
| // commonjs | ||
| const { ipv4: ip } = require('cidr-block') | ||
| import { ipv4 } from 'cidr-block'; | ||
| const addr = ipv4.address('192.168.1.100'); | ||
| addr.hasNextAddress(); // true | ||
| addr.nextAddress()?.toString(); // "192.168.1.101" | ||
| addr.hasPreviousAddress(); // true | ||
| addr.previousAddress()?.toString(); // "192.168.1.99" | ||
| // Edge cases | ||
| const maxAddr = ipv4.address('255.255.255.255'); | ||
| maxAddr.hasNextAddress(); // false | ||
| maxAddr.nextAddress(); // undefined | ||
| const minAddr = ipv4.address('0.0.0.0'); | ||
| minAddr.hasPreviousAddress(); // false | ||
| minAddr.previousAddress(); // undefined | ||
| ``` | ||
| While you don't have to follow this convention, the API is design like this on purpose to help speed | ||
| up a refactoring of ipv4 to ipv6, as you would only need to change the number on the import. | ||
| #### Creating CIDR Blocks | ||
| ```typescript | ||
| import { ipv4 } from 'cidr-block'; | ||
| // From string | ||
| const cidr1 = ipv4.cidr('192.168.0.0/24'); | ||
| // From object | ||
| const cidr2 = ipv4.cidr({ address: '192.168.0.0', range: 24 }); | ||
| // From tuple | ||
| const cidr3 = ipv4.cidr(['192.168.0.0', 24]); | ||
| // Mixed formats work too | ||
| const cidr4 = ipv4.cidr({ address: [192, 168, 0, 0], range: 24 }); | ||
| ``` | ||
| #### CIDR Validation | ||
| ```typescript | ||
| import { ipv4 } from 'cidr-block'; | ||
| ipv4.isValidCIDR('192.168.0.0/24'); // true | ||
| ipv4.isValidCIDR('192.168.0.0/33'); // false (range exceeds 32) | ||
| ipv4.isValidCIDR('256.0.0.0/24'); // false (invalid address) | ||
| ipv4.isValidCIDR(['10.0.0.0', 8]); // true | ||
| ``` | ||
| #### CIDR Properties | ||
| ```typescript | ||
| import { ipv4 } from 'cidr-block'; | ||
| const cidr = ipv4.cidr('192.168.0.0/24'); | ||
| cidr.toString(); // "192.168.0.0/24" | ||
| cidr.baseAddress().toString(); // "192.168.0.0" | ||
| cidr.range(); // 24 | ||
| cidr.netmask().toString(); // "255.255.255.0" | ||
| cidr.addressCount(); // 256 | ||
| cidr.rangeParts(); // [Ipv4Address, 24] | ||
| ``` | ||
| #### Usable Addresses | ||
| ```typescript | ||
| import { ipv4 } from 'cidr-block'; | ||
| const cidr = ipv4.cidr('192.168.1.0/24'); | ||
| // First usable (excludes network address) | ||
| cidr.getFirstUsableAddress()?.toString(); // "192.168.1.1" | ||
| // Last usable (excludes broadcast address) | ||
| cidr.getLastUsableAddress()?.toString(); // "192.168.1.254" | ||
| // For /32, there are no usable addresses | ||
| const hostCidr = ipv4.cidr('192.168.1.1/32'); | ||
| hostCidr.getFirstUsableAddress(); // undefined | ||
| hostCidr.getLastUsableAddress(); // undefined | ||
| ``` | ||
| #### Iterating Addresses | ||
| ```typescript | ||
| import { ipv4 } from 'cidr-block'; | ||
| const cidr = ipv4.cidr('192.168.1.0/30'); | ||
| // Using the generator | ||
| for (const addr of cidr.addresses()) { | ||
| console.log(addr.toString()); | ||
| } | ||
| // Output: | ||
| // 192.168.1.0 | ||
| // 192.168.1.1 | ||
| // 192.168.1.2 | ||
| // 192.168.1.3 | ||
| // Convert to array | ||
| const allAddresses = [...cidr.addresses()]; | ||
| console.log(allAddresses.length); // 4 | ||
| ``` | ||
| #### Address Containment | ||
| ```typescript | ||
| import { ipv4 } from 'cidr-block'; | ||
| const cidr = ipv4.cidr('192.168.0.0/24'); | ||
| cidr.includes(ipv4.address('192.168.0.100')); // true | ||
| cidr.includes(ipv4.address('192.168.1.1')); // false | ||
| cidr.includes(ipv4.address('192.168.0.0')); // true | ||
| cidr.includes(ipv4.address('192.168.0.255')); // true | ||
| ``` | ||
| #### CIDR Overlap Detection | ||
| ```typescript | ||
| import { ipv4 } from 'cidr-block'; | ||
| const cidr1 = ipv4.cidr('192.168.0.0/24'); | ||
| const cidr2 = ipv4.cidr('192.168.0.128/25'); | ||
| const cidr3 = ipv4.cidr('192.168.1.0/24'); | ||
| cidr1.overlaps(cidr2); // true (cidr2 is a subnet of cidr1) | ||
| cidr1.overlaps(cidr3); // false (different networks) | ||
| // Also accepts string format | ||
| cidr1.overlaps('10.0.0.0/8'); // false | ||
| ``` | ||
| #### Subnetting | ||
| ```typescript | ||
| import { ipv4 } from 'cidr-block'; | ||
| const cidr = ipv4.cidr('192.168.0.0/24'); | ||
| // Split into equal subnets | ||
| const subnets = cidr.subnet(26); | ||
| subnets.forEach(s => console.log(s.toString())); | ||
| // Output: | ||
| // 192.168.0.0/26 | ||
| // 192.168.0.64/26 | ||
| // 192.168.0.128/26 | ||
| // 192.168.0.192/26 | ||
| // Split into variable-sized subnets | ||
| const varSubnets = cidr.subnetBy([26, 27, 27, 26]); | ||
| varSubnets.forEach(s => console.log(s.toString())); | ||
| // Output: | ||
| // 192.168.0.0/26 | ||
| // 192.168.0.64/27 | ||
| // 192.168.0.96/27 | ||
| // 192.168.0.128/26 | ||
| ``` | ||
| #### CIDR Navigation | ||
| ```typescript | ||
| import { ipv4 } from 'cidr-block'; | ||
| const cidr = ipv4.cidr('192.168.0.0/24'); | ||
| cidr.hasNextCIDR(); // true | ||
| cidr.nextCIDR()?.toString(); // "192.168.1.0/24" | ||
| cidr.hasPreviousCIDR(); // true | ||
| cidr.previousCIDR()?.toString(); // "192.167.255.0/24" | ||
| ``` | ||
| ### IPv6 | ||
| #### Creating Addresses | ||
| ```typescript | ||
| import { ipv6 } from 'cidr-block'; | ||
| // From string (with :: compression) | ||
| const addr1 = ipv6.address('2001:db8::1'); | ||
| // From full string | ||
| const addr2 = ipv6.address('2001:0db8:0000:0000:0000:0000:0000:0001'); | ||
| // From BigInt | ||
| const addr3 = ipv6.address(42540766411282592856903984951653826561n); | ||
| // From hextets array | ||
| const addr4 = ipv6.address([0x2001, 0x0db8, 0, 0, 0, 0, 0, 1]); | ||
| ``` | ||
| #### Address Validation | ||
| ```typescript | ||
| import { ipv6 } from 'cidr-block'; | ||
| ipv6.isValidAddress('2001:db8::1'); // true | ||
| ipv6.isValidAddress('::1'); // true | ||
| ipv6.isValidAddress('::'); // true | ||
| ipv6.isValidAddress('::ffff:192.168.1.1'); // true (IPv4-mapped) | ||
| ipv6.isValidAddress('2001:db8::g'); // false (invalid hex) | ||
| ipv6.isValidAddress('2001:db8:::1'); // false (multiple ::) | ||
| ``` | ||
| #### Address Conversion | ||
| ```typescript | ||
| import { ipv6 } from 'cidr-block'; | ||
| const addr = ipv6.address('2001:db8::1'); | ||
| addr.toString(); // "2001:db8::1" (compressed) | ||
| addr.toFullString(); // "2001:0db8:0000:0000:0000:0000:0000:0001" | ||
| addr.toBigInt(); // 42540766411282592856903984951653826561n | ||
| addr.hextets(); // [8193, 3512, 0, 0, 0, 0, 0, 1] | ||
| addr.toBinaryString(); // Binary representation with colons | ||
| ``` | ||
| #### Address Type Detection | ||
| ```typescript | ||
| import { ipv6 } from 'cidr-block'; | ||
| // Loopback | ||
| ipv6.address('::1').isLoopbackAddress(); // true | ||
| // Unspecified | ||
| ipv6.address('::').isUnspecifiedAddress(); // true | ||
| // Unique local (private equivalent) | ||
| ipv6.address('fc00::1').isUniqueLocalAddress(); // true | ||
| ipv6.address('fd00::1').isUniqueLocalAddress(); // true | ||
| // Link-local | ||
| ipv6.address('fe80::1').isLinkLocalAddress(); // true | ||
| // Multicast | ||
| ipv6.address('ff02::1').isMulticastAddress(); // true | ||
| // IPv4-mapped | ||
| ipv6.address('::ffff:192.168.1.1').isIPv4MappedAddress(); // true | ||
| // Documentation | ||
| ipv6.address('2001:db8::1').isDocumentationAddress(); // true | ||
| ``` | ||
| #### Address Comparison | ||
| ```typescript | ||
| import { ipv6 } from 'cidr-block'; | ||
| const addr1 = ipv6.address('2001:db8::1'); | ||
| const addr2 = ipv6.address('2001:db8::2'); | ||
| addr1.equals('2001:db8::1'); // true | ||
| addr1.equals(addr2); // false | ||
| addr1.isLessThan(addr2); // true | ||
| addr1.isGreaterThan(addr2); // false | ||
| addr1.isLessThanOrEqual(addr2); // true | ||
| addr1.isGreaterThanOrEqual(addr2); // false | ||
| ``` | ||
| #### Address Navigation | ||
| ```typescript | ||
| import { ipv6 } from 'cidr-block'; | ||
| const addr = ipv6.address('2001:db8::1'); | ||
| addr.hasNextAddress(); // true | ||
| addr.nextAddress()?.toString(); // "2001:db8::2" | ||
| addr.hasPreviousAddress(); // true | ||
| addr.previousAddress()?.toString(); // "2001:db8::" | ||
| ``` | ||
| #### Creating CIDR Blocks | ||
| ```typescript | ||
| import { ipv6 } from 'cidr-block'; | ||
| // From string | ||
| const cidr1 = ipv6.cidr('2001:db8::/32'); | ||
| // From object | ||
| const cidr2 = ipv6.cidr({ address: '2001:db8::', range: 32 }); | ||
| // From tuple | ||
| const cidr3 = ipv6.cidr(['2001:db8::', 32]); | ||
| ``` | ||
| #### CIDR Validation | ||
| ```typescript | ||
| import { ipv6 } from 'cidr-block'; | ||
| ipv6.isValidCIDR('2001:db8::/32'); // true | ||
| ipv6.isValidCIDR('2001:db8::/129'); // false (range exceeds 128) | ||
| ipv6.isValidCIDR(['::1', 128]); // true | ||
| ``` | ||
| #### CIDR Properties | ||
| ```typescript | ||
| import { ipv6 } from 'cidr-block'; | ||
| const cidr = ipv6.cidr('2001:db8::/32'); | ||
| cidr.toString(); // "2001:db8::/32" | ||
| cidr.baseAddress().toString(); // "2001:db8::" | ||
| cidr.range(); // 32 | ||
| cidr.netmask().toString(); // "ffff:ffff::" | ||
| cidr.addressCount(); // 79228162514264337593543950336n (BigInt) | ||
| ``` | ||
| #### Usable Addresses | ||
| ```typescript | ||
| import { ipv6 } from 'cidr-block'; | ||
| const cidr = ipv6.cidr('2001:db8::/126'); | ||
| cidr.getFirstUsableAddress()?.toString(); // "2001:db8::1" | ||
| cidr.getLastUsableAddress()?.toString(); // "2001:db8::2" | ||
| // For /128, there are no usable addresses | ||
| const hostCidr = ipv6.cidr('2001:db8::1/128'); | ||
| hostCidr.getFirstUsableAddress(); // undefined | ||
| hostCidr.getLastUsableAddress(); // undefined | ||
| ``` | ||
| #### Iterating Addresses | ||
| ```typescript | ||
| import { ipv6 } from 'cidr-block'; | ||
| const cidr = ipv6.cidr('2001:db8::/126'); | ||
| for (const addr of cidr.addresses()) { | ||
| console.log(addr.toString()); | ||
| } | ||
| // Output: | ||
| // 2001:db8:: | ||
| // 2001:db8::1 | ||
| // 2001:db8::2 | ||
| // 2001:db8::3 | ||
| // With limit (useful for large ranges) | ||
| for (const addr of cidr.addresses(2n)) { | ||
| console.log(addr.toString()); | ||
| } | ||
| // Output: | ||
| // 2001:db8:: | ||
| // 2001:db8::1 | ||
| ``` | ||
| #### Address Containment and Overlap | ||
| ```typescript | ||
| import { ipv6 } from 'cidr-block'; | ||
| const cidr = ipv6.cidr('2001:db8::/32'); | ||
| cidr.includes(ipv6.address('2001:db8::1')); // true | ||
| cidr.includes(ipv6.address('2001:db9::1')); // false | ||
| const cidr2 = ipv6.cidr('2001:db8:1::/48'); | ||
| cidr.overlaps(cidr2); // true | ||
| ``` | ||
| #### Subnetting | ||
| ```typescript | ||
| import { ipv6 } from 'cidr-block'; | ||
| const cidr = ipv6.cidr('2001:db8::/32'); | ||
| // Split into /34 subnets | ||
| const subnets = cidr.subnet(34); | ||
| subnets.forEach(s => console.log(s.toString())); | ||
| // Output: | ||
| // 2001:db8::/34 | ||
| // 2001:db8:4000::/34 | ||
| // 2001:db8:8000::/34 | ||
| // 2001:db8:c000::/34 | ||
| // Variable-sized subnets | ||
| const varSubnets = cidr.subnetBy([34, 34, 33]); | ||
| varSubnets.forEach(s => console.log(s.toString())); | ||
| ``` | ||
| #### CIDR Navigation | ||
| ```typescript | ||
| import { ipv6 } from 'cidr-block'; | ||
| const cidr = ipv6.cidr('2001:db8::/32'); | ||
| cidr.hasNextCIDR(); // true | ||
| cidr.nextCIDR()?.toString(); // "2001:db9::/32" | ||
| cidr.hasPreviousCIDR(); // true | ||
| cidr.previousCIDR()?.toString(); // "2001:db7::/32" | ||
| ``` | ||
| ### Error Handling | ||
| ```typescript | ||
| import { | ||
| ipv4, | ||
| ipv6, | ||
| InvalidIpv4AddressError, | ||
| InvalidIpv4CidrError, | ||
| InvalidIpv4CidrRangeError, | ||
| InvalidIpv6AddressError, | ||
| InvalidIpv6CidrError, | ||
| InvalidIpv6CidrRangeError | ||
| } from 'cidr-block'; | ||
| // Invalid address throws error | ||
| try { | ||
| ipv4.address('256.0.0.1'); | ||
| } catch (e) { | ||
| if (e instanceof InvalidIpv4AddressError) { | ||
| console.log(e.message); // "256.0.0.1 is not a valid IPv4 address" | ||
| } | ||
| } | ||
| // Invalid CIDR throws error | ||
| try { | ||
| ipv4.cidr('192.168.0.0/33'); | ||
| } catch (e) { | ||
| if (e instanceof InvalidIpv4CidrError) { | ||
| console.log(e.message); // "192.168.0.0/33 is not a valid IPv4 CIDR range" | ||
| } | ||
| } | ||
| // Invalid subnet operation throws error | ||
| try { | ||
| const cidr = ipv4.cidr('192.168.0.0/24'); | ||
| cidr.subnet(20); // Can't create larger subnets | ||
| } catch (e) { | ||
| if (e instanceof InvalidIpv4CidrRangeError) { | ||
| console.log('Invalid subnet range'); | ||
| } | ||
| } | ||
| // Use validation to avoid exceptions | ||
| if (ipv4.isValidAddress(userInput)) { | ||
| const addr = ipv4.address(userInput); | ||
| // Safe to use | ||
| } | ||
| ``` | ||
| ### Constants | ||
| ```typescript | ||
| import { ipv4, ipv6 } from 'cidr-block'; | ||
| // IPv4 constants | ||
| ipv4.MAX_SIZE; // 0xffffffff (4294967295) | ||
| ipv4.MIN_SIZE; // 0x00000000 | ||
| ipv4.MAX_RANGE; // 32 | ||
| ipv4.MIN_RANGE; // 0 | ||
| // IPv6 constants | ||
| ipv6.MAX_SIZE; // (1n << 128n) - 1n | ||
| ipv6.MIN_SIZE; // 0n | ||
| ipv6.MAX_RANGE; // 128 | ||
| ipv6.MIN_RANGE; // 0 | ||
| ``` | ||
| ### Type Definitions | ||
| ```typescript | ||
| import type { | ||
| // IPv4 types | ||
| Ipv4AddressLiteral, // string | number | number[] | ||
| Ipv4AddressString, // "${number}.${number}.${number}.${number}" | ||
| Ipv4AddressOctets, // [number, number, number, number] | ||
| Ipv4CidrLiteral, // string | { address, range } | [address, range] | ||
| Ipv4CidrString, // "${number}.${number}.${number}.${number}/${number}" | ||
| // IPv6 types | ||
| Ipv6AddressLiteral, // string | bigint | number[] | ||
| Ipv6AddressHextets, // [number, number, number, number, number, number, number, number] | ||
| Ipv6CidrLiteral, // string | { address, range } | [address, range] | ||
| } from 'cidr-block'; | ||
| ``` | ||
| ## Common Use Cases | ||
| ### Checking if an IP is in a Private Network | ||
| ```typescript | ||
| import { ipv4 } from 'cidr-block'; | ||
| function isInternalIP(ip: string): boolean { | ||
| if (!ipv4.isValidAddress(ip)) return false; | ||
| const addr = ipv4.address(ip); | ||
| return addr.isPrivateAddress() || addr.isLoopbackAddress(); | ||
| } | ||
| isInternalIP('192.168.1.1'); // true | ||
| isInternalIP('10.0.0.1'); // true | ||
| isInternalIP('8.8.8.8'); // false | ||
| ``` | ||
| ### Allocating Subnets from a Pool | ||
| ```typescript | ||
| import { ipv4 } from 'cidr-block'; | ||
| function allocateSubnets(poolCidr: string, subnetSize: number, count: number) { | ||
| const pool = ipv4.cidr(poolCidr); | ||
| const subnets = pool.subnet(subnetSize); | ||
| return subnets.slice(0, count); | ||
| } | ||
| const allocated = allocateSubnets('10.0.0.0/16', 24, 3); | ||
| allocated.forEach(s => console.log(s.toString())); | ||
| // 10.0.0.0/24 | ||
| // 10.0.1.0/24 | ||
| // 10.0.2.0/24 | ||
| ``` | ||
| ### Checking for CIDR Conflicts | ||
| ```typescript | ||
| import { ipv4, Ipv4Cidr } from 'cidr-block'; | ||
| function findConflicts(newCidr: string, existing: string[]): string[] { | ||
| const cidr = ipv4.cidr(newCidr); | ||
| return existing.filter(e => cidr.overlaps(e)); | ||
| } | ||
| const existingRanges = ['10.0.0.0/24', '10.0.1.0/24', '192.168.0.0/16']; | ||
| const conflicts = findConflicts('10.0.0.0/16', existingRanges); | ||
| // ['10.0.0.0/24', '10.0.1.0/24'] | ||
| ``` | ||
| ### Generating IP Addresses in a Range | ||
| ```typescript | ||
| import { ipv4 } from 'cidr-block'; | ||
| function getUsableIPs(cidrStr: string): string[] { | ||
| const cidr = ipv4.cidr(cidrStr); | ||
| const ips: string[] = []; | ||
| for (const addr of cidr.addresses()) { | ||
| // Skip network and broadcast addresses for practical use | ||
| if (addr.equals(cidr.baseAddress())) continue; | ||
| const lastOctet = addr.octets()[3]; | ||
| if (lastOctet === 255) continue; // Skip broadcast | ||
| ips.push(addr.toString()); | ||
| } | ||
| return ips; | ||
| } | ||
| const usable = getUsableIPs('192.168.1.0/29'); | ||
| // ['192.168.1.1', '192.168.1.2', '192.168.1.3', '192.168.1.4', '192.168.1.5', '192.168.1.6'] | ||
| ``` |
| export declare class InvalidIpAddressError extends Error { | ||
| constructor(badIp: string); | ||
| } | ||
| export declare class InvalidCidrBlockError extends Error { | ||
| constructor(badCidr: string); | ||
| } |
| export * as ipv4 from './ipv4/index'; | ||
| export * as ipv6 from './ipv6/index'; | ||
| export * as errors from './errors'; |
| class InvalidIpAddressError extends Error { | ||
| constructor(badIp) { | ||
| super(`${badIp} is not a valid IPv4 address.`); | ||
| } | ||
| } | ||
| class InvalidCidrBlockError extends Error { | ||
| constructor(badCidr) { | ||
| super(`${badCidr} is not a valid IPv4 cidr block.`); | ||
| } | ||
| }var errors=/*#__PURE__*/Object.freeze({__proto__:null,InvalidIpAddressError:InvalidIpAddressError,InvalidCidrBlockError:InvalidCidrBlockError});/** | ||
| * The numerical maximum size an IPv4 address can be | ||
| */ | ||
| const MAX$1 = 2 ** 32 - 1;const MAX_OCTET_SIZE = 255; | ||
| /** | ||
| * Representation of an IPv4 address. Provides various utility methods like equality | ||
| * checking. | ||
| * | ||
| * @remarks | ||
| * Avoid direct instantiation; use {@link ipv4.address} instead. | ||
| */ | ||
| class Ipv4Address { | ||
| constructor(address) { | ||
| this._address = typeof address === 'number' ? address : stringToNum$1(address); | ||
| } | ||
| /** | ||
| * The address as a number | ||
| */ | ||
| get address() { | ||
| return this._address; | ||
| } | ||
| /** | ||
| * Returns the string representation of the address | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv4 as ip } from 'cidr-block' | ||
| * | ||
| * ip.address(255) // ==> '0.0.0.255' | ||
| * ip.address(0b11111111_00000000_11111111_00000000) // ==> '255.0.255.0' | ||
| * ```` | ||
| * | ||
| * @public | ||
| * @returns the IPv4 address as a string | ||
| */ | ||
| toString() { | ||
| return numToString$1(this._address); | ||
| } | ||
| /** | ||
| * Compares if two IPv4 addresses are the same. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv4 as ip } from 'cidr-block' | ||
| * | ||
| * function isLoopback(address: Ipv4Representable) { | ||
| * return ip.address(address).equals('127.0.0.1') | ||
| * } | ||
| * ``` | ||
| * | ||
| * @public | ||
| * @param otherIpAddress the other IPv4 address to compare | ||
| * @returns if the other IP address is the same | ||
| */ | ||
| equals(otherIpAddress) { | ||
| if (otherIpAddress instanceof Ipv4Address) { | ||
| return this._address === otherIpAddress._address; | ||
| } | ||
| else { | ||
| return this._address === address$1(otherIpAddress)._address; | ||
| } | ||
| } | ||
| /** | ||
| * Calculates the next logical IPv4 address. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv4 as ip } from 'cidr-block' | ||
| * | ||
| * const myIp = ip.address('52.89.32.255') | ||
| * myIp.nextIp() // ==> '52.89.33.0' | ||
| * ``` | ||
| * | ||
| * @public | ||
| * @returns the next consecutive IPv4 address | ||
| */ | ||
| nextIp() { | ||
| // TODO: Handle last ip address | ||
| return address$1(this._address + 1); | ||
| } | ||
| /** | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv4 as ip } from 'cidr-block' | ||
| * | ||
| * const myIp = ip.address('52.89.32.19') | ||
| * myIp.previousIp() // ==> '52.89.32.18' | ||
| * ``` | ||
| * | ||
| * @public | ||
| * @returns the preceding IPv4 address | ||
| */ | ||
| previousIp() { | ||
| return address$1(this._address - 1); | ||
| } | ||
| } | ||
| /** | ||
| * Convenience function for creating an IPv4 address instance. | ||
| * | ||
| * @remarks | ||
| * In general, you should use this function instead of instantiating an Ipv4Address | ||
| * object directly. | ||
| * | ||
| * @example | ||
| * | ||
| * ```typescript | ||
| * import { ipv4 as ip } from 'cidr-block' | ||
| * | ||
| * const localhost = ip.address('127.0.0.1') | ||
| * ``` | ||
| * | ||
| * @see {@link Ipv4Address} | ||
| * | ||
| * @public | ||
| * @param ip string representation of the IPv4 address | ||
| * @returns an instance of Ipv4Address | ||
| */ | ||
| function address$1(ip) { | ||
| // TODO: Implement memoization | ||
| return new Ipv4Address(ip); | ||
| } | ||
| /** | ||
| * Converts the string representation of an IPv4 address to a number. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import * as cidr from 'cidr-block' | ||
| * | ||
| * cidr.ipv4.stringToNum('255.255.255.255') === 4_294_967_295 // ==> true | ||
| * cidr.ipv4.stringToNum('0.0.0.255') === 255 // ==> true | ||
| * ``` | ||
| * | ||
| * @see This method is the inverse of {@link ipv4.numToString} | ||
| * @throws {@link InvalidIpAddressError} | ||
| * | ||
| * @public | ||
| * @param address IPv4 address represented as a string | ||
| * @returns numerical number representation of the address | ||
| */ | ||
| function stringToNum$1(address) { | ||
| try { | ||
| if (address.length < 7) { | ||
| throw new Error(); | ||
| } | ||
| let octets = address.split('.').map(Number); | ||
| if (octets.some(octet => octet < 0 || octet > MAX_OCTET_SIZE)) { | ||
| throw new Error(); | ||
| } | ||
| let [firstOctet, secondOctet, thirdOctet, fourthOctet] = octets; | ||
| firstOctet = (firstOctet << 24) >>> 0; | ||
| secondOctet = (secondOctet << 16) >>> 0; | ||
| thirdOctet = (thirdOctet << 8) >>> 0; | ||
| return firstOctet + secondOctet + thirdOctet + fourthOctet; | ||
| } | ||
| catch { | ||
| throw new InvalidIpAddressError(address); | ||
| } | ||
| } | ||
| /** | ||
| * Converts the numerical representation of an IPv4 address to its string representation. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import * as cidr from 'cidr-block' | ||
| * | ||
| * cidr.ipv4.numToString(0) === '0.0.0.0' // ==> true | ||
| * cidr.ipv4.numToString(65_280) === '0.0.255.0' // ==> true | ||
| * cidr.ipv4.numToString(4_294_967_295) === '255.255.255.255' // ==> true | ||
| * ``` | ||
| * | ||
| * @see This method is the inverse of {@link ipv4.stringToNum} | ||
| * @throws {@link InvalidIpAddressError} | ||
| * | ||
| * @public | ||
| * @param ip IPv4 address as a number | ||
| * @returns string representation of the address | ||
| */ | ||
| function numToString$1(ip) { | ||
| try { | ||
| if (ip < 0 || ip > MAX$1) { | ||
| throw new Error(); | ||
| } | ||
| const firstOctet = (ip >>> 24) & MAX_OCTET_SIZE; | ||
| const secondOctet = (ip >>> 16) & MAX_OCTET_SIZE; | ||
| const thirdOctet = (ip >>> 8) & MAX_OCTET_SIZE; | ||
| const fourthOctet = ip & MAX_OCTET_SIZE; | ||
| return `${firstOctet}.${secondOctet}.${thirdOctet}.${fourthOctet}`; | ||
| } | ||
| catch { | ||
| throw new InvalidIpAddressError(ip.toString()); | ||
| } | ||
| }class Ipv4Cidr { | ||
| // TODO: Allow wider-range of values that can be used to create a cidr | ||
| constructor(cidrRange) { | ||
| try { | ||
| const [address, subnetMask] = cidrRange.split('/'); | ||
| this._ipAddress = address$1(address); | ||
| this._maskSize = Number(subnetMask); | ||
| } | ||
| catch { | ||
| throw new InvalidCidrBlockError(cidrRange); | ||
| } | ||
| } | ||
| /** | ||
| * The size of the cidr netmask (the number after the slash in cidr notation) | ||
| */ | ||
| get maskSize() { | ||
| return this._maskSize; | ||
| } | ||
| /** | ||
| * Number of IP addresses within the cidr range | ||
| */ | ||
| get allocatableIpCount() { | ||
| return 2 ** this.addressLength; | ||
| } | ||
| /** | ||
| * The actual IPv4 netmask address | ||
| */ | ||
| get netmask() { | ||
| return address$1((2 ** this.maskSize - 1) << this.addressLength); | ||
| } | ||
| /** | ||
| * The first IPv4 address that is usable within the given cidr range | ||
| */ | ||
| get firstUsableIp() { | ||
| return address$1(this._ipAddress.address); | ||
| } | ||
| /** | ||
| * The last IPv4 address that is usable within the given cidr range | ||
| */ | ||
| get lastUsableIp() { | ||
| // FIXME: Handle edge case of when cidr range goes outside valid ip range | ||
| return address$1(this._ipAddress.address + 2 ** this.addressLength - 1); | ||
| } | ||
| get addressLength() { | ||
| return Math.abs(32 - this._maskSize); | ||
| } | ||
| /** | ||
| * @returns string representation of the cidr range | ||
| */ | ||
| toString() { | ||
| return `${this._ipAddress.toString()}/${this._maskSize}`; | ||
| } | ||
| /** | ||
| * @returns the next consecutive cidr block | ||
| */ | ||
| nextBlock(ofSize) { | ||
| const nextIp = this._ipAddress.address + 2 ** this.addressLength; | ||
| return cidr(`${numToString$1(nextIp)}/${ofSize ?? this._maskSize}`); | ||
| } | ||
| /** | ||
| * @returns the previous cidr block | ||
| */ | ||
| previousBlock() { | ||
| const nextIp = this._ipAddress.address - 2 ** this.addressLength; | ||
| return cidr(`${numToString$1(nextIp)}/${this._maskSize}`); | ||
| } | ||
| /** | ||
| * @returns if the given IPv4 address is within the cidr range | ||
| */ | ||
| includes(address) { | ||
| const ip = address instanceof Ipv4Address ? address : address$1(address); | ||
| return ( | ||
| // FIXME: How to handle edge case of next block erroring out? | ||
| ip.address >= this._ipAddress.address && ip.address <= this.nextBlock()._ipAddress.address); | ||
| } | ||
| } | ||
| /** | ||
| * Convenience function for creating an IPv4 cidr range instance. | ||
| * | ||
| * @remarks | ||
| * | ||
| * In general, you should use this function instead of instantiating an Ipv4Cidr | ||
| * object directly. While there is nothing wrong with direct instantiation, convenience | ||
| * methods like these are meant to help reduce the footprint of your code and increase | ||
| * readability. | ||
| * | ||
| * @example | ||
| * | ||
| * ```typescript | ||
| * import { ipv4 as ip } from 'cidr-block' | ||
| * | ||
| * const vpcCidrRange = ip.cidr('10.0.0.0/16') | ||
| * ``` | ||
| * | ||
| * @see {@link Ipv4Cidr} | ||
| * | ||
| * @param cidrRange string representation of the cidr range | ||
| * @returns an instance of Ipv4Cidr | ||
| */ | ||
| function cidr(cidrRange) { | ||
| return new Ipv4Cidr(cidrRange); | ||
| }const RFC_1918_CIDRS = [cidr('10.0.0.0/8'), cidr('172.16.0.0/12'), cidr('192.168.0.0/16')]; | ||
| /** | ||
| * Predicate function that will return true if the given | ||
| * address is in the private RFC 1918 ipv4 address space. | ||
| * | ||
| * See more {@link https://datatracker.ietf.org/doc/html/rfc1918} | ||
| */ | ||
| function isPrivateRFC1918(address) { | ||
| for (const rfcCidr of RFC_1918_CIDRS) { | ||
| if (rfcCidr.includes(address)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| }var rfc1918=/*#__PURE__*/Object.freeze({__proto__:null,isPrivateRFC1918:isPrivateRFC1918});var index$1=/*#__PURE__*/Object.freeze({__proto__:null,rfc1918:rfc1918,Ipv4Address:Ipv4Address,address:address$1,stringToNum:stringToNum$1,numToString:numToString$1,Ipv4Cidr:Ipv4Cidr,cidr:cidr,MAX:MAX$1});const MAX_HEXTET_SIZE = 65535n; | ||
| /** | ||
| * Representation of an IPv6 address. Provides various utilities methods like equality | ||
| * checking. | ||
| * | ||
| * @remarks | ||
| * Avoid direct instantiation; use {@link ipv6.address} instead. | ||
| */ | ||
| class Ipv6Address { | ||
| constructor(address) { | ||
| this._address = typeof address === 'bigint' ? address : stringToNum(address); | ||
| } | ||
| /** | ||
| * The address as a bigint | ||
| * | ||
| * @remarks | ||
| * Because the representation of an IPv6 address is too large to fit into a typical | ||
| * JavaScript integer, a | ||
| * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt} | ||
| * is used instead. | ||
| */ | ||
| get address() { | ||
| return this._address; | ||
| } | ||
| // TODO: Add example code | ||
| /** | ||
| * Returns the string representation of the address | ||
| */ | ||
| toString() { | ||
| return numToString(this._address); | ||
| } | ||
| /** | ||
| * Compares if two IPv6 addresses are the same. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv6 as ip } from 'cidr-block' | ||
| * | ||
| * function isLoopback(address: Ipv6Representable) { | ||
| * return ip.address(address).equals('::1') | ||
| * } | ||
| * | ||
| * @public | ||
| * @param otherIpAddress the other Ipv6 address to compare | ||
| * @returns if the other IP address is the same | ||
| * ``` | ||
| */ | ||
| equals(otherIpAddress) { | ||
| if (otherIpAddress instanceof Ipv6Address) { | ||
| return this._address === otherIpAddress._address; | ||
| } | ||
| else { | ||
| return this._address === address(otherIpAddress)._address; | ||
| } | ||
| } | ||
| /** | ||
| * Calculates the next logical IPv6 address. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv6 as ip } from 'cidr-block' | ||
| * | ||
| * const myIp = ip.address('2001:0db8::ac10') | ||
| * myIp.nextIp() // ==> '2001:0db8::ac11' | ||
| * ``` | ||
| */ | ||
| nextIp() { | ||
| // TODO: Handle last ip address | ||
| return address(this._address + 1n); | ||
| } | ||
| /** | ||
| * Calculates the previous logical IPv6 address. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv6 as ip } from 'cidr-block' | ||
| * | ||
| * const myIp = ip.address('2001:0db8::ac10') | ||
| * myIp.previousIp() // ==> '2001:0db8::ac09' | ||
| * ``` | ||
| */ | ||
| previousIp() { | ||
| return address(this._address - 1n); | ||
| } | ||
| } | ||
| /** | ||
| * Convenience function for creating an IPv6 address instance. | ||
| * | ||
| * @remarks | ||
| * In general, you should use this function instead of instantiating an Ipv6Address | ||
| * object directly. | ||
| * | ||
| * @example | ||
| * | ||
| * ```typescript | ||
| * import { ipv6 as ip } from 'cidr-block' | ||
| * | ||
| * const localhost = ip.address('::1') | ||
| * ``` | ||
| * | ||
| * @see {@link Ipv6Address} | ||
| * | ||
| * @param ip string representation of the IPv6 address | ||
| * @returns an instance of Ipv6Address | ||
| */ | ||
| function address(ip) { | ||
| // TODO: Implement memoization | ||
| return new Ipv6Address(ip); | ||
| } | ||
| // TODO: Add code example | ||
| /** | ||
| * Converts the string representation of an IPv6 address to a bigint. | ||
| * | ||
| * @see {@link Ipv6Address} | ||
| * | ||
| * @public | ||
| * @param ip string representation of the IPv6 address | ||
| * @returns an instance of Ipv6Address | ||
| */ | ||
| function stringToNum(address) { | ||
| if (address === '::') { | ||
| return 0n; | ||
| } | ||
| let ipv6 = 0n; | ||
| const rawHextets = []; | ||
| const [leftAddress, rightAddress] = address.split('::'); | ||
| for (const hextet of leftAddress.split(':')) { | ||
| rawHextets.push(hextet || '0'); | ||
| } | ||
| if (rightAddress !== undefined) { | ||
| const rightHextets = rightAddress.split(':'); | ||
| const emptyFillCount = 8 - (rawHextets.length + rightHextets.length); | ||
| for (let i = 0; i < emptyFillCount; i++) { | ||
| rawHextets.push('0'); | ||
| } | ||
| for (const hextet of rightHextets) { | ||
| rawHextets.push(hextet || '0'); | ||
| } | ||
| } | ||
| const decimals = rawHextets.map(hextet => parseInt(hextet, 16)); | ||
| let shiftSize = 0n; | ||
| let binHex = 0n; | ||
| for (const pos in decimals) { | ||
| const num = decimals[pos]; | ||
| if (num === 0) { | ||
| continue; | ||
| } | ||
| shiftSize = BigInt(Math.abs(parseInt(pos) - 7) * 16); | ||
| binHex = BigInt(num) << shiftSize; | ||
| ipv6 |= binHex; | ||
| } | ||
| return ipv6; | ||
| } | ||
| /** | ||
| * Converts the numerical representation of an IPv6 address to its string representation. | ||
| * | ||
| * @see This method is the inverse of {@link ipv6.stringToNum} | ||
| * @throws {@link InvalidIpAddressError} | ||
| * | ||
| * @public | ||
| * @param ip IPv6 address as a number | ||
| * @returns string representation of the address | ||
| */ | ||
| function numToString(num) { | ||
| if (num === 0n) { | ||
| return '::'; | ||
| } | ||
| const hextets = []; | ||
| for (let n = 0; n < 8; n++) { | ||
| const bitOffset = BigInt(Math.abs(n - 7) * 16); | ||
| hextets.push(((num >> bitOffset) & MAX_HEXTET_SIZE).toString(16)); | ||
| } | ||
| const dropStartIdx = hextets.indexOf('0'); | ||
| if (dropStartIdx >= 0) { | ||
| let dropCount = 1; | ||
| for (let i = dropStartIdx + 1; hextets[i] === '0'; i++) { | ||
| dropCount++; | ||
| } | ||
| hextets.splice(dropStartIdx, dropCount, dropStartIdx === 0 || dropStartIdx + dropCount === 8 ? ':' : ''); | ||
| } | ||
| return hextets.join(':'); | ||
| }/** | ||
| * The numerical maximum size an IPv6 address can be | ||
| */ | ||
| const MAX = 2n ** 128n;var index=/*#__PURE__*/Object.freeze({__proto__:null,Ipv6Address:Ipv6Address,address:address,stringToNum:stringToNum,numToString:numToString,MAX:MAX});export{errors,index$1 as ipv4,index as ipv6};//# sourceMappingURL=index.esm.js.map |
| {"version":3,"file":"index.esm.js","sources":["../src/src/errors.ts","../src/src/ipv4/constants.ts","../src/src/ipv4/ipv4-address.ts","../src/src/ipv4/ipv4-cidr.ts","../src/src/ipv4/rfc1918.ts","../src/src/ipv6/ipv6-address.ts","../src/src/ipv6/constants.ts"],"sourcesContent":[null,null,null,null,null,null,null],"names":["MAX","stringToNum","numToString","address","ipAddress"],"mappings":"MAAa,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,KAAa;QACvB,KAAK,CAAC,GAAG,KAAK,+BAA+B,CAAC,CAAA;KAC/C;CACF;MAEY,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,OAAe;QACzB,KAAK,CAAC,GAAG,OAAO,kCAAkC,CAAC,CAAA;KACpD;iJCTH;;;AAGO,MAAMA,KAAG,GAAW,CAAC,IAAI,EAAE,GAAG,CAAC,CCCtC,MAAM,cAAc,GAAG,GAAG,CAAA;AAE1B;;;;;;;MAOa,WAAW;IAGtB,YAAmB,OAAoB;QACrC,IAAI,CAAC,QAAQ,GAAG,OAAO,OAAO,KAAK,QAAQ,GAAG,OAAO,GAAGC,aAAW,CAAC,OAAO,CAAC,CAAA;KAC7E;;;;IAKD,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAA;KACrB;;;;;;;;;;;;;;;IAgBM,QAAQ;QACb,OAAOC,aAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;KAClC;;;;;;;;;;;;;;;;;IAkBM,MAAM,CAAC,cAAiC;QAC7C,IAAI,cAAc,YAAY,WAAW,EAAE;YACzC,OAAO,IAAI,CAAC,QAAQ,KAAK,cAAc,CAAC,QAAQ,CAAA;SACjD;aAAM;YACL,OAAO,IAAI,CAAC,QAAQ,KAAKC,SAAO,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAA;SAC1D;KACF;;;;;;;;;;;;;;;IAgBM,MAAM;;QAEX,OAAOA,SAAO,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAA;KAClC;;;;;;;;;;;;;IAcM,UAAU;QACf,OAAOA,SAAO,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAA;KAClC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;SAq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G,KAAK,EAAE,EAAE;QACd,OAAO,IAAI,CAAA;KACZ;IACD,MAAM,OAAO,GAAa,EAAE,CAAA;IAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;QAC1B,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAA;QAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,SAAS,IAAI,eAAe,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA;KAClE;IACD,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACzC,IAAI,YAAY,IAAI,CAAC,EAAE;QACrB,IAAI,SAAS,GAAG,CAAC,CAAA;QACjB,KAAK,IAAI,CAAC,GAAG,YAAY,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC,EAAE,EAAE;YACtD,SAAS,EAAE,CAAA;SACZ;QACD,OAAO,CAAC,MAAM,CACZ,YAAY,EACZ,SAAS,EACT,YAAY,KAAK,CAAC,IAAI,YAAY,GAAG,SAAS,KAAK,CAAC,GAAG,GAAG,GAAG,EAAE,CAChE,CAAA;KACF;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC1B,CC5MA;;;AAGO,MAAM,GAAG,GAAG,EAAE,IAAI,IAAI"} |
-500
| 'use strict';Object.defineProperty(exports,'__esModule',{value:true});class InvalidIpAddressError extends Error { | ||
| constructor(badIp) { | ||
| super(`${badIp} is not a valid IPv4 address.`); | ||
| } | ||
| } | ||
| class InvalidCidrBlockError extends Error { | ||
| constructor(badCidr) { | ||
| super(`${badCidr} is not a valid IPv4 cidr block.`); | ||
| } | ||
| }var errors=/*#__PURE__*/Object.freeze({__proto__:null,InvalidIpAddressError:InvalidIpAddressError,InvalidCidrBlockError:InvalidCidrBlockError});/** | ||
| * The numerical maximum size an IPv4 address can be | ||
| */ | ||
| const MAX$1 = 2 ** 32 - 1;const MAX_OCTET_SIZE = 255; | ||
| /** | ||
| * Representation of an IPv4 address. Provides various utility methods like equality | ||
| * checking. | ||
| * | ||
| * @remarks | ||
| * Avoid direct instantiation; use {@link ipv4.address} instead. | ||
| */ | ||
| class Ipv4Address { | ||
| constructor(address) { | ||
| this._address = typeof address === 'number' ? address : stringToNum$1(address); | ||
| } | ||
| /** | ||
| * The address as a number | ||
| */ | ||
| get address() { | ||
| return this._address; | ||
| } | ||
| /** | ||
| * Returns the string representation of the address | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv4 as ip } from 'cidr-block' | ||
| * | ||
| * ip.address(255) // ==> '0.0.0.255' | ||
| * ip.address(0b11111111_00000000_11111111_00000000) // ==> '255.0.255.0' | ||
| * ```` | ||
| * | ||
| * @public | ||
| * @returns the IPv4 address as a string | ||
| */ | ||
| toString() { | ||
| return numToString$1(this._address); | ||
| } | ||
| /** | ||
| * Compares if two IPv4 addresses are the same. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv4 as ip } from 'cidr-block' | ||
| * | ||
| * function isLoopback(address: Ipv4Representable) { | ||
| * return ip.address(address).equals('127.0.0.1') | ||
| * } | ||
| * ``` | ||
| * | ||
| * @public | ||
| * @param otherIpAddress the other IPv4 address to compare | ||
| * @returns if the other IP address is the same | ||
| */ | ||
| equals(otherIpAddress) { | ||
| if (otherIpAddress instanceof Ipv4Address) { | ||
| return this._address === otherIpAddress._address; | ||
| } | ||
| else { | ||
| return this._address === address$1(otherIpAddress)._address; | ||
| } | ||
| } | ||
| /** | ||
| * Calculates the next logical IPv4 address. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv4 as ip } from 'cidr-block' | ||
| * | ||
| * const myIp = ip.address('52.89.32.255') | ||
| * myIp.nextIp() // ==> '52.89.33.0' | ||
| * ``` | ||
| * | ||
| * @public | ||
| * @returns the next consecutive IPv4 address | ||
| */ | ||
| nextIp() { | ||
| // TODO: Handle last ip address | ||
| return address$1(this._address + 1); | ||
| } | ||
| /** | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv4 as ip } from 'cidr-block' | ||
| * | ||
| * const myIp = ip.address('52.89.32.19') | ||
| * myIp.previousIp() // ==> '52.89.32.18' | ||
| * ``` | ||
| * | ||
| * @public | ||
| * @returns the preceding IPv4 address | ||
| */ | ||
| previousIp() { | ||
| return address$1(this._address - 1); | ||
| } | ||
| } | ||
| /** | ||
| * Convenience function for creating an IPv4 address instance. | ||
| * | ||
| * @remarks | ||
| * In general, you should use this function instead of instantiating an Ipv4Address | ||
| * object directly. | ||
| * | ||
| * @example | ||
| * | ||
| * ```typescript | ||
| * import { ipv4 as ip } from 'cidr-block' | ||
| * | ||
| * const localhost = ip.address('127.0.0.1') | ||
| * ``` | ||
| * | ||
| * @see {@link Ipv4Address} | ||
| * | ||
| * @public | ||
| * @param ip string representation of the IPv4 address | ||
| * @returns an instance of Ipv4Address | ||
| */ | ||
| function address$1(ip) { | ||
| // TODO: Implement memoization | ||
| return new Ipv4Address(ip); | ||
| } | ||
| /** | ||
| * Converts the string representation of an IPv4 address to a number. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import * as cidr from 'cidr-block' | ||
| * | ||
| * cidr.ipv4.stringToNum('255.255.255.255') === 4_294_967_295 // ==> true | ||
| * cidr.ipv4.stringToNum('0.0.0.255') === 255 // ==> true | ||
| * ``` | ||
| * | ||
| * @see This method is the inverse of {@link ipv4.numToString} | ||
| * @throws {@link InvalidIpAddressError} | ||
| * | ||
| * @public | ||
| * @param address IPv4 address represented as a string | ||
| * @returns numerical number representation of the address | ||
| */ | ||
| function stringToNum$1(address) { | ||
| try { | ||
| if (address.length < 7) { | ||
| throw new Error(); | ||
| } | ||
| let octets = address.split('.').map(Number); | ||
| if (octets.some(octet => octet < 0 || octet > MAX_OCTET_SIZE)) { | ||
| throw new Error(); | ||
| } | ||
| let [firstOctet, secondOctet, thirdOctet, fourthOctet] = octets; | ||
| firstOctet = (firstOctet << 24) >>> 0; | ||
| secondOctet = (secondOctet << 16) >>> 0; | ||
| thirdOctet = (thirdOctet << 8) >>> 0; | ||
| return firstOctet + secondOctet + thirdOctet + fourthOctet; | ||
| } | ||
| catch { | ||
| throw new InvalidIpAddressError(address); | ||
| } | ||
| } | ||
| /** | ||
| * Converts the numerical representation of an IPv4 address to its string representation. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import * as cidr from 'cidr-block' | ||
| * | ||
| * cidr.ipv4.numToString(0) === '0.0.0.0' // ==> true | ||
| * cidr.ipv4.numToString(65_280) === '0.0.255.0' // ==> true | ||
| * cidr.ipv4.numToString(4_294_967_295) === '255.255.255.255' // ==> true | ||
| * ``` | ||
| * | ||
| * @see This method is the inverse of {@link ipv4.stringToNum} | ||
| * @throws {@link InvalidIpAddressError} | ||
| * | ||
| * @public | ||
| * @param ip IPv4 address as a number | ||
| * @returns string representation of the address | ||
| */ | ||
| function numToString$1(ip) { | ||
| try { | ||
| if (ip < 0 || ip > MAX$1) { | ||
| throw new Error(); | ||
| } | ||
| const firstOctet = (ip >>> 24) & MAX_OCTET_SIZE; | ||
| const secondOctet = (ip >>> 16) & MAX_OCTET_SIZE; | ||
| const thirdOctet = (ip >>> 8) & MAX_OCTET_SIZE; | ||
| const fourthOctet = ip & MAX_OCTET_SIZE; | ||
| return `${firstOctet}.${secondOctet}.${thirdOctet}.${fourthOctet}`; | ||
| } | ||
| catch { | ||
| throw new InvalidIpAddressError(ip.toString()); | ||
| } | ||
| }class Ipv4Cidr { | ||
| // TODO: Allow wider-range of values that can be used to create a cidr | ||
| constructor(cidrRange) { | ||
| try { | ||
| const [address, subnetMask] = cidrRange.split('/'); | ||
| this._ipAddress = address$1(address); | ||
| this._maskSize = Number(subnetMask); | ||
| } | ||
| catch { | ||
| throw new InvalidCidrBlockError(cidrRange); | ||
| } | ||
| } | ||
| /** | ||
| * The size of the cidr netmask (the number after the slash in cidr notation) | ||
| */ | ||
| get maskSize() { | ||
| return this._maskSize; | ||
| } | ||
| /** | ||
| * Number of IP addresses within the cidr range | ||
| */ | ||
| get allocatableIpCount() { | ||
| return 2 ** this.addressLength; | ||
| } | ||
| /** | ||
| * The actual IPv4 netmask address | ||
| */ | ||
| get netmask() { | ||
| return address$1((2 ** this.maskSize - 1) << this.addressLength); | ||
| } | ||
| /** | ||
| * The first IPv4 address that is usable within the given cidr range | ||
| */ | ||
| get firstUsableIp() { | ||
| return address$1(this._ipAddress.address); | ||
| } | ||
| /** | ||
| * The last IPv4 address that is usable within the given cidr range | ||
| */ | ||
| get lastUsableIp() { | ||
| // FIXME: Handle edge case of when cidr range goes outside valid ip range | ||
| return address$1(this._ipAddress.address + 2 ** this.addressLength - 1); | ||
| } | ||
| get addressLength() { | ||
| return Math.abs(32 - this._maskSize); | ||
| } | ||
| /** | ||
| * @returns string representation of the cidr range | ||
| */ | ||
| toString() { | ||
| return `${this._ipAddress.toString()}/${this._maskSize}`; | ||
| } | ||
| /** | ||
| * @returns the next consecutive cidr block | ||
| */ | ||
| nextBlock(ofSize) { | ||
| const nextIp = this._ipAddress.address + 2 ** this.addressLength; | ||
| return cidr(`${numToString$1(nextIp)}/${ofSize ?? this._maskSize}`); | ||
| } | ||
| /** | ||
| * @returns the previous cidr block | ||
| */ | ||
| previousBlock() { | ||
| const nextIp = this._ipAddress.address - 2 ** this.addressLength; | ||
| return cidr(`${numToString$1(nextIp)}/${this._maskSize}`); | ||
| } | ||
| /** | ||
| * @returns if the given IPv4 address is within the cidr range | ||
| */ | ||
| includes(address) { | ||
| const ip = address instanceof Ipv4Address ? address : address$1(address); | ||
| return ( | ||
| // FIXME: How to handle edge case of next block erroring out? | ||
| ip.address >= this._ipAddress.address && ip.address <= this.nextBlock()._ipAddress.address); | ||
| } | ||
| } | ||
| /** | ||
| * Convenience function for creating an IPv4 cidr range instance. | ||
| * | ||
| * @remarks | ||
| * | ||
| * In general, you should use this function instead of instantiating an Ipv4Cidr | ||
| * object directly. While there is nothing wrong with direct instantiation, convenience | ||
| * methods like these are meant to help reduce the footprint of your code and increase | ||
| * readability. | ||
| * | ||
| * @example | ||
| * | ||
| * ```typescript | ||
| * import { ipv4 as ip } from 'cidr-block' | ||
| * | ||
| * const vpcCidrRange = ip.cidr('10.0.0.0/16') | ||
| * ``` | ||
| * | ||
| * @see {@link Ipv4Cidr} | ||
| * | ||
| * @param cidrRange string representation of the cidr range | ||
| * @returns an instance of Ipv4Cidr | ||
| */ | ||
| function cidr(cidrRange) { | ||
| return new Ipv4Cidr(cidrRange); | ||
| }const RFC_1918_CIDRS = [cidr('10.0.0.0/8'), cidr('172.16.0.0/12'), cidr('192.168.0.0/16')]; | ||
| /** | ||
| * Predicate function that will return true if the given | ||
| * address is in the private RFC 1918 ipv4 address space. | ||
| * | ||
| * See more {@link https://datatracker.ietf.org/doc/html/rfc1918} | ||
| */ | ||
| function isPrivateRFC1918(address) { | ||
| for (const rfcCidr of RFC_1918_CIDRS) { | ||
| if (rfcCidr.includes(address)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| }var rfc1918=/*#__PURE__*/Object.freeze({__proto__:null,isPrivateRFC1918:isPrivateRFC1918});var index$1=/*#__PURE__*/Object.freeze({__proto__:null,rfc1918:rfc1918,Ipv4Address:Ipv4Address,address:address$1,stringToNum:stringToNum$1,numToString:numToString$1,Ipv4Cidr:Ipv4Cidr,cidr:cidr,MAX:MAX$1});const MAX_HEXTET_SIZE = 65535n; | ||
| /** | ||
| * Representation of an IPv6 address. Provides various utilities methods like equality | ||
| * checking. | ||
| * | ||
| * @remarks | ||
| * Avoid direct instantiation; use {@link ipv6.address} instead. | ||
| */ | ||
| class Ipv6Address { | ||
| constructor(address) { | ||
| this._address = typeof address === 'bigint' ? address : stringToNum(address); | ||
| } | ||
| /** | ||
| * The address as a bigint | ||
| * | ||
| * @remarks | ||
| * Because the representation of an IPv6 address is too large to fit into a typical | ||
| * JavaScript integer, a | ||
| * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt} | ||
| * is used instead. | ||
| */ | ||
| get address() { | ||
| return this._address; | ||
| } | ||
| // TODO: Add example code | ||
| /** | ||
| * Returns the string representation of the address | ||
| */ | ||
| toString() { | ||
| return numToString(this._address); | ||
| } | ||
| /** | ||
| * Compares if two IPv6 addresses are the same. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv6 as ip } from 'cidr-block' | ||
| * | ||
| * function isLoopback(address: Ipv6Representable) { | ||
| * return ip.address(address).equals('::1') | ||
| * } | ||
| * | ||
| * @public | ||
| * @param otherIpAddress the other Ipv6 address to compare | ||
| * @returns if the other IP address is the same | ||
| * ``` | ||
| */ | ||
| equals(otherIpAddress) { | ||
| if (otherIpAddress instanceof Ipv6Address) { | ||
| return this._address === otherIpAddress._address; | ||
| } | ||
| else { | ||
| return this._address === address(otherIpAddress)._address; | ||
| } | ||
| } | ||
| /** | ||
| * Calculates the next logical IPv6 address. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv6 as ip } from 'cidr-block' | ||
| * | ||
| * const myIp = ip.address('2001:0db8::ac10') | ||
| * myIp.nextIp() // ==> '2001:0db8::ac11' | ||
| * ``` | ||
| */ | ||
| nextIp() { | ||
| // TODO: Handle last ip address | ||
| return address(this._address + 1n); | ||
| } | ||
| /** | ||
| * Calculates the previous logical IPv6 address. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv6 as ip } from 'cidr-block' | ||
| * | ||
| * const myIp = ip.address('2001:0db8::ac10') | ||
| * myIp.previousIp() // ==> '2001:0db8::ac09' | ||
| * ``` | ||
| */ | ||
| previousIp() { | ||
| return address(this._address - 1n); | ||
| } | ||
| } | ||
| /** | ||
| * Convenience function for creating an IPv6 address instance. | ||
| * | ||
| * @remarks | ||
| * In general, you should use this function instead of instantiating an Ipv6Address | ||
| * object directly. | ||
| * | ||
| * @example | ||
| * | ||
| * ```typescript | ||
| * import { ipv6 as ip } from 'cidr-block' | ||
| * | ||
| * const localhost = ip.address('::1') | ||
| * ``` | ||
| * | ||
| * @see {@link Ipv6Address} | ||
| * | ||
| * @param ip string representation of the IPv6 address | ||
| * @returns an instance of Ipv6Address | ||
| */ | ||
| function address(ip) { | ||
| // TODO: Implement memoization | ||
| return new Ipv6Address(ip); | ||
| } | ||
| // TODO: Add code example | ||
| /** | ||
| * Converts the string representation of an IPv6 address to a bigint. | ||
| * | ||
| * @see {@link Ipv6Address} | ||
| * | ||
| * @public | ||
| * @param ip string representation of the IPv6 address | ||
| * @returns an instance of Ipv6Address | ||
| */ | ||
| function stringToNum(address) { | ||
| if (address === '::') { | ||
| return 0n; | ||
| } | ||
| let ipv6 = 0n; | ||
| const rawHextets = []; | ||
| const [leftAddress, rightAddress] = address.split('::'); | ||
| for (const hextet of leftAddress.split(':')) { | ||
| rawHextets.push(hextet || '0'); | ||
| } | ||
| if (rightAddress !== undefined) { | ||
| const rightHextets = rightAddress.split(':'); | ||
| const emptyFillCount = 8 - (rawHextets.length + rightHextets.length); | ||
| for (let i = 0; i < emptyFillCount; i++) { | ||
| rawHextets.push('0'); | ||
| } | ||
| for (const hextet of rightHextets) { | ||
| rawHextets.push(hextet || '0'); | ||
| } | ||
| } | ||
| const decimals = rawHextets.map(hextet => parseInt(hextet, 16)); | ||
| let shiftSize = 0n; | ||
| let binHex = 0n; | ||
| for (const pos in decimals) { | ||
| const num = decimals[pos]; | ||
| if (num === 0) { | ||
| continue; | ||
| } | ||
| shiftSize = BigInt(Math.abs(parseInt(pos) - 7) * 16); | ||
| binHex = BigInt(num) << shiftSize; | ||
| ipv6 |= binHex; | ||
| } | ||
| return ipv6; | ||
| } | ||
| /** | ||
| * Converts the numerical representation of an IPv6 address to its string representation. | ||
| * | ||
| * @see This method is the inverse of {@link ipv6.stringToNum} | ||
| * @throws {@link InvalidIpAddressError} | ||
| * | ||
| * @public | ||
| * @param ip IPv6 address as a number | ||
| * @returns string representation of the address | ||
| */ | ||
| function numToString(num) { | ||
| if (num === 0n) { | ||
| return '::'; | ||
| } | ||
| const hextets = []; | ||
| for (let n = 0; n < 8; n++) { | ||
| const bitOffset = BigInt(Math.abs(n - 7) * 16); | ||
| hextets.push(((num >> bitOffset) & MAX_HEXTET_SIZE).toString(16)); | ||
| } | ||
| const dropStartIdx = hextets.indexOf('0'); | ||
| if (dropStartIdx >= 0) { | ||
| let dropCount = 1; | ||
| for (let i = dropStartIdx + 1; hextets[i] === '0'; i++) { | ||
| dropCount++; | ||
| } | ||
| hextets.splice(dropStartIdx, dropCount, dropStartIdx === 0 || dropStartIdx + dropCount === 8 ? ':' : ''); | ||
| } | ||
| return hextets.join(':'); | ||
| }/** | ||
| * The numerical maximum size an IPv6 address can be | ||
| */ | ||
| const MAX = 2n ** 128n;var index=/*#__PURE__*/Object.freeze({__proto__:null,Ipv6Address:Ipv6Address,address:address,stringToNum:stringToNum,numToString:numToString,MAX:MAX});exports.errors=errors;exports.ipv4=index$1;exports.ipv6=index;//# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sources":["../src/src/errors.ts","../src/src/ipv4/constants.ts","../src/src/ipv4/ipv4-address.ts","../src/src/ipv4/ipv4-cidr.ts","../src/src/ipv4/rfc1918.ts","../src/src/ipv6/ipv6-address.ts","../src/src/ipv6/constants.ts"],"sourcesContent":[null,null,null,null,null,null,null],"names":["MAX","stringToNum","numToString","address","ipAddress"],"mappings":"4EAAa,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,KAAa;QACvB,KAAK,CAAC,GAAG,KAAK,+BAA+B,CAAC,CAAA;KAC/C;CACF;MAEY,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,OAAe;QACzB,KAAK,CAAC,GAAG,OAAO,kCAAkC,CAAC,CAAA;KACpD;iJCTH;;;AAGO,MAAMA,KAAG,GAAW,CAAC,IAAI,EAAE,GAAG,CAAC,CCCtC,MAAM,cAAc,GAAG,GAAG,CAAA;AAE1B;;;;;;;MAO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AAO,CAAC,GAAG,CAAC,CAAA;IACzC,IAAI,YAAY,IAAI,CAAC,EAAE;QACrB,IAAI,SAAS,GAAG,CAAC,CAAA;QACjB,KAAK,IAAI,CAAC,GAAG,YAAY,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC,EAAE,EAAE;YACtD,SAAS,EAAE,CAAA;SACZ;QACD,OAAO,CAAC,MAAM,CACZ,YAAY,EACZ,SAAS,EACT,YAAY,KAAK,CAAC,IAAI,YAAY,GAAG,SAAS,KAAK,CAAC,GAAG,GAAG,GAAG,EAAE,CAChE,CAAA;KACF;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC1B,CC5MA;;;AAGO,MAAM,GAAG,GAAG,EAAE,IAAI,IAAI"} |
| /** | ||
| * The numerical maximum size an IPv4 address can be | ||
| */ | ||
| export declare const MAX: number; |
| export * from './ipv4-address'; | ||
| export * from './ipv4-cidr'; | ||
| export * from './constants'; | ||
| export * from './types'; | ||
| export * as rfc1918 from './rfc1918'; |
| import { Ipv4Literal, Ipv4Representable } from './types'; | ||
| /** | ||
| * Representation of an IPv4 address. Provides various utility methods like equality | ||
| * checking. | ||
| * | ||
| * @remarks | ||
| * Avoid direct instantiation; use {@link ipv4.address} instead. | ||
| */ | ||
| export declare class Ipv4Address { | ||
| private _address; | ||
| constructor(address: Ipv4Literal); | ||
| /** | ||
| * The address as a number | ||
| */ | ||
| get address(): number; | ||
| /** | ||
| * Returns the string representation of the address | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv4 as ip } from 'cidr-block' | ||
| * | ||
| * ip.address(255) // ==> '0.0.0.255' | ||
| * ip.address(0b11111111_00000000_11111111_00000000) // ==> '255.0.255.0' | ||
| * ```` | ||
| * | ||
| * @public | ||
| * @returns the IPv4 address as a string | ||
| */ | ||
| toString(): string; | ||
| /** | ||
| * Compares if two IPv4 addresses are the same. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv4 as ip } from 'cidr-block' | ||
| * | ||
| * function isLoopback(address: Ipv4Representable) { | ||
| * return ip.address(address).equals('127.0.0.1') | ||
| * } | ||
| * ``` | ||
| * | ||
| * @public | ||
| * @param otherIpAddress the other IPv4 address to compare | ||
| * @returns if the other IP address is the same | ||
| */ | ||
| equals(otherIpAddress: Ipv4Representable): boolean; | ||
| /** | ||
| * Calculates the next logical IPv4 address. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv4 as ip } from 'cidr-block' | ||
| * | ||
| * const myIp = ip.address('52.89.32.255') | ||
| * myIp.nextIp() // ==> '52.89.33.0' | ||
| * ``` | ||
| * | ||
| * @public | ||
| * @returns the next consecutive IPv4 address | ||
| */ | ||
| nextIp(): Ipv4Address; | ||
| /** | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv4 as ip } from 'cidr-block' | ||
| * | ||
| * const myIp = ip.address('52.89.32.19') | ||
| * myIp.previousIp() // ==> '52.89.32.18' | ||
| * ``` | ||
| * | ||
| * @public | ||
| * @returns the preceding IPv4 address | ||
| */ | ||
| previousIp(): Ipv4Address; | ||
| } | ||
| /** | ||
| * Convenience function for creating an IPv4 address instance. | ||
| * | ||
| * @remarks | ||
| * In general, you should use this function instead of instantiating an Ipv4Address | ||
| * object directly. | ||
| * | ||
| * @example | ||
| * | ||
| * ```typescript | ||
| * import { ipv4 as ip } from 'cidr-block' | ||
| * | ||
| * const localhost = ip.address('127.0.0.1') | ||
| * ``` | ||
| * | ||
| * @see {@link Ipv4Address} | ||
| * | ||
| * @public | ||
| * @param ip string representation of the IPv4 address | ||
| * @returns an instance of Ipv4Address | ||
| */ | ||
| export declare function address(ip: Ipv4Literal): Ipv4Address; | ||
| /** | ||
| * Converts the string representation of an IPv4 address to a number. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import * as cidr from 'cidr-block' | ||
| * | ||
| * cidr.ipv4.stringToNum('255.255.255.255') === 4_294_967_295 // ==> true | ||
| * cidr.ipv4.stringToNum('0.0.0.255') === 255 // ==> true | ||
| * ``` | ||
| * | ||
| * @see This method is the inverse of {@link ipv4.numToString} | ||
| * @throws {@link InvalidIpAddressError} | ||
| * | ||
| * @public | ||
| * @param address IPv4 address represented as a string | ||
| * @returns numerical number representation of the address | ||
| */ | ||
| export declare function stringToNum(address: string): number; | ||
| /** | ||
| * Converts the numerical representation of an IPv4 address to its string representation. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import * as cidr from 'cidr-block' | ||
| * | ||
| * cidr.ipv4.numToString(0) === '0.0.0.0' // ==> true | ||
| * cidr.ipv4.numToString(65_280) === '0.0.255.0' // ==> true | ||
| * cidr.ipv4.numToString(4_294_967_295) === '255.255.255.255' // ==> true | ||
| * ``` | ||
| * | ||
| * @see This method is the inverse of {@link ipv4.stringToNum} | ||
| * @throws {@link InvalidIpAddressError} | ||
| * | ||
| * @public | ||
| * @param ip IPv4 address as a number | ||
| * @returns string representation of the address | ||
| */ | ||
| export declare function numToString(ip: number): string; |
| import { Ipv4Representable } from './types'; | ||
| import { Ipv4Address } from './ipv4-address'; | ||
| export declare class Ipv4Cidr { | ||
| private _ipAddress; | ||
| private _maskSize; | ||
| constructor(cidrRange: string); | ||
| /** | ||
| * The size of the cidr netmask (the number after the slash in cidr notation) | ||
| */ | ||
| get maskSize(): number; | ||
| /** | ||
| * Number of IP addresses within the cidr range | ||
| */ | ||
| get allocatableIpCount(): number; | ||
| /** | ||
| * The actual IPv4 netmask address | ||
| */ | ||
| get netmask(): Ipv4Address; | ||
| /** | ||
| * The first IPv4 address that is usable within the given cidr range | ||
| */ | ||
| get firstUsableIp(): Ipv4Address; | ||
| /** | ||
| * The last IPv4 address that is usable within the given cidr range | ||
| */ | ||
| get lastUsableIp(): Ipv4Address; | ||
| private get addressLength(); | ||
| /** | ||
| * @returns string representation of the cidr range | ||
| */ | ||
| toString(): string; | ||
| /** | ||
| * @returns the next consecutive cidr block | ||
| */ | ||
| nextBlock(ofSize?: number): Ipv4Cidr; | ||
| /** | ||
| * @returns the previous cidr block | ||
| */ | ||
| previousBlock(): Ipv4Cidr; | ||
| /** | ||
| * @returns if the given IPv4 address is within the cidr range | ||
| */ | ||
| includes(address: Ipv4Representable): boolean; | ||
| } | ||
| /** | ||
| * Convenience function for creating an IPv4 cidr range instance. | ||
| * | ||
| * @remarks | ||
| * | ||
| * In general, you should use this function instead of instantiating an Ipv4Cidr | ||
| * object directly. While there is nothing wrong with direct instantiation, convenience | ||
| * methods like these are meant to help reduce the footprint of your code and increase | ||
| * readability. | ||
| * | ||
| * @example | ||
| * | ||
| * ```typescript | ||
| * import { ipv4 as ip } from 'cidr-block' | ||
| * | ||
| * const vpcCidrRange = ip.cidr('10.0.0.0/16') | ||
| * ``` | ||
| * | ||
| * @see {@link Ipv4Cidr} | ||
| * | ||
| * @param cidrRange string representation of the cidr range | ||
| * @returns an instance of Ipv4Cidr | ||
| */ | ||
| export declare function cidr(cidrRange: string): Ipv4Cidr; |
| import { Ipv4Address } from './ipv4-address'; | ||
| /** | ||
| * Predicate function that will return true if the given | ||
| * address is in the private RFC 1918 ipv4 address space. | ||
| * | ||
| * See more {@link https://datatracker.ietf.org/doc/html/rfc1918} | ||
| */ | ||
| export declare function isPrivateRFC1918(address: Ipv4Address): boolean; |
| import { Ipv4Address } from './ipv4-address'; | ||
| /** | ||
| * Type that indicates a literal string or number value that represents an IPv4 address | ||
| */ | ||
| export declare type Ipv4Literal = string | number; | ||
| /** | ||
| * Type that indicates either a literal value or an address instance that is an IPv4 | ||
| */ | ||
| export declare type Ipv4Representable = Ipv4Address | Ipv4Literal; |
| /** | ||
| * The numerical maximum size an IPv6 address can be | ||
| */ | ||
| export declare const MAX: bigint; |
| export * from './ipv6-address'; | ||
| export * from './constants'; | ||
| export * from './types'; |
| import { Ipv6Literal, Ipv6Representable } from './types'; | ||
| /** | ||
| * Representation of an IPv6 address. Provides various utilities methods like equality | ||
| * checking. | ||
| * | ||
| * @remarks | ||
| * Avoid direct instantiation; use {@link ipv6.address} instead. | ||
| */ | ||
| export declare class Ipv6Address { | ||
| private _address; | ||
| constructor(address: Ipv6Literal); | ||
| /** | ||
| * The address as a bigint | ||
| * | ||
| * @remarks | ||
| * Because the representation of an IPv6 address is too large to fit into a typical | ||
| * JavaScript integer, a | ||
| * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt} | ||
| * is used instead. | ||
| */ | ||
| get address(): bigint; | ||
| /** | ||
| * Returns the string representation of the address | ||
| */ | ||
| toString(): string; | ||
| /** | ||
| * Compares if two IPv6 addresses are the same. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv6 as ip } from 'cidr-block' | ||
| * | ||
| * function isLoopback(address: Ipv6Representable) { | ||
| * return ip.address(address).equals('::1') | ||
| * } | ||
| * | ||
| * @public | ||
| * @param otherIpAddress the other Ipv6 address to compare | ||
| * @returns if the other IP address is the same | ||
| * ``` | ||
| */ | ||
| equals(otherIpAddress: Ipv6Representable): boolean; | ||
| /** | ||
| * Calculates the next logical IPv6 address. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv6 as ip } from 'cidr-block' | ||
| * | ||
| * const myIp = ip.address('2001:0db8::ac10') | ||
| * myIp.nextIp() // ==> '2001:0db8::ac11' | ||
| * ``` | ||
| */ | ||
| nextIp(): Ipv6Address; | ||
| /** | ||
| * Calculates the previous logical IPv6 address. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { ipv6 as ip } from 'cidr-block' | ||
| * | ||
| * const myIp = ip.address('2001:0db8::ac10') | ||
| * myIp.previousIp() // ==> '2001:0db8::ac09' | ||
| * ``` | ||
| */ | ||
| previousIp(): Ipv6Address; | ||
| } | ||
| /** | ||
| * Convenience function for creating an IPv6 address instance. | ||
| * | ||
| * @remarks | ||
| * In general, you should use this function instead of instantiating an Ipv6Address | ||
| * object directly. | ||
| * | ||
| * @example | ||
| * | ||
| * ```typescript | ||
| * import { ipv6 as ip } from 'cidr-block' | ||
| * | ||
| * const localhost = ip.address('::1') | ||
| * ``` | ||
| * | ||
| * @see {@link Ipv6Address} | ||
| * | ||
| * @param ip string representation of the IPv6 address | ||
| * @returns an instance of Ipv6Address | ||
| */ | ||
| export declare function address(ip: Ipv6Literal): Ipv6Address; | ||
| /** | ||
| * Converts the string representation of an IPv6 address to a bigint. | ||
| * | ||
| * @see {@link Ipv6Address} | ||
| * | ||
| * @public | ||
| * @param ip string representation of the IPv6 address | ||
| * @returns an instance of Ipv6Address | ||
| */ | ||
| export declare function stringToNum(address: string): bigint; | ||
| /** | ||
| * Converts the numerical representation of an IPv6 address to its string representation. | ||
| * | ||
| * @see This method is the inverse of {@link ipv6.stringToNum} | ||
| * @throws {@link InvalidIpAddressError} | ||
| * | ||
| * @public | ||
| * @param ip IPv6 address as a number | ||
| * @returns string representation of the address | ||
| */ | ||
| export declare function numToString(num: bigint): string; |
| import { Ipv6Address } from './ipv6-address'; | ||
| /** | ||
| * Type that indicates a literal string or number value that represents an IPv6 address | ||
| */ | ||
| export declare type Ipv6Literal = string | bigint; | ||
| /** | ||
| * Type that indicates either a literal value or an address instance that is an IPv6 | ||
| */ | ||
| export declare type Ipv6Representable = Ipv6Address | Ipv6Literal; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
423523
591.76%10
-33.33%62
226.32%7335
436.18%694
905.8%0
-100%Yes
NaN1
Infinity%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added