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

dfx-qrcode

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dfx-qrcode

tiny and simple-to-use Angular QR-Code generator library

  • 3.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

dfx-qrcode

dfx-qrcode is a tiny and simple-to-use Angular QR-Code generator library.

npm version npm downloads per week npm bundle size

Features

  • ESM based
  • Tiny (~ 10.2kB minified + gzipped)
  • Accessible
  • Server Side Rendering (Angular Universal)
  • Standalone Component API
  • Supports Canvas, PNG and SVG

Version compatibility

Angulardfx-qrcode
18.x.x3.x.x
17.x.x2.x.x
16.x.x1.x.x

Installation

  • npm
    npm install dfx-qrcode
    
  • pnpm
    pnpm install dfx-qrcode
    

Usage

Standalone Components

import { QRCodeComponent } from 'dfx-qrcode';

@Component({
  standalone: true,
  selector: 'app-root',
  template: ` <qrcode data="hello" /> `,
  imports: [QRCodeComponent],
})
export class AppComponent {}

Module

import { QRCodeComponent } from 'dfx-qrcode';

@NgModule({
  declaration: [AppComponent],
  imports: [QRCodeComponent],
})
export class AppModule {}

@Component({
  selector: 'app-root',
  template: ` <qrcode data="hello" /> `,
})
export class AppComponent {}

Configuration

Standalone Components

import {
  provideQRCode,
  QRCodeComponent,
  withAllowEmptyString,
  withColorDark,
  withColorLight,
  withElementType,
  withErrorCorrectionLevel,
  withImage,
  withImageHeight,
  withImageSrc,
  withImageWidth,
  withMargin,
  withSize,
  withVersion,
} from 'dfx-qrcode';

@Component({
  // ...
  standalone: true,
  imports: [QRCodeComponent],
  providers: [
    provideQRCode(
      withAllowEmptyString(false),
      withColorDark('#000000'),
      withColorLight('#FFFFFF'),
      withCssClass('qrcode'),
      withElementType('img'),
      withErrorCorrectionLevel('L'),
      withMargin(4),
      withImage(withImageSrc('assets/logo.png'), withImageWidth(40), withImageHeight(40)),
      withVersion(-1),
      withSize(5),
    ),
  ],
  template: ` <qrcode data="hello" /> `,
  // ...
})
export class AppComponent {}

Module

import {
  provideQRCode,
  QRCodeComponent,
  withAllowEmptyString,
  withColorDark,
  withColorLight,
  withElementType,
  withErrorCorrectionLevel,
  withImage,
  withImageHeight,
  withImageSrc,
  withImageWidth,
  withMargin,
  withSize,
  withVersion,
} from 'dfx-qrcode';

@NgModule({
  declaration: [AppComponent],
  imports: [QRCodeComponent],
  providers: [
    provideQRCode(
      withAllowEmptyString(false),
      withColorDark('#000000'),
      withColorLight('#FFFFFF'),
      withCssClass('qrcode'),
      withElementType('img'),
      withErrorCorrectionLevel('L'),
      withMargin(4),
      withImage(withImageSrc('assets/logo.png'), withImageWidth(40), withImageHeight(40)),
      withVersion(-1),
      withSize(5),
    ),
  ],
})
export class AppModule {}

On component usage

@Component({
  // ...
  selector: 'app-root',
  template: `
    <qrcode
      [data]="'hello'"
      [allowEmptyString]="true"
      [elementType]="'img'"
      [errorCorrectionLevel]="'L'"
      [ariaLabel]="'Description of QR-Code'"
      [title]="'Description of QR-Code'"
      [alt]="'Description of QR-Code'"
      [cssClass]="'qrcode'"
      [colorDark]="'#000000'"
      [colorLight]="'#FFFFFF'"
      [margin]="4"
      [size]="5"
      [version]="-1"
      [imageSrc]="'assets/logo.png'"
      [imageWidth]="40"
      [imageHeight]="40"
    />
  `,
  // ...
})
export class AppComponent {}

Parameters

NameTypeDefault valueDescription
allowEmptyStringbooleanfalseDefine if empty or undefined strings should be converted to a space (" ") or throw an error.
elementType'img' | 'canvas' | 'svg'imgDefine if the QR-Code should be rendered as HTMLImageElement or HTMLCanvasElement
errorCorrectionLevel'L' | 'M' | 'Q' | 'H'LDefine the error correction level
cssClassstringqrcodeDefine a css class for the wrapper element of the QR-Code
colorDarkHex color#000000Define the color of the dark elements
colorLightHex color#FFFFFFDefined the color of the light elements
marginnumber4Define the margin around the QR-Code in px
sizenumber5Define the size of the modules of the QR-Code in px
versionnumber-1Define the QR-Code version. -1 means auto-select
ariaLabelstring | undefinedundefinedString which should be set as aria-label tag
titlestring | undefinedundefinedString which should be set as title tag
altstring | undefinedundefinedString which should be set as alt tag
imageSrcstring | undefinedundefinedPath to image displayed in the QR-Code center
imageHeightnumber | undefinedundefinedHeight of center image in px
imageWidthnumber | undefinedundefinedWidth of center image in px

Error correction level

Error correction capability allows to successfully scan a QR Code even if the symbol is dirty or damaged. Four levels are available to choose according to the operating environment.

Higher levels offer a better error resistance but reduce the symbol's capacity.
If the chances that the QR Code symbol may be corrupted are low (for example if it is showed through a monitor) is possible to safely use a low error level such as Low or Medium.

Possible levels are shown below:

LevelError resistance
L (Low)~7%
M (Medium)~15%
Q (Quartile)~25%
H (High)~30%

The percentage indicates the maximum amount of damaged surface after which the symbol becomes unreadable.

If not specified, the default value is L.

QR Code capacity

Capacity depends on symbol version and error correction level. Also encoding modes may influence the amount of storable data.

The QR Code versions range from version 1 to version 40.
Each version has a different number of modules (black and white dots), which define the symbol's size. For version 1 they are 21x21, for version 2 25x25 e so on. Higher is the version, more are the storable data, and of course bigger will be the QR Code symbol.

The table below shows the maximum number of storable characters in each encoding mode and for each error correction level.

ModeLMQH
Numeric7089559639933057
Alphanumeric4296339124201852
Byte2953233116631273

If no version is specified, the more suitable value will be used. Unless a specific version is required, this option is not needed.

By Dafnik

Keywords

FAQs

Package last updated on 14 Jul 2024

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