# address-range

> ```sh npm install --save address-range # or yarn add address-range ```

Latest version **0.2.14** (published 2023-10-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install address-range
pnpm add address-range
yarn add address-range
bun add address-range
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.14 |
| Published | 2023-10-02 |
| First published | 2021-04-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 10.4.0 |
| Dependencies | 5 |
| Unpacked size | 40.2 KB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | BlackGlory |
| Maintainers | black_glory |

## Links

- npm: https://www.npmjs.com/package/address-range
- Repository: https://github.com/BlackGlory/address-range
- Homepage: https://github.com/BlackGlory/address-range#readme
- Issues: https://github.com/BlackGlory/address-range/issues
- npm.io page: https://npm.io/package/address-range

## Dependencies (5)

- [ip](https://npm.io/package/ip.md) ^1.1.8
- [ip-address](https://npm.io/package/ip-address.md) ^8.1.0
- [extra-utils](https://npm.io/package/extra-utils.md) ^3.1.0
- [iterable-operator](https://npm.io/package/iterable-operator.md) ^2.2.0
- [@blackglory/structures](https://npm.io/package/@blackglory/structures.md) ^0.11.4

## Recent versions

- 0.2.14 (latest) — 2023-10-02
- 0.2.13 — 2023-06-10
- 0.2.12 — 2022-11-07
- 0.2.11 — 2022-08-06
- 0.2.10 — 2022-08-01
- 0.2.9 — 2021-11-18
- 0.2.7 — 2021-08-25
- 0.2.6 — 2021-07-12
- 0.2.5 — 2021-07-03
- 0.2.4 — 2021-05-16
- 0.2.3 — 2021-05-16
- 0.2.2 — 2021-05-07
- 0.2.1 — 2021-04-11
- 0.2.0 — 2021-04-11
- 0.1.0 — 2021-04-10

## README

# address-range
## Install
```sh
npm install --save address-range
# or
yarn add address-range
```

## API
### AddressRange
```ts
class AddressRange {
  readonly startAddress: bigint
  readonly endAddress: bigint

  constructor(startAddress: bigint, endAddress: bigint)

  includes(address: bigint): boolean
  isSubSetOf(addressRange: AddressRange): boolean
  hasIntersectionOf(addressRange: AddressRange): boolean
  hasLeftIntersectionOf(addressRange: AddressRange): boolean
  hasRightIntersectionOf(addressRange: AddressRange): boolean
  toString(): string
}
```

### IPv4AddressRange
```ts
class IPv4AddressRange extends AddressRange {
  static from(startAddress: string, endAddress: string): IPv4AddressRange
  static from(startAddress: string, hosts: number): IPv4AddressRange

  includes(address: string): boolean
  includes(address: bigint): boolean
  toString(): string
}
```

### IPv6AddressRange
```ts
class IPv6AddressRange extends AddressRange {
  static from(startAddress: string, endAddress: string): IPv6AddressRange
  static from(startAddress: string, hosts: number): IPv6AddressRange

  includes(address: string): boolean
  includes(address: bigint): boolean
  toString(): string
}
```

### concat
```ts
function concat<T extends AddressRange>(
  ranges: T[]
, constructor: new (startAddress: bigint, endAddress: bigint) => T
): T[]
```

If the address ranges are concatenated at the beginning and end,
concat the address ranges.

### merge
```ts
function merge<T extends AddressRange>(
  ranges: T[]
, constructor: new (startAddress: bigint, endAddress: bigint) => T
): T[]
```

If the address ranges have intersections, merge the address ranges.

### removeSubsets
```ts
function removeSubsets<T extends AddressRange>(ranges: T[]): T[]
```

If the address range is a subset of another address range,
remove the address range.

### compress
```ts
function compress<T extends AddressRange>(
  ranges: T[]
, constructor: new (startAddress: bigint, endAddress: bigint) => T
): T[]
```

Lossless compression of address ranges.

### convertIPv4AddressBigIntToString
```ts
function convertIPv4AddressBigIntToString(address: bigint): string
```

### convertIPv4AddressStringToBigInt
```ts
function convertIPv4AddressStringToBigInt(address: string): bigint
```

### convertIPv6AddressBigIntToString
```ts
function convertIPv6AddressBigIntToString(address: bigint): string
```

### convertIPv6AddressStringToBigInt
```ts
function convertIPv6AddressStringToBigInt(address: string): bigint
```

---
_Source: https://npm.io/package/address-range · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
