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-generator-es

v1.0.3

Published

ES二维码生成模块

Downloads

192

Readme

qrcode-generator-es

介绍

基于 qr-code-generator-library 的二维码生成器,支持 tree-shaking

安装

npm install qrcode-generator-es --save

使用

import {
  QRCodeRender,
  renderToSvg,
  renderToTable,
  renderToCanvas,
  renderToImg,
} from "./index";

const $canvas = document.getElementById("canvas");
const qrcode = new QRCodeRender({
  renderFn: renderToCanvas,
  text: "Hello World!!!",
  el: $canvas,
});
qrcode.render();

参数

| 参数名 | 类型 | 默认值 | 说明 | 必填 | | ---- | ---- | ---- | ---- | ---- | | text | string | - | 二维码内容, 如果不传, 则需要手动调用 addData 函数 | 否 | | size | number | 100 | 生成的二维码大小 | 否 | | level | string | L | 二维码纠错等级, L (默认)、MQH | 否 | | fill | string | #000000 | 二维码填充色 | 否 | | background | string | #ffffff | 二维码背景色 | 否 | | el | HTMLElementstring | - | 渲染的元素, 可以是 canvas 或者 img 元素, 或者 选择器 | 否 | | renderFn | function | - | 渲染函数 | 是 | | icon | { src: string, size?: number } | - | 二维码中间的图标 | 否 |

渲染函数

  1. renderToSvg: 渲染到 svg 元素
  2. renderToTable: 渲染到 table 元素
  3. renderToCanvas: 渲染到 canvas 元素
  4. renderToImg: 渲染到 img 元素

添加二维码内容

如果二维码内容初始化了后,后续会根据接口动态变化的时候,可以根据 API 手动调整

1. 添加二维码内容

import {
  QRCodeRender,
  renderToCanvas
} from "./index";

const qrcode = new QRCodeRender({
  renderFn: renderToCanvas,
  text: "Hello",
  el: '#canvas',
});
qrcode.render();

qrcode.addData(' World')

重置二维码内容

添加二维码内容调用的是 addData 函数,重置则调用 resetData 函数

qrcode.resetData('new data')

addDataresetData 函数不需要手动调用 render 函数,会自动调用