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.
npm install qrcode-generatorVerified import paths — ran on the pinned version, not inferred.
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.
For ES Modules, use `import qrcode from 'qrcode-generator';`. For CommonJS, use `const qrcode = require('qrcode-generator');`. Ensure proper script inclusion or bundling in browser environments if not using module imports.Always call `qr.make();` after `qr.addData(...)` and before any rendering or module inspection methods.
For non-default encoding, provide a custom implementation for `qrcode.stringToBytes(s)` that returns an array of byte numbers for the given string `s`.
In module environments, add `import qrcode from 'qrcode-generator';` (ESM) or `const qrcode = require('qrcode-generator');` (CJS). In browsers, ensure the `qrcode.js` script is loaded before use.Verify that `qr.addData('your content here')` is called with the correct string, and critically, that `qr.make();` is executed immediately after `addData()` and before any rendering functions.Double-check the arguments passed to `qrcode(typeNumber, errorCorrectionLevel)` to ensure they are valid numbers and strings, respectively. Ensure `qrcode` itself is correctly imported and available.
No dependency data recorded yet.