wc-qrcode
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

wc-qrcode

published coverage npm npm jsDelivr GitHub issues license

NPM

An efficient and lightweight QR Code WebComponent integrated with Rust wasm library.

Installation

You can install wc-qrcode with npm, or just get started quickly with CDN.

Install from npm

To install from npm, open terminal in your project folder and run:

npm install wc-qrcode

After the package is installed, then you can import the qrcode webcomponent into you code:

import 'wc-qrcode';

window.onload = function() {
  let qrElement = document.createElement('qr-code');
  qrElement.setAttribute('text', 'https://example.org');
  qrElement.setAttribute('size', '6');
  document.body.appendChild(qrElement);
}

Install from CDN

There is jsDelivr CDN available for quickly integrated with your web page.

https://cdn.jsdelivr.net/npm/wc-qrcode@0.1.6

or

<script src="https://cdn.jsdelivr.net/npm/wc-qrcode@0.1.6"></script>

Basic Usages:

<html>
  <head>

    <!-- Load QR WebComponent library -->
    <script src="https://cdn.jsdelivr.net/npm/wc-qrcode@0.1.6"></script>
    <!-- End Load -->

  </head>

  <body>

    <!-- Using "qr-code" html tag to generate QR Code -->
    <qr-code
      text="https://github.com/yishiashia/wc-qrcode"
      size="6"
    ></qr-code>

  </body>
</html>

Demo page

Live Demo

Attributes

text

String type. The data of QR Code.

size

Number type. The QR code image size (multiply by 16px).

alt

String type. The alt description text of the generated qrcode image.

Element Properties

Property Type Description
text String The data string to generate QR code.
size Integer The QR Code image size (width and height would be the size multiply by 16px).
alt String The alt description text of the generated qrcode image.

You can update the qrcode component by setting its properties.

For example:

const qrElement = document.getElementsByTagName("qr-code")[0];

if (qrElement !== undefined) {
  qrElement.text = "https://www.example.org";
  qrElement.alt = "URL of example.org";
  qrElement.size = 10;
}

Package Sidebar

Install

npm i wc-qrcode

Weekly Downloads

25

Version

0.2.0

License

MIT

Unpacked Size

179 kB

Total Files

7

Last publish

Collaborators

  • yishiashia