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

qr-creator

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

qr-creator

Lightweight QR code generator for stylish QR codes

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
57K
decreased by-1.82%
Maintainers
1
Weekly downloads
 
Created
Source

QR Code Encoder

A lightweight library generating stylish QR codes that also support gradient fills and rounded corners in only 12.2kB minified (4.75kB gzipped). Try out the demo!

Origin

This library is a trimmed down version of Lars Jung's jQuery.qrcode library. Our library is however not based on jQuery anymore and doesnt make use of it. Lars Jung's library itself is based on this QR code Generator.

All parts are licensed under the MIT License.

Installation

To install via npm:

npm install --save qr-creator

To install via yarn:

yarn add qr-creator

Or simply copy qr-creator.min.js over to your project.

Usage

Call the QrCreator API with a configuration object and a DOM element or canvas to render the QR code into:

  import QrCreator from 'qr-creator';

  QrCreator.render({
    text: 'some text',
    radius: 0.5, // 0.0 to 0.5
    ecLevel: 'H', // L, M, Q, H
    fill: '#536DFE', // foreground color
    background: null, // color or null for transparent
    size: 128 // in pixels
  }, document.querySelector('#qr-code'));
AttributeOptionsDefaultDescription
textString""Any kind of text, also links, email addresses, any thing. The library will figure out the size of the QR code to fit all the text inside.
radius0 .. 0.50.5Defines how round the blocks should be. Numbers from 0 (squares) to 0.5 (maximum round) are supported.
ecLevelL, M, Q, HLMeans "Error correction levels". The four values L, M, Q, and H will use %7, 15%, 25%, and 30% of the QR code for error correction respectively. So on one hand the code will get bigger but chances are also higher that it will be read without errors later on.
fillcolor or gradient#000000What color you want your QR code to be. Use the demo to try different colors.
backgroundcolor codenullThe background color or null for transparent background.
sizeint200The total size of the final QR code in pixels - it will be a square.

If you want to fill the QR code with a gradient, use the following format:

{
    type: 'radial-gradient', // or 'linear-gradient'
    position: [ ... ],
    colorStops: [
        [ offset0, color0 ],
        [ offset1, color1 ],
        ...
    ]
}

Where the position is specified as in createLinearGradient / createRadialGradient. However, each value is relative to the QR code size, i.e. will be multiplied by that size to yield the absolute position.

Trimmed down to be low weight

The goal of the library is to generate QR codes only. For that reason we have removed all additional code such as GIF image generation, background image support, rendering a label on top, removed some dead code, and freed it from depending on jQuery. Also, the resulting library does not use any global variables, is all strict mode, and relies on modern browser standards instead.

The resultOriginalNew
Lines of code23321556 (-33%)
Size64kB50kB (-22%)
Minified20.6kB11.95kB (-40%)
Gzipped7.3kB4.77kB (-35%)

Building

To install the dependencies run:

npm install

and then to build the project:

npm run build

Keywords

FAQs

Package last updated on 25 May 2020

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