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

code-generator-lib

v1.0.4

Published

A zero-dependency universal npm library for generating Code 128 Barcodes and QR Codes as SVG strings or Base64 Data URIs.

Readme

⚠️ DEPRECATED: code-generator-lib

🛑 IMPORTANT: This package has been renamed and moved to code-generator-library. Please update your dependencies to use the new package.

npm uninstall code-generator-lib
npm install code-generator-library

This repository and npm package are no longer maintained.


A zero-dependency, incredibly lightweight npm library for generating QR Codes and Code 128 Barcodes.

Because this library is 100% dependency-free, it is exceptionally fast, small, and works universally in both Node.js and the Browser out of the box! It generates pure SVG strings or Base64 Data URIs.

Installation

npm install code-generator-lib

Usage

You can import the library using ES Modules (import) or CommonJS (require).

Generating QR Codes

Generate QR codes easily and get the output as a Base64 SVG Data URI (perfect for <img> tags) or a pure SVG string.

import { generateQR } from 'code-generator-lib';

async function main() {
  // 1. Generate as a Data URI (Base64 SVG - Default)
  const qrDataUri = await generateQR('https://example.com');
  // Result: data:image/svg+xml;base64,PHN2ZyB4bWxucz0...

  // 2. Generate as a pure SVG string
  const qrSvg = await generateQR('https://example.com', { type: 'svg', margin: 2 });
  // Result: <svg xmlns="http://www.w3.org/2000/svg" ...></svg>
}

Generating Barcodes

Generate Code 128 (Set B) barcodes.

import { generateBarcode } from 'code-generator-lib';

async function main() {
  // 1. Generate as a Data URI (Base64 SVG)
  const barcodeDataUri = await generateBarcode('HELLO WORLD');
  // Result: data:image/svg+xml;base64,PHN2ZyB4bWxucz0...

  // 2. Generate as a pure SVG string
  const barcodeSvg = await generateBarcode('1234567890', { 
    type: 'svg',
    height: 60,
    scale: 3
  });
}

API Options

generateQR(text, options)

  • text (string): The string/URL to encode.
  • options (object):
    • type ('dataUrl' | 'svg'): Output format. (Default: 'dataUrl')
    • width (number): Pixel width/height of the QR code. (Default: 200)
    • margin (number): Margin blocks around the code. (Default: 4)
    • errorCorrectionLevel ('L' | 'M' | 'Q' | 'H'): EC Level. (Default: 'M')
    • color: Object defining dark and light hex colors (Default: { dark: '#000000', light: '#ffffff' }).

generateBarcode(text, options)

  • text (string): The string to encode (ASCII 32-127).
  • options (object):
    • type ('dataUrl' | 'svg'): Output format. (Default: 'dataUrl')
    • height (number): Bar height in pixels. (Default: 50)
    • scale (number): Barcode width scaling factor. (Default: 2)