Skip to main content
Home

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

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
88%
Published
6 months ago (1.0.2)

universal-qrcode

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

Install

# Using npm
npx jsr add @openjs/universal-qrcode

# Using deno
deno add jsr:@openjs/universal-qrcode

# Using yarn
yarn dlx jsr add @openjs/universal-qrcode

# Using pnpm
pnpm dlx jsr add @openjs/universal-qrcode

# Using bun
bunx jsr add @openjs/universal-qrcode

Usage

import {
  encode,
  renderANSI,
  renderSVG,
  renderUnicode,
  renderUnicodeCompact,
} from "@openjs/universal-qrcode";

const svg = renderSVG("Hello, World!");

const ansi = renderANSI("https://192.168.1.100:3000", {
  // Error correction level
  ecc: "L",
  // Border width
  border: 2,
});

// display QR Code in terminal
console.log(ansi);

API

encode

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

import { encode } from "@openjs/universal-qrcode";

const {
  data, // 2D array of boolean, representing the QR Code
  version, // QR Code version
  size, // size of the QR Code
} = encode(text, options);

renderANSI

Render QR Code to ANSI colored string.

import { renderANSI } from "@openjs/universal-qrcode";

const string = renderANSI(text, options);

console.log(string);

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.

import { renderUnicode } from "@openjs/universal-qrcode";

const string = renderUnicode(text, {
  blackChar: "█",
  whiteChar: "░",
  // ...other options
});

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.

import { renderUnicodeCompact } from "@openjs/universal-qrcode";

const string = renderUnicodeCompact(text, options);

console.log(string);

renderSVG

Render QR Code to SVG string.

import { renderSVG } from "@openjs/universal-qrcode";

const string = renderSVG(text, options);

License

MIT License

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@openjs/universal-qrcode

Import symbol

import * as universal_qrcode from "@openjs/universal-qrcode";
or

Import directly with a jsr specifier

import * as universal_qrcode from "jsr:@openjs/universal-qrcode";

Add Package

pnpm i jsr:@openjs/universal-qrcode
or (using pnpm 10.8 or older)
pnpm dlx jsr add @openjs/universal-qrcode

Import symbol

import * as universal_qrcode from "@openjs/universal-qrcode";

Add Package

yarn add jsr:@openjs/universal-qrcode
or (using Yarn 4.8 or older)
yarn dlx jsr add @openjs/universal-qrcode

Import symbol

import * as universal_qrcode from "@openjs/universal-qrcode";

Add Package

npx jsr add @openjs/universal-qrcode

Import symbol

import * as universal_qrcode from "@openjs/universal-qrcode";

Add Package

bunx jsr add @openjs/universal-qrcode

Import symbol

import * as universal_qrcode from "@openjs/universal-qrcode";