QR Code Encoding (Legacy)

0.0.0 · abandoned · verified Sun Apr 19

qr.js is a minimalist JavaScript library designed for encoding QR codes directly within the browser or Node.js environments. Published as version 0.0.0, the package has been unmaintained since its last update in November 2015. It is notable for its pure JavaScript implementation with no external dependencies, repackaging work from a Japanese qrcode library. Despite its initial purpose and wide adoption in older projects, its lack of maintenance and critical security issues, including a repository hijacking incident, make it unsuitable for new development. Developers are strongly advised to consider modern, actively maintained alternatives for QR code generation to ensure security and compatibility.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `qr.js` to encode a string into a QR code data structure and inspect its underlying cell matrix (`modules`). It then prints a small portion of the QR code's visual representation using block characters.

const qr = require('qr.js');

// Data to encode in the QR code
const data = 'Hello, Checklist Day!';

// Generate the QR code data structure
const qrcode = qr(data);

// Access the QR code cells (modules)
const cells = qrcode.modules;

console.log(`QR Code for: "${data}"`);
console.log(`Version: ${qrcode.typeNumber}`);
console.log(`Error Correction Level: ${qrcode.correctLevel}`);
console.log(`Number of cells (rows): ${cells.length}`);
console.log(`First row of cells: ${cells[0].map(cell => cell ? '██' : '  ').join('')}`);

// Example: Manually printing a small part of the QR code
for (let r = 0; r < Math.min(5, cells.length); r++) {
  let rowOutput = '';
  for (let c = 0; c < Math.min(10, cells[r].length); c++) {
    rowOutput += cells[r][c] ? '██' : '  ';
  }
  console.log(rowOutput);
}

view raw JSON →