npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dfx-qrcode

v3.0.0

Published

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

Downloads

483

Readme

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

| Angular | dfx-qrcode | | ------- | ---------- | | 18.x.x | 3.x.x | | 17.x.x | 2.x.x | | 16.x.x | 1.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

| Name | Type | Default value | Description | | -------------------- | ---------------------------- | ----------------- | ----------------------------------------------------------------------------------------------- | | allowEmptyString | boolean | false | Define if empty or undefined strings should be converted to a space (" ") or throw an error. | | elementType | 'img' \| 'canvas' \| 'svg' | img | Define if the QR-Code should be rendered as HTMLImageElement or HTMLCanvasElement | | errorCorrectionLevel | 'L' \| 'M' \| 'Q' \| 'H' | L | Define the error correction level | | cssClass | string | qrcode | Define a css class for the wrapper element of the QR-Code | | colorDark | Hex color | #000000 | Define the color of the dark elements | | colorLight | Hex color | #FFFFFF | Defined the color of the light elements | | margin | number | 4 | Define the margin around the QR-Code in px | | size | number | 5 | Define the size of the modules of the QR-Code in px | | version | number | -1 | Define the QR-Code version. -1 means auto-select | | ariaLabel | string \| undefined | undefined | String which should be set as aria-label tag | | title | string \| undefined | undefined | String which should be set as title tag | | alt | string \| undefined | undefined | String which should be set as alt tag | | imageSrc | string \| undefined | undefined | Path to image displayed in the QR-Code center | | imageHeight | number \| undefined | undefined | Height of center image in px | | imageWidth | number \| undefined | undefined | Width 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:

| Level | Error 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.

| Mode | L | M | Q | H | | ------------ | ---- | ---- | ---- | ---- | | Numeric | 7089 | 5596 | 3993 | 3057 | | Alphanumeric | 4296 | 3391 | 2420 | 1852 | | Byte | 2953 | 2331 | 1663 | 1273 |

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