Internet.ts overview
Internet related schemas and filters
Since v1.0.0
Exports Grouped by Category
- Regular expressions
- Schemas
- Address (class)
- AddressBigint (class)
- AddressString (class)
- CidrBlock (class)
- CidrBlockFromString (class)
- Family (class)
- IPv4 (class)
- IPv4Bigint (class)
- IPv4CidrBlock (class)
- IPv4CidrBlockFromString (class)
- IPv4CidrMask (class)
- IPv4Family (class)
- IPv4String
- IPv6 (class)
- IPv6Bigint (class)
- IPv6CidrBlock (class)
- IPv6CidrBlockFromString (class)
- IPv6CidrMask (class)
- IPv6Family (class)
- IPv6String
- MacAddress (class)
- Port (class)
- PortWithMaybeProtocol (class)
- utils
Regular expressions
IPv4Regex
Signature
declare const IPv4Regex: RegExp
Since v1.0.0
IPv4Segment
See
- https://github.com/nodejs/node/blob/e08a654fae0ecc91678819e0b62a2e014bad3339/lib/internal/net.js#L16-L18
Signature
declare const IPv4Segment: "(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])"
Since v1.0.0
IPv4StringRegex
Signature
declare const IPv4StringRegex: "(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])"
Since v1.0.0
IPv6Regex
Signature
declare const IPv6Regex: RegExp
Since v1.0.0
IPv6Segment
See
- https://github.com/nodejs/node/blob/e08a654fae0ecc91678819e0b62a2e014bad3339/lib/internal/net.js#L21-L31
Signature
declare const IPv6Segment: "(?:[0-9a-fA-F]{1,4})"
Since v1.0.0
MacAddressRegex
See
- https://stackoverflow.com/questions/4260467/what-is-a-regular-expression-for-a-mac-address
Signature
declare const MacAddressRegex: RegExp
Since v1.0.0
Schemas
Address (class)
An IP address, which is either an IPv4 or IPv6 address.
Example
import * as assert from "node:assert"
import * as Schema from "effect/Schema";
import { Address } from "@leonitousconforti/effect-schemas/Internet";
const decodeAddress = Schema.decodeSync(Address);
assert.throws(() => decodeAddress("1.1.b.1"));
assert.throws(() => decodeAddress("2001:0db8:85a3:0000:0000:8a2e:0370:7334:"));
assert.doesNotThrow(() => decodeAddress("1.1.1.2"));
assert.doesNotThrow(() => decodeAddress("2001:0db8:85a3:0000:0000:8a2e:0370:7334"));
```;
**See**
- `IPv4`
- `IPv6`
**Signature**
```ts
declare class Address
Since v1.0.0
AddressBigint (class)
An IP address as a bigint.
Signature
declare class AddressBigint
Since v1.0.0
AddressString (class)
An IP address in string format, which is either an IPv4 or IPv6 address.
Signature
declare class AddressString
Since v1.0.0
CidrBlock (class)
Signature
declare class CidrBlock
Since v1.0.0
CidrBlockFromString (class)
A schema that transforms a string
into a CidrBlock
.
Signature
declare class CidrBlockFromString
Since v1.0.0
Family (class)
See
IPv4Family
IPv6Family
Signature
declare class Family
Since v1.0.0
IPv4 (class)
An IPv4 address.
Example
import * as assert from "node:assert"
import * as Schema from "effect/Schema";
import { IPv4 } from "@leonitousconforti/effect-schemas/Internet";
const decodeIPv4 = Schema.decodeSync(IPv4);
assert.deepEqual(decodeIPv4("1.1.1.1"), {
family: "ipv4",
ip: "1.1.1.1",
});
assert.throws(() => decodeIPv4("1.1.a.1"));
assert.doesNotThrow(() => decodeIPv4("1.1.1.2"));
```;
**Signature**
```ts
declare class IPv4
Since v1.0.0
IPv4Bigint (class)
An IPv4 as a bigint.
Signature
declare class IPv4Bigint
Since v1.0.0
IPv4CidrBlock (class)
Signature
declare class IPv4CidrBlock
Since v1.0.0
networkAddressAsBigint (property)
The first address in the range given by this address’ subnet, often referred to as the Network Address.
Signature
networkAddressAsBigint: this extends IPv4CidrBlock ? { readonly value: bigint & Brand<"IPv4Bigint">; readonly family: "ipv4"; } : this extends IPv6CidrBlock ? { readonly value: bigint & Brand<"IPv6Bigint">; readonly family: "ipv6"; } : never
Since v1.0.0
networkAddress (property)
The first address in the range given by this address’ subnet, often referred to as the Network Address.
Signature
networkAddress: this extends IPv4CidrBlock ? { readonly family: "ipv4"; readonly ip: string & Brand<"IPv4">; } : this extends IPv6CidrBlock ? { readonly family: "ipv6"; readonly ip: string & Brand<"IPv6">; } : never
Since v1.0.0
broadcastAddressAsBigint (property)
The last address in the range given by this address’ subnet, often referred to as the Broadcast Address.
Signature
broadcastAddressAsBigint: this extends IPv4CidrBlock ? { readonly value: bigint & Brand<"IPv4Bigint">; readonly family: "ipv4"; } : this extends IPv6CidrBlock ? { readonly value: bigint & Brand<"IPv6Bigint">; readonly family: "ipv6"; } : never
Since v1.0.0
broadcastAddress (property)
The last address in the range given by this address’ subnet, often referred to as the Broadcast Address.
Signature
broadcastAddress: this extends IPv4CidrBlock ? { readonly family: "ipv4"; readonly ip: string & Brand<"IPv4">; } : this extends IPv6CidrBlock ? { readonly family: "ipv6"; readonly ip: string & Brand<"IPv6">; } : never
Since v1.0.0
range (property)
A stream of all addresses in the range given by this address’ subnet.
Signature
range: this extends IPv4CidrBlock ? Stream.Stream<{ readonly family: "ipv4"; readonly ip: string & Brand<"IPv4">; }, ParseResult.ParseError, never> : this extends IPv6CidrBlock ? Stream.Stream<{ readonly family: "ipv6"; readonly ip: string & Brand<"IPv6">; }, ParseResult.ParseError, never> : never
Since v1.0.0
total (property)
The total number of addresses in the range given by this address’ subnet.
Signature
total: bigint
Since v1.0.0
IPv4CidrBlockFromString (class)
A schema that transforms a string
into a CidrBlock
.
Signature
declare class IPv4CidrBlockFromString
Since v1.0.0
IPv4CidrMask (class)
An ipv4 cidr mask, which is a number between 0 and 32.
Signature
declare class IPv4CidrMask
Since v1.0.0
IPv4Family (class)
Signature
declare class IPv4Family
Since v1.0.0
IPv4String
An IPv4 address in dot-decimal notation with no leading zeros.
Signature
declare const IPv4String: Schema.filter<typeof Schema.String>
Since v1.0.0
IPv6 (class)
An IPv6 address.
Example
import * as assert from "node:assert"
import * as Schema from "effect/Schema";
import { IPv6 } from "@leonitousconforti/effect-schemas/Internet";
const decodeIPv6 = Schema.decodeSync(IPv6);
assert.deepEqual(decodeIPv6("2001:0db8:85a3:0000:0000:8a2e:0370:7334"), {
family: "ipv6",
ip: "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
});
assert.throws(() =>
decodeIPv6("2001:0db8:85a3:0000:0000:8a2e:0370:7334:")
);
assert.throws(() => decodeIPv6("2001::85a3::0000::0370:7334"));
assert.doesNotThrow(() =>
decodeIPv6("2001:0db8:85a3:0000:0000:8a2e:0370:7334")
);
```;
**Signature**
```ts
declare class IPv6
Since v1.0.0
IPv6Bigint (class)
An IPv6 as a bigint.
Signature
declare class IPv6Bigint
Since v1.0.0
IPv6CidrBlock (class)
Signature
declare class IPv6CidrBlock
Since v1.0.0
networkAddressAsBigint (property)
The first address in the range given by this address’ subnet, often referred to as the Network Address.
Signature
networkAddressAsBigint: { readonly value: bigint & Brand<"IPv6Bigint">; readonly family: "ipv6"; }
Since v1.0.0
networkAddress (property)
The first address in the range given by this address’ subnet, often referred to as the Network Address.
Signature
networkAddress: this extends IPv4CidrBlock ? { readonly family: "ipv4"; readonly ip: string & Brand<"IPv4">; } : this extends IPv6CidrBlock ? { readonly family: "ipv6"; readonly ip: string & Brand<"IPv6">; } : never
Since v1.0.0
broadcastAddressAsBigint (property)
The last address in the range given by this address’ subnet, often referred to as the Broadcast Address.
Signature
broadcastAddressAsBigint: this extends IPv4CidrBlock ? { readonly value: bigint & Brand<"IPv4Bigint">; readonly family: "ipv4"; } : this extends IPv6CidrBlock ? { readonly value: bigint & Brand<"IPv6Bigint">; readonly family: "ipv6"; } : never
Since v1.0.0
broadcastAddress (property)
The last address in the range given by this address’ subnet, often referred to as the Broadcast Address.
Signature
broadcastAddress: this extends IPv4CidrBlock ? { readonly family: "ipv4"; readonly ip: string & Brand<"IPv4">; } : this extends IPv6CidrBlock ? { readonly family: "ipv6"; readonly ip: string & Brand<"IPv6">; } : never
Since v1.0.0
range (property)
A stream of all addresses in the range given by this address’ subnet.
Signature
range: this extends IPv4CidrBlock ? Stream.Stream<{ readonly family: "ipv4"; readonly ip: string & Brand<"IPv4">; }, ParseResult.ParseError, never> : this extends IPv6CidrBlock ? Stream.Stream<{ readonly family: "ipv6"; readonly ip: string & Brand<"IPv6">; }, ParseResult.ParseError, never> : never
Since v1.0.0
total (property)
The total number of addresses in the range given by this address’ subnet.
Signature
total: bigint
Since v1.0.0
IPv6CidrBlockFromString (class)
A schema that transforms a string
into a CidrBlock
.
Signature
declare class IPv6CidrBlockFromString
Since v1.0.0
IPv6CidrMask (class)
An ipv6 cidr mask, which is a number between 0 and 128.
Signature
declare class IPv6CidrMask
Since v1.0.0
IPv6Family (class)
Signature
declare class IPv6Family
Since v1.0.0
IPv6String
An IPv6 address in string format.
Signature
declare const IPv6String: Schema.filter<typeof Schema.String>
Since v1.0.0
MacAddress (class)
A Mac Address.
Signature
declare class MacAddress
Since v1.0.0
Port (class)
An operating system port number.
Example
import * as assert from "node:assert"
import * as Schema from "effect/Schema";
import { Port } from "@leonitousconforti/effect-schemas/Internet";
const decodePort = Schema.decodeSync(Port);
assert.strictEqual(decodePort(8080), 8080);
assert.throws(() => decodePort(65536));
```;
**Signature**
```ts
declare class Port
Since v1.0.0
PortWithMaybeProtocol (class)
An operating system port number with an optional protocol.
Example
import * as assert from "node:assert"
import * as Schema from "effect/Schema";
import { PortWithMaybeProtocol } from "@leonitousconforti/effect-schemas/Internet";
const decodePortWithMaybeProtocol = Schema.decodeUnknownSync(PortWithMaybeProtocol);
assert.strictEqual(decodePortWithMaybeProtocol("8080"), "8080");
assert.strictEqual(decodePortWithMaybeProtocol("8080/tcp"), "8080/tcp");
assert.strictEqual(decodePortWithMaybeProtocol("8080/udp"), "8080/udp");
assert.throws(() => decodePortWithMaybeProtocol("8080/icmp"));
assert.throws(() => decodePortWithMaybeProtocol("70000"));
```;
**Signature**
```ts
declare class PortWithMaybeProtocol
Since v1.0.0
utils
broadcastAddress
The last address in the range given by this address’ subnet, often referred to as the Broadcast Address.
Signature
declare const broadcastAddress: <Input extends IPv4CidrBlock | IPv6CidrBlock>(
input: Input
) => Input extends IPv4CidrBlock
? Schema.Schema.Type<IPv4>
: Input extends IPv6CidrBlock
? Schema.Schema.Type<IPv6>
: never
Since v1.0.0
broadcastAddressAsBigint
The last address in the range given by this address’ subnet, often referred to as the Broadcast Address.
Signature
declare const broadcastAddressAsBigint: <Input extends IPv4CidrBlock | IPv6CidrBlock>(
input: Input
) => Input extends IPv4CidrBlock
? Schema.Schema.Type<IPv4Bigint>
: Input extends IPv6CidrBlock
? Schema.Schema.Type<IPv6Bigint>
: never
Since v1.0.0
cidrBlockForRange
Finds the smallest CIDR block that contains all the given IP addresses.
Signature
declare const cidrBlockForRange: <
Input extends
| Array.NonEmptyReadonlyArray<Schema.Schema.Type<IPv4>>
| Array.NonEmptyReadonlyArray<Schema.Schema.Type<IPv6>>
>(
inputs: Input
) => IPv4CidrBlock | IPv6CidrBlock
Since v1.0.0
networkAddress
The first address in the range given by this address’ subnet, often referred to as the Network Address.
Signature
declare const networkAddress: <Input extends IPv4CidrBlock | IPv6CidrBlock>(
input: Input
) => Input extends IPv4CidrBlock
? Schema.Schema.Type<IPv4>
: Input extends IPv6CidrBlock
? Schema.Schema.Type<IPv6>
: never
Since v1.0.0
networkAddressAsBigint
The first address in the range given by this address’ subnet, often referred to as the Network Address.
Signature
declare const networkAddressAsBigint: <Input extends IPv4CidrBlock | IPv6CidrBlock>(
input: Input
) => Input extends IPv4CidrBlock
? Schema.Schema.Type<IPv4Bigint>
: Input extends IPv6CidrBlock
? Schema.Schema.Type<IPv6Bigint>
: never
Since v1.0.0
range
A stream of all addresses in the range given by this address’ subnet.
Signature
declare const range: <Input extends IPv4CidrBlock | IPv6CidrBlock>(
input: Input
) => Input extends IPv4CidrBlock
? Stream.Stream<Schema.Schema.Type<IPv4>, ParseResult.ParseError, never>
: Input extends IPv6CidrBlock
? Stream.Stream<Schema.Schema.Type<IPv6>, ParseResult.ParseError, never>
: never
Since v1.0.0
total
The total number of addresses in the range given by this address’ subnet.
Signature
declare const total: (input: IPv4CidrBlock | IPv6CidrBlock) => bigint
Since v1.0.0