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

miniprogram-qrcode-svg

v0.2.1

Published

A QRCode generator use javascript in weixin miniprogram

Readme

miniprogram-qrcode-svg

纯 JavaScript 二维码生成器,输出 SVG 字符串或 SVG dataURL。适用于现代浏览器与微信小程序,不依赖 DOM、Canvas 与原生绘图接口。

安装

npm install miniprogram-qrcode-svg

快速开始

import qrCodeSVG from 'miniprogram-qrcode-svg';

const svg = qrCodeSVG('https://example.com', {
  padding: 4,
  width: 256,
  height: 256,
  color: '#000000',
  background: '#ffffff',
  ecl: 'M',
}).toSVG();

在微信小程序中,SVG 无法直接渲染为图片,可转为 dataURL 后交由渲染层处理:

const dataURL = qrCodeSVG('https://example.com').toDataURL();

API

qrCodeSVG(content, options)

创建二维码实例。content 为待编码字符串,必须非空;options 见下方选项表。

返回实例方法:

  • toSVG(opt):生成 SVG 字符串。opt 可覆盖构造时的选项,但不含 ecl 与 typeNumber。
  • toDataURL(opt):生成 data:image/svg+xml;utf8, 前缀的 dataURL,参数同 toSVG。

选项

| 选项 | 默认值 | 说明 | | --- | --- | --- | | ecl | M | 纠错等级,取值 L、M、Q、H | | typeNumber | 0 | 二维码版本号 1–40,0 表示按内容长度自动选择 | | padding | 0 | 静默区宽度(模块数),0 表示无边框 | | width | 256 | 输出宽度(像素) | | height | 256 | 输出高度(像素) | | color | #000 | 模块颜色,颜色名或十六进制字符串 | | background | #fff | 背景颜色,颜色名或十六进制字符串 | | container | svg | 外层容器类型,取值见下表 | | join | true | 将所有模块合并为单个 <path>,体积更小,推荐使用 | | predefined | false | 以 <defs> 中的预定义形状配合 <use> 渲染模块;仅在 join 为 false 时生效 | | pretty | false | 输出缩进与换行 | | swap | false | 交换 X、Y 坐标,用于个别扫码器识别异常的场景 | | xmlDeclaration | false | 在 SVG 头部添加 <?xml version="1.0" standalone="yes"?> 声明 |

container 取值

| 值 | 说明 | | --- | --- | | svg | 输出带 width/height 属性的完整 SVG 文档,适合转换为位图或 PDF 等固定尺寸场景 | | viewbox | 输出带 viewBox 属性的 SVG 文档,适合需要自适应缩放的网页 | | g | 仅输出 <g> 分组,便于在单个 SVG 中组合多个二维码 | | none | 不包裹容器,直接输出图形元素 |

许可证

MIT