QR Code Generator for JavaScript

2.0.4 · active · verified Sun Apr 19

qrcode-generator is a robust, pure JavaScript implementation for generating QR codes, supporting a wide range of features including various error correction levels (L, M, Q, H), different data encoding modes (Numeric, Alphanumeric, Byte, Kanji), and output formats (HTML Image Tag, SVG, Canvas, ASCII, Data URL). It is based on the JIS X 0510:1999 standard. The current stable version is 2.0.4, released in April 2024, with releases occurring periodically to address issues and add features like module support and TypeScript types in recent major versions. Key differentiators include its lightweight nature, direct HTML rendering capabilities, and foundational adherence to the QR Code specification, making it suitable for both browser and Node.js environments without external dependencies.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to import the `qrcode` factory function, configure a QR code, add data, generate the code matrix, and then render it as an SVG string, suitable for both Node.js console output or browser DOM manipulation.

import qrcode from 'qrcode-generator';

// Configuration for QR Code
const typeNumber = 4; // Type number (1-40), or 0 for auto-detection
const errorCorrectionLevel = 'M'; // Error correction level ('L', 'M', 'Q', 'H')
const dataToEncode = 'Hello, Checklist Day! This is a test QR code generated using qrcode-generator in a modern JavaScript environment.';

// Create a QR Code instance
const qr = qrcode(typeNumber, errorCorrectionLevel);

// Add data to the QR Code
qr.addData(dataToEncode);

// Make the QR Code (generate the matrix)
qr.make();

// Render the QR Code to an SVG string (Node.js example)
const svgString = qr.createSvgTag(5, 5); // cellSize = 5, margin = 5

console.log('Generated SVG for QR Code:\n', svgString);

// Example for browser environment (hypothetical DOM interaction)
// If running in a browser, you might append this to a DOM element:
// document.getElementById('qr-container').innerHTML = qr.createImgTag(4, 4, 'My QR Code');

view raw JSON →