@bybrave/qrcode-terminal2
v1.0.1
Published
Maintained fork of qrcode-terminal — render QR codes in the terminal, with dual ESM+CJS, bundled TypeScript types (no separate @types/qrcode-terminal), and a strict-mode/ESM fix
Maintainers
Readme
@bybrave/qrcode-terminal2
Maintained fork of qrcode-terminal — render QR codes as text in the terminal — with dual ESM + CommonJS, bundled TypeScript types, and a strict-mode/ESM fix.
The original has ~30M downloads/month and no release since March 2018. It's already dependency-free (the QR engine is vendored in), so this fork keeps the rendering byte-for-byte identical and focuses on what modern consumers were blocked on: ESM import, built-in types (no separate @types/qrcode-terminal), and source that survives a strict-mode / bundler build.
npm install @bybrave/qrcode-terminal2// CommonJS — drop-in
const qrcode = require('@bybrave/qrcode-terminal2');
qrcode.generate('https://example.com');
// ESM — default or named import
import qrcode from '@bybrave/qrcode-terminal2';
import { generate, setErrorLevel } from '@bybrave/qrcode-terminal2';
// TypeScript types built in — no @types/qrcode-terminal neededUsage
const qrcode = require('@bybrave/qrcode-terminal2');
// Print a QR code
qrcode.generate('https://example.com');
// Smaller half-block rendering
qrcode.generate('https://example.com', { small: true });
// Get the string instead of printing (callback or return value)
qrcode.generate('https://example.com', (code) => console.log(code));
const code = qrcode.generate('https://example.com', { small: true }); // also returned
// Error-correction level: 'L' (default) | 'M' | 'Q' | 'H'
qrcode.setErrorLevel('H');
qrcode.generate('https://example.com');CLI
# installed globally as `qrcode-terminal2`
qrcode-terminal2 "hello world"
echo "https://example.com" | qrcode-terminal2
qrcode-terminal2 --help
qrcode-terminal2 --versionWhy this fork
| Fixed / improved | Original issue |
|---|---|
| Built-in TypeScript types — replaces the separate @types/qrcode-terminal package | #27 |
| Strict-mode / ESM safe — ANSI escapes rewritten from octal \033 to hex \x1b, so the source no longer throws Octal literal in strict mode under ESM or a bundler | #52 |
| generate() returns the string — in addition to the callback / console.log, so you can capture output without a callback | #24 |
| Dual ESM + CommonJS — import and require both work | — |
The QR generation engine (vendor/QRCode, a port of Kazuhiko Arase's QR Code for JavaScript) and the terminal rendering are unchanged from [email protected], gated by a byte-for-byte golden test. The octal→hex escape change produces identical bytes (\033 === \x1b === ESC).
Migration
Drop-in — change the dependency name:
- const qrcode = require('qrcode-terminal');
+ const qrcode = require('@bybrave/qrcode-terminal2');- "qrcode-terminal": "^0.12.0",
- "@types/qrcode-terminal": "^0.12.0",
+ "@bybrave/qrcode-terminal2": "^1.0.0",Remove @types/qrcode-terminal — the types ship with this package. Requires Node.js >= 18.
Known limitations (by design)
- Small QR codes may not scan on some terminal fonts (#21, #44). The
{ small: true }half-block rendering packs two module rows into one character row; on fonts/terminals with non-square cells or line-height gaps the scanner can't resolve the modules. This is a terminal rendering constraint, not something the library can fix reliably — use a terminal with a square monospace font, or the default (larger) rendering, if a code won't scan. - You can't set an arbitrary pixel size (#51, #9). A QR code's dimensions are determined by how much data it encodes and the chosen version/error-correction level — it can't be stretched to a target width in the terminal. Shorten the payload or lower the error-correction level to get a smaller code.
Support
If this package saves you time, you can support maintenance:
Bitcoin (BTC): bc1q37557q5jpeaxqydzwvf3jgj7zhnfpn2td3q40q
License
Apache-2.0. Copyright (c) Gord Tanner and Michael Brooks (original qrcode-terminal); modifications copyright (c) 2026 bybrave. The vendored QR engine (vendor/QRCode) is MIT, copyright (c) 2009 Kazuhiko Arase. See LICENSE and NOTICE.
