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-library

v1.0.3

Published

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

Readme

code-generator-library

npm version license zero dependencies TypeScript

Ultra-fast, 100% Zero-Dependency QR Code & Code 128 Barcode Generator for JavaScript & TypeScript.
Effortlessly generate high-resolution QR codes and barcodes as SVG strings or Base64 Data URIs in both Node.js and Browser environments out of the box.


⚡ Features

  • 🚀 100% Zero Dependencies: Lightweight, secure, and blazingly fast. No heavy native canvas or native binary dependencies.
  • 📦 Universal / Cross-Platform: Runs seamlessly in Node.js, Browsers, React, Next.js, Vue, Angular, Svelte, and React Native.
  • 🔲 QR Code Generator: Creates customizable QR codes with custom error correction levels (L, M, Q, H), colors, sizes, and margins.
  • 📊 Code 128 Barcode Generator: Generates crisp, standard Code 128 (Set B) barcodes for inventory, logistics, labels, and products.
  • 🎨 Multiple Output Formats: Output directly as Base64 SVG Data URIs (perfect for <img src="...">) or raw SVG strings.
  • 📘 First-Class TypeScript Support: Full type definitions built right into the package.

📥 Installation

Install via npm, yarn, or pnpm:

# npm
npm install code-generator-library

# yarn
yarn add code-generator-library

# pnpm
pnpm add code-generator-library

🚀 Quick Start & Usage

Supports both ES Modules (import) and CommonJS (require).

1. Generating QR Codes (generateQR)

Generate QR Code Data URIs for instant rendering in <img> tags or get pure SVG markup:

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

async function generateQRCodeExample() {
  // Option A: Generate as Base64 SVG Data URI (Default)
  const qrDataUri = await generateQR('https://github.com/twinkal3453/code-generator-lib');
  // Result: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0..."

  // Option B: Generate as a raw SVG string with custom colors & margin
  const qrSvg = await generateQR('https://example.com', {
    type: 'svg',
    width: 250,
    margin: 2,
    errorCorrectionLevel: 'H',
    color: {
      dark: '#1e293b',  // QR Modules color
      light: '#ffffff'  // Background color
    }
  });
}

Render in React / Next.js:

import React, { useEffect, useState } from 'react';
import { generateQR } from 'code-generator-library';

export function QRCodeComponent({ url }: { url: string }) {
  const [src, setSrc] = useState('');

  useEffect(() => {
    generateQR(url).then(setSrc);
  }, [url]);

  return <img src={src} alt="Generated QR Code" />;
}

2. Generating Barcodes (generateBarcode)

Generate Code 128 Barcodes instantly:

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

async function generateBarcodeExample() {
  // Option A: Generate Code 128 Barcode as Base64 Data URI
  const barcodeDataUri = await generateBarcode('PACKAGE-98765');
  // Result: "data:image/svg+xml;base64,PHN2ZyB4..."

  // Option B: Generate Code 128 Barcode as raw SVG string
  const barcodeSvg = await generateBarcode('1234567890', {
    type: 'svg',
    height: 70,
    scale: 3
  });
}

Render in Express / Node.js Server:

const express = require('express');
const { generateBarcode, generateQR } = require('code-generator-library');

const app = express();

app.get('/api/barcode', async (req, res) => {
  const text = req.query.text || '123456789';
  const svg = await generateBarcode(text, { type: 'svg' });
  res.setHeader('Content-Type', 'image/svg+xml');
  res.send(svg);
});

📖 API Reference

generateQR(text, options?)

| Option | Type | Default | Description | | :--- | :--- | :--- | :--- | | text | string | Required | Text, URL, or data payload to encode into the QR code. | | options.type | 'dataUrl' \| 'svg' | 'dataUrl' | 'dataUrl' returns Base64 Data URI, 'svg' returns raw SVG string. | | options.width | number | 200 | Width and height dimension in pixels. | | options.margin | number | 4 | Quiet zone margin blocks around the QR code. | | options.errorCorrectionLevel | 'L' \| 'M' \| 'Q' \| 'H' | 'M' | Error correction recovery level (L ~7%, M ~15%, Q ~25%, H ~30%). | | options.color.dark | string | '#000000' | Hex/RGB color string for the dark blocks. | | options.color.light | string | '#ffffff' | Hex/RGB color string for the background. |

generateBarcode(text, options?)

| Option | Type | Default | Description | | :--- | :--- | :--- | :--- | | text | string | Required | ASCII text string (Code 128 Set B format) to encode. | | options.type | 'dataUrl' \| 'svg' | 'dataUrl' | 'dataUrl' returns Base64 Data URI, 'svg' returns raw SVG string. | | options.height | number | 50 | Height of barcode bars in pixels. | | options.scale | number | 2 | Barcode width scale multiplier. |


🌐 Compatibility & Keywords

  • Frameworks: React, Next.js, Vue, Nuxt, Angular, Svelte, Express, Fastify, NestJS, Vite, Webpack.
  • Environments: Node.js, Deno, Bun, Cloudflare Workers, Vercel Edge Functions, Browser JS.
  • Search Keywords: qr code generator, barcode generator, code 128 barcode, svg qr code, base64 qr code, javascript qr code library, typescript barcode library, zero dependency qr code, zero dependency barcode generator.

📄 License

ISC © Twinkal K Raj