# @cordobo/qrcode 中文文档

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

版本：1\.5\.0
npm 元数据更新时间：2022-11-18T01:41:18.700Z
中文译文更新时间：2026-11-10T18:44:15.432Z
软件包许可：MIT

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

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

弃用说明：Package no longer supported\. Contact Support at https://www\.npmjs\.com/support for more info\.

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

- 包体积（解压后）：179 kB，43 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：4 个
- 首次发布：2022-01-11T23:13:14.779Z
- 最新版本发布：2022-01-11T23:13:14.993Z
- 近 30 天下载量：51906（2026-10-11 至 2026-11-09，npm 官方下载统计）
- 已发布版本数：1（近 12 个月 0 个）

## 中文简介

QRCode / 2d 有服务器侧和客户端侧支持的条形码 api

## 安装

```sh
npm install @cordobo/qrcode
```

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

## README

# 节点-qrcode

> QR 代码/2d条码生成器.

[![Travis](https://img.shields.io/travis/soldair/node-qrcode.svg?style=flat-square)](http://travis-ci.org/soldair/node-qrcode) [![npm](https://img.shields.io/npm/v/qrcode.svg?style=flat-square)](https://www.npmjs.com/package/qrcode) [![npm](https://img.shields.io/npm/dt/qrcode.svg?style=flat-square)](https://www.npmjs.com/package/qrcode) [![npm](https://img.shields.io/npm/l/qrcode.svg?style=flat-square)](https://github.com/soldair/node-qrcode/blob/master/license)

-   [要点](https://npmcn.com/package/%40cordobo/qrcode/#readme-highlights)
-   [安装](https://npmcn.com/package/%40cordobo/qrcode/#readme-installation)
-   [使用量](https://npmcn.com/package/%40cordobo/qrcode/#readme-usage)
-   [错误更正级别](https://npmcn.com/package/%40cordobo/qrcode/#readme-error-correction-level)
-   [QR 代码容量](https://npmcn.com/package/%40cordobo/qrcode/#readme-qr-code-capacity)
-   [编码模式](https://npmcn.com/package/%40cordobo/qrcode/#readme-encoding-modes)
-   [二进制数据](https://npmcn.com/package/%40cordobo/qrcode/#readme-binary-data)
-   [多字节字符](https://npmcn.com/package/%40cordobo/qrcode/#readme-multibyte-characters)
-   [API 密码](https://npmcn.com/package/%40cordobo/qrcode/#readme-api)
-   [GS1 QR 码](https://npmcn.com/package/%40cordobo/qrcode/#readme-gs1-qr-codes)
-   [贷项](https://npmcn.com/package/%40cordobo/qrcode/#readme-credits)
-   [许可证](https://npmcn.com/package/%40cordobo/qrcode/#readme-license)

## 要点

-   在服务器和客户端上的工作( 用 svg 进行本地反应)
-   CLI 工具
-   QR 代码另存为图像
-   支持数字、 字母、 坎吉和字节模式
-   支持混合模式
-   支持中国人、希腊人和日本人
-   支持多字节字符( 如 emojis : smile :)
-   自动生成最佳数据压缩和最小QR码大小的优化片段
-   应用不可知读性, QR 代码的定义是应用不可知性

## 安装

在您的工程文件夹中 :

```shell
npm install --save qrcode
```

或,在全球安装用于 `qrcode` 从命令行中保存 qrcode 图像或生成您可以在终端中查看的图像.

```shell
npm install -g qrcode
```

## 使用量

### 国 际

```
Usage: qrcode [options] <input string>

QR Code options:
  -v, --qversion  QR Code symbol version (1 - 40)                       [number]
  -e, --error     Error correction level           [choices: "L", "M", "Q", "H"]
  -m, --mask      Mask pattern (0 - 7)                                  [number]

Renderer options:
  -t, --type        Output type                  [choices: "png", "svg", "utf8"]
  -w, --width       Image width (px)                                    [number]
  -s, --scale       Scale factor                                        [number]
  -q, --qzone       Quiet zone size                                     [number]
  -l, --lightcolor  Light RGBA hex color
  -d, --darkcolor   Dark RGBA hex color
  --small  Output smaller QR code to terminal                          [boolean]

Options:
  -o, --output  Output file
  -h, --help    Show help                                              [boolean]
  --version     Show version number                                    [boolean]

Examples:
  qrcode "some text"                    Draw in terminal window
  qrcode -o out.png "some text"         Save as png image
  qrcode -d F00 -o out.png "some text"  Use red as foreground color
```

如果没有指定,则从文件扩展名中猜测输出类型.  
公认的扩展为 `png`, (中文(简体) ), `svg` 财务报告和审定财务报表 `txt`。 。 。 .

### 浏览器

`node-qrcode` 可以通过模块捆绑器在浏览器中使用 [浏览器](https://github.com/substack/node-browserify) 财务报告和审定财务报表 [网络软件包](https://github.com/webpack/webpack) 或将预编成的捆绑包含在 `build/` 文件夹.

#### 模块捆绑器

```html
<!-- index.html -->
<html>
  <body>
    <canvas id="canvas"></canvas>
    <script src="bundle.js"></script>
  </body>
</html>
```

```javascript
// index.js -> bundle.js
var QRCode = require('qrcode')
var canvas = document.getElementById('canvas')

QRCode.toCanvas(canvas, 'sample text', function (error) {
  if (error) console.error(error)
  console.log('success!');
})
```

#### 预编译捆绑

```html
<canvas id="canvas"></canvas>

<script src="/build/qrcode.js"></script>
<script>
  QRCode.toCanvas(document.getElementById('canvas'), 'sample text', function (error) {
    if (error) console.error(error)
    console.log('success!');
  })
</script>
```

如果您安装通过 `npm`,预编译文件将在 `node_modules/qrcode/build/` 文件夹.

预编集有支持 [Internet Explorer 10+, Safari 5.1+, 以及所有常绿浏览器](https://browserl.ist/?q=defaults%2C+IE+%3E%3D+10%2C+Safari+%3E%3D+5.1)。 。 。 .

### 节点JS

需要模块 `qrcode`

```javascript
var QRCode = require('qrcode')

QRCode.toDataURL('I am a pony!', function (err, url) {
  console.log(url)
})
```

制作终端的 qrcode

```js
var QRCode = require('qrcode')

QRCode.toString('I am a pony!',{type:'terminal'}, function (err, url) {
  console.log(url)
})
```

### ES6/ES7 (英语)

承诺和Async/Await可以用来代替回调功能.

```javascript
import QRCode from 'qrcode'

// With promises
QRCode.toDataURL('I am a pony!')
  .then(url => {
    console.log(url)
  })
  .catch(err => {
    console.error(err)
  })

// With async/await
const generateQR = async text => {
  try {
    console.log(await QRCode.toDataURL(text))
  } catch (err) {
    console.error(err)
  }
}
```

## 错误更正级别

出错校正能力允许成功扫描一个QR代码,即使该符号是脏的或被损坏. 根据操作环境可以选择四个等级.

更高等能提供更好的防出错,但能降低符号的能力.  
如果QR 代码符号被损坏的可能性很低( 例如通过显示器显示) 可以安全使用低出错级别,例如 `Low` 或者说 `Medium`。 。 。 .

可能的水平如下:

| 职等 | 防错误 |
| --- | --- |
| **L** (低声) | **~7%(** |
| **联合国** (ium | **\- 15%** |
| **Q 问** (夸特尔语) | **约25%** |
| **页:1** (高声) | **~30%** |

百分比表示受损地表的最大数量,之后该符号变得无法读取.

错误级别可以通过 `options.errorCorrectionLevel` 属性.  
如果没有指定,则默认值为 `M`。 。 。 .

```javascript
QRCode.toDataURL('some text', { errorCorrectionLevel: 'H' }, function (err, url) {
  console.log(url)
})
```

## QR 代码容量

能力取决于符号版本和错误校正级别. 另外编码模式也可能影响可存储数据的数量.

QR 代码版本从版本到版本 **1个** 改为版本 **第40条**。 。 。 .  
每个版本都有不同数量的模块(黑白点),它们定义了符号的大小. 对第一版来说,他们是 `21x21`,用于版本2 `25x25` e类. 更高的是版本,更多的是可存储的数据,当然更大的是QR代码符号.

下表列出每个编码模式和每个错误更正级别中可存储字符的最大数量.

| 模式 | L | 联合国 | Q 问 | 页:1 |
| --- | --- | --- | --- | --- |
| 数字 | 7089 (英语) | 5596 (英语) | 第3993条 | 3057 (英语) |
| 数字 | 4296 (英语) | 3391 (英语) | 2420 (英语) | 1852 (英语) |
| 字节 | 第2953条 | 2331号 | 1663 (韩语) | 第1273号 |
| Kan | 1817 (英语) | 第1435号 | 第1024号 | 784个 |

**说明:** 最大字符编号在使用时可能不同 [混合模式](https://npmcn.com/package/%40cordobo/qrcode/#readme-mixed-modes)。 。 。 .

QR 码版本可以通过 `options.version` 属性.  
如果没有指定版本,则会使用更合适的值. 除非需要特定版本,否则不需要此选项.

```javascript
QRCode.toDataURL('some text', { version: 2 }, function (err, url) {
  console.log(url)
})
```

## 编码模式

模式可以用更高效的方式来编码字符串.  
一个模式可能比其他模式更适合,取决于字符串内容. 下表列出了所支持的模式:

| 模式 | 字符 | 压缩 |
| --- | --- | --- |
| 数字 | 0、1、2、3、4、5、6、7、8、9 | 3个字符用10个比特表示 |
| 数字 | 0–9, A-Z(仅上例), 空格, $, %, \*, +, -., /, : | 2个字符由11个比特代表 |
| Kan | 基于JIS X 0208的Shift JIS系统的字符 | 2个kanji代表13位 |
| 字节 | ISO/IEC 8859-1字符集中的字符 | 每个字符由8位代表 |

如果输入文本未知, 选择正确的模式可能很棘手 .  
在这些情况下 **字节** 模式是最佳选择,因为所有字符都可以用它编码。 (见 [多字节字符](https://npmcn.com/package/%40cordobo/qrcode/#readme-multibyte-characters)(中文(简体) )  
然而,如果QR码读取器支持混合模式,则使用 [自动模式](https://npmcn.com/package/%40cordobo/qrcode/#readme-auto-mode) 可能会产生更好的结果.

### 混合模式

混合模式也是可能的。 QR代码可以从一系列具有不同编码模式的段来生成,以优化数据压缩.  
然而,从一种模式转换到另一种模式会产生成本,如果不考虑成本,可能导致最坏的结果. 见 [手动模式](https://npmcn.com/package/%40cordobo/qrcode/#readme-manual-mode) 例如,如何指定有不同编码模式的片段.

### 自动模式

以 **默认**,使用自动模式选择.  
输入字符串被自动分解为被优化的各段,以便使用混合模式产生尽可能最短的位流.  
这是生成QR码的首选方式.

例如,字符串 **ABCDE12345678 (英语). A1A 对** 将分为3个段,模式如下:

| 部分 | 模式 |
| --- | --- |
| ABCDE 亚足联 | 数字 |
| 12345678 (英语) | 数字 |
| ? 吗? A1A 对 | 字节 |

任何其它的片段和模式的组合,都会使比特流更长.  
如果您需要保持QR码大小小,此模式将产生最佳效果.

### 手动模式

如果自动模式对您不起作用或者您有特定的需求,也可以用相对模式手动指定每个段. 这样,不会在罩下应用分段优化.  
片段列表可以作为对象数组传递 :

```javascript
  var QRCode = require('qrcode')

  var segs = [
    { data: 'ABCDEFG', mode: 'alphanumeric' },
    { data: '0123456', mode: 'numeric' }
  ]

  QRCode.toDataURL(segs, function (err, url) {
    console.log(url)
  })
```

### 坎吉模式

使用kanji模式可以优化从Shift JIS系统中编码字符.  
不幸的是,没有办法从UTF-8编码的字符中计算出一个已转移的JIS值,因此需要从输入字符到SJIS值的转换表.  
本表默认不包含在捆绑中,以尽量保持大小.

如果您的应用程序需要 kanji 支持, 您需要通过一个功能来将输入字符转换为合适的值 .

帮助方法由 lib 通过可选文件提供,您可以包含如下示例所示.

**说明:** 只有当您想要从数据压缩中受益时,才需要支持Kanji模式,否则仍有可能使用字节模式编码Kanji(见 [多字节字符](https://npmcn.com/package/%40cordobo/qrcode/#readme-multibyte-characters)) (中文(简体) ).

```javascript
  var QRCode = require('qrcode')
  var toSJIS = require('qrcode/helper/to-sjis')

  QRCode.toDataURL(kanjiString, { toSJISFunc: toSJIS }, function (err, url) {
    console.log(url)
  })
```

使用预编译的捆绑 :

```html
<canvas id="canvas"></canvas>

<script src="/build/qrcode.min.js"></script>
<script src="/build/qrcode.tosjis.min.js"></script>
<script>
  QRCode.toCanvas(document.getElementById('canvas'),
    'sample text', { toSJISFunc: QRCode.toSJIS }, function (error) {
    if (error) console.error(error)
    console.log('success!')
  })
</script>
```

## 二进制数据

QR代码可以持有任意的以字节为基础的二进制数据. 如果尝试通过先将数据转换为JavaScript字符串来创建二进制QR代码,则会因为字符串编码增加了额外的字节而无法编码正版. 相反,你必须通过一个 [`Uint8ClampedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray) 或兼容的数组,或节点 [缓冲](https://nodejs.org/api/buffer.html),内容如下:

```javascript
// Regular array example
// WARNING: Element values will be clamped to 0-255 even if your data contains higher values.
const QRCode = require('qrcode')
QRCode.toFile(
  'foo.png',
  [{ data: [253,254,255], mode: 'byte' }],
  ...options...,
  ...callback...
)
```

```javascript
// Uint8ClampedArray example
const QRCode = require('qrcode')

QRCode.toFile(
  'foo.png',
  [{ data: new Uint8ClampedArray([253,254,255]), mode: 'byte' }],
  ...options...,
  ...callback...
)
```

```javascript
// Node Buffer example
// WARNING: Element values will be clamped to 0-255 even if your data contains higher values.
const QRCode = require('qrcode')

QRCode.toFile(
  'foo.png',
  [{ data: Buffer.from([253,254,255]), mode: 'byte' }],
  ...options...,
  ...callback...
)
```

类型脚本用户: 如果您正在使用 [@ t类型/ qrcode](https://www.npmjs.com/package/@types/qrcode),您需要添加一个 `// @ts-ignore` 在数据段之上,因为它期望 `data: string`。 。 。 .

## 多字节字符

对多字节字符的支持在最初的QR代码标准中并不存在,而是可以在字节模式下将UTF-8字符编码.

QR代码提供了一个通过ECI(扩展通道解释)来指定不同类型字符集的方法,但它在这个 lib 中还没有完全执行.

多数 QR 然而,代码阅读器即使没有ECI也能识别多字节字符.

注意,单个Kanji/Kana或Emoji最多可取取4个字节.

## API 密码

浏览器 :

-   [创建()](https://npmcn.com/package/%40cordobo/qrcode/#readme-createtext-options)
-   [转到 Canvas ()](https://npmcn.com/package/%40cordobo/qrcode/#readme-tocanvascanvaselement-text-options-cberror)
-   [数据URL ()](https://npmcn.com/package/%40cordobo/qrcode/#readme-todataurltext-options-cberror-url)
-   [转到 String ()](https://npmcn.com/package/%40cordobo/qrcode/#readme-tostringtext-options-cberror-string)

服务器 :

-   [创建()](https://npmcn.com/package/%40cordobo/qrcode/#readme-createtext-options)
-   [转到 Canvas ()](https://npmcn.com/package/%40cordobo/qrcode/#readme-tocanvascanvas-text-options-cberror)
-   [数据URL ()](https://npmcn.com/package/%40cordobo/qrcode/#readme-todataurltext-options-cberror-url-1)
-   [转到 String ()](https://npmcn.com/package/%40cordobo/qrcode/#readme-tostringtext-options-cberror-string-1)
-   [移动到文件 ()](https://npmcn.com/package/%40cordobo/qrcode/#readme-tofilepath-text-options-cberror)
-   [切换到FileStream ()](https://npmcn.com/package/%40cordobo/qrcode/#readme-tofilestreamstream-text-options)

### 浏览器 API

#### `create(text, [options])`

创建 QR 代码符号并返回 qrcode 对象.

##### `text`

类型 : `String|Array`

要编码的文字或描述片段的对象列表.

##### `options`

见 [QR 代码选项](https://npmcn.com/package/%40cordobo/qrcode/#readme-qr-code-options)。 。 。 .

##### `returns`

类型 : `Object`

```javascript
// QRCode object
{
  modules,              // Bitmatrix class with modules data
  version,              // Calculated QR Code version
  errorCorrectionLevel, // Error Correction Level
  maskPattern,          // Calculated Mask pattern
  segments              // Generated segments
}
```

  

#### `toCanvas(canvasElement, text, [options], [cb(error)])`

#### `toCanvas(text, [options], [cb(error, canvas)])`

绘制 qr 代码符号来画画 .  
若为 `canvasElement` 中省略新画布.

##### `canvasElement`

类型 : `DOMElement`

画出 QR 代码的 Canvas .

##### `text`

类型 : `String|Array`

要编码的文字或描述片段的对象列表.

##### `options`

见 [选项](https://npmcn.com/package/%40cordobo/qrcode/#readme-options)。 。 。 .

##### `cb`

类型 : `Function`

回调函数调用完成 .

##### 示例

```javascript
QRCode.toCanvas('text', { errorCorrectionLevel: 'H' }, function (err, canvas) {
  if (err) throw err

  var container = document.getElementById('container')
  container.appendChild(canvas)
})
```

  

#### `toDataURL(text, [options], [cb(error, url)])`

#### `toDataURL(canvasElement, text, [options], [cb(error, url)])`

返回包含 QR 代码图像的表示值的数据 URI .  
如果提供, `canvasElement` 用于生成数据 URI.

##### `canvasElement`

类型 : `DOMElement`

画出 QR 代码的 Canvas .

##### `text`

类型 : `String|Array`

要编码的文字或描述片段的对象列表.

##### `options`

-   ###### `type`
    
    类型 : `String`  
    默认 : `image/png`
    
    数据URI格式.  
    可能的值是: `image/png`, (中文(简体) ), `image/jpeg`, (中文(简体) ), `image/webp`。 。 。 .  
    
-   ###### `rendererOpts.quality`
    
    类型 : `Number`  
    默认 : `0.92`
    
    A 数字之间 `0` 财务报告和审定财务报表 `1` 如果请求的类型是图像质量 `image/jpeg` 或者说 `image/webp`。 。 。 .
    

见 [选项](https://npmcn.com/package/%40cordobo/qrcode/#readme-options) 用于其他设置.

##### `cb`

类型 : `Function`

回调函数调用完成 .

##### 示例

```javascript
var opts = {
  errorCorrectionLevel: 'H',
  type: 'image/jpeg',
  quality: 0.3,
  margin: 1,
  color: {
    dark:"#010599FF",
    light:"#FFBF60FF"
  }
}

QRCode.toDataURL('text', opts, function (err, url) {
  if (err) throw err

  var img = document.getElementById('image')
  img.src = url
})
```

  

#### `toString(text, [options], [cb(error, string)])`

返回 QR 代码的字符串表达式.  

##### `text`

类型 : `String|Array`

要编码的文字或描述片段的对象列表.

##### `options`

-   ###### `type`
    
    类型 : `String`  
    默认 : `utf8`
    
    输出格式.  
    可能的值是: `terminal`, (中文(简体) ),`utf8`,以及 `svg`。 。 。 .
    

见 [选项](https://npmcn.com/package/%40cordobo/qrcode/#readme-options) 用于其他设置.

##### `cb`

类型 : `Function`

回调函数调用完成 .

##### 示例

```javascript
QRCode.toString('http://www.google.com', function (err, string) {
  if (err) throw err
  console.log(string)
})
```

  

### 服务器 API

#### `create(text, [options])`

见 [创建](https://npmcn.com/package/%40cordobo/qrcode/#readme-createtext-options)。 。 。 .

  

#### `toCanvas(canvas, text, [options], [cb(error)])`

绘制 qr 代码符号到 [节点画布](https://github.com/Automattic/node-canvas)。 。 。 .

##### `text`

类型 : `String|Array`

要编码的文字或描述片段的对象列表.

##### `options`

见 [选项](https://npmcn.com/package/%40cordobo/qrcode/#readme-options)。 。 。 .

##### `cb`

类型 : `Function`

回调函数调用完成 .

  

#### `toDataURL(text, [options], [cb(error, url)])`

返回包含 QR 代码图像的表示值的数据 URI .  
仅与 `image/png` 类型.

##### `text`

类型 : `String|Array`

要编码的文字或描述片段的对象列表.

##### `options`

见 [选项](https://npmcn.com/package/%40cordobo/qrcode/#readme-options) 用于其他设置.

##### `cb`

类型 : `Function`

回调函数调用完成 .

  

#### `toString(text, [options], [cb(error, string)])`

返回 QR 代码的字符串表达式.  
如果所选输出格式是 `svg` 它将返回含有 xml 代码的字符串.

##### `text`

类型 : `String|Array`

要编码的文字或描述片段的对象列表.

##### `options`

-   ###### `type`
    
    类型 : `String`  
    默认 : `utf8`
    
    输出格式.  
    可能的值是: `utf8`, (中文(简体) ), `svg`, (中文(简体) ), `terminal`。 。 。 .
    

见 [选项](https://npmcn.com/package/%40cordobo/qrcode/#readme-options) 用于其他设置.

##### `cb`

类型 : `Function`

回调函数调用完成 .

##### 示例

```javascript
QRCode.toString('http://www.google.com', function (err, string) {
  if (err) throw err
  console.log(string)
})
```

  

#### `toFile(path, text, [options], [cb(error)])`

保存 QR 图像文件代码 .  
若为 `options.type` 未指定,格式将从文件扩展名中猜测.  
公认的扩展为 `png`, (中文(简体) ), `svg`, (中文(简体) ), `txt`。 。 。 .

##### `path`

类型 : `String`

保存文件的路径 .

##### `text`

类型 : `String|Array`

要编码的文字或描述片段的对象列表.

##### `options`

-   ###### `type`
    
    类型 : `String`  
    默认 : `png`
    
    输出格式.  
    可能的值是: `png`, (中文(简体) ), `svg`, (中文(简体) ), `utf8`。 。 。 .
    
-   ###### `rendererOpts.deflateLevel` **(仅png)**
    
    类型 : `Number`  
    默认 : `9`
    
    降能压平等分.
    
-   ###### `rendererOpts.deflateStrategy` **(仅png)**
    
    类型 : `Number`  
    默认 : `3`
    
    降压策略.
    

见 [选项](https://npmcn.com/package/%40cordobo/qrcode/#readme-options) 用于其他设置.

##### `cb`

类型 : `Function`

回调函数调用完成 .

##### 示例

```javascript
QRCode.toFile('path/to/filename.png', 'Some text', {
  color: {
    dark: '#00F',  // Blue dots
    light: '#0000' // Transparent background
  }
}, function (err) {
  if (err) throw err
  console.log('done')
})
```

  

#### `toFileStream(stream, text, [options])`

写入 QR 代码图像到流 。 仅与 `png` 目前的格式.

##### `stream`

类型 : `stream.Writable`

节点流.

##### `text`

类型 : `String|Array`

要编码的文字或描述片段的对象列表.

##### `options`

见 [选项](https://npmcn.com/package/%40cordobo/qrcode/#readme-options)。 。 。 .

  

### 选项

#### QR 代码选项

##### `version`

类型 : `Number`  

QR代码版本. 如果没有指定,则将计算更合适的值.

##### `errorCorrectionLevel`

类型 : `String`  
默认 : `M`

错误校正级别 .  
可能值为 `low, medium, quartile, high` 或者说 `L, M, Q, H`。 。 。 .

##### `maskPattern`

类型 : `Number`  

面具图案用来遮住符号.  
可能值为 `0`, (中文(简体) ), `1`, (中文(简体) ), `2`, (中文(简体) ), `3`, (中文(简体) ), `4`, (中文(简体) ), `5`, (中文(简体) ), `6`, (中文(简体) ), `7`。 。 。 .  
如果没有指定,则将计算更合适的值.

##### `toSJISFunc`

类型 : `Function`  

内部用于将 kanji 转换为 Shift JIS 值的帮助函数 .  
如果您需要坎吉模式的支持, 请提供此功能 .

#### 渲染者选项

##### `margin`

类型 : `Number`  
默认 : `4`

确定安静区应该有多宽.

##### `scale`

类型 : `Number`  
默认 : `4`

尺度因子. 价值为 `1` 指每个模块1px(黑点).

##### `small`

类型 : `Boolean`  
默认 : `false`

仅与终端渲染器有关。 输出更小的QR代码.

##### `width`

类型 : `Number`  

强制输出图像的特定宽度 .  
如果宽度太小无法包含 qr 符号, 此选项将被忽略 .  
胜过 `scale`。 。 。 .

##### `color.dark`

类型 : `String`  
默认 : `#000000ff`

黑色模块的颜色 。 值必须采用十六进制格式(RGBA).  
注意: 暗色应该总是比 `color.light`。 。 。 .

##### `color.light`

类型 : `String`  
默认 : `#ffffffff`

亮相模块的颜色 。 值必须采用十六进制格式(RGBA).  

  

## GS1 QR 码

这里对他们进行了很好的讨论。 但简而言之,任何 qrcode 生成器都会使 gs1 兼容 qrcode, 但是定义 gs1 qrcode 的是一个带有元数据来描述您的 gs1 信息的头.

[https://github.com/soldair/node-qrcode/issues/45 互联网档案馆的存檔,存档日期2013-12-21](https://github.com/soldair/node-qrcode/issues/45)

## 贷项

这个lib是基于"QRCode for JavaScript",Kazuhiko Arase感激地获得了麻省理工学院的许可.

## 许可证

[麻省理工学院](https://github.com/soldair/node-qrcode/blob/master/license)

"QR代码"是:  
戴森·怀特(签名)

## 常见问题

### @cordobo/qrcode 是什么？

QRCode / 2d 有服务器侧和客户端侧支持的条形码 api注意：该包已被作者标记为弃用——Package no longer supported\. Contact Support at https://www\.npmjs\.com/support for more info\.

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

在项目目录运行 npm install @cordobo/qrcode，或使用 pnpm add / yarn add / bun add。它还提供命令行工具 qrcode，可以用 npx qrcode 直接运行。

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

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

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

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

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

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

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

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

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

最新版本 1\.5\.0 发布于 2022/01/12（4 年前）；至今共发布 1 个版本，其中过去 12 个月发布了 0 个；首次发布于 2022/01/12。作者已将其标记为弃用，新项目建议寻找替代方案。

