wireguard-config-parser
v1.0.0
Published
Zero-dependency parser, serialiser and validator for WireGuard (.conf) configuration files — [Interface] and [Peer] sections.
Downloads
142
Maintainers
Readme
wireguard-config-parser
Zero-dependency parser, serialiser and validator for WireGuard .conf
configuration files — the INI-style format used by wg-quick, with an
[Interface] section and one or more [Peer] sections.
Install
npm install wireguard-config-parserUsage
const { parse, stringify, validate } = require('wireguard-config-parser');
const conf = `
[Interface]
PrivateKey = <key>
Address = 10.0.0.2/24
DNS = 1.1.1.1
[Peer]
PublicKey = <key>
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = vpn.example.com:51820
`;
const cfg = parse(conf);
// { interface: { PrivateKey, Address: ['10.0.0.2/24'], DNS: ['1.1.1.1'] },
// peers: [ { PublicKey, AllowedIPs: ['0.0.0.0/0','::/0'], Endpoint } ] }
console.log(validate(cfg)); // [] when the essentials are present
console.log(stringify(cfg)); // back to .conf text- Comma-separated keys (
Address,DNS,AllowedIPs) are parsed into arrays. #comments are stripped.validate()returns human-readable problems (missing PrivateKey/Address/PublicKey/AllowedIPs, no peers).
API
parse(text)→{ interface, peers }stringify(config)→.confstringvalidate(config)→string[](empty means valid)
More on WireGuard & VPNs
Guides on WireGuard, VPN protocols and choosing a VPN: vpnsmith.com.
License
MIT
