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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@skyordi/simple-qr-gen

v1.5.0

Published

This project implements a QR code generator featuring resizing functionality, customizable background and foreground colors, adjustable error correction levels, shape structure modifications, and export capabilities for JPEG and SVG formats

Readme

Simple QR Generator

Simple QR Generator is a lightweight TypeScript toolkit for producing highly-customizable QR codes as SVG strings. It wraps the battle-tested qrcodegen algorithm with a fluent builder API, rich content helpers (WiFi, SMS, email, phone, URLs, free text), and advanced styling controls for finder patterns and data modules.

Features

  • Fluent QRBuilder guides you through setting the content type, providing structured config data, tuning rendering options, and exporting an SVG payload in one chainable flow.[^1]
  • Fine-grained styling: switch finder borders, finder centers, and data modules between circular, square, rounded, squircle, triangle, diamond, bagel, and corner-flow variants to match your brand.[^3]
  • You can add your svg styling type using ISegmentCreateStrategy interface.[^3]

Installation

npm install @skyordi/simple-qr-gen

The package ships pre-compiled CommonJS in dist/ and TypeScript sources for editor tooling.

Quick Start

import {
  QRBuilder,
  QRContentType,
  SegmentStrategyType,
  Ecc,
} from '@skyordi/simple-qr-gen';

const svg = new QRBuilder()
  .setQRType(QRContentType.WIFI)
  .setQRConfig({
    ssid: 'My Network',
    password: 'super-secret',
  })
  .setQrOptions({
    foregroundColor: '#0f172a',
    backgroundColor: '#f8fafc',
    margin: 8,
    moduleScale: 1.25,
    ErrorCorrection: Ecc.HIGH,
    FinderBorderSegments: SegmentStrategyType.SquircleBorder,
    FinderInsideSegments: SegmentStrategyType.SquircleInside,
    DataSegments: SegmentStrategyType.RoundedSquare,
  })
  .buildQRSVG();

console.log(svg); // => <svg ...>...</svg>

API Overview

QRBuilder

| Step | Description | | ---- | ----------- | | setQRType(type) | Select the logical content type (WiFi, phone, SMS, email, URL, text). | | setQRConfig(config) | Provide the strongly-typed payload for the chosen content type. | | setQrOptions(options) | Adjust rendering options (colors, margins, module scale, error correction, segment strategies). | | buildQRSVG() | Validates prerequisites, formats the payload, encodes the QR matrix, and returns an SVG string. |

Content Helpers

Supported content enums and config interfaces:

| Type | Config | | ---- | ------ | | QRContentType.WIFI | WiFiConfig (ssid, optional password, encryption, hidden) | | QRContentType.PHONE | PhoneConfig (phoneNumber) | | QRContentType.SMS | SMSConfig (phoneNumber, optional message) | | QRContentType.EMAIL | EmailConfig (email, optional subject, body) | | QRContentType.URL | URLConfig (url) | | QRContentType.TEXT | TextConfig (text) |

Each formatter escapes or normalizes input to match QR payload conventions—for example, WiFi credentials escape reserved characters, phone numbers strip non-dialable characters, and URLs gain a default scheme if missing.[^2]

Styling Options

QrSvgOptions lets you influence the renderer without digging into SVG primitives:[^5]

| Option | Purpose | | ------ | ------- | | margin | Quiet zone padding around the code (default 4). | | foregroundColor | Color of modules (default #000000). | | backgroundColor | Canvas color (default #fff). | | moduleScale | Radius/size multiplier for modules (default 1). | | ErrorCorrection | One of Ecc.LOW, MEDIUM, QUARTILE, HIGH. | | FinderInsideSegments | Strategy for the finder center (Circular, Square, Diamond, RoundedSquare, CircularInside, CornerflowInside, SquircleInside). | | FinderBorderSegments | Strategy for finder rings (Circular, Square, BagelBorder, RoundedSquare, SquircleBorder, CornerflowBorder). | | DataSegments | Strategy for data modules (Circular, Square, Triangle, RoundedSquare, Diamond). |

Segment strategies are implemented via a factory that produces circles, rounded squares, squircles, triangles, diamonds, rings, and corner-flow glyphs on demand.[^3]

SVG Output

SVGBuildHelper composes the final markup by registering segment buckets, accumulating shapes, and emitting <rect>, <circle>, <polygon>, or <path> elements with optional fill-rule / clip-rule attributes.[^6] The result is a standalone <svg> string ready to inline in HTML, convert to raster imagery, or pipe into downstream tooling.

QR Gallery

Each sample was generated with QRBuilder by swapping segment strategies to highlight the segnebt styling.

Extending Segment Strategies

SegmentCreatorFactory is the central registry that maps a SegmentStrategyType enum to a concrete ISegmentCreateStrategy implementation.[^3] Add your own glyphs in three steps:

  1. Create a new enum entry in SegmentStrategyType (and update the FinderInsideSegments, FinderBorderSegments, or DataSupportedSegments unions if it applies).[^5]
  2. Implement a strategy that draws your shape with SVGBuildHelper. You can mix primitives (AddRectInSegment, AddCircleInSegment, AddPathInSegment, etc.) and inspect SegmentData.neighbors to merge corners.
  3. Register the strategy inside the SegmentCreatorFactory constructor so builders can request it by enum value.

Example skeleton for a diamond-outline finder border:

// src/Types/QREnums.ts
export enum SegmentStrategyType {
  // ...
  DiamondOutline,
}

// src/SegmentCreator/ISegmentCreate.ts
class DiamondOutlineFinderBorderStrategy implements ISegmentCreateStrategy {
  createSegmentStrategy(builder: SVGBuildHelper, data: SegmentData): void {
    const size = data.size;
    const anchors = [
      { x0: 0, y0: 0 },
      { x0: size - FINDER_SIZE, y0: 0 },
      { x0: 0, y0: size - FINDER_SIZE },
    ];
    const isAnchorTopLeft = anchors.some(a => a.x0 === data.point.X && a.y0 === data.point.Y);
    if (!isAnchorTopLeft) return;

    for (const { x0, y0 } of anchors) {
      const x = x0 + data.margin;
      const y = y0 + data.margin;
      const d = `M${x + 3.5} ${y} L${x + 7} ${y + 3.5} L${x + 3.5} ${y + 7} L${x} ${y + 3.5} Z`;
      builder.AddPathInSegment(data.segmentName, d, data.color);
    }
  }
}

export class SegmentCreatorFactory {
  constructor() {
    // ...
    this.strategies.set(SegmentStrategyType.DiamondOutline, new DiamondOutlineFinderBorderStrategy());
  }
}

Once registered, choose the strategy in your build chain:

const svg = new QRBuilder()
  .setQRType(QRContentType.TEXT)
  .setQRConfig({ text: 'Custom finder diamond outline' })
  .setQrOptions({
    FinderBorderSegments: SegmentStrategyType.DiamondOutline,
  })
  .buildQRSVG();

Because everything funnels through the same factory and helper utilities, new strategies automatically benefit from existing defaults, coloring, and SVG assembly logic.

Acknowledgements

This project embeds the MIT-licensed qrcodegen implementation by Project Nayuki.[^4]


[^1]: See the builder workflow, validation, defaults, and SVG generation in src/QRBuilder.ts. [^2]: Content formatter logic lives in src/Helpers/QRContentFormatter.ts and content typings in src/Types/QRContentTypes.ts. [^3]: Segment enums and strategy factory implementations reside in src/Types/QREnums.ts, src/Types/QRTypes.ts, and src/SegmentCreator/ISegmentCreate.ts. [^4]: The underlying QR matrix generation is powered by src/qrcore.ts. [^5]: Rendering option typings and defaults are defined in src/Types/QRTypes.ts and src/QRBuilder.ts. [^6]: SVG assembly helpers are implemented in src/Helpers/SVGBuildHelper.ts.