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

@qzsy/weapp-qrcode

v1.1.1

Published

微信小程序条码、二维码生成模块 (TypeScript + Vite)

Readme

@qzsy/weapp-qrcode

现代化微信小程序条码和二维码生成库,基于 TypeScript + Vite 构建。

NPM Version NPM Downloads

NPM

特性

  • TypeScript: 完整的类型安全支持
  • 现代构建: 使用 Vite 构建,支持 ES Module 和 CommonJS
  • Canvas 2D API: 仅支持小程序新版 Canvas 2D API,性能更佳
  • Promise: 支持 async/await 语法
  • 高清渲染: 自动适配设备像素比
  • 体积小巧: 移除旧版兼容代码,专注现代小程序

特色功能

🎯 专为现代小程序打造

  • 仅支持 Canvas 2D API: 专注现代小程序,性能更佳
  • TypeScript 原生支持: 完整的类型安全
  • 现代化构建: 使用 Vite,支持 ES Module 和 CommonJS
  • Promise 友好: 支持 async/await 语法

安装

npm install @qzsy/weapp-qrcode

使用方法

基础用法

import wxbarcode from '@qzsy/weapp-qrcode'

Page({
    async onLoad() {
        try {
            // 生成条码
            await wxbarcode.barcode('barcode', '1234567890123456789', 680, 200);
            
            // 生成二维码
            await wxbarcode.qrcode('qrcode', 'Hello World', 420, 420);
            
            // 生成二维码(带错误纠正级别)
            await wxbarcode.qrcode('qrcode-high', 'Hello World', 420, 420, {
                errorCorrectionLevel: 'H'
            });
        } catch (error) {
            console.error('生成失败:', error);
        }
    }
})

WXML 模板

<!-- 使用 Canvas 2D API -->
<canvas type="2d" id="barcode" style="width: 680rpx; height: 200rpx;"></canvas>
<canvas type="2d" id="qrcode" style="width: 420rpx; height: 420rpx;"></canvas>

API 文档

barcode(id, text, width, height)

生成 Code 128 条码

参数:

  • id (string): Canvas 元素的 id
  • text (string): 要编码的文本
  • width (number): 条码宽度 (单位: rpx)
  • height (number): 条码高度 (单位: rpx)

返回: Promise<void>

qrcode(id, text, width, height, options?)

生成二维码

参数:

  • id (string): Canvas 元素的 id
  • text (string): 要编码的文本
  • width (number): 二维码宽度 (单位: rpx)
  • height (number): 二维码高度 (单位: rpx)
  • options (可选): 配置选项
    • errorCorrectionLevel ('L' | 'M' | 'Q' | 'H'): 错误纠正级别,默认 'L'

返回: Promise<void>

TypeScript 支持

import wxbarcode, { type BarcodeOptions, type QRCodeOptions } from '@qzsy/weapp-qrcode';

// 类型安全的使用方式
const options: Partial<QRCodeOptions> = {
  errorCorrectionLevel: 'H'
};

await wxbarcode.qrcode('my-qrcode', 'Hello TypeScript', 400, 400, options);

错误处理

try {
  await wxbarcode.barcode('barcode', 'test', 400, 200);
} catch (error) {
  console.error('条码生成失败:', error);
  // 处理错误情况
}

示例代码

查看 example/ 目录下的完整小程序示例。

从其他包迁移

  1. 更新 WXML: 确保使用 Canvas 2D API

    <!-- 旧版本 -->
    <canvas canvas-id="barcode" />
       
    <!-- 新版本 -->
    <canvas type="2d" id="barcode" />
  2. 使用 async/await: 所有方法现在都是异步的

    // 旧版本
    wxbarcode.barcode('barcode', 'test', 400, 200);
       
    // 新版本
    await wxbarcode.barcode('barcode', 'test', 400, 200);
  3. TypeScript 支持: 如果使用 TypeScript,可获得完整类型支持

浏览器兼容性

  • 微信小程序基础库 2.9.0+
  • 支持 Canvas 2D API 的小程序环境

开发

# 安装依赖
npm install

# 开发模式
npm run dev

# 构建
npm run build

# 类型检查
npm run type-check

# 代码检查
npm run lint

许可证

MIT

更新日志

v1.0.0

  • 🎉 TypeScript 原生支持
  • 🎉 使用 Vite 现代化构建
  • 🎉 仅支持 Canvas 2D API
  • 🎉 Promise/async 支持
  • 🎉 完整的类型定义
  • 🎉 更小的包体积