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

@ikenxuan/qrcode

v1.2.0

Published

基于 Rust qr-code-styling 的高性能 QR 码生成器

Readme

@ikenxuan/qrcode

基于 Rust qr-code-styling + rxing 的高性能 QR 码生成与扫描工具。通过 WebAssembly 实现跨平台运行,Node.js 和浏览器通用。

安装

pnpm add @ikenxuan/qrcode

快速开始

import { generate, generateSvg, scan } from '@ikenxuan/qrcode'

// 生成 PNG 二进制
const png = generate({ data: 'https://example.com' }, 'png')

// 生成 base64 字符串
const b64 = generate({ data: 'https://example.com' }, 'png', 'base64')

// 生成 SVG 字符串
const svg = generateSvg({ data: 'https://example.com' })

// 扫描图片中的 QR 码
const result = scan(png) // 'https://example.com'

WASM 已内联,import 即用,无需初始化,无需关心 .wasm 文件路径。


API

generate(options, format, encoding?)

生成 QR 码。

| 参数 | 类型 | 说明 | |------|------|------| | options | QRCodeOptions | QR 码配置 | | format | OutputFormat | 输出格式 | | encoding | 'binary' \| 'base64' | 编码方式,默认 'binary' |

返回值根据 encoding 自动推导类型:

  • 'binary'(默认)→ Uint8Array
  • 'base64'string

generateSvg(options)

生成 SVG 字符串,返回 string

scan(imageData)

扫描图片中的 QR 码。

| 参数 | 类型 | 说明 | |------|------|------| | imageData | Uint8Array | 图片文件的二进制数据(PNG/JPEG/WebP) |

返回值:string | null,解码成功返回 QR 码文本内容,未识别到返回 null


QRCodeOptions

interface QRCodeOptions {
  data: string                // 编码内容
  size?: number               // 尺寸(像素),默认 300
  margin?: number             // 外边距(像素)
  shape?: ShapeType           // 整体形状
  dotsOptions?: DotsOptions   // 点阵样式
  cornersSquareOptions?: CornersSquareOptions
  cornersDotOptions?: CornersDotOptions
  backgroundOptions?: BackgroundOptions
  image?: Uint8Array          // Logo 图片数据
  imageOptions?: ImageOptions
}

可选值

| 类型 | 可选值 | |------|--------| | OutputFormat | 'svg', 'png', 'jpeg', 'webp' | | DotType | 'square', 'dots', 'rounded', 'classy', 'classy-rounded', 'extra-rounded' | | CornerSquareType | 'square', 'dot', 'extra-rounded' | | CornerDotType | 'square', 'dot' | | ShapeType | 'square', 'circle' |

也可以使用常量对象:DotType.RoundedOutputFormat.Png 等。

BackgroundOptions

interface BackgroundOptions {
  color?: string        // 背景色,十六进制
  transparent?: boolean // 透明背景
  gradient?: Gradient   // 渐变背景
  round?: number        // 圆角比例 0.0 ~ 0.5
}

示例

import { generate, scan } from '@ikenxuan/qrcode'

// 圆形二维码 + 渐变色 + 透明背景
const png = generate({
  data: 'https://github.com/ikenxuan',
  size: 400,
  shape: 'circle',
  dotsOptions: {
    dotType: 'dots',
    gradient: { colorFrom: '#667eea', colorTo: '#764ba2' },
  },
  backgroundOptions: { transparent: true },
}, 'png')

// base64 输出,可直接用于 <img src>
const b64 = generate({
  data: 'https://example.com',
  dotsOptions: { dotType: 'rounded', color: '#1a1a2e' },
}, 'png', 'base64')

// 扫描 QR 码
import { readFileSync } from 'fs'
const img = readFileSync('qrcode.png')
const content = scan(img) // 'https://example.com'

License

MIT