New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@qrcode-js/core

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@qrcode-js/core

An awesome but simple QR code generator written in JavaScript.

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Awesome-qr.js

license

An awesome but simple QR code generator written in JavaScript.

Most of the work is based on the work by @SumiMakito

TODO

Contents

Getting Started

This project is divided in three projects.

The "core" project is a platform-agnostic implementation to draw a QR on a canvas

The "node" project is a wrapper around the "core" project using "node-canvas" as backend

The "browser" project is a wrapper around the "core" project using the buil'in canvas in the browsers

Please install one of "node" or "browser" package

Do not install the "core" package unless you know what you0re doing

Options

Options is an object that you can pass to the generator to customize your QR code.

type Options = {
  text: string;
  size?: number;
  margin?: number;
  correctLevel?: number;
  maskPattern?: number;
  version?: number;
  components?: ComponentOptions;
  colorDark?: string;
  colorLight?: string;
  autoColor?: boolean;
  backgroundImage?: string | Buffer;
  backgroundDimming?: string;
  gifBackground?: ArrayBuffer;
  whiteMargin?: boolean;
  logoImage?: string | Buffer;
  logoScale?: number;
  logoMargin?: number;
  logoCornerRadius?: number;
};

text

Type string

Text to be encoded in the QR code.


size

Type number?

Default 400

Size of the QR code in pixel.


margin

Type number?

Default 20

Size of margins around the QR code body in pixel.


correctLevel

Type number?

Default QRErrorCorrectLevel.M ~> 0

For more information, please refer to Error correction feature | QRcode.com | DENSO WAVE.

Error correction level of the QR code.


maskPattern

Type number?

This is an advanced option.

Leave untouched to let the code decide which mask pattern to use.

Specify the mask pattern to be used in QR code encoding.

Accepts a value provided by QRMaskPattern.

To find out all eight mask patterns, please refer to Wikipedia File:QR_Code_Mask_Patterns.svg

For more information, please refer to Reed–Solomon codes for coders: Masking.


version

Type number?

This is an advanced option.

Leave untouched to let the code decide which version to use.

Specify the version to be used in QR code encoding.

Accepts an integer in range [1, 40].

⚠️   An error might occurs if the specified version does not have enough space for the input data.

For more information, please refer to Information capacity and versions of QR Code | QRcode.com | DENSO WAVE.


components

Type ComponentOptions

Controls the appearances of parts in the QR code.

Read section ComponentOptions to learn more.


colorDark

Type string?, CSS <color>

Default "#000000"

For more information about CSS <color>, please refer to <color> - CSS: Cascading Style Sheets | MDN

Color of the blocks on the QR code.


colorLight

Type string?, CSS <color>

Default "#ffffff"

Color of the empty areas on the QR code.


autoColor

Type boolean?

Default true

Automatically calculate the colorDark value from the QR code's background.


backgroundImage

Type (string|Buffer)?

Default undefined

Background image to be used in the QR code.

Accepts a data: string in web browsers or a Buffer in Node.js.


backgroundDimming

Type string?, CSS <color>

Default "rgba(0, 0, 0, 0)"

Color of the dimming mask above the background image.


whiteMargin

Type boolean?

Default true

Use a white margin instead of a transparent one which reveals the background of the QR code on margins.


logoImage

Type (string|Buffer)?

Default undefined

Logo image to be displayed at the center of the QR code.

Accepts a data: string in web browsers or a Buffer in Node.js.

When set to undefined or null, the logo is disabled.


logoScale

Type number?

Default 0.2

Ratio of the logo size to the QR code size.


logoMargin

Type number?

Default 6

Size of margins around the logo image in pixels.


logoCornerRadius

Type number?

Default 0

Ratio of the logo corner radius. 0 means no round. 1 means max round


gradient

Type (ctx: CanvasRenderingContext2D, size: number) => CanvasGradient?

Custom function to create a gradient as a foreground color (data blocks and finders). Inside the body you must create a gradient with the provided context, add stop colors and return it. Below is an example.

new AwesomeQR({
  gradient: (ctx: CanvasRenderingContext2D, size: number) => {
    // This creates a horizontal gradient from left to right
    const gradient = ctx.createLinearGradient(0, 0, size, 0);
    gradient.addColorStop(0, "red");
    gradient.addColorStop(1, "blue");
    return gradient;
  },
});

drawFunction

Type "telegram" | (( canvasContext: CanvasRenderingContext2D, left: number, top: number, nSize: number, scale: number, round: number, parameters: { isTiming: boolean; isAlignment: boolean; }, otherCells: { top: boolean; left: boolean; right: boolean; bottom: boolean; } ) => undefined)

Accepts either a string or a custom function. As a string it currently accepts only "telegram" mode. As a function here are the parameters:

  • canvasContext: the current drawing context
  • left: how many cells are from the left margin
  • top: how many cells are from the top margin
  • nSize: size in pixels of a single cell
  • scale: scale of data blocks as provided in initial options
  • round: round of data block as provided in initial options
  • parameters: tell if the cell is special (timing or alignment) or regular
  • otherCells: tell if the neighbour cells are empty or full

onEvent

Type ( type: string, canvasContext: CanvasRenderingContext2D, parameters: object ) => undefined

Special function called in certain points when drawing the QR onto the canvas. Might be useful if you have to manipulate the canvas manually. Actually it's called before data is drawed and before the background is applied to the entire canvas

ComponentOptions

ComponentOptions controls the appearances of parts in the QR code.

type ComponentOptions = {
  data?: {
    scale?: number;
    round?: number;
  };
  finder?: {
    round?: number;
  };
};
// default ComponentOptions

{
  data: {
    scale: 1,
    round: 0,
  },
  finder: {
    round: 0,
  }
}

scale

Type number?

Scale factor for blocks in the specified area of the QR code.


round

Type number?

Ratio of rounded corner for finders or data blocks. 0 means no round. 1 means max round (a circle)

Sponsors

Support me here

qrcode-js code is licensed under MIT License.

Copyright (c) 2017-2020 Makito

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
jquery-qrcode
Copyright (c) 2011 Jerome Etienne, http://jetienne.com

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
QRCode for JavaScript
Copyright (c) 2009 Kazuhiko Arase
URL: http://www.d-project.com/
Licensed under the MIT license:
    http://www.opensource.org/licenses/mit-license.php
The word "QR Code" is registered trademark of
DENSO WAVE INCORPORATED
    http://www.denso-wave.com/qrcode/faqpatent-e.html

Keywords

FAQs

Package last updated on 18 Aug 2022

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