uqr

Generate QR Code universally, in any runtime, to ANSI, Unicode or SVG.

README

uqr


Generate QR Code universally, in any runtime, to ANSI, Unicode or SVG. ES module , zero dependency, tree-shakable.

Install


  1. ```bash
  2. # Using npm
  3. npm install uqr

  4. # Using yarn
  5. yarn add uqr

  6. # Using pnpm
  7. pnpm add uqr
  8. ```

Usage


  1. ```ts
  2. import {
  3.   encode,
  4.   renderANSI,
  5.   renderSVG,
  6.   renderUnicode,
  7.   renderUnicodeCompact,
  8. } from 'uqr'

  9. const svg = renderSVG('Hello, World!')

  10. const ansi = renderANSI('https://192.168.1.100:3000', {
  11.   // Error correction level
  12.   ecc: 'L',
  13.   // Border width
  14.   border: 2,
  15. })

  16. // display QR Code in terminal
  17. console.log(ansi)
  18. ```

API


encode


Encode plain text or binary data into QR Code represented by a 2D array.

  1. ```ts
  2. import { encode } from 'uqr'

  3. const {
  4.   data, // 2D array of boolean, representing the QR Code
  5.   version, // QR Code version
  6.   size, // size of the QR Code
  7. } = encode(text, options)
  8. ```

renderANSI


Render QR Code to ANSI colored string.

  1. ```ts
  2. import { renderANSI } from 'uqr'

  3. const string = renderANSI(text, options)

  4. console.log(string)
  5. ```

renderUnicode


Render QR Code to Unicode string for each pixel. By default it uses and to represent black and white pixels, and it can be customizable.

  1. ```ts
  2. import { renderUnicode } from 'uqr'

  3. const string = renderUnicode(text, {
  4.   blackChar: '█',
  5.   whiteChar: '░',
  6.   // ...other options
  7. })
  8. ```

renderUnicodeCompact


Render QR Code with two rows into one line with unicode , , , . It is useful when you want to display QR Code in terminal with limited height.

  1. ```ts
  2. import { renderUnicodeCompact } from 'uqr'

  3. const string = renderUnicodeCompact(text, options)

  4. console.log(string)
  5. ```

renderSVG


Render QR Code to SVG string.

  1. ```ts
  2. import { renderSVG } from 'uqr'

  3. const string = renderSVG(text, options)
  4. ```

Credits


QR Code generation algorithm is modified from nayuki/QR-Code-generator by Project Nayuki.

CLI renders are inspired by qrcode-terminal.