qrcode-terminal

repository·master·Indexed 23 days ago

https://github.com/gtanner/qrcode-terminal

A Node.js library and CLI tool for rendering QR codes directly within a terminal environment. Version 0.12.0 provides functionality to generate QR codes from strings, set error correction levels, and output results either directly to the console or via a callback function.

Tokens
984
Snippets
4
Records
9
Agent score
30%

What's inside qrcode-terminal

  1. Use the qrcode-terminal Node library

    master

    Import the library using require('qrcode-terminal'). You can generate QR codes directly to the terminal, set error correction levels, or capture the QR code as a string via a callback.

    var qrcode = require('qrcode-terminal');
    
    // Basic usage: displays to terminal
    qrcode.generate('This will be a QRCode, eh!');
    
    // Set error level (default is 'L')
    qrcode.setErrorLevel('Q');
    qrcode.generate('This will be a QRCode with error level Q!');
    
    // Get QR code as a string via callback (does not display to terminal)
    qrcode.generate('http://github.com', function (qrcode) {
        console.log(qrcode);
    });
    
    // Small output mode
    qrcode.generate('This will be a small QRCode, eh!', {small: true});
    
    // Small output mode with callback
    qrcode.generate('This will be a small QRCode, eh!', {small: true}, function (qrcode) {
        console.log(qrcode);
    });
  2. Generate a QR code in the terminal with generate()

    master

    The generate(input, opts, cb) method creates a QR code from the provided input string and outputs it to the terminal or via a callback.

    Parameters:

    • input (string): The data to encode in the QR code.
    • opts (object, optional): Configuration options.
      • small (boolean): If true, uses special Unicode block characters (, , ) to render a more compact QR code. If false (default), uses ANSI color codes for a standard block output.
    • cb (function, optional): A callback function that receives the generated string output. If no callback is provided, the output is printed directly to console.log.

    Behavior:

    • If opts is omitted, it defaults to an empty object.
    • If opts is passed as a function, it is treated as the callback cb.
  3. Set the QR code error correction level with setErrorLevel()

    master

    The setErrorLevel(error) method sets the error correction level for subsequent generate() calls. It uses levels defined in the internal QRErrorCorrectLevel mapping.

    Parameters:

    • error (string): The name of the error correction level. If the provided string does not match a valid level, the current level is retained.

    Note: The default error level is QRErrorCorrectLevel.L.