or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-qrcode-terminal

QR code generator for terminal output using ASCII/ANSI characters

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/qrcode-terminal@0.12.x

To install, run

npx @tessl/cli install tessl/npm-qrcode-terminal@0.12.0

index.mddocs/

QRCode Terminal

QRCode Terminal generates and displays QR codes directly in the terminal using ASCII/ANSI characters. It provides both a Node.js library API and a command-line interface for creating QR codes from text input, supporting different error correction levels and output formats (normal and compact).

Package Information

  • Package Name: qrcode-terminal
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install qrcode-terminal

Core Imports

const qrcode = require('qrcode-terminal');

Basic Usage

const qrcode = require('qrcode-terminal');

// Generate QR code and print to console
qrcode.generate('https://example.com');

// Generate QR code with callback
qrcode.generate('Hello World', function(qrcode) {
    console.log(qrcode);
});

// Generate compact QR code
qrcode.generate('Hello World', { small: true });

// Set error correction level
qrcode.setErrorLevel('H');
qrcode.generate('Hello World');

CLI Usage

Install globally for command-line usage:

npm install -g qrcode-terminal

Generate QR codes from the command line:

# Direct argument
qrcode-terminal "Hello World"

# Piped input
echo "Hello World" | qrcode-terminal

# Help and version
qrcode-terminal --help
qrcode-terminal --version

Capabilities

QR Code Generation

Generate QR codes for terminal display with customizable options and output formats.

/**
 * Generate QR code and display in terminal or pass to callback
 * @param input - Text to encode in QR code
 * @param opts - Optional configuration object
 * @param cb - Optional callback function to receive QR code string
 */
function generate(input, opts, cb);

/**
 * Configuration options for QR code generation
 */
interface GenerateOptions {
  /** Generate compact QR code using Unicode block characters */
  small?: boolean;
}

The generate function supports multiple calling patterns:

  • generate(input) - Print to console
  • generate(input, callback) - Pass result to callback
  • generate(input, options) - Print with options
  • generate(input, options, callback) - Pass result with options to callback

Error Correction Level Configuration

Set the error correction level for QR code generation. Higher levels provide better error recovery but result in denser QR codes.

/**
 * Set error correction level for subsequent QR code generation
 * @param error - Error correction level ('L', 'M', 'Q', or 'H')
 */
function setErrorLevel(error);

Error Correction Levels

Built-in error correction level constants available from the library.

/**
 * Default error correction level (Low - ~7% recovery)
 */
error: 1;

Available Error Correction Levels:

  • 'L' (Low): ~7% error recovery capability (default)
  • 'M' (Medium): ~15% error recovery capability
  • 'Q' (Quartile): ~25% error recovery capability
  • 'H' (High): ~30% error recovery capability

CLI Interface

Command-line interface for generating QR codes from terminal input.

# Generate QR code from argument
qrcode-terminal <message>

# Generate QR code from piped input
echo <message> | qrcode-terminal

# Display help information
qrcode-terminal --help
qrcode-terminal -h

# Display version number
qrcode-terminal --version
qrcode-terminal -v

Usage Examples

Basic QR Code Generation

const qrcode = require('qrcode-terminal');

// Simple QR code generation
qrcode.generate('Visit https://github.com');

QR Code with Callback

const qrcode = require('qrcode-terminal');

qrcode.generate('Hello World', function(qrString) {
    // Process the QR code string
    console.log('Generated QR code:');
    console.log(qrString);
    
    // Save to file, send over network, etc.
});

Compact QR Code Format

const qrcode = require('qrcode-terminal');

// Generate smaller QR code using Unicode block characters
qrcode.generate('https://example.com', { small: true }, function(qrString) {
    console.log('Compact QR code:');
    console.log(qrString);
});

Error Correction Level Configuration

const qrcode = require('qrcode-terminal');

// Set high error correction for better recovery
qrcode.setErrorLevel('H');
qrcode.generate('Important data that needs high reliability');

// Set low error correction for simpler QR codes  
qrcode.setErrorLevel('L');
qrcode.generate('Simple message');

Command Line Usage

# Generate QR code for a URL
qrcode-terminal "https://github.com/gtanner/qrcode-terminal"

# Generate QR code from command output
echo "Hello from the terminal" | qrcode-terminal

# Generate QR code for file contents
cat message.txt | qrcode-terminal