### Install ip-address via npm
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Install the ip-address library using npm. This is the standard installation command for adding the package to a project.
```sh
npm install ip-address
```
--------------------------------
### fromBigInt usage example
Source: https://github.com/beaugunderson/ip-address
Example of converting a bigint to an Address4 and getting its correct form.
```TypeScript
Address4.fromBigInt(3232235777n).correctForm(); // '192.168.1.1'
```
--------------------------------
### fromBigInt usage example
Source: https://github.com/beaugunderson/ip-address
Converts a bigint to an Address6 and gets its canonical form.
```TypeScript
const a = Address6.fromBigInt(BigInt('1000000000000'));
a.correctForm(); // '::e8:d4a5:1000'
```
--------------------------------
### startAddress usage example
Source: https://github.com/beaugunderson/ip-address
Example showing network address and first host address.
```typescript
const net = new Address4('192.168.1.0/24');
net.startAddress().correctForm(); // '192.168.1.0'
net.startAddressExclusive().correctForm(); // '192.168.1.1'
```
--------------------------------
### getBitsBase2(start: number, end: number): string
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns the bits in the given range as a base-2 string.
```APIDOC
## getBitsBase2(start: number, end: number): string
### Description
Returns the bits in the given range as a base-2 string.
### Method
getBitsBase2
### Parameters
- **start** (number) - Required - The start bit index.
- **end** (number) - Required - The end bit index.
### Returns
- **string** - The bits in the range as a base-2 string.
```
--------------------------------
### getBitsBase2(start, end)
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns the bits in the given range as a base-2 string.
```APIDOC
## getBitsBase2(start, end)
### Description
Returns the bits in the given range as a base-2 string.
### Method
`getBitsBase2(start: number, end: number): string`
### Parameters
- **start** (number) - Required - The start bit index.
- **end** (number) - Required - The end bit index.
### Returns
- **string** - The bits in the given range as a base-2 string.
```
--------------------------------
### getBits(start: number, end: number): bigint
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns the bits in the given range as a BigInt.
```APIDOC
## getBits(start: number, end: number): bigint
### Description
Returns the bits in the given range as a BigInt.
### Method
getBits
### Parameters
- **start** (number) - Required - The start bit index.
- **end** (number) - Required - The end bit index.
### Returns
- **bigint** - The bits in the range as a BigInt.
```
--------------------------------
### nextNetwork usage example
Source: https://github.com/beaugunderson/ip-address
Example showing next network address.
```typescript
new Address4('10.0.0.0/24').nextNetwork().networkForm(); // '10.0.1.0/24'
```
--------------------------------
### offset usage examples
Source: https://github.com/beaugunderson/ip-address
Examples showing positive and negative offsets and error handling.
```typescript
new Address4('10.0.0.0/24').offset(1).correctForm(); // '10.0.0.1'
new Address4('10.0.0.0/24').offset(-1).correctForm(); // '9.255.255.255'
try {
new Address4('255.255.255.255').offset(1);
} catch (err) {
err.message; // 'IPv4 offset leaves the address space'
}
```
--------------------------------
### getBitsBase16(start: number, end: number): string
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns the bits in the given range as a base-16 string.
```APIDOC
## getBitsBase16(start: number, end: number): string
### Description
Returns the bits in the given range as a base-16 string.
### Method
getBitsBase16
### Parameters
- **start** (number) - Required - The start bit index.
- **end** (number) - Required - The end bit index.
### Returns
- **string** - The bits in the range as a base-16 string.
```
--------------------------------
### getScope() usage examples
Source: https://github.com/beaugunderson/ip-address
Shows example calls to getScope() with expected return values for various addresses.
```TypeScript
new Address6('ff02::1').getScope(); // 'Link local' (multicast scope field)
new Address6('fe80::1').getScope(); // 'Link local' (type-derived)
new Address6('2001:db8::1').getScope(); // 'Global'
new Address6('::').getScope(); // 'Unknown'
```
--------------------------------
### binaryZeroPad usage example
Source: https://github.com/beaugunderson/ip-address
Example call showing the zero-padded binary string for '192.168.0.1'.
```TypeScript
new Address4('192.168.0.1').binaryZeroPad(); // '11000000101010000000000000000001'
```
--------------------------------
### fromByteArray usage example
Source: https://github.com/beaugunderson/ip-address
Example of converting a byte array (from hex buffer) to an Address4 and getting its correct form.
```TypeScript
import { Buffer } from 'node:buffer';
Address4.fromByteArray([...Buffer.from('c0a80101', 'hex')]).correctForm(); // '192.168.1.1'
```
--------------------------------
### groupForV6 usage example
Source: https://github.com/beaugunderson/ip-address
Example call showing the HTML output for '192.168.0.1'.
```TypeScript
new Address4('192.168.0.1').groupForV6();
// '192.168.0.1'
```
--------------------------------
### decimal(): string
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Return the decimal form of the address.
```APIDOC
## decimal(): string
### Description
Return the decimal form of the address.
### Method
decimal
### Returns
- **string** - The decimal form of the address.
```
--------------------------------
### regularExpressionString usage example
Source: https://github.com/beaugunderson/ip-address
Shows the anchored pattern structure and usage. The pattern starts with '(?=^|' and ends with '|$)', and includes ADDRESS_BOUNDARY lookarounds. The example tests matching with and without zero compression.
```TypeScript
// The full string starts with the anchor '(?=^|' and ends with '|$)':
// '(?=^|' + '[^A-Fa-f0-9:]' + '|[^\w\:])(…group alternatives…)(?=[^\w\:]|' + '[^A-Fa-f0-9:]' + '|$)'
new Address6('2001:db8::1').regularExpressionString().includes('(?=^|'); // true
const re = new Address6('2001:db8::1').regularExpression(); // case-insensitive
re.test('2001:db8::1'); // true
re.test('2001:0db8::1'); // true
re.test('2001:db8::2'); // false (different host bits)
```
--------------------------------
### possibleSubnets usage examples
Source: https://github.com/beaugunderson/ip-address
Examples of calling possibleSubnets with different subnet sizes on an Address6 instance, showing the returned counts.
```ts
new Address6('2001:db8::/32').possibleSubnets(48); // '65536'
new Address6('2001:db8::/32').possibleSubnets(64); // '4294967296'
new Address6('2001:db8::/32').possibleSubnets(16); // '0'
```
--------------------------------
### toGroup6 usage example
Source: https://github.com/beaugunderson/ip-address
Example converting to two IPv6 hex groups.
```typescript
new Address4('192.168.1.1').toGroup6(); // 'c0a8:101'
```
--------------------------------
### toByteArray(): number[]
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Return a byte array. To get a Node.js `Buffer`, wrap the result: `Buffer.from(address.toByteArray())`.
```APIDOC
## toByteArray(): number[]
### Description
Return a byte array. To get a Node.js `Buffer`, wrap the result: `Buffer.from(address.toByteArray())`.
### Method
toByteArray
### Returns
- **number[]** - The byte array representation.
```
--------------------------------
### Constructor usage examples
Source: https://github.com/beaugunderson/ip-address
Shows constructing Address6 with a subnet and zone, and catching an out-of-range subnet error.
```TypeScript
const a = new Address6('2001:db8::1/64');
a.subnetMask; // 64
a.correctForm(); // '2001:db8::1'
const z = new Address6('fe80::1%eth0');
z.zone; // '%eth0'
z.correctForm(); // 'fe80::1'
try {
new Address6('2001:db8::1/129'); // out-of-range subnet
} catch (err) {
err.message; // 'Invalid subnet mask.'
}
```
--------------------------------
### bigInt()
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns the address as a bigint.
```APIDOC
## bigInt()
### Description
Returns the address as a `bigint`.
### Method
`bigInt(): bigint`
### Returns
- **bigint** - The address as a bigint.
```
--------------------------------
### endAddress usage example
Source: https://github.com/beaugunderson/ip-address
Example showing broadcast address and last host address.
```typescript
new Address4('192.168.1.0/24').endAddress().correctForm(); // '192.168.1.255'
new Address4('192.168.1.0/24').endAddressExclusive().correctForm(); // '192.168.1.254'
```
--------------------------------
### binaryZeroPad(): string
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns a zero-padded base-2 string representation of the address.
```APIDOC
## binaryZeroPad(): string
### Description
Returns a zero-padded base-2 string representation of the address.
### Method
binaryZeroPad
### Returns
- **string** - The zero-padded binary string.
```
--------------------------------
### to4in6(): string
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Return the v4-in-v6 form of the address.
```APIDOC
## to4in6(): string
### Description
Return the v4-in-v6 form of the address.
### Method
to4in6
### Returns
- **string** - The v4-in-v6 form of the address.
```
--------------------------------
### bigInt usage example
Source: https://github.com/beaugunderson/ip-address
Example returning bigint representation.
```typescript
new Address4('192.168.1.1').bigInt(); // 3232235777n
```
--------------------------------
### getType() usage examples
Source: https://github.com/beaugunderson/ip-address
Shows example calls to getType() with expected return values for various addresses.
```TypeScript
new Address6('ff02::1').getType(); // 'Multicast (All nodes on this link)'
new Address6('::1').getType(); // 'Loopback'
new Address6('2001:db8::1').getType(); // 'Documentation'
```
--------------------------------
### fromURL usage examples
Source: https://github.com/beaugunderson/ip-address
Parses a valid URL with port and an invalid URL, showing the error variant.
```TypeScript
const r = Address6.fromURL('http://[ffff::]:8080/foo/');
r.address.correctForm(); // 'ffff::'
r.port; // 8080
const bad = Address6.fromURL('http://[not-an-address]/');
bad.error; // 'failed to parse address from URL'
bad.address; // null
```
--------------------------------
### bigInt(): bigint
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Return the address as a BigInt.
```APIDOC
## bigInt(): bigint
### Description
Return the address as a BigInt.
### Method
bigInt
### Returns
- **bigint** - The address as a BigInt.
```
--------------------------------
### Properties
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Properties of the Address4 class.
```APIDOC
## Properties
### Description
Properties of the Address4 class.
### Properties
- **address** (string) - The address.
- **addressMinusSuffix** (string) - The address without the subnet suffix.
- **groups** (number) - The number of groups.
- **parsedAddress** (string[]) - The parsed address groups.
- **parsedSubnet** (string) - The parsed subnet.
- **subnet** (string) - The subnet.
- **subnetMask** (number) - The subnet mask.
- **v4** (boolean) - Always true for IPv4.
- **isCorrect** (() => boolean) - Returns true if the address is correct, false otherwise.
- **isInSubnet** ((address: Address4 | Address6) => boolean) - Returns true if the given address is in the subnet of the current address. An `Address6` is never in the subnet of an `Address4`; convert with `to4()` or `Address6.fromAddress4()` to compare across families.
- **isHostInSubnet** ((address: Address4 | Address6) => boolean) - Returns true if this address's host bits fall inside the given subnet, ignoring this address's own subnet mask. Prefer this over `isInSubnet` when classifying a single address, so the answer doesn't change with the CIDR suffix the caller happened to write — notably when the address came from untrusted input and the result backs a trust-boundary decision. An `Address6` is never in the subnet of an `Address4`; convert with `to4()` or `Address6.fromAddress4()` to compare across families.
```
--------------------------------
### binaryZeroPad()
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns a zero-padded base-2 string representation of the address.
```APIDOC
## binaryZeroPad()
### Description
Returns a zero-padded base-2 string representation of the address.
### Method
binaryZeroPad()
### Returns
- **string** - Zero-padded binary string representation.
```
--------------------------------
### isHostInSubnet usage example
Source: https://github.com/beaugunderson/ip-address
Example showing true for a host inside a /16 subnet even when the address has a /8 mask.
```TypeScript
new Address4('192.168.1.42/8').isHostInSubnet(new Address4('192.168.0.0/16')); // true
```
--------------------------------
### toHex usage example
Source: https://github.com/beaugunderson/ip-address
Example converting an IPv4 address to colon-separated hex octets.
```typescript
new Address4('127.0.0.1').toHex(); // '7f:00:00:01'
```
--------------------------------
### parse usage example
Source: https://github.com/beaugunderson/ip-address
Example of calling parse on an Address4 instance; returns array of octet strings.
```typescript
const a = new Address4('192.168.1.1');
a.parse('10.0.0.1'); // ['10', '0', '0', '1']
```
--------------------------------
### toArray usage example
Source: https://github.com/beaugunderson/ip-address
Example returning array of four byte values.
```typescript
new Address4('192.168.1.1').toArray(); // [192, 168, 1, 1]
```
--------------------------------
### correctForm usage example
Source: https://github.com/beaugunderson/ip-address
Example showing leading zeros stripped in correctForm output.
```typescript
new Address4('192.168.001.001').correctForm(); // '192.168.1.1'
```
--------------------------------
### possibleSubnets(subnetSize?: number): string
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns the number of possible subnets of a given size in the address.
```APIDOC
## possibleSubnets(subnetSize?: number): string
### Description
Returns the number of possible subnets of a given size in the address.
### Method
possibleSubnets
### Parameters
- **subnetSize** (number) - Optional - The size of the subnet.
### Returns
- **string** - The number of possible subnets.
```
--------------------------------
### getType(): string
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns the type of the address.
```APIDOC
## getType(): string
### Description
Returns the type of the address.
### Method
getType
### Returns
- **string** - The type of the address.
```
--------------------------------
### isCorrect usage examples
Source: https://github.com/beaugunderson/ip-address
Examples showing correct and incorrect spellings and subnet normalization.
```typescript
new Address4('192.168.1.1').isCorrect(); // true
new Address4('192.168.1.1/24').isCorrect(); // true
new Address4('192.168.001.1').isCorrect(); // false
new Address4('127.0.0.1/02').isCorrect(); // false ('02' vs '2')
```
--------------------------------
### getBitsPastSubnet(): string
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns the bits that are set past the subnet mask length.
```APIDOC
## getBitsPastSubnet(): string
### Description
Returns the bits that are set past the subnet mask length.
### Method
getBitsPastSubnet
### Returns
- **string** - The bits past the subnet mask length.
```
--------------------------------
### isBenchmarking()
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns true if the address is in the benchmarking range 198.18.0.0/15 (RFC 2544).
```APIDOC
## isBenchmarking()
### Description
Returns true if the address is in the benchmarking range `198.18.0.0/15` ([RFC 2544](https://datatracker.ietf.org/doc/html/rfc2544)).
### Method
isBenchmarking()
### Returns
- **boolean** - True if the address is in the benchmarking range.
```
--------------------------------
### isHostInSubnet usage example
Source: https://github.com/beaugunderson/ip-address
Example showing isHostInSubnet returns true when the host bits fall inside the given subnet.
```TypeScript
new Address6('2001:db8::1/128').isHostInSubnet(new Address6('2001:db8::/32')); // true
```
--------------------------------
### to6to4(): Address6 | null
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Return a v6 6to4 address from a v6 v4inv6 address.
```APIDOC
## to6to4(): Address6 | null
### Description
Return a v6 6to4 address from a v6 v4inv6 address.
### Method
to6to4
### Returns
- **Address6 | null** - The 6to4 address, or null if not applicable.
```
--------------------------------
### isInSubnet usage examples
Source: https://github.com/beaugunderson/ip-address
Examples showing isInSubnet returns true when the network is contained, false when narrower.
```TypeScript
new Address6('2001:db8::1').isInSubnet(new Address6('2001:db8::/32')); // true
new Address6('2001:db8::/32').isInSubnet(new Address6('2001::/16')); // false (narrower)
```
--------------------------------
### reverseForm usage examples
Source: https://github.com/beaugunderson/ip-address
Shows default and omitSuffix variants for 192.0.2.42.
```TypeScript
new Address4('192.0.2.42').reverseForm(); // '42.2.0.192.in-addr.arpa.'
new Address4('192.0.2.42').reverseForm({ omitSuffix: true }); // '42.2.0.192'
```
--------------------------------
### binaryZeroPad usage example
Source: https://github.com/beaugunderson/ip-address
Example of calling binaryZeroPad() on an Address6 instance, returning the full 128-bit binary string.
```ts
new Address6('2001:4860:4001:803::1011').binaryZeroPad();
// '0010000000000001010010000110000001000000000000010000100000000011...'
```
--------------------------------
### fromUnsignedByteArray usage example
Source: https://github.com/beaugunderson/ip-address
Example of converting an unsigned byte array to an Address4 and accessing its subnet property.
```TypeScript
Address4.fromUnsignedByteArray([192, 168, 0, 1]).subnet; // '/32'
```
--------------------------------
### AddressError constructor
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Creates a new AddressError instance with a message and optional parse message.
```APIDOC
## new AddressError(message, parseMessage?)
### Description
Creates a new AddressError instance with a message and optional parse message.
### Method
Constructor
### Parameters
- **message** (string) - Required - The error message.
- **parseMessage** (string) - Optional - The offending address with the portion that failed to parse wrapped in ``.
### Response
- **AddressError** - The new AddressError instance.
```
--------------------------------
### getBitsPastSubnet usage example
Source: https://github.com/beaugunderson/ip-address
Example of calling getBitsPastSubnet() on an Address6 instance with a /120 subnet, returning the host bits.
```ts
new Address6('2001:db8::1/120').getBitsPastSubnet(); // '00000001'
```
--------------------------------
### reverseForm(options?: ReverseFormOptions): string
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns the reversed ip6.arpa form of the address.
```APIDOC
## reverseForm(options?: ReverseFormOptions): string
### Description
Returns the reversed ip6.arpa form of the address.
### Method
reverseForm
### Parameters
- **options** (ReverseFormOptions) - Optional - Options for the reverse form.
### Returns
- **string** - The reversed ip6.arpa form.
```
--------------------------------
### mask(mask?)
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns the first n bits of the address, defaulting to the subnet mask.
```APIDOC
## mask(mask?)
### Description
Returns the first n bits of the address, defaulting to the subnet mask.
### Method
`mask(mask?: number): string`
### Parameters
- **mask** (number) - Optional - The number of bits to include.
### Returns
- **string** - The first n bits of the address.
```
--------------------------------
### isUnspecified(): boolean
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns true if the address is the unspecified address ::.
```APIDOC
## isUnspecified(): boolean
### Description
Returns true if the address is the unspecified address ::.
### Method
isUnspecified()
### Returns
- **boolean** - True if the address is unspecified, false otherwise.
```
--------------------------------
### Address4.toHex(): string
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Instance method that converts an IPv4 address object to a hex string.
```APIDOC
## Address4.toHex(): string
### Description
Converts an IPv4 address object to a hex string.
### Method
Instance method
### Returns
- **string** - The hex string representation of the address.
```
--------------------------------
### getBits usage example
Source: https://github.com/beaugunderson/ip-address
Example of calling getBits(0, 8) on an Address6 instance, returning the first 8 bits as a bigint.
```ts
new Address6('ff02::1').getBits(0, 8); // 255n
```
--------------------------------
### Address6 constructor examples
Source: https://github.com/beaugunderson/ip-address
Shows how to construct Address6 with zone, subnet, and optionalGroups parameters. The optionalGroups parameter is primarily internal, used by to4in6() to parse 6 groups.
```TypeScript
new Address6('fe80::1%eth0'); // zone parsed into `zone`
new Address6('2001:db8::1/64'); // subnet parsed into `subnetMask`
new Address6('2001:db8:0:0:0:0', 6); // internal use: parse 6 groups (see to4in6(), src/ipv6.ts#L996)
```
--------------------------------
### mask usage example
Source: https://github.com/beaugunderson/ip-address
Example of calling mask(16) on an Address6 instance, returning the first 16 bits as a base-2 string.
```ts
new Address6('2001:db8::1').mask(16); // '0010000000000001'
```
--------------------------------
### fromArpa usage example
Source: https://github.com/beaugunderson/ip-address
Example of converting an in-addr.arpa string to an Address4 and getting its correct form. Round-trips reverseForm().
```TypeScript
Address4.fromArpa('42.2.0.192.in-addr.arpa.').correctForm(); // '192.0.2.42'
```
--------------------------------
### startAddress()
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns the first address in the range given by this address' subnet, often referred to as the Network Address.
```APIDOC
## startAddress()
### Description
Returns the first address in the range given by this address' subnet, often referred to as the Network Address.
### Method
`startAddress(): Address4`
### Returns
- **Address4** - The first address in the subnet.
```
--------------------------------
### microsoftTranscription(): string
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Instance method that returns the Microsoft UNC transcription of the address.
```APIDOC
## microsoftTranscription(): string
### Description
Return the Microsoft UNC transcription of the address.
### Method
instance
### Returns
- **string** - The Microsoft UNC transcription.
```
--------------------------------
### isLoopback(): boolean
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns true if the address is a loopback address, false otherwise.
```APIDOC
## isLoopback(): boolean
### Description
Returns true if the address is a loopback address, false otherwise.
### Method
isLoopback()
### Returns
- **boolean** - True if the address is loopback, false otherwise.
```
--------------------------------
### getBitsBase2 usage example
Source: https://github.com/beaugunderson/ip-address
Example of calling getBitsBase2(0, 8) on an Address6 instance, returning the first 8 bits as a base-2 string.
```ts
new Address6('ff02::1').getBitsBase2(0, 8); // '11111111'
```
--------------------------------
### fromAddressAndMask usage example
Source: https://github.com/beaugunderson/ip-address
Constructs an Address6 with a mask and retrieves the subnet mask as a number.
```TypeScript
Address6.fromAddressAndMask('fe80::1', 'ffff:ffff:ffff:ffff::').subnetMask; // 64
```
--------------------------------
### fromAddressAndWildcardMask usage example
Source: https://github.com/beaugunderson/ip-address
Constructs an Address6 with a wildcard mask and retrieves the subnet mask.
```TypeScript
Address6.fromAddressAndWildcardMask('fe80::1', '::ffff:ffff:ffff:ffff').subnetMask; // 64
```
--------------------------------
### toGroup6()
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Converts an IPv4 address object to an IPv6 address group.
```APIDOC
## toGroup6()
### Description
Converts an IPv4 address object to an IPv6 address group.
### Method
`toGroup6(): string`
### Returns
- **string** - The IPv6 address group representation.
```
--------------------------------
### Address6.isCorrect
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns true if the address is correct, false otherwise.
```APIDOC
## isCorrect
### Description
Returns true if the address is correct, false otherwise.
### Method
isCorrect
### Parameters
None
### Response
- **boolean** - True if the address is correct, false otherwise.
```
--------------------------------
### startAddress(): Address6
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns the first address in the range given by this address' subnet, often referred to as the Network Address.
```APIDOC
## startAddress(): Address6
### Description
Returns the first address in the range given by this address' subnet, often referred to as the Network Address.
### Method
startAddress
### Returns
- **Address6** - The first address in the subnet.
```
--------------------------------
### isCanonical(): boolean
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns true if the address is in the canonical form, false otherwise.
```APIDOC
## isCanonical(): boolean
### Description
Returns true if the address is in the canonical form, false otherwise.
### Method
isCanonical
### Returns
- **boolean** - True if canonical, false otherwise.
```
--------------------------------
### is6to4(): boolean
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns true if the address is a 6to4 address, false otherwise.
```APIDOC
## is6to4(): boolean
### Description
Returns true if the address is a 6to4 address, false otherwise.
### Method
is6to4()
### Returns
- **boolean** - True if the address is 6to4, false otherwise.
```
--------------------------------
### toUnsignedByteArray(): number[]
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Return an unsigned byte array. To get a Node.js `Buffer`, wrap the result: `Buffer.from(address.toUnsignedByteArray())`.
```APIDOC
## toUnsignedByteArray(): number[]
### Description
Return an unsigned byte array. To get a Node.js `Buffer`, wrap the result: `Buffer.from(address.toUnsignedByteArray())`.
### Method
toUnsignedByteArray
### Returns
- **number[]** - The unsigned byte array representation.
```
--------------------------------
### Address4.toArray(): number[]
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Instance method that converts an IPv4 address object to an array of bytes. To get a Node.js Buffer, wrap the result: Buffer.from(address.toArray()).
```APIDOC
## Address4.toArray(): number[]
### Description
Converts an IPv4 address object to an array of bytes. To get a Node.js `Buffer`, wrap the result: `Buffer.from(address.toArray())`.
### Method
Instance method
### Returns
- **number[]** - The array of bytes.
```
--------------------------------
### reverseForm usage with omitSuffix
Source: https://github.com/beaugunderson/ip-address
Example calls to reverseForm with omitSuffix true, showing returned strings for IPv4 and IPv6 addresses.
```TypeScript
import { Address4, Address6 } from 'ip-address';
new Address4('192.0.2.42').reverseForm({ omitSuffix: true }); // '42.2.0.192'
new Address6('2001:db8::/32').reverseForm({ omitSuffix: true }); // '8.b.d.0.1.0.0.2'
```
--------------------------------
### Validate, parse, and manipulate IPv4 and IPv6 addresses
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Comprehensive example covering validation, parsing, subnet membership, range queries, strict network-address checks, address properties, numeric/byte representations, embedded IPv4 and Teredo, and URL parsing. Note that parsing throws AddressError on invalid input, and isValid() accepts CIDRs with host bits set but such addresses are not network addresses.
```ts
import { Address4, Address6 } from 'ip-address';
// Validation
Address4.isValid('192.168.1.1'); // true
Address6.isValid('2001:db8::1'); // true
Address6.isValid('not an address'); // false
// Parsing (throws AddressError on invalid input)
const v4 = new Address4('192.168.1.1/24');
const v6 = new Address6('2001:db8::1/64');
// Subnet membership
const host = new Address4('192.168.1.42');
const network = new Address4('192.168.1.0/24');
host.isInSubnet(network); // true
// Subnet range
network.startAddress().correctForm(); // '192.168.1.0'
network.endAddress().correctForm(); // '192.168.1.255'
// Strict network-address check (host bits must be zero).
// isValid() accepts CIDRs with host bits set — '192.168.1.5/24' is a valid
// host-with-subnet, but it isn't a network address.
const cidr = new Address4('192.168.1.5/24');
Address4.isValid('192.168.1.5/24'); // true
cidr.correctForm() === cidr.startAddress().correctForm(); // false
// Address properties
const link = new Address6('fe80::1');
link.isLinkLocal(); // true
link.isMulticast(); // false
link.isLoopback(); // false
new Address4('192.168.1.1').isPrivate(); // true (RFC 1918)
new Address6('fc00::1').isULA(); // true (RFC 4193)
// Numeric and byte representations
v4.bigInt(); // 3232235777n
v4.toArray(); // [192, 168, 1, 1]
v6.canonicalForm(); // '2001:0db8:0000:0000:0000:0000:0000:0001'
// Embedded IPv4 + Teredo
const teredo = new Address6('2001:0:ce49:7601:e866:efff:62c3:fffe');
teredo.inspectTeredo().client4; // '157.60.0.1'
// Parse host + port from a URL
Address6.fromURL('http://[2001:db8::1]:8080/').port; // 8080
```
--------------------------------
### reverseForm(options?)
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns the reversed in-addr.arpa form of the address, e.g., 42.2.0.192.in-addr.arpa. for 192.0.2.42.
```APIDOC
## reverseForm(options?)
### Description
Returns the reversed in-addr.arpa form of the address, e.g., `42.2.0.192.in-addr.arpa.` for `192.0.2.42`.
### Method
`reverseForm(options?: ReverseFormOptions): string`
### Parameters
- **options** (ReverseFormOptions) - Optional - Options for the reverse form.
### Returns
- **string** - The reversed in-addr.arpa form.
```
--------------------------------
### isDocumentation(): boolean
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns true if the address is in the documentation prefix 2001:db8::/32 (RFC 3849).
```APIDOC
## isDocumentation(): boolean
### Description
Returns true if the address is in the documentation prefix 2001:db8::/32 (RFC 3849).
### Method
isDocumentation()
### Returns
- **boolean** - True if the address is documentation, false otherwise.
```
--------------------------------
### startAddressExclusive()
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns the first host address in the range given by this address's subnet, i.e., the first address after the Network Address.
```APIDOC
## startAddressExclusive()
### Description
Returns the first host address in the range given by this address's subnet, i.e., the first address after the Network Address.
### Method
`startAddressExclusive(): Address4`
### Returns
- **Address4** - The first host address in the subnet.
```
--------------------------------
### subnetMaskAddress and wildcardMask usage examples
Source: https://github.com/beaugunderson/ip-address
Shows dotted-decimal subnet mask for /20 and Cisco-style wildcard mask for /24.
```TypeScript
new Address4('10.0.0.0/20').subnetMaskAddress().correctForm(); // '255.255.240.0'
new Address4('10.0.0.0/24').wildcardMask().correctForm(); // '0.0.0.255'
```
--------------------------------
### mask usage example
Source: https://github.com/beaugunderson/ip-address
Example showing mask(8) returning '11000000' for 192.168.1.1.
```TypeScript
new Address4('192.168.1.1').mask(8); // '11000000'
```
--------------------------------
### href usage examples
Source: https://github.com/beaugunderson/ip-address
Shows how to generate URLs with and without a port. The first returns 'http://[2001:db8::1]/' and the second 'http://[2001:db8::1]:8080/'.
```ts
new Address6('2001:db8::1').href(); // 'http://[2001:db8::1]/'
new Address6('2001:db8::1').href(8080); // 'http://[2001:db8::1]:8080/'
```
--------------------------------
### getBitsBase2 usage example
Source: https://github.com/beaugunderson/ip-address
Example showing getBitsBase2(0, 4) returning '1100' for 192.168.1.1.
```TypeScript
new Address4('192.168.1.1').getBitsBase2(0, 4); // '1100'
```
--------------------------------
### networkForm usage example
Source: https://github.com/beaugunderson/ip-address
Example showing networkForm() returning '192.168.1.0/24' for an address with /24 prefix.
```TypeScript
new Address4('192.168.1.5/24').networkForm(); // '192.168.1.0/24'
```
--------------------------------
### startAddressExclusive(): Address6
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns the first host address in the range given by this address's subnet, i.e., the first address after the Network Address.
```APIDOC
## startAddressExclusive(): Address6
### Description
Returns the first host address in the range given by this address's subnet, i.e., the first address after the Network Address.
### Method
startAddressExclusive
### Returns
- **Address6** - The first host address in the subnet.
```
--------------------------------
### regularExpression usage example
Source: https://github.com/beaugunderson/ip-address
Shows how to create a case-insensitive regular expression and test it against various address formats. The pattern matches addresses with leading zeros and rejects different host bits.
```TypeScript
const re = new Address6('2001:db8::1').regularExpression();
re.test('2001:db8::1'); // true
re.test('2001:0db8::0001'); // true
re.test('2001:db8::2'); // false
```
--------------------------------
### Import Address6 from 'ip-address'
Source: https://github.com/beaugunderson/ip-address
Import the Address6 class from the package entry point to construct and work with IPv6 addresses.
```TypeScript
import { Address6 } from 'ip-address';
```
--------------------------------
### inspect6to4 usage example
Source: https://github.com/beaugunderson/ip-address
Example of calling inspect6to4 on an Address6 instance and the resulting object with prefix and gateway values.
```TypeScript
new Address6('2002:c000:204::').inspect6to4();
// { prefix: '2002', gateway: '192.0.2.4' }
```
--------------------------------
### isGlobal usage examples
Source: https://github.com/beaugunderson/ip-address
Examples of isGlobal() on various addresses. It returns false for NAT64/DNS64 Discovery (192.0.0.170), private (192.168.1.1), and reserved (240.0.0.1) addresses.
```TypeScript
new Address4('8.8.8.8').isGlobal(); // true
new Address4('192.0.0.170').isGlobal(); // false (NAT64/DNS64 Discovery)
new Address4('192.168.1.1').isGlobal(); // false
new Address4('240.0.0.1').isGlobal(); // false
```
--------------------------------
### link(options?: { className?: string; prefix?: string; v4?: boolean }): string
Source: https://github.com/beaugunderson/ip-address/blob/main/README.md
Returns an HTML `` element whose `href` encodes the address in a URL hash fragment (default prefix `/#address=`). Useful for linking between pages of an address-inspector UI.
```APIDOC
## link(options?: { className?: string; prefix?: string; v4?: boolean }): string
### Description
Returns an HTML `` element whose `href` encodes the address in a URL hash fragment (default prefix `/#address=`). Useful for linking between pages of an address-inspector UI.
### Method
link(options?)
### Parameters
#### Optional Parameters
- **options** (object) - Optional - Options for the link.
- **className** (string) - Optional - CSS class for the anchor element.
- **prefix** (string) - Optional - Prefix for the hash fragment.
- **v4** (boolean) - Optional - Whether to treat as IPv4.
### Returns
- **string** - An HTML `` element.
```
--------------------------------
### fromWildcard
Source: https://github.com/beaugunderson/ip-address
Creates an Address6 instance from a wildcard pattern with trailing `*` groups. Each trailing `*` contributes 16 bits, and `::` is expanded to zero groups before evaluating trailing wildcards. Throws AddressError for invalid patterns.
```APIDOC
## fromWildcard
### Description
Creates an Address6 instance from a wildcard pattern with trailing `*` groups. Each trailing `*` contributes 16 bits, and `::` is expanded to zero groups before evaluating trailing wildcards. Throws AddressError for invalid patterns.
### Method
static
### Endpoint
`static fromWildcard(input: string): Address6`
### Parameters
#### Path Parameters
- `input` (string) - Required - Wildcard pattern with trailing `*` groups
### Response
#### Success Response
Returns an Address6 instance.
#### Error Handling
Throws `AddressError` with messages: `'Wildcard pattern must not include a zone or CIDR suffix'`, `"Wildcard pattern cannot contain more than one '::'"`, `"Wildcard pattern with '::' has too many groups"`, `'Wildcard pattern must have 8 groups'`, `'Wildcard `*` must only appear in trailing groups (e.g. `2001:db8:*:*:*:*:*:*`)'`.
### Request Example
```ts
Address6.fromWildcard('2001:db8:*:*:*:*:*:*').subnet; // '/32'
Address6.fromWildcard('2001:db8::*').subnet; // '/112'
Address6.fromWildcard('*:*:*:*:*:*:*:*').subnet; // '/0'
```
```
--------------------------------
### getBits method signature
Source: https://github.com/beaugunderson/ip-address
Returns the bits in the range [start, end) as a bigint. start is the most significant bit index.
```ts
getBits(start: number, end: number): bigint
```
--------------------------------
### Address6 Constructor
Source: https://github.com/beaugunderson/ip-address
Creates an Address6 instance from an IPv6 address string. Parses RFC 4291 notation including :: elision, subnets, zones, and v4-in-v6 dotted-quad tails.
```APIDOC
## Address6 Constructor
### Description
Creates an Address6 instance from an IPv6 address string. Parses RFC 4291 notation including :: elision, subnets, zones, and v4-in-v6 dotted-quad tails.
### Method
Constructor
### Parameters
#### Constructor Parameters
- **address** (string) - Required - The IPv6 address string to parse.
- **optionalGroups** (number) - Optional - Number of groups to parse (defaults to 8).
### Response
#### Instance Properties
- **address** (string) - The original input string.
- **addressMinusSuffix** (string) - Input with the /cidr suffix removed.
- **elidedGroups** (number) - Count of groups represented by :: (0 when no elision).
- **elisionBegin** (number) - Index where the elided run of zero groups begins.
- **elisionEnd** (number) - Index one past where the elided run of zero groups ends.
- **groups** (number) - Number of groups to parse.
- **parsedAddress** (string[]) - The parsed groups as lowercase hex strings.
- **parsedSubnet** (string) - CIDR suffix digits as text, empty if none.
- **subnet** (string) - The subnet as a /prefix string.
- **subnetMask** (number) - Prefix length as an integer.
- **v4** (boolean) - True when the input used v4-in-v6 dotted-quad notation.
- **zone** (string) - Zone identifier, empty if none.
- **address4** (Address4) - Embedded Address4 set when parsing a v4-in-v6 address.
- **parsedAddress4** (string) - The textual dotted-quad tail from a v4-in-v6 address.
- **isInSubnet** (function) - Shared membership function.
- **isHostInSubnet** (function) - Shared membership function.
- **isCorrect** (function) - Correct-form predicate.
```
--------------------------------
### link usage examples
Source: https://github.com/beaugunderson/ip-address
Shows generating an anchor tag with default options and with v4-in-v6 rendering plus a custom class. The first produces '2001:db8::1' and the second '::ffff:192.168.0.1'.
```ts
new Address6('2001:db8::1').link();
// '2001:db8::1'
new Address6('::ffff:192.168.0.1').link({ v4: true, className: 'addr' });
// '::ffff:192.168.0.1'
```
--------------------------------
### isCanonical usage examples
Source: https://github.com/beaugunderson/ip-address
Examples showing isCanonical returns true for fully-expanded canonical form and false for compressed notation.
```TypeScript
new Address6('2001:0db8:0000:0000:0000:0000:0000:0001').isCanonical(); // true
new Address6('2001:db8::1').isCanonical(); // false
```
--------------------------------
### getBitsBase16 usage example
Source: https://github.com/beaugunderson/ip-address
Example of calling getBitsBase16(0, 16) on an Address6 instance, returning the first 16 bits as a base-16 string.
```ts
new Address6('2001:db8::1').getBitsBase16(0, 16); // '2001'
```
--------------------------------
### isInSubnet usage examples
Source: https://github.com/beaugunderson/ip-address
Shows true for a contained address and false for a narrower subnet.
```TypeScript
new Address4('192.168.1.42').isInSubnet(new Address4('192.168.1.0/24')); // true
new Address4('192.168.1.0/24').isInSubnet(new Address4('10.0.0.0/8')); // false (narrower)
```