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

qrcode-matrix

v1.0.0-beta.6

Published

QRCode matrix generator

Readme

qrcode-matrix

qrcode-matrix 是QR码矩阵数据生成库, 最终生成QR码的点阵. 非一步到位生成二维码图片, 主要用于二维码图片生成/美化, 矢量图片二维码生成等场景

特点:

  • splitMake 方法, 会返回二维码不同功能的点阵信息数组.
  • 支持转为GBK编码保存(实际上已经剥离出了数据转换部份,存任何编码方式都很方便)
  • 提供精简版(gzip 5.2k),只保留Byte(utf8)模式;
    • './onlyUTF8.js' or './dist/qrcodeMatrix.utf8.js'

生成的点阵用的是BitMatrix库,其基于ArrayBuffer实现以节约内存,但只适用于ES6以上的环境。

demo

var QRCode = require('../').default;
var qrcode = QRCode({
	errorCorrectionLevel: 'M', //纠错等级 默认M   'L','M','Q','H' -> [1,0,3,2]
	typeNumber: 2, //QR码版本 默认0 (自动)  1 to 40
	minTypeNumber: 0, //最小typeNumber版本,当typeNumber自动时才有效
	maskPattern: 'auto', //掩模 'random','auto'  [0-7]
	dataMode: 'Byte' //默认数据类型, 参看 QRCode.QRModes 对像
});
qrcode.setData('1234');
var matrix = qrcode.make(); // 一个布尔值的二维点阵对像

//在控制台打印出二维码试试 (我的控制台是黑色背景,所以我加上了一圈边框)
var $0 = '8 ',
    $1 = '  ';
console.log($0.repeat(matrix.width + 2));
for(var r =0; r<matrix.height; r++){
	let row = matrix.getRow(r);
	let str = row.map(item => (item ? $1 : $0)).join('');
	console.log($0 + str + $0);
}
console.log($0.repeat(matrix.width + 2));
/*
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
8               8               8   8               8
8   8 8 8 8 8   8 8 8 8 8 8       8 8   8 8 8 8 8   8
8   8       8   8 8   8     8   8 8 8   8       8   8
8   8       8   8     8 8 8 8 8 8 8 8   8       8   8
8   8       8   8     8     8 8 8 8 8   8       8   8
8   8 8 8 8 8   8       8 8 8 8 8   8   8 8 8 8 8   8
8               8   8   8   8   8   8               8
8 8 8 8 8 8 8 8 8     8   8   8     8 8 8 8 8 8 8 8 8
8   8 8 8   8       8     8   8 8 8           8 8   8
8   8       8 8     8   8       8   8   8 8 8 8   8 8
8 8     8               8   8 8 8     8 8   8 8   8 8
8 8 8 8   8 8 8 8 8   8     8   8 8 8 8             8
8 8   8 8 8 8   8   8 8   8         8   8       8   8
8     8 8   8 8 8 8     8   8 8 8 8           8   8 8
8 8 8       8         8           8 8     8       8 8
8 8 8     8 8 8 8 8 8 8   8   8         8 8     8 8 8
8     8     8   8 8     8     8 8           8 8 8   8
8 8 8 8 8 8 8 8 8   8   8 8     8   8 8 8         8 8
8               8   8   8 8 8 8     8   8     8   8 8
8   8 8 8 8 8   8 8   8 8   8   8   8 8 8   8 8   8 8
8   8       8   8   8     8                 8 8     8
8   8       8   8 8     8   8 8 8     8     8 8 8   8
8   8       8   8 8             8 8   8     8     8 8
8   8 8 8 8 8   8 8 8     8   8 8     8 8         8 8
8               8       8     8 8 8     8 8   8     8
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
*/

API

数据类型 mode

  • 'Numeric' //数字 0-9
  • 'Alphanumeric' //支持数字,大写字母,英文空格及 % * + - . /:
  • 'Byte' //以字节存储数据 字符串数据默认会转为UTF-8编码存储
  • 'Byte-GBK' //以字节存储数据 字符串转为'GBK'编码字节
  • 'Kanji' //双字节日文编码 字符串数据默认会以SJIS编码存储

QRcode.QRErrorCorrectionLevel 纠错等级

QRcode.QRErrorCorrectionLevel['L'] = 1 // 7%
QRcode.QRErrorCorrectionLevel['M'] = 0 // 15%
QRcode.QRErrorCorrectionLevel['Q'] = 3 // 25%
QRcode.QRErrorCorrectionLevel['H'] = 2 // 30%

QRcode.QRModes 支持的的 mode 类型列表

var QRCode = require('qrcode.js') 
var QRCode_utf8 = require('qrcode.js/anlyUTF8') //QRModes只有一种 即 'Byte', 用于web端, 引用文件较小

console.log(Object.keys(QRCode.QRModes)); 
//["Numeric","Alphanumeric","Byte","Byte-GBK","Kanji"]

console.log(Object.keys(QRCode_utf8.QRModes));
//["Byte"]

QRcode(options) 根据配制生成一个 qrcode 对像

qrcode.addData(data,mode) //添加数据 可以多次添加

qucode.setData(data,mode) //重新添加数据 会移除之前的数据

qucode.make() //根据添加的数据生成QR码的二维点阵对像

qucode(data,mode) //一个语法糖

//等同于执行以下代码
qucode.setData(data,mode)
return qucode.make();

qucode.splitMake() //拆分QR码的二维数组 将返回一个对像

  • all : 所有数据 make 方法返回的二维点阵相同
  • data : 除探测相并数据 的其它数据
  • allDiscover : 所有定位,矫正 等数据
  • positionProbe : 定位图数据
  • positionAdjust : 矫正图数据
  • timing : 定位图 splitMake

大至关系如下:

all  == data | allDiscover
allDiscover == positionProbe | positionAdjust | timing

相关应用

二维码美化