Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

qrcode.es

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

qrcode.es

QR Code Generator

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

qrcode.es

license circleCi

babel

Introduction

qrCode.js is a web based QrCode generation library in javascript. It extends the functionality of qrcode-generator.

Getting started

    npm i qrcode.es

OR

    yarn add qrcode.es

Usage

ES6 Modules

import { qrcode, modes, ecLevel } from 'qrcode.es';
    
const qrCodeSetting = {
    size: 400,
    ecLevel: ecLevel.QUARTILE,
    minVersion: 8,
    background: '#fff',
    mode: modes.DRAW_WITH_IMAGE_BOX,
    radius: 0.5,
    image: 'https://raw.githubusercontent.com/AdactiveSAS/qrcode.js/master/adactiveLogo.jpg',
    mSize: 0.15,
};

const element = document.getElementById("qrCode"); //Element must be an instance of HTMLCanvasElement or HTMLDivElement
const qrCode = new qrcode(element); //Initializing the QrCode
await qrCode.generate('https://adactive.com', qrCodeSetting); // Function that generates the QrCode
let image = this.qrCode.getImage(); // Function to get the data Url of the QrCode Image

Browser

<!DOCTYPE html>
<html>
    <head>
        <style>
            html, body {
                height: 100%;
                width: 100%;
                position: relative;
                margin: 0;
                overflow: hidden;
            }
        </style>
    </head>
    <body>
        <div id="qrCode"></div>

        <!-- Assuming node_modules is located in parent directory -->
        <script src="../node_modules/qrcode.umd.js"></script>
        <script type="application/javascript">

            const image = './assets/logo.jpg'; // To modify path to the image url
            const element = document.getElementById("qrCode"); //Element must be an instance of HTMLCanvasElement or HTMLDivElement
            const qrCode = new QrCode.qrcode(element);

            const qrCodeSetting = {
                size: 400,
                ecLevel: QrCode.ecLevel.QUARTILE,
                minVersion: 8,
                background: '#fff',
                mode: QrCode.MODES.DRAW_WITH_IMAGE_BOX,
                radius: 0.5,
                image: image,
                mSize: 0.15,
            };

            let qrCodeImageUrl = null;

            qrCode.generate('https://adactive.com', qrCodeSetting)
                .then(() => {
                    qrCodeImageUrl = qrCode.getImage();
                    console.log("[IMAGE URL] : ", qrCodeImageUrl);
                });

        </script>
    </body>
</html>

API

constructor (element: instance of HTMLDivElement | instance of HTMLCanvasElement): qrcode
fucntion generate(text: string, options: Object): Promise
function getImage(): string

Options

NameTypeDefaultDescription
minVersionnumber1Version Range: Minimum 1*
maxVersionnumber40Version Range: Maximum 40*
ecLevelstring'H'Error Correction Level*
sizenumber500Size of QrCode in pixel
fillstring'#000'Color of Module in Color Code
backgroundstringnullBackground color or null for transparent background
radiusnumber0Corner radius relative to module width: Range from 0.0 to 0.5
quietnumber0Quiet zone in modules (White border around the QrCode)
modenumber0Mode of QrCode - Refer to the end of table for more information
mSizenumber0.3Size of Label or Image
mPosXnumber0.5Position of Label or Image on x-Axis
mPosYnumber0.5Position of Label or Image on y-Axis
fontnamestring'sans'Font Name to be used
fontcolorstring'#000'Font Colour in Color Code
labelstring'no label'Label used for Mode with Label
imagestringnullImage used for Mode with Image

Modules

QrCode Modules refers to the black and white dots that make up the QrCode.

Version

QrCode version ranges from 1 - 40 where which version has a different number of modules. Each higher version consists of a higher number of modules which allows the QrCode to contain more data.

Error Correction Level (ecLevel)

QR Code has error correction capability to restore data if the code is dirty or damaged. Four error correction levels are available for users to choose according to the operating environment.

##Enums

ecLevel

NameLevelError Correction Capability
LOW'L'~7%
MEDIUM'M'~15%
QUARTILE'Q'~25%
HIGH'H'~30%

Modes

NameDescription
NORMALTo generate a default QrCode
DRAW_WITH_LABEL_STRIPTo add a label with a white strip taking the width of the QrCode
DRAW_WITH_LABEL_BOXTo add a label base on the length of text on the QrCode
DRAW_WITH_IMAGE_STRIPTo add an image with a white strip taking the width of the QrCode
DRAW_WITH_IMAGE_BOXTo add an image base on the image width on the QrCode

License

MIT License (MIT)

The word "QR Code" is registered trademark of DENSO WAVE INCORPORATED

http://www.denso-wave.com/qrcode/faqpatent-e.html

Special Thanks

This library is greatly inspired by Lars Jung, Author of jquery-qrcode.

Thanks to Kazuhiko Arase for original QrCode generation.

Keywords

FAQs

Package last updated on 26 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc