Toolpal

@toolpal/qr-code

public

v2.0published 1 download this weekMIT

Generates a scannable QR code image (PNG or SVG) offline for any text: a URL, a Wi-Fi login (WIFI:T:WPA;S:<network>;P:<password>;;), a vCard, a phone number (tel:...), an email (mailto:...) or plain text. Returns the image file. No API key needed.

README.md1.0 KBRaw
# @toolpal/qr-code

Generates a scannable ISO/IEC 18004 QR code image (`PNG` or `SVG`) completely offline — no API key, no network access, and zero external dependencies.

## How it works

1. Encodes any UTF-8 text (URL, Wi-Fi config, vCard, `tel:`, `mailto:`, or plain text) into the smallest QR version (1–40) that fits at the chosen error correction level (`L`, `M`, `Q`, or `H`).
2. Evaluates all 8 standard mask patterns and picks the lowest-penalty pattern for reliable scanning.
3. Renders either a crisp PNG (with configurable pixel `scale`) or a scalable SVG file with a 4-module quiet zone.

## Example

```json
{
  "text": "https://toolpal.dev",
  "errorCorrection": "M",
  "format": "png",
  "scale": 10
}
```

Returns:

```json
{
  "image": "out/qr-code.png",
  "version": 2,
  "modules": 25,
  "errorCorrection": "M",
  "bytes": 19
}
```

## Notes

- Runs 100% offline (`net: false`, no environment variables required).
- Supports up to 2,953 bytes of UTF-8 text (at error correction level `L`).
- Wi-Fi QR format: `WIFI:T:WPA;S:<network>;P:<password>;;`.