Runtime-agnostic QR code generation. Pure-SVG core runs on Cloudflare Workers, Node, and browsers — no DOM, no Node built-ins.
Pre-1.0. API may change. See CHANGELOG.md for release history.
npm install @nazarf/qrforge
# or
pnpm add @nazarf/qrforgeimport { buildUrlPayload, generateSvg } from "@nazarf/qrforge";
const svg = generateSvg({
payload: buildUrlPayload("https://example.com", {
utm: { source: "qr", medium: "print" },
}),
size: 512,
style: { fgColor: "#0F172A", bgColor: "#FFFFFF" },
});Validates a URL and returns a QrPayload. Throws InvalidPayloadError if the URL is not parseable or not http:/https:.
Options:
utm— partial UTM parameters that are appended to the URL without overwriting existing values.
Returns a QrMatrix with the quiet zone included in the modules array.
ecc:"L" | "M" | "Q" | "H"— error correction level, default"M".quietZone: integer 0-16, default 4.
Returns a pure SVG string. No DOM access.
Config:
payload: requiredsize: output px (default 512; range 32-8192)style.fgColor,style.bgColor: hex colors (default#000000/#FFFFFF)style.margin: module-units of quiet zone (default 4; range 0-16)ecc: error correction level (default"M")
All library errors extend QrForgeError (with a .code discriminator):
InvalidPayloadError— bad URL or unsupported protocolPayloadTooLargeError— payload exceeds QR capacity for given ECCInvalidConfigError— size/margin/quietZone out of range
- Cloudflare Workers
- Node 18+
- Modern browsers
MIT