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

qrcode-pure

v0.0.5

Published

qrcode encode and decode

Downloads

1

Readme

qrcode-pure

二维码编码与解码。 核心源码来自项目qrcode,但qrcode使用的是jquery封装,qrcode-pure在此将两个功能拆分了出来,单纯的作为两个函数调用。

安装

# 安装依赖
npm i install --save qrcode-pure

文档

qrdecode 解码

调用参数

需要传入一个canvas DOM

返回值

调用qrdecode解码后返回的值为一个对象。

|参数|备注| |-|:-:| |text|解码后的值| |canvas|解析的canvasDOM|

qrencode 编码

调用参数

可参考项目qrcode内的参数。

返回值

调用qrencode编码后返回的值为一个对象。

|参数|备注| |-|:-:| |canvas|编码后的的canvasDOM|

使用

全部引入

// 全部引入
import qrcodePure from 'qrcode-pure'

// 解码
qrcodePure.QRDecode()

// 编码
qrcodePure.QREncode()

单独引入

解码

在项目中使用:(解析单张二维码)

<!-- template -->
<input type="file" @change="handleChange">
<canvas ref="decode-canvas">
<button @click="decode">点击解码</button>
// 引入解码函数

// script 
import qrdecode from 'qrcode-pure/lib/qrdecode'

// methods
handleChange(e) {
  var canvas = this.$refs['decode-canvas'],
    ctx = canvas.getContext('2d'),
    file = e.target.files[0],
    reader = new FileReader()

  reader.onload = function(e) {
    var img = new Image()

    img.onload = function() {
      canvas.width = img.width
      canvas.height = img.height
      ctx.drawImage(img, 0, 0)
    }

    img.src = e.target.result
  }

  file && reader.readAsDataURL(file)
}

// 调用解码函数
// 传入一个canvas,内容为二维码
// 如果是上传的图片,需要调用canvas的drawImage方法,生成canvas
function decode(){
  let result = qrdecode(this.$refs['decode-canvas')

  // result返回值为解码后的值
  console.log('result', result)
}

在项目中使用:(解析多张二维码)

<!-- template -->
<input type="file" multiple @change="handleChange">
// 引入解码函数

// script 
import qrdecode from 'qrcode-pure/lib/qrdecode'

// methods
handleChange(e) {
  if (e.target.files.length === 0) return
    Object.values(e.target.files).forEach(v => {
      let canvas = document.createElement('canvas'),
        ctx = canvas.getContext('2d'),
        reader = new FileReader()

      reader.onload = function(e) {
        var img = new Image()

        img.onload = function() {
          canvas.width = img.width
          canvas.height = img.height
          ctx.drawImage(img, 0, 0)

          // 调用结果 result 为对象,具体参数参考 文档 => decode 解码
          let result = qrdecode(canvas)
        }

        img.src = e.target.result
      }

      v && reader.readAsDataURL(v)
    })
}
编码

在项目中使用:(vue单文件组件为例)

<!-- template -->
<el-button @click="encode" type="primary" size="mini" class="m-l_2">编码</el-button>
// 引入解码函数

// script 
import qrencode from 'qrcode-pure/lib/qrencode'

// methods
encode() {
  // 调用 qrencode 编码函数,可接受一个对象参数
  // 参数具体内容请参考项目[qrcode](https://github.com/nuintun/qrcode),在此不再赘述。
  // 返回值为一个对象
  // 其中canvas属性为编码后二维码的canvas DOM
  let result = qrencode({ text: 'https://pkjy.github.io' })
}

在线体验

注:本项目处理建设阶段,代码变化比较频繁。

qrcode-pure体验