High-level helpers to parse and stringify WireGuard wg-quick configuration files.
This module uses the lower-level @hertzg/wg-ini streams to provide convenient
functions for working with wg-quick(8) configuration files.
Parse a WireGuard configuration
Parse a WireGuard configuration
import { parse } from "@hertzg/wg-conf"; import { assertEquals } from "@std/assert"; const text = [ '[Interface]', 'ListenPort = 51820', 'PrivateKey = PRIV', '', '[Peer]', 'PublicKey = PUB', '' ].join("\n"); const conf = await parse(text); assertEquals(conf.Interface.ListenPort, 51820); assertEquals(conf.Interface.PrivateKey, "PRIV"); assertEquals(conf.Peers[0].PublicKey, "PUB");
Stringify a WireGuard configuration
Stringify a WireGuard configuration
import { stringify } from "@hertzg/wg-conf"; import { assert } from "@std/assert"; const conf = { Interface: { ListenPort: 51820, PrivateKey: "PRIV" }, Peers: [{ PublicKey: "PUB" }], }; const text = await stringify(conf); assert(text.includes('[Interface]')); assert(text.includes('ListenPort = 51820')); assert(text.includes('[Peer]')); assert(text.includes('PublicKey = PUB'));