Skip to content

Render Terminal Text

Use this when you need developer-facing QR output in a terminal, CLI, log, text file, or deterministic snapshot test.

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.

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.

import {QRCodeTextRenderer, qrcode} from '@qrcodesdk/core';
const text = qrcode('HELLO WORLD').render(QRCodeTextRenderer());
console.log(text);
import {QRCodeTextRenderer, qrcode} from '@qrcodesdk/core';
const text = qrcode('HELLO WORLD')
.mode('alphanumeric')
.render(QRCodeTextRenderer({size: 1, margin: 2}));
console.log(text);
import {writeFileSync} from 'node:fs';
import {QRCodeTextRenderer, qrcode} from '@qrcodesdk/core';
const text = qrcode('HELLO WORLD').render(QRCodeTextRenderer());
writeFileSync('qrcode.txt', text, 'utf8');

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.