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

@suckless/qr-code

v0.6.0

Published

Minimal, zero-dependency QR code generator with SVG and terminal rendering

Downloads

231

Readme

@suckless/qr-code

Minimal, zero-dependency QR code generator with SVG and terminal rendering. Implements QR encoding from scratch (ISO 18004).

Install

npm install @suckless/qr-code

Usage

import { createQrCode, encodeData, renderSvg } from "@suckless/qr-code"

// Encode structured data into a QR-compatible string
const text = encodeData({
	type: "url",
	value: "https://example.com",
})

// Generate the QR code matrix
const qr = createQrCode(text, { errorCorrection: "M" })

// Render as SVG
const svg = renderSvg(qr, {
	size: 400,
	dotStyle: "rounded",
	foreground: "#000000",
	background: "#ffffff",
})

Each layer is independent. If you only need the matrix (e.g. for a canvas renderer), skip renderSvg:

const qr = createQrCode("hello")
// qr.version, qr.size, qr.modules (Uint8Array)

Data types

encodeData supports structured data:

// WiFi
encodeData({
	type: "wifi",
	ssid: "MyNetwork",
	password: "secret",
	encryption: "WPA",
})

// Contact (vCard)
encodeData({
	type: "contact",
	firstName: "John",
	lastName: "Doe",
	phone: "+1234567890",
	email: "[email protected]",
})

API

encodeData(data: QrData): string

Converts structured data into a QR-compatible string. Handles WiFi encoding, vCard formatting, and special character escaping.

createQrCode(text: string, options?: QrOptions): QrCode

Generates a QR code from a string. Automatically selects the optimal encoding mode (numeric, alphanumeric, or byte), version (1–40), and mask pattern.

Options:

  • errorCorrection"L" | "M" (default) | "Q" | "H"

Returns:

  • version — QR version (1–40)
  • size — Module count per side (version * 4 + 17)
  • modulesUint8Array of 0 (light) and 1 (dark) values, row-major

Throws RangeError if the data exceeds the capacity of version 40.

renderSvg(qr: QrCode, options?: SvgOptions): string

Renders a QR code as an SVG string.

Options:

  • size — SVG dimensions in pixels (default 400)
  • foreground — Module color (default "#000000")
  • background — Background color or "transparent" (default "#ffffff")
  • dotStyle"square" (default) | "rounded" | "dots"
  • cornerSquareStyle"square" (default) | "rounded" | "dot"
  • cornerDotStyle"square" (default) | "dot"
  • logo{ src: string; sizeRatio?: number } to embed an image in the center (default sizeRatio is 0.12; prefer errorCorrection: "H" for denser payloads)

renderText(qr: QrCode, options?: TextOptions): string

Renders a QR code as a compact Unicode string using half-block characters (▀ ▄ █). Each text line encodes two module rows.

import { createQrCode, renderText } from "@suckless/qr-code"

console.log(renderText(createQrCode("hello"), { invert: true }))

Options:

  • margin — Quiet zone in modules (default 4)
  • invert — Swap filled/empty for dark-background terminals (default false)

Input sanitization

encodeData escapes characters required by each format spec (WiFi: \ ; , " and vCard: \ ; , plus newlines), but it does not strip control characters (tabs, carriage returns, etc.) from input strings.

For WiFi payloads built from untrusted user input, sanitize control characters before calling encodeData:

const sanitize = (s: string) => s.replaceAll(/[\x00-\x1f\x7f]/g, "")

encodeData({
	type: "wifi",
	ssid: sanitize(userInput),
	password: sanitize(userPassword),
	encryption: "WPA",
})

For vCard payloads, avoid blanket control-character stripping if you need intentional formatting (for example, user-entered line breaks in addresses).

License

MIT