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

@qr-platform/qr-code.js

v0.20.11

Published

QRCode.js is a professional JavaScript/TypeScript library for creating customized QR codes, offering a blend of simplicity and sophistication. With versatile styling options—dot shapes, colors, gradients, embedded images, borders, and text—it enables you

Readme

QRCode.js - Simple, Beautiful, Reliable

npm version

Create Beautiful, Reliable QR Codes with Ease

QRCode.js is a professional JavaScript/TypeScript library for creating customized QR codes, offering a blend of simplicity and sophistication. With versatile styling options—dot shapes, colors, gradients, embedded images, borders, and text—it enables you to design unique, visually appealing QR codes that work flawlessly with standard scanners. QRCode.js is part of QR-Platform: All-in-One QR Codes Management Solution.

✨ Features

  • Core QR Code Generation: Encode any text, URL, or data.
  • Highly Customizable: Control dot shapes, colors, sizes, corner styles, and background.
  • Gradients: Apply linear or radial gradients to dots, corners, and backgrounds.
  • Image Embedding: Embed logos or other images in the center, as an overlay, or as a background. Control image precedence with global QRCodeJs.setImage() or builder useImage(), both supporting an override option.
  • Borders: Add basic borders or advanced, customizable borders with text/images. Control text precedence with QRCodeJs.setText() or builder useText(), both supporting an override option.
  • Flexible Border Configuration: Set global border defaults (setBorder/setBorderId) or use the builder pattern (useBorder/useBorderId) for instance-specific borders.
  • Templates & Styles: Use predefined templates and styles, or create your own for consistent branding. Apply them globally with QRCodeJs.setTemplate() / QRCodeJs.setStyle() or per-instance with the builder's useTemplate() / useStyle().
  • Comprehensive Configuration:
    • Use QRCodeJs.setData(), QRCodeJs.setOptions(), and QRCodeJs.setSettings() for powerful global default configurations, with override options for strong precedence.
    • Employ the builder pattern's useData(), useOptions(), and useSettings() for instance-specific comprehensive setups, also with override capabilities. useSettings() resets prior builder steps to establish a new baseline.
  • Flexible Output: Generate QR codes as SVG elements in the browser or SVG strings in Node.js.
  • Download Options: Download QR codes as SVG, PNG, JPEG, or WEBP.
  • TypeScript Support: Fully typed for a better development experience.
  • Node.js Compatible: Works seamlessly in server-side environments.
  • Responsive: Option to make SVG output responsive to container size.
  • Scan Validation: Verify the scannability of generated QR codes.

🚀 Installation

NPM ⤵️

npm install @qr-platform/qr-code.js

YARN ⤵️

yarn add @qr-platform/qr-code.js

PNPM ⤵️

pnpm add @qr-platform/qr-code.js

💡 Basic Usage

import { QRCodeJs } from '@qr-platform/qr-code.js';

const qrCode = new QRCodeJs({ data: 'https://example.com' });
qrCode.append(document.getElementById('qr-container'));

or

import { QRCodeJs, Options } from '@qr-platform/qr-code.js';

// 1. Define options (only 'data' is required)
const options: Options = {
  data: 'https://example.com',
  width: 300,       // Fixed 300px width
  height: 300,      // Fixed 300px height
  dotsOptions: {
    color: '#007bff', // Blue dots
    type: 'rounded'   // Use rounded dots
  },
  backgroundOptions: {
    color: '#ffffff' // White background
  }
};

// 2. Create QR Code instance
const qrCode = new QRCodeJs(options);

// 3. Append to a container element (in browser)
const container = document.getElementById('qr-container');
if (container) {
  // Remove any existing content before appending the QR code
  qrCode.append(container, { clearContainer: true });
}

// Or get SVG string (Browser or Node.js)
qrCode.serialize().then(svgString => {
  if (svgString) {
    console.log('QR Code SVG:', svgString);
    // In Node.js, you might save this string to a file
    // require('fs').writeFileSync('qrcode.svg', svgString);
  }
});

⚙️ Key Options Overview

| Option | Description | Example Value | | :--------------------- | :----------------------------------------------- | :------------------- | | data | Required. The content to encode. | 'Your URL here' | | shape | Overall shape ('square' or 'circle'). | 'circle' | | width | QR code width (pixels/CSS units). Ignored when isResponsive: true. | 300 or '20rem' | | height | QR code height (pixels/CSS units). Ignored when isResponsive: true. | 300 or '20rem' | | margin | Quiet zone around the QR code (pixels). | 10 | | isResponsive | Makes SVG responsive (100% width/height), ignoring width/height. | true | | qrOptions.errorCorrectionLevel | Error correction ('L', 'M', 'Q', 'H'). | 'H' | | dotsOptions.type | Shape of the data dots (e.g., rounded, dot). | 'rounded' | | dotsOptions.color | Color of the data dots. | '#ff5733' | | dotsOptions.gradient | Gradient for dots (see Gradients). | { type: 'linear', ... } | | cornersSquareOptions | Style for the large corner squares. | { type: 'dot', color: '#00ff00' } | | cornersDotOptions | Style for the small dots inside corners. | { type: 'square', color: '#ffffff' } | | backgroundOptions | Background style (color, roundness, gradient). | { color: '#f0f0f0', round: 0.2 } | | image | URL/Buffer/Blob of image to embed. | 'logo.png' | | imageOptions | Options for the embedded image (size, margin). | { imageSize: 0.3, margin: 2 } | | borderOptions | Options for decorative borders. | { hasBorder: true, thickness: 20, ... } | | SettingsOptions | Comprehensive object for setSettings/useSettings. | { templateId: '...', data: '...', ...} |

For a full list of options and detailed explanations of SettingsOptions, setData, setOptions, and their builder counterparts, see the API Reference Guide and Usage Guide.

🎨 Examples

Explore various configurations:

🖥️ Node.js Usage

QRCode.js works in Node.js for server-side generation.

import { QRCodeJs, Options } from '@qr-platform/qr-code.js/node'; // Note the '/node' import
import fs from 'fs';

const options: Options = {
  data: 'https://example.com/from-node',
  dotsOptions: {
    color: '#8A2BE2' // BlueViolet
  }
};

const qrCode = new QRCodeJs(options);

qrCode.serialize().then(svgString => {
  if (svgString) {
    fs.writeFileSync('qrcode-node.svg', svgString);
    console.log('QR Code saved to qrcode-node.svg');
  }
});

Key Differences:

  • Import from @qr-platform/qr-code.js/node.

  • Methods requiring a DOM like append() or download() are not available. Use serialize() to get the SVG string.

  • Peer Dependencies: You must install the required peerDependencies for Node.js functionality.

    Install automatically using npx:

    npx i-peers

    Install manually using npm:

     npm i @xmldom/xmldom @undecaf/zbar-wasm image-size jose jimp @resvg/resvg-js file-type

📚 Documentation

📜 License and Support

QRCode.js by QR-Platform is free for personal projects, open-source projects, or general non-commercial use. For commercial use, a license is required.

See the full license at LICENSE.md for more information. For commercial licenses, including full source code and support, contact [email protected].