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

@ashaffah/qrcodegen

v1.0.0

Published

QR Code generator library

Downloads

58

Readme

@ashaffah/qrcodegen

A TypeScript QR Code generator library with zero runtime dependencies. Supports SVG output and raw pixel buffer for custom rendering pipelines.

Based on the QR Code generator library by Project Nayuki (MIT License).

Installation

npm install @ashaffah/qrcodegen

Usage

Generate an SVG

import { QrCode, toSvgString } from "@ashaffah/qrcodegen";

const qr = QrCode.encodeText("Hello, World!", QrCode.Ecc.MEDIUM);
const svg = toSvgString(qr);

// Write to file
import fs from "node:fs";
fs.writeFileSync("qrcode.svg", svg);

Encode Binary Data

import { QrCode } from "@ashaffah/qrcodegen";

const data = [0x48, 0x65, 0x6c, 0x6c, 0x6f]; // "Hello" in bytes
const qr = QrCode.encodeBinary(data, QrCode.Ecc.HIGH);

Advanced: Custom Segments

import { QrCode, QrSegment } from "@ashaffah/qrcodegen";

const segments = QrSegment.makeSegments("HELLO WORLD");
const qr = QrCode.encodeSegments(segments, QrCode.Ecc.LOW, 1, 40, -1, true);

API

QrCode

The main class for generating QR Codes.

Static Methods

| Method | Description | | ------------------------------------------------------------------------------ | ----------------------------------------------------------------------- | | QrCode.encodeText(text, ecl) | Encode a Unicode string. Automatically selects the smallest QR version. | | QrCode.encodeBinary(data, ecl) | Encode raw bytes (max 2953 bytes). | | QrCode.encodeSegments(segs, ecl, minVersion?, maxVersion?, mask?, boostEcl?) | Mid-level API for fine-grained control over encoding. |

Properties

| Property | Type | Description | | ---------------------- | -------- | -------------------------------------------------------------- | | size | number | Width/height in modules (21–177). Equal to version * 4 + 17. | | version | number | QR Code version (1–40). | | mask | number | Mask pattern used (0–7). | | errorCorrectionLevel | Ecc | The error correction level of this QR Code. |

Methods

| Method | Description | | ----------------- | ----------------------------------------------------------------- | | getModule(x, y) | Returns true if the module at (x, y) is dark, false if light. |

QrCode.Ecc — Error Correction Levels

| Level | Tolerance | Constant | | -------- | --------- | --------------------- | | Low | ~7% | QrCode.Ecc.LOW | | Medium | ~15% | QrCode.Ecc.MEDIUM | | Quartile | ~25% | QrCode.Ecc.QUARTILE | | High | ~30% | QrCode.Ecc.HIGH |

Higher error correction increases QR Code size but improves scan reliability in damaged or obscured conditions.

toSvgString(qr, border?, lightColor?, darkColor?)

Converts a QrCode object to an SVG string.

| Parameter | Type | Default | Description | | ------------ | -------- | ----------- | ------------------------------------ | | qr | QrCode | — | The QR Code to render. | | border | number | 4 | Quiet zone size in modules. | | lightColor | string | "#FFFFFF" | Background color (CSS color string). | | darkColor | string | "#000000" | Foreground color (CSS color string). |

const svg = toSvgString(qr, 4, "#FFFFFF", "#000000");

QrSegment

Mid-level API for manually constructing encoding segments.

| Method | Description | | ---------------------------------- | ------------------------------------------------------------- | | QrSegment.makeBytes(data) | Encode raw bytes in byte mode. | | QrSegment.makeNumeric(digits) | Encode a numeric string (digits 0–9 only). | | QrSegment.makeAlphanumeric(text) | Encode uppercase alphanumeric text. | | QrSegment.makeSegments(text) | Automatically choose the optimal segment mode for a string. | | QrSegment.makeEci(assignVal) | Create an Extended Channel Interpretation designator segment. |

Development

# Install dependencies
npm install

# Build the library
npm run build

# Type-check tests
npm test

Output is emitted to dist/ with TypeScript declarations and source maps included.

License

MIT — Copyright (c) Ashraf Ashaffah.

This project is based on the QR Code generator library by Project Nayuki, also under the MIT License.