The structural layer of IP notation: splitting a string into its address, zone ID and prefix slots without reading any of them.

Every parser in this package is a narrowing of one grammar (ADR 0003):

notation = address [ "%" zoneId ] [ "/" prefix ]

splitNotation is the first of three layers. It knows nothing about IP: it does not know what a colon or a dot means, only that % and / are delimiters, that each occurs at most once, that the zone comes before the prefix (RFC 4007 section 11.7), and that no slot is empty. Everything else -- whether the address is IPv4 or IPv6, whether the prefix is a length or a mask, whether the zone is well-formed -- is decided by the parser that called it.

Examples

Splitting the three slots

import { assertEquals } from "@std/assert";
import { splitNotation } from "@hertzg/ip/notation";

assertEquals(splitNotation("fe80::%ether1/64"), {
  address: "fe80::",
  zoneId: "ether1",
  prefix: "64",
});
assertEquals(splitNotation("10.0.0.0/255.0.0.0"), {
  address: "10.0.0.0",
  prefix: "255.0.0.0",
});
assertEquals(splitNotation("192.168.1.1%ether1"), {
  address: "192.168.1.1",
  zoneId: "ether1",
});

Functions

f
splitNotation(notation: string): Notation

Splits an IP notation string into its address, zone ID and prefix slots.

Type Aliases

T
Notation = { readonly address: string; readonly zoneId?: ZoneId; readonly prefix?: string; }

The three slots of an IP notation string, as slices of it, before any of them is read. Absent slots are absent, not empty: splitNotation rejects an empty slot rather than returning "".

T
ZoneId = string

The zone ID of an address, the interface tail after % in fe80::1%eth0 (RFC 4007 section 11). Carried verbatim by the Parsed* types; never percent-decoded, so %25eth0 is the zone 25eth0.