function parse
parse(mac: string): Uint8Array

Parses a canonical EUI-48 MAC address string into its 6-byte binary form.

Accepts colon (aa:bb:cc:dd:ee:ff) or hyphen (aa-bb-cc-dd-ee-ff) delimiters. Hex digits are case-insensitive. Each octet must be exactly two hex characters — no leading-zero tricks, no abbreviations.

Examples

Colon-delimited

import { assertEquals } from "@std/assert";
import { parse } from "@hertzg/mac";

assertEquals(
  parse("00:11:22:33:44:55"),
  new Uint8Array([0x00, 0x11, 0x22, 0x33, 0x44, 0x55]),
);

Hyphen-delimited (IEEE form)

import { assertEquals } from "@std/assert";
import { parse } from "@hertzg/mac";

assertEquals(
  parse("AA-BB-CC-DD-EE-FF"),
  new Uint8Array([0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff]),
);

Rejects malformed input

import { assertThrows } from "@std/assert";
import { parse } from "@hertzg/mac";

assertThrows(() => parse("aa:bb:cc:dd:ee"), TypeError);
assertThrows(() => parse("aa:bb:cc:dd:ee:ff:00"), TypeError);
assertThrows(() => parse("aa:bb:cc:dd:ee:gg"), TypeError);
assertThrows(() => parse("aabbccddeeff"), TypeError);
assertThrows(() => parse("a:bb:cc:dd:ee:ff"), TypeError);

Parameters

mac: string

MAC address in canonical text form.

Return Type

6-byte Uint8Array containing the address octets.

Throws

TypeError

when the input is not 6 octets, the delimiter is mixed, an octet is not exactly two hex characters, or any character is not hex.