@openjs/universal-qrcode@1.0.2
Generate QR Code universally, in any runtime, to ANSI, Unicode or SVG. ES module , zero dependency, tree-shakable.
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
Add Package
deno add jsr:@openjs/universal-qrcode
Import symbol
import * as universal_qrcode from "@openjs/universal-qrcode";
Import directly with a jsr specifier
import * as universal_qrcode from "jsr:@openjs/universal-qrcode";
Add Package
pnpm i jsr:@openjs/universal-qrcode
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
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";