Render Terminal Text
Use this when you need developer-facing QR output in a terminal, CLI, log, text file, or deterministic snapshot test.
Minimal example
Section titled “Minimal example”import {QRCodeTextRenderer, qrcode} from '@qrcodesdk/core';
const text = qrcode('HELLO WORLD').render(QRCodeTextRenderer());
console.log(text);The returned value is a string containing block characters and newline separators.
Common options
Section titled “Common options”You can control the rendered text size and margin by passing options to QRCodeTextRenderer.
import {QRCodeTextRenderer, qrcode} from '@qrcodesdk/core';
const text = qrcode('HELLO WORLD').render( QRCodeTextRenderer({ size: 2, margin: 2, }),);
console.log(text);| Option | Type | Default | Description |
|---|---|---|---|
size |
number |
5 |
Integer scale factor for each QR module. |
margin |
number |
4 |
Quiet-zone margin around the QR code, in modules. |
The text renderer only uses size and margin. Color options are ignored because the output is plain text.
Common recipes
Section titled “Common recipes”Print to the terminal
Section titled “Print to the terminal”import {QRCodeTextRenderer, qrcode} from '@qrcodesdk/core';
const text = qrcode('HELLO WORLD').render(QRCodeTextRenderer());
console.log(text);Use alphanumeric mode
Section titled “Use alphanumeric mode”import {QRCodeTextRenderer, qrcode} from '@qrcodesdk/core';
const text = qrcode('HELLO WORLD') .mode('alphanumeric') .render(QRCodeTextRenderer({size: 1, margin: 2}));
console.log(text);Write to a text file
Section titled “Write to a text file”import {writeFileSync} from 'node:fs';
import {QRCodeTextRenderer, qrcode} from '@qrcodesdk/core';
const text = qrcode('HELLO WORLD').render(QRCodeTextRenderer());
writeFileSync('qrcode.txt', text, 'utf8');Output details
Section titled “Output details”The renderer uses Unicode block characters to create compact terminal output:
| Character | Meaning |
|---|---|
█ |
Upper and lower module are dark |
▀ |
Upper module is dark |
▄ |
Lower module is dark |
| space | Upper and lower module are light |
The renderer combines two vertical rows of QR modules into one terminal line, making the output shorter while preserving the QR pattern.