# @chillerlan/qrcode 中文文档

规范地址：https://npmcn.com/package/%40chillerlan/qrcode/

版本：1\.0\.1
npm 元数据更新时间：2024-08-25T12:11:26.983Z
中文译文更新时间：2026-11-09T16:03:39.558Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40chillerlan/qrcode
原文对照：https://npmcn.com/package/%40chillerlan/qrcode/?lang=original
项目主页：https://github.com/chillerlan/js-qrcode
源码仓库：https://github.com/chillerlan/js-qrcode

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：3.9 MB，46 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：未声明
- 运行依赖：0 个
- 首次发布：2024-08-25T12:07:16.514Z
- 最新版本发布：2024-08-25T12:11:26.774Z
- 近 30 天下载量：2276（2026-10-10 至 2026-11-08，npm 官方下载统计）
- 已发布版本数：2（近 12 个月 0 个）

## 中文简介

QR 代码生成器 - 从php- qrcode 端出 ([https://github.com/chillerlan/php-qrcode (中文(简体) )](https://github.com/chillerlan/php-qrcode)(中文(简体) )

## 安装

```sh
npm install @chillerlan/qrcode
```

也可以使用：`pnpm add @chillerlan/qrcode`、`yarn add @chillerlan/qrcode`、`bun add @chillerlan/qrcode`

## README

# 冷冻剂/js-qrcode

一个 Javascript 端口 [冷冻机/php-qrcode](https://github.com/chillerlan/php-qrcode),基于 [执行](https://github.com/kazuhikoarase/qrcode-generator) 原泽和子.

[![NPM version](https://img.shields.io/github/package-json/v/chillerlan/js-qrcode?logo=npm&logoColor=ccc)](https://github.com/chillerlan/js-qrcode/pkgs/npm/qrcode) [![License](https://img.shields.io/github/license/chillerlan/js-qrcode.svg)](https://github.com/chillerlan/js-qrcode/blob/main/LICENSE) [![CodeCov](https://img.shields.io/codecov/c/github/chillerlan/js-qrcode?logo=codecov&logoColor=ccc)](https://codecov.io/github/chillerlan/js-qrcode) [![Build](https://img.shields.io/github/actions/workflow/status/chillerlan/js-qrcode/build.yml?branch=main&logo=github&logoColor=ccc)](https://github.com/chillerlan/js-qrcode/actions/workflows/build.yml?query=branch%3Amain)

# 概览

## 特征

-   创建 [型号 2 QR 码](https://www.qrcode.com/en/codes/model12.html), (中文(简体) ), [版本1至40](https://www.qrcode.com/en/about/version.html)
-   [ECC 级别](https://www.qrcode.com/en/about/error_correction.html) 得到L/M/Q/H支持
-   混合模式支持(编码模式可以在QR符号内结合). 支持的模式 :
    -   数字
    -   数字
    -   8 二进制
-   灵活、易于扩展的输出模块,内置支持以下输出格式:
    -   标记类型: SVG等.
    -   字符串类型:JSON,纯文本等.
    -   通过 Raster 图像类型 [帆布](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement)

## 文档

API非常类似 [此库的 PHP 版本](https://github.com/chillerlan/php-qrcode),可以参考其 [文档](https://php-qrcode.readthedocs.io/) 财务报告和审定财务报表 [实例](https://github.com/chillerlan/php-qrcode/tree/main/examples) 大部分时间.

关键差异 :

-   PHP版本的类常数是这里的常数,例如. `QRMatrix::M_DATA` 变成 `M_DATA`, (中文(简体) ), `Version::AUTO` 实值 `VERSION_AUTO` 财务报告和审定财务报表 `EccLevel:L` 改为 `ECC_L` - 看见没 [指数.js](https://github.com/chillerlan/js-qrcode/blob/main/src/index.js) 所有符号的正名.
-   Kanji 和 Hanzi 字符集没有多模式支持( Javascript中处理/转换非 UTF8 字符串是一团糟), 不 [厄立特里亚](https://en.wikipedia.org/wiki/Extended_Channel_Interpretation) 支持同样的原因.
-   不支持保存到文件。 你可以重新执行这个方法 `QROutputAbstract::saveToFile()` 如果你需要的话。 它被称作"内部",但是没有功能.
-   不包括QR 码读取器
-   通常的Javascript语:
    -   某些类的内部结构可能偏离其优先选择的对应结构
    -   键值数组成为对象,在某些情况下导致返回值不一致,更不用提每个对象的回路类型不一致(pun意图)
    -   数字可能有点奇怪
    -   魔力的获得者和定者,都是有缺点的, [见此注释](https://github.com/chillerlan/js-qrcode/blob/76a7a8db1b6e39d09a09f2091a830dcd7d98e9ff/src/QROptions.js#L352-L412)

API 文档创建 [日记](https://github.com/jsdoc/jsdoc) 可见于 [https://chillerlan.github.io/js-qrcode/ 页面存档备份,存于互联网档案馆](https://chillerlan.github.io/js-qrcode/) (维基文库).

### 快速启动

服务器端, 在节点中 :

```js
import {QRCode} from './dist/js-qrcode-node-src.cjs';

let data   = 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net';
let qrcode = (new QRCode()).render(data);

// do stuff
console.log(qrcode);
```

客户端, 在网页浏览器中 :

```html
<div id="qrcode-container"></div>
<script type="module">
    import {QRCode} from './dist/js-qrcode-es6-src.js';
    
    // an SVG image as base64 data URI will be returned by default
    let qrcode = (new QRCode()).render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');

    // append it to the DOM
    let img = document.createElement('img');
    img.alt = 'QRCode';
    img.src = qrcode
    
    document.getElementById('qrcode-container').appendChild(img);
</script>
```

![QR codes are awesome!](https://raw.githubusercontent.com/chillerlan/php-qrcode/main/.github/images/example.svg)

来看看 [在示例文件夹中](https://github.com/chillerlan/js-qrcode/tree/main/examples) 用于更多使用实例.

#### 许可证通知

此代码的部分从 : [ZXing项目](https://github.com/zxing/zxing) 根据《公约》第19条 [Apache 许可证,2.0版本](https://npmcn.com/package/%40chillerlan/qrcode/NOTICE)。 。 。 .

#### 商标通知

"QR代码"一词是一个注册商标,即: _戴森·怀特(签名)_  
[https://www.qrcode.com/en/faq.html#patentH2 Title (中文(简体) )](https://www.qrcode.com/en/faq.html#patentH2Title)

## 常见问题

### @chillerlan/qrcode 是什么？

QR 代码生成器 - 从php- qrcode 端出 \(https://github\.com/chillerlan/php-qrcode \(中文\(简体\) \)\(中文\(简体\) \)

### 如何安装 @chillerlan/qrcode？

在项目目录运行 npm install @chillerlan/qrcode，或使用 pnpm add / yarn add / bun add。

### @chillerlan/qrcode 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/chillerlan\_\_qrcode 是否存在。

### @chillerlan/qrcode 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @chillerlan/qrcode 可以商用吗？

@chillerlan/qrcode 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @chillerlan/qrcode 的下载量有多少？

根据 npm 官方下载统计，@chillerlan/qrcode 在 2026/10/10 – 2026/11/08 这 30 天内被下载 2,276 次，日均约 76 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @chillerlan/qrcode 还在维护吗？

最新版本 1\.0\.1 发布于 2024/08/25（2 年前）；至今共发布 2 个版本，其中过去 12 个月发布了 0 个；首次发布于 2024/08/25。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

