npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

qrmake

v1.2.0

Published

Generate QR codes as SVG, PNG, data URLs or terminal text. From-scratch ISO/IEC 18004 encoder (versions 1-40, L/M/Q/H, numeric/alphanumeric/byte/kanji, optimal segments), sync pure-JS PNG, Wi-Fi/vCard/email helpers, CLI. ESM + CommonJS, zero dependencies.

Readme

qrmake

Make QR codes as SVG, PNG, data URLs or terminal text, with no dependencies.

npm version bundle size license

qrmake turns text, links, Wi-Fi details or contact cards into QR codes. Every function is synchronous and works the same in Node.js, Deno, Bun, browsers and workers. Use it to save QR code images, show them on a web page, print them in a terminal, or make them from the command line.

Features

  • Follows the QR code standard (ISO/IEC 18004): all sizes (versions 1-40), all four error correction levels (L, M, Q, H), all 8 masks. Tested against published reference data and read back with OpenCV.
  • Smallest code for your data: text is split into numeric, alphanumeric and byte parts automatically. Kanji mode is optional.
  • Unicode support: text is encoded as UTF-8, emoji included.
  • Many output formats: SVG (one small <path>), PNG, data URL, terminal text, plain text, or the raw grid of squares.
  • PNG without zlib or canvas: a built-in, synchronous encoder that runs in every JavaScript runtime.
  • Payload helpers for Wi-Fi, email, SMS, phone, map location, URL, MECARD and vCard, with correct escaping.
  • Command line tool: npx qrmake "text", or save to .svg, .png or .txt.
  • Small and typed: about 9 KB gzipped, zero dependencies, TypeScript types included, ESM and CommonJS.

Installation

npm install qrmake
pnpm add qrmake
yarn add qrmake
bun add qrmake

Quick start

import { toSVG, toPNG, toDataURL, toTerminal, wifi } from 'qrmake'

toSVG('https://example.com')
// => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 33 33" width="132" ...'

toPNG('https://example.com', { scale: 8 })
// => Uint8Array [137, 80, 78, 71, ...] (the bytes of a PNG file)

toDataURL('https://example.com')
// => 'data:image/png;base64,iVBORw0KGgo...'

console.log(toTerminal('https://example.com')) // prints the code in the terminal

toSVG(wifi({ ssid: 'Home', password: 'secret' })) // scan this to join the network

CommonJS works too: const qrmake = require('qrmake'), then qrmake.toSVG('hi').

Table of contents

Usage

A few words used below:

  • Module: one small square of the QR code. Each module is dark or light.
  • Quiet zone: the empty border around the code. Scanners need it to find the code.
  • Version: the size of the code, from 1 (21 x 21 modules) to 40 (177 x 177 modules). qrmake picks the smallest version that fits your data.

Save a PNG or SVG file

toPNG() returns the bytes of a PNG file. toSVG() returns the SVG as a string. Write either one to disk with node:fs.

import { writeFileSync } from 'node:fs'
import { toPNG, toSVG } from 'qrmake'

writeFileSync('code.png', toPNG('https://example.com', { size: 512 })) // 512 x 512 pixels
writeFileSync('code.svg', toSVG('https://example.com'))

Use scale to set the pixels per module, or size to set the exact image width in pixels.

Show a QR code in the browser

The simplest way is a data URL in an <img> tag. A data URL holds the whole image inside the string, so no file or server is needed.

import { toDataURL } from 'qrmake'

const img = document.createElement('img')
img.src = toDataURL('https://example.com', { type: 'svg' }) // or leave out type for PNG
img.alt = 'QR code for example.com'
document.body.append(img)

The same in React:

import { toDataURL } from 'qrmake'

export function QRCode({ value }) {
  return <img src={toDataURL(value, { scale: 6 })} alt={`QR code: ${value}`} />
}

To put the SVG straight into the page, use toSVG(). With size: 0 the SVG has no fixed width or height, so it fills its container:

import { toSVG } from 'qrmake'

container.innerHTML = toSVG('https://example.com', { size: 0, title: 'Link to example.com' })

To let users download a PNG, wrap the bytes in a Blob:

import { toPNG } from 'qrmake'

const blob = new Blob([toPNG('https://example.com', { size: 512 })], { type: 'image/png' })
link.href = URL.createObjectURL(blob)
link.download = 'qr-code.png'

Print a QR code in the terminal

toTerminal() draws the code with the block characters ▀ ▄ █. Two rows of modules fit in one line of text, so the code stays square and small.

import { toTerminal } from 'qrmake'

console.log(toTerminal('https://example.com'))
█████████████████████████████
██ ▄▄▄▄▄ ███▀▄▄ ▀▀ █ ▄▄▄▄▄ ██
██ █   █ █ ▄█▄█▀ ▀██ █   █ ██
██ █▄▄▄█ █ ▄▄▀█▄▀▀▄█ █▄▄▄█ ██
██▄▄▄▄▄▄▄█ █▄█▄█ █ █▄▄▄▄▄▄▄██
...

By default the output suits a terminal with a dark background. For a light background, use { invert: true }. To make the code scan on any terminal theme, use { ansi: true }: it paints the code black on white with ANSI colours.

Share Wi-Fi login details

wifi() builds the text that phone cameras read as "join this network". Pass it to any renderer.

import { writeFileSync } from 'node:fs'
import { wifi, toPNG } from 'qrmake'

const text = wifi({ ssid: 'Office Guest', password: 'tea&biscuits' })
// => 'WIFI:T:WPA;S:Office Guest;P:tea&biscuits;;'

writeFileSync('wifi.png', toPNG(text, { size: 400 }))

Special characters in the name or password are escaped for you:

wifi({ ssid: 'My;Net', password: 'p:w', security: 'WPA', hidden: true })
// => 'WIFI:T:WPA;S:My\\;Net;P:p\\:w;H:true;;'

wifi({ ssid: 'Cafe' }) // open network, no password
// => 'WIFI:T:nopass;S:Cafe;;'

Share a contact card

vcard() makes a contact card that phones can save to the address book. mecard() makes a shorter card with fewer fields, so the QR code is smaller.

import { vcard, mecard, toSVG } from 'qrmake'

const card = vcard({
  name: 'Jane Doe',
  org: 'Acme Inc.',
  title: 'Sales Manager',
  phone: '+1 555 0100',
  email: '[email protected]',
  url: 'https://example.com',
})
// => 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Doe;Jane;;;\r\nFN:Jane Doe\r\nORG:Acme Inc.\r\n...'

const svg = toSVG(card)

mecard({ name: 'Jane Doe', phone: '+1 555 0100', email: '[email protected]' })
// => 'MECARD:N:Jane Doe;TEL:+15550100;EMAIL:[email protected];;'

Choose an error correction level

A QR code stores extra recovery data. If part of the code is dirty, torn or covered, a scanner can still read it. The error correction level sets how much of the code can be damaged:

| Level | Damage it can recover from | When to use it | |---|---|---| | L | about 7% | Clean screens, when you need the smallest code | | M (default) | about 15% | Most uses | | Q | about 25% | Printed codes that may get dirty or worn | | H | about 30% | Codes with a logo on top, or harsh places |

A higher level makes the code bigger for the same data:

import qrmake from 'qrmake'

qrmake('https://example.com/products/12345', { ecl: 'L' }).size // => 29
qrmake('https://example.com/products/12345', { ecl: 'H' }).size // => 33

With boostEcl: true, qrmake uses a higher level for free when the data still fits in the same size:

qrmake('https://example.com', { boostEcl: true }).ecl // => 'Q'

Encode once, render in several ways

qrmake() returns the encoded grid of modules. Every renderer accepts this grid as well as plain text, so you can encode once and draw it many times.

import qrmake, { toSVG, toPNG } from 'qrmake'

const qr = qrmake('https://example.com', { ecl: 'H' })
const svg = toSVG(qr, { dark: '#1a1a2e' })
const png = toPNG(qr, { size: 1024 })

Handle data that is too long

A QR code holds a limited amount of data. If your data does not fit, qrmake throws a QRError. Use capacity() to check the limits ahead of time.

import qrmake, { capacity, QRError } from 'qrmake'

capacity(40, 'L').byte // => 2953 (the largest code holds 2953 bytes)

try {
  qrmake('x'.repeat(3000), { ecl: 'L' })
} catch (error) {
  error instanceof QRError // => true
  error.message // => 'Data too long: needs 24020 bits, but version 40-L holds 23648'
}

Command line

qrmake includes a command line tool. Run it with npx, or install the package and run qrmake.

npx qrmake "https://example.com"                         # print in the terminal
npx qrmake -i "text"                                     # for terminals with a light background
npx qrmake -o code.svg -e H "Hello"                      # save an SVG with level H
npx qrmake -o code.png --size 512 --dark "#123" "Hello"  # save a 512 x 512 PNG
npx qrmake -o code.txt "Hello"                           # save as plain text
git remote get-url origin | npx qrmake                   # read the text from stdin
npx qrmake -t svg "Hello" > code.svg                     # write SVG (or png, text) to stdout

With -o, the file extension sets the format: .svg, .png or .txt. When the text comes from stdin, one trailing newline is removed.

| Flag | Value | Default | Description | |---|---|---|---| | -o, --output | file | none | Write to a file. The format comes from the extension (.svg, .png, .txt). | | -t, --type | terminal, svg, png, text | terminal | Output format. Also overrides the format from the -o extension. | | -e, --ecl | L, M, Q, H | M | Error correction level. | | --qr-version | 1-40 | smallest that fits | Force a QR version (size). | | -m, --margin | number | 2 in the terminal, else 4 | Quiet zone in modules. | | -s, --scale | number | 4 | Pixels per module for SVG and PNG. | | --size | pixels | none | Image width and height for SVG and PNG. | | --dark | colour | #000 | Dark module colour for SVG and PNG. | | --light | colour | #fff | Background colour for SVG and PNG, or transparent. | | -i, --invert | | off | Terminal: draw the dark modules, for light backgrounds. | | -l, --large | | off | Terminal: two characters per module instead of half blocks. | | -a, --ansi | | off | Terminal: paint black on white with ANSI colours. | | -h, --help | | | Show help. | | -v, --version | | | Show the qrmake version. |

Long flags also accept --flag=value. The tool exits with code 0 on success, 1 when the code cannot be made (for example, the text is too long) and 2 for wrong flags or missing text.

API

qrmake(input, options?)

function qrmake(input: QRInput, options?: QROptions): QRCode
function encode(input: QRInput, options?: QROptions): QRCode

Encodes text, bytes or segments into a QRCode grid. encode is the same function. qrmake is also the default export, and it has every other export attached (qrmake.toSVG, qrmake.wifi, and so on).

import qrmake from 'qrmake'

const qr = qrmake('HELLO WORLD', { ecl: 'Q' })
qr.version   // => 1
qr.size      // => 21
qr.ecl       // => 'Q'
qr.mask      // => 6
qr.segments  // => [{ mode: 'alphanumeric', length: 11 }]
qr.get(0, 0) // => true (dark module at column 0, row 0)

Input

  • A string: encoded as UTF-8. Runs of digits or capital letters use the smaller numeric and alphanumeric modes when that saves space. For example, 'Order 12345678901234567890' uses byte mode for Order and numeric mode for the digits.
  • A Uint8Array: raw bytes (binary data), also split into the best modes.
  • An array of segments, to choose the modes yourself:
qrmake([
  { mode: 'alphanumeric', data: 'INVOICE:' },
  { mode: 'numeric', data: '000123456' },
  { mode: 'byte', data: ' paid €' },
])

kanji segments take a string, or Shift JIS bytes as a Uint8Array.

Encoder options

Every function that takes text (qrmake, encode and all renderers) accepts these options.

| Option | Type | Default | Description | |---|---|---|---| | ecl | 'L' \| 'M' \| 'Q' \| 'H' | 'M' | Error correction level: about 7%, 15%, 25% or 30% of the code can be damaged. See Choose an error correction level. | | boostEcl | boolean | false | Use a higher level for free when the data still fits in the same version. | | version | number | smallest that fits | Force a version, 1-40 (21 x 21 to 177 x 177 modules). Throws if the data does not fit. | | minVersion | number | 1 | Smallest version to consider. | | maxVersion | number | 40 | Largest version to consider. | | mask | 0-7 | lowest penalty | Force a mask pattern. A mask flips some modules so the code is easier to scan; by default qrmake tries all 8 and picks the best. | | mode | 'numeric' \| 'alphanumeric' \| 'byte' \| 'kanji' | automatic | Encode everything in one mode. Throws if a character does not fit that mode. | | optimize | boolean | true | Split text into the cheapest mix of modes. false uses one segment in the most compact mode that fits all of it. | | kanji | boolean | false | Allow kanji mode for Japanese text (13 bits per character instead of 24 for UTF-8). Needs TextDecoder with Shift JIS support; throws otherwise. | | eci | boolean | false | Add a UTF-8 ECI header (a marker that says "this text is UTF-8", designator 26) when the text is not plain ASCII. Most readers assume UTF-8 anyway; some older ones need this. |

The QRCode object

| Property | Type | Description | |---|---|---| | version | number | Version used, 1-40. | | size | number | Width and height in modules (version * 4 + 17), without the quiet zone. | | ecl | ErrorCorrectionLevel | Error correction level used. | | mask | MaskPattern | Mask pattern used, 0-7. | | segments | SegmentInfo[] | How the data was split into modes: { mode, length }. | | modules | Uint8Array | All modules, row by row. 1 is dark. Index with y * size + x. | | get(x, y) | boolean | true if the module at column x, row y is dark. Outside the code it returns false. | | toArray() | boolean[][] | The modules as rows of booleans (true is dark). |

toSVG(input, options?)

function toSVG(input: RenderInput, options?: SVGOptions): string

Returns an SVG string. All dark modules are drawn as one <path> with side-by-side modules merged, so the markup stays small. Colours and the title are XML-escaped. input is text, bytes, segments, or a QRCode from qrmake(). All encoder options also apply.

| Option | Type | Default | Description | |---|---|---|---| | margin | number | 4 | Quiet zone in modules. 4 is what the standard asks for. | | scale | number | 4 | Pixels per module, used for the width and height attributes. | | size | number | (size + 2 * margin) * scale | width and height attributes in pixels. 0 leaves them out, so the SVG fills its container. | | dark | string | '#000' | Colour of dark modules. Any CSS colour. | | light | string | '#fff' | Background colour. Any CSS colour, or 'transparent' for no background. | | radius | number | 0 | Corner radius of each module, from 0 (square) to 0.5 (round dots). | | title | string | none | Adds a <title> element for screen readers. |

toSVG('hi', { size: 256 })                         // width="256" height="256"
toSVG('hi', { dark: '#0b5', light: 'transparent' }) // green, no background
toSVG('hi', { radius: 0.5 })                        // round dots

toPNG(input, options?)

function toPNG(input: RenderInput, options?: PNGOptions): Uint8Array

Returns the bytes of a 1-bit palette PNG file. It uses a small built-in deflate (compression) encoder, so it needs no zlib, canvas or Buffer, and runs synchronously anywhere. All encoder options also apply.

| Option | Type | Default | Description | |---|---|---|---| | margin | number | 4 | Quiet zone in modules. | | scale | number | 4 | Pixels per module. Must be a whole number. Ignored when size is set. | | size | number | none | Exact width and height in pixels. Each module gets a whole number of pixels; leftover pixels widen the quiet zone so the image stays sharp. Throws if the size is too small for 1 pixel per module. | | dark | string | '#000000' | Dark module colour: #rgb, #rgba, #rrggbb or #rrggbbaa. | | light | string | '#ffffff' | Background colour in the same formats, or 'transparent'. |

toDataURL(input, options?)

function toDataURL(input: RenderInput, options?: DataURLOptions): string

Returns a data: URL, ready for <img src>. By default it is a PNG (data:image/png;base64,...) and the PNG options apply. With { type: 'svg' } it is an SVG (data:image/svg+xml;charset=utf-8,...) and the SVG options apply.

| Option | Type | Default | Description | |---|---|---|---| | type | 'png' \| 'svg' | 'png' | Image format. |

toTerminal(input, options?)

function toTerminal(input: RenderInput, options?: TerminalOptions): string

Returns text that draws the code with Unicode block characters. Print it with console.log(). All encoder options also apply.

| Option | Type | Default | Description | |---|---|---|---| | margin | number | 2 | Quiet zone in modules. | | invert | boolean | false | By default the light modules are drawn, which suits terminals with a dark background. Set true for a light background. | | small | boolean | true | Two rows of modules per line with half blocks (▀ ▄ █). false draws each module as ██, which is twice as big. | | ansi | boolean | false | Paint black on white with ANSI colours, so the code scans on any terminal theme. |

toText(input, options?)

function toText(input: RenderInput, options?: TextOptions): string

Returns plain text with one line per row of modules. All encoder options also apply.

toText('hi', { margin: 0, dark: '#', light: '.' }).split('\n')[0]
// => '#######..####.#######'

| Option | Type | Default | Description | |---|---|---|---| | margin | number | 4 | Quiet zone in modules. | | dark | string | '##' | Text for a dark module. | | light | string | ' ' | Text for a light module. | | newline | string | '\n' | Line separator. |

wifi(options)

function wifi(options: WifiOptions): string

Returns the text to join a Wi-Fi network. The characters \ ; , : " are escaped with a backslash. Throws a TypeError if ssid is empty, or if a password is needed but missing.

| Option | Type | Default | Description | |---|---|---|---| | ssid | string | required | Network name. | | password | string | none | Leave out for an open network. | | security | 'WPA' \| 'WEP' \| 'SAE' \| 'nopass' | 'WPA' with a password, 'nopass' without | 'WPA' covers WPA and WPA2 personal. 'SAE' is WPA3 only. | | hidden | boolean | false | The network does not broadcast its name. |

email(to, options?)

function email(to: string | string[], options?: EmailOptions): string

Returns a mailto: link. Values are percent-encoded.

email('[email protected]', { subject: 'Hello', body: 'Hi!' })
// => 'mailto:[email protected]?subject=Hello&body=Hi!'

| Option | Type | Default | Description | |---|---|---|---| | subject | string | none | Email subject. | | body | string | none | Email text. | | cc | string \| string[] | none | Copy to these addresses. | | bcc | string \| string[] | none | Blind copy to these addresses. |

sms(number, message?)

function sms(number: string, message?: string): string

Returns the text to send an SMS. Spaces, dashes, dots and brackets are removed from the number. Any other invalid character throws a TypeError.

sms('+1 555 0100', 'On my way') // => 'SMSTO:+15550100:On my way'

tel(number)

function tel(number: string): string

Returns a tel: link to call a number. The number is cleaned the same way as in sms().

tel('+1 (555) 010-0199') // => 'tel:+15550100199'

geo(latitude, longitude, altitude?)

function geo(latitude: number, longitude: number, altitude?: number): string

Returns a geo: link to a map location. Values out of range (latitude beyond 90, longitude beyond 180) throw a RangeError.

geo(48.8584, 2.2945) // => 'geo:48.8584,2.2945'

url(link)

function url(link: string): string

Returns the link, with https:// added when it has no scheme.

url('example.com') // => 'https://example.com'

vcard(contact)

function vcard(contact: ContactOptions): string

Returns a vCard 3.0 contact card. It carries more fields than MECARD. Throws a TypeError if name is missing.

| Option | Type | Default | Description | |---|---|---|---| | name | string | required | Full name, for example 'Jane Doe'. | | phone | string \| string[] | none | One or more phone numbers. | | email | string \| string[] | none | One or more email addresses. | | url | string | none | Website. | | org | string | none | Company or organization. | | title | string | none | Job title. vCard only; mecard() ignores it. | | address | string | none | Postal address as one line. | | note | string | none | Free text. | | birthday | string | none | Date as YYYY-MM-DD. |

mecard(contact)

function mecard(contact: ContactOptions): string

Returns a MECARD contact card. It is smaller than a vCard, so the QR code is smaller too. It takes the same options as vcard(), except title. Throws a TypeError if name is missing.

capacity(version, ecl?)

function capacity(version: number, ecl?: ErrorCorrectionLevel): Capacity

Returns how much fits in one segment of each mode, for a version and error correction level (default 'M'). bits is the total data space, including mode and length headers.

capacity(1, 'M')  // => { bits: 128, numeric: 34, alphanumeric: 20, byte: 14, kanji: 8 }
capacity(40, 'L') // => { bits: 23648, numeric: 7089, alphanumeric: 4296, byte: 2953, kanji: 1817 }

isQRCode(value)

function isQRCode(value: unknown): value is QRCode

Returns true if value is a QRCode returned by qrmake().

isQRCode(qrmake('hi')) // => true
isQRCode({})           // => false

QRError

class QRError extends RangeError {}

Thrown when the data does not fit, or when an option is invalid. Because it extends RangeError, error instanceof RangeError is also true.

Types

All types are exported: QRCode, QROptions, QRInput, QRMake, Segment, SegmentInfo, ErrorCorrectionLevel, Mode, MaskPattern, Capacity, RenderInput, SVGOptions, PNGOptions, DataURLOptions, TerminalOptions, TextOptions, WifiOptions, WifiSecurity, EmailOptions, ContactOptions.

Comparison

How qrmake compares with qrcode, qrcode-generator, qrcode-terminal and qr-image:

| | qrcode | qrcode-generator | qrcode-terminal | qr-image | qrmake | |---|---|---|---|---|---| | Runtime dependencies | 3 (pngjs, yargs, dijkstrajs) | 0 | 0 | 0 | 0 | | SVG | Yes | Yes | No | Yes | Yes | | PNG | Yes: Node (via pngjs), canvas in browsers | No (GIF only) | No | Node only (zlib, Buffer) | Yes, in every runtime | | PNG and data URL API | Async (callback or Promise) | Sync | n/a | Sync or stream | Sync | | Terminal output | Yes | Half-block ASCII | Yes | No | Yes (plus invert and ANSI colours) | | Mixed-mode segment optimization | Yes | No (you pick the mode per addData) | No (byte mode only) | No (one mode per code; parse_url splits a URL in two) | Yes | | UTF-8 text by default | Yes | No (keeps the low byte of each character unless you change stringToBytes) | No (keeps the low byte of each character) | Yes | Yes | | Kanji mode | Yes, with a Shift JIS helper | Yes | No | No | Yes (opt-in, no extra code) | | Wi-Fi, vCard and email helpers | No | No | No | No | Yes | | Command line tool | Yes | No | Yes | No | Yes | | TypeScript types | @types/qrcode | Yes | @types/qrcode-terminal | @types/qr-image | Yes, built in |

Migrating from qrcode

The main change: qrmake is synchronous, so you do not need await.

// Before (qrcode)
const svg = await QRCode.toString(text, { type: 'svg' })
const url = await QRCode.toDataURL(text, { errorCorrectionLevel: 'H' })
const png = await QRCode.toBuffer(text, { width: 512 })
const modules = QRCode.create(text).modules

// After (qrmake)
const svg = toSVG(text)
const url = toDataURL(text, { ecl: 'H' })
const png = toPNG(text, { size: 512 })
const qr = qrmake(text)

Option names:

| qrcode | qrmake | |---|---| | errorCorrectionLevel | ecl | | color.dark, color.light | dark, light | | width | size | | margin, scale, version | same names |

How it is tested

  • Reed-Solomon codewords (the recovery data) match published examples: the Thonky tutorial's HELLO WORLD 1-M and 5-Q blocks (including the final interleaved message), and the 01234567 1-M example from ISO/IEC 18004 Annex I.
  • All 32 format strings and all 34 version strings match the published tables. Alignment positions and block structure match ISO/IEC 18004 Annex E and Table 9 for every version and level.
  • Capacity is spot-checked against the published capacity table, and version selection is checked at every boundary.
  • Every version at every level, filled to capacity in numeric, alphanumeric and byte mode, plus every mask, is read back by an independent reader in the test suite. The reader checks the format and version information, every Reed-Solomon block, the padding and the decoded text.
  • PNGs are decoded by OpenCV's QR reader when Python with cv2 is installed. The test is skipped otherwise.
  • During development, 480 codes made by OpenCV's own encoder (every version and level, in numeric, alphanumeric and byte mode) were compared with qrmake's output for the same data, version, level and mask. The codewords matched every time, except for version 21, where OpenCV puts the last alignment pattern at 92 instead of 94 (ISO/IEC 18004 Annex E). The matrices were identical, except for a few unmasked remainder bits in OpenCV's versions 2-6.

Notes and limitations

  • Kanji mode needs TextDecoder with Shift JIS support (Node.js with ICU, Deno, browsers). Without it, kanji: true throws.
  • PNG colours must be hex (#rgb, #rgba, #rrggbb, #rrggbbaa) or 'transparent'. SVG accepts any CSS colour.
  • PNG scale must be a whole number. A PNG size that is too small for 1 pixel per module throws a QRError.
  • Quiet zone: keep margin at 4 or more for images, as the standard asks. A smaller border can make the code harder to scan.
  • Non-ASCII text: most readers assume UTF-8. If an older reader shows the wrong characters, try eci: true.
  • Errors: the encoder and renderers throw QRError. The payload helpers throw TypeError (or RangeError from geo()) for invalid input.
  • Command line colours: --dark and --light only affect SVG and PNG output, not the terminal.

Requirements

  • Node.js 20 or newer. Also runs in Deno, Bun, browsers and web workers.
  • ESM and CommonJS builds.
  • TypeScript types included.
  • Zero dependencies.

License

MIT