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

@pkvsinha/symbol-codec

v0.0.2

Published

A modern **symbol encoding toolkit** for the web. Currently supports **QR Code** (v1–v40 planned; v1–v10 implemented), with extensible design for adding other optical codes (Barcodes, EAN, DataMatrix, …).

Readme

@pkvsinha/symbol-codec

A modern symbol encoding toolkit for the web.
Currently supports QR Code (v1–v40 planned; v1–v10 implemented), with extensible design for adding other optical codes (Barcodes, EAN, DataMatrix, …).

  • ✅ Written in TypeScript
  • ✅ Zero runtime dependencies
  • ✅ ESM, CJS, and UMD/IIFE builds
  • ✅ Works in Node.js and browsers (via CDN or bundlers)
  • ✅ Modular & tree-shakable
  • ✅ Correct Reed–Solomon, masking, format/version info, placement order
  • ✅ Supports ECC levels L/M/Q/H, version auto-selection, mask scoring
  • ✅ Helpers for common use-cases (e.g. UPI payments, text, URLs)
  • 🚧 Roadmap: add barcodes (EAN-13, Code128, UPC-A), DataMatrix, PDF417

Installation

npm install @pkvsinha/symbol-codec

Usage

Node.js (CJS)

const { encodeJS, renderCanvas } = require("@pkvsinha/symbol-codec");

const { grid } = encodeJS("HELLO WORLD", { ecc: "M", version: "auto" });
// renderCanvas is browser-only; in Node you can write PNG/SVG manually

ES Modules

import { encodeJS } from "@pkvsinha/symbol-codec";
import { renderSVG } from "@pkvsinha/symbol-codec/render";

const { grid } = encodeJS("https://heypkv.com", { ecc: "Q" });
const svg = renderSVG(grid, 8, 4); // scale=8, margin=4
document.body.innerHTML = svg;

Browser via CDN (UMD/IIFE)

<!-- jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/@pkvsinha/symbol-codec/dist/umd/symbol-codec.min.js"></script>

<!-- or unpkg -->
<!-- <script src="https://unpkg.com/@pkvsinha/symbol-codec/dist/umd/symbol-codec.min.js"></script> -->

<canvas id="qr" width="256" height="256"></canvas>
<script>
  const { encodeJS, renderCanvas } = window.SymbolCodec;
  const { grid } = encodeJS(
    "upi://pay?pa=prashant@oksbi&pn=HEYPKV&am=990&cu=INR&tn=Invoice%20INV-1042",
    {
      ecc: "M",
      version: "auto",
    }
  );
  renderCanvas(document.getElementById("qr"), grid, 8, 4);
</script>

API

encodeJS(input: string, options?: EncodeOptions): EncodeResult

Encodes a string into a QR Code matrix.

Options

ecc: Error correction level 'L'|'M'|'Q'|'H' (default 'M')

version: Version number 1..40 or 'auto' (default 'auto')

mask: Force mask 0..7 or 'auto' (default 'auto')

Result

{
  grid: { size: number; data: Uint8Array }, // size x size, row-major
  version: number,
  mask: number,
  ecc: 'L'|'M'|'Q'|'H'
}

Renderers

  • renderCanvas(canvas: HTMLCanvasElement, grid, scale, margin)
  • renderSVG(grid, scale, margin): string

Both accept a grid (from encodeJS), a module scale, and margin modules.

Helpers

helpers.makeUPIPayload(address, name, amount, currency, note)

More to be added for common patterns (URLs, WiFi, contact vCards).

Builds

  • ESM: dist/esm → modern bundlers
  • CJS: dist/cjs → Node.js require
  • Types: dist/types → .d.ts
  • UMD/IIFE: dist/umd/symbol-codec.min.js → global window.SymbolCodec

CDN fields in package.json:

  • unpkg: dist/umd/symbol-codec.min.js
  • jsdelivr: dist/umd/symbol-codec.min.js

Example: Generate a UPI QR Code

import { encodeJS } from "@pkvsinha/symbol-codec";
import { renderSVG } from "@pkvsinha/symbol-codec/render";

const payload =
  "upi://pay?pa=prashant@oksbi&pn=HEYPKV&am=990&cu=INR&tn=Invoice%20INV-1042";
const { grid } = encodeJS(payload, { ecc: "M", version: "auto" });
const svg = renderSVG(grid, 8, 4);
console.log(svg);

Development

git clone <repo>
cd symbol-codec
npm install
npm run build      # builds esm/cjs/types/umd
npm run dev        # runs vite dev server with examples
npm run size-check # prints bundle sizes

Roadmap

  • ✅ QR Code v1–v10 basic support (text, URLs, UPI)
  • ✅ Correct RS error correction and mask selection
  • ✅ ESM/CJS/UMD builds
  • 🚧 Expand QR to full v1–v40
  • 🚧 Add barcodes: EAN-13, UPC-A, Code128
  • 🚧 Add DataMatrix, PDF417
  • 🚧 Add optimal DP segmentation for mode mixes

License

MIT © Prashant Sinha