function stringify
stringify(conf: WGQuickConf): Promise<string>

Stringify a WireGuard configuration object to wg-quick(8) format.

Examples

Stringify a configuration with multiple peers

import { stringify } from "@hertzg/wg-conf";
import { assertEquals } from "@std/assert";

const obj = {
  Interface: {
    ListenPort: 51820,
    PrivateKey: "PRIV",
  },
  Peers: [
    { PublicKey: "PUB" },
    { PublicKey: "PUB2" },
  ],
};

assertEquals(await stringify(obj), [
  '[Interface]',
  'ListenPort = 51820',
  'PrivateKey = PRIV',
  '',
  '[Peer]',
  'PublicKey = PUB',
  '',
  '[Peer]',
  'PublicKey = PUB2',
  ''
].join("\n"));

Parameters

The WGQuickConf object to stringify.

Return Type

Promise<string>

A promise that resolves to the configuration as a string.

Usage

import { stringify } from ".";