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 🙏

© 2024 – Pkg Stats / Ryan Hefner

qrcode-currency

v1.0.0

Published

Qrcode.js currency version. It can support wechat.

Downloads

3

Readme

qrcode-currency

说明

本项目是对qrcode-generator项目进行了修改,删除了里面的一些功能,增加了其他一些功能,目的是做出web端和小程序端通用二维码生成框架。

下载

可以直接使用 qrcode.js 文件,也可以通过 npm i qrcode-currency 下载使用。

使用方法

  1. 配置了解,以下参数为默认值
    {
        // 需要变成二维码的文本
        text: "text",
        // 用于指定每一小块二维码长宽
        cellSize: 2,
        // 1 - 40 选择版本
        typeNumber: 4,
        // 黑块颜色
        colorDark: "#000000",
        // 亮块颜色
        colorLight: "#ffffff",
        // 纠错等级(见下面纠错等级)
        correctionLevel: QRCode.QRErrorCorrectionLevel.H,
        // 边距
        margin: 8
    };
  1. 纠错等级
    {
        L: 1,
        M: 0,
        Q: 3,
        H: 2
    }
    调用方式 QRCode.CorrectionLevel.H 等
    纠错等级越高能够容纳的字符越少
  1. 使用Demo (其中参数可以根据自己需要配置)
    • Web端

      • 返回 DataURL (颜色参数只能是十六进制 如:#000000)
          // 通过配置文件配置数据
          <div id="demo"></div>
          <script type="text/javascript" src="qrcode.js"></script>
          <script type="text/javascript">
              var qr =new QRCode({
                  text:"demo"
              });
              document.getElementById("demo").innerHTML  = "<img src='"+qr.dataURL()+"'></img>"
          </script>
          // 直接指定数据
          <div id="demo"></div>
          <script type="text/javascript" src="qrcode.js"></script>
          <script type="text/javascript">
              var qr =new QRCode("demo");
              document.getElementById("demo").innerHTML  = "<img src='"+qr.dataURL()+"'></img>"
          </script>
          // 动态添加数据
          <div id="demo"></div>
          <script type="text/javascript" src="qrcode.js"></script>
          <script type="text/javascript">
              var qr =new QRCode();
              qr.addData("demo");
              qr.make();
              document.getElementById("demo").innerHTML  = "<img src='"+qr.dataURL()+"'></img>"
          </script>
          // addData 和 make 返回原对象可以连着一起书写。
          <div id="demo"></div>
          <script type="text/javascript" src="qrcode.js"></script>
          <script type="text/javascript">
              var qr =new QRCode("demo");
              document.getElementById("demo").innerHTML  = "<img src='"+qr.addData("demo").make().dataURL()+"'></img>"
          </script>
      • 操作 canvas 画布 (颜色可以为任何类型)
          <canvas id="demo"></canvas>
          <script type="text/javascript" src="qrcode.js"></script>
          <script type="text/javascript">
              var qr =new QRCode({
                  text:"demo",
              });
              var c = document.getElementById("demo");
              // qr.height 表示二维码高度
              c.height = qr.height ;
              // qr.width 表示二维码宽度
              c.width = qr.width;
              var d = c.getContext("2d");
              qr.renderTo2dContext(d);
          </script>
          // 其余的用法和 DataURL 相同
    • 微信小程序端

      • 返回 DataURL (颜色参数只能是十六进制 如:#000000)
      // wxml 文件
         <image src="{{imgURL}}"></image>
      // js 文件
          import QRCode from "qrcode-currency";
          Page({
              data: {
                  imgURL:""
              },
              onReady: function () {
                  const qrcode = new QRCode({
                      text:"demo",
                      colorDark: "#9ff312",
                      margin:10,
                      cellSize:8
                  });
                  this.setData({
                  imgURL:qrcode.dataURL()
                  })
              }
          })
      // 其他的使用方法和上面类似
      • 操作 canvas 画布 (颜色可以为任何类型)
      // wxml 文件
          <canvas type="2d" id="qrcode"></canvas>
      // js 文件
      // 其他的使用方法和上面类似
          import QRCode from "qrcode-currency";
          Page({
          onReady: function () {
              const qrcode = new QRCode({
              text:"demo",
              margin:10,
              cellSize:8
              });
              // 下面这些代码都是获取 context 对象和设置画布大小
              const query = wx.createSelectorQuery()
              query.select('#qrcode')
              .fields({ node: true, size: true })
              .exec((res) => {
                  const canvas = res[0].node
                  const ctx = canvas.getContext('2d')
                  const dpr = wx.getSystemInfoSync().pixelRatio
                  canvas.width = qrcode.width * dpr
                  canvas.height = qrcode.height * dpr
                  // 把 wxml 中 canvas 的 context 对象交给框架
                  qrcode.renderTo2dContext(ctx)
              })
          }
          })