@types/qrcode

  • Version 1.5.5
  • Published
  • 18.4 kB
  • 1 dependency
  • MIT license

Install

npm i @types/qrcode
yarn add @types/qrcode
pnpm add @types/qrcode

Overview

TypeScript definitions for qrcode

Index

Functions

function create

create: (text: string | QRCodeSegment[], options?: QRCodeOptions) => QRCode;
  • Creates QR Code symbol and returns a qrcode object.

    Parameter text

    Text to encode or a list of objects describing segments.

function toBuffer

toBuffer: {
(
text: string | QRCodeSegment[],
callback: (error: Error | null | undefined, buffer: Buffer) => void
): void;
(
text: string | QRCodeSegment[],
options?: QRCodeToBufferOptions
): Promise<Buffer>;
(
text: string | QRCodeSegment[],
options: QRCodeToBufferOptions,
callback: (error: Error, buffer: Buffer) => void
): void;
};
  • Returns a Buffer containing a representation of the QR Code image. Only works with png format.

function toCanvas

toCanvas: {
(
canvasElement: HTMLCanvasElement,
text: string | QRCodeSegment[],
callback: (error: Error | null | undefined) => void
): void;
(
canvasElement: HTMLCanvasElement,
text: string | QRCodeSegment[],
options?: QRCodeRenderersOptions
): Promise<void>;
(
canvasElement: HTMLCanvasElement,
text: string | QRCodeSegment[],
options: QRCodeRenderersOptions,
callback: (error: Error) => void
): void;
(
text: string | QRCodeSegment[],
callback: (error: Error, canvas: HTMLCanvasElement) => void
): void;
(
text: string | QRCodeSegment[],
options?: QRCodeRenderersOptions
): Promise<HTMLCanvasElement>;
(
text: string | QRCodeSegment[],
options: QRCodeRenderersOptions,
callback: (error: Error, canvas: HTMLCanvasElement) => void
): void;
(
canvas: any,
text: string | QRCodeSegment[],
callback: (error: Error) => void
): void;
(
canvas: any,
text: string | QRCodeSegment[],
options?: QRCodeRenderersOptions
): Promise<void>;
(
canvas: any,
text: string | QRCodeSegment[],
options: QRCodeRenderersOptions,
callback: (error: Error) => void
): void;
};
  • Draws qr code symbol to canvas.

  • Draws qr code symbol to node canvas.

function toDataURL

toDataURL: {
(
canvasElement: HTMLCanvasElement,
text: string | QRCodeSegment[],
callback: (error: Error | null | undefined, url: string) => void
): void;
(
canvasElement: HTMLCanvasElement,
text: string | QRCodeSegment[],
options?: QRCodeToDataURLOptions
): Promise<string>;
(
canvasElement: HTMLCanvasElement,
text: string | QRCodeSegment[],
options: QRCodeToDataURLOptions,
callback: (error: Error, url: string) => void
): void;
(
text: string | QRCodeSegment[],
callback: (error: Error, url: string) => void
): void;
(
text: string | QRCodeSegment[],
options?: QRCodeToDataURLOptions
): Promise<string>;
(
text: string | QRCodeSegment[],
options: QRCodeToDataURLOptions,
callback: (error: Error, url: string) => void
): void;
};
  • Returns a Data URI containing a representation of the QR Code image.

function toFile

toFile: {
(
path: string,
text: string | QRCodeSegment[],
callback: (error: Error | null | undefined) => void
): void;
(
path: string,
text: string | QRCodeSegment[],
options?: QRCodeToFileOptions
): Promise<void>;
(
path: string,
text: string | QRCodeSegment[],
options: QRCodeToFileOptions,
callback: (error: Error) => void
): void;
};
  • Saves QR Code to image file. If options.type is not specified, the format will be guessed from file extension.

function toFileStream

toFileStream: {
(
stream: stream.Writable,
text: string | QRCodeSegment[],
callback: (error: Error | null | undefined) => void
): void;
(
stream: stream.Writable,
text: string | QRCodeSegment[],
options?: QRCodeToFileStreamOptions
): Promise<void>;
(
stream: stream.Writable,
text: string | QRCodeSegment[],
options: QRCodeToFileStreamOptions,
callback: (error: Error) => void
): void;
};
  • Writes QR Code image to stream. Only works with png format for now.

function toString

toString: {
(
text: string | QRCodeSegment[],
callback: (error: Error | null | undefined, string: string) => void
): void;
(
text: string | QRCodeSegment[],
options?: QRCodeToStringOptions
): Promise<string>;
(
text: string | QRCodeSegment[],
options: QRCodeToStringOptions,
callback: (error: Error, string: string) => void
): void;
};
  • Returns a string representation of the QR Code.

Interfaces

interface AlphanumericData

interface AlphanumericData extends DataSegment {}

    property data

    data: string;

      property mode

      mode: Mode<'Alphanumeric'>;

        interface BitMatrix

        interface BitMatrix {}
        • Helper class to handle QR Code symbol modules.

        property data

        data: Uint8Array;

          property reservedBit

          reservedBit: Uint8Array;

            property size

            size: number;
            • Symbol size.

            method get

            get: (row: number, col: number) => number;
            • Bit value at specified location.

            method isReserved

            isReserved: (row: number, col: number) => number;
            • Check if bit at specified location is reserved.

            method set

            set: (row: number, col: number, value: number, reserved: boolean) => void;
            • Set bit value at specified location If reserved flag is set, this bit will be ignored during masking process.

            method xor

            xor: (row: number, col: number, value: number) => void;
            • Applies xor operator at specified location (used during masking process).

            interface ByteData

            interface ByteData extends DataSegment {}

              property data

              data: Uint8Array;

                property mode

                mode: Mode<'Byte'>;

                  interface DataSegment

                  interface DataSegment {}

                    method getBitsLength

                    getBitsLength: () => number;

                      method getLength

                      getLength: () => number;

                        interface ErrorCorrectionLevel

                        interface ErrorCorrectionLevel {}

                          property bit

                          bit: 0 | 1 | 2 | 3;

                            interface KanjiData

                            interface KanjiData extends DataSegment {}

                              property data

                              data: string;

                                property mode

                                mode: Mode<'Kanji'>;

                                  interface Mode

                                  interface Mode<TModeId extends ModeId = ModeId> {}

                                    property bit

                                    bit: number;

                                      property ccBits

                                      ccBits: readonly number[];

                                        property id

                                        id: TModeId;

                                          interface NumericData

                                          interface NumericData extends DataSegment {}

                                            property data

                                            data: string;

                                              property mode

                                              mode: Mode<'Numeric'>;

                                                interface QRCode

                                                interface QRCode {}

                                                  property errorCorrectionLevel

                                                  errorCorrectionLevel: ErrorCorrectionLevel;
                                                  • Error Correction Level

                                                  property maskPattern

                                                  maskPattern: QRCodeMaskPattern | undefined;
                                                  • Calculated Mask pattern

                                                  property modules

                                                  modules: BitMatrix;
                                                  • BitMatrix class with modules data

                                                  property segments

                                                  segments: GeneratedQRCodeSegment[];
                                                  • Generated segments

                                                  property version

                                                  version: number;
                                                  • Calculated QR Code version

                                                  interface QRCodeAlphanumericSegment

                                                  interface QRCodeAlphanumericSegment {}

                                                    property data

                                                    data: string;

                                                      property mode

                                                      mode: 'alphanumeric';

                                                        interface QRCodeByteSegment

                                                        interface QRCodeByteSegment {}

                                                          property data

                                                          data: Buffer | Uint8ClampedArray | Uint8Array;

                                                            property mode

                                                            mode: 'byte';

                                                              interface QRCodeKanjiSegment

                                                              interface QRCodeKanjiSegment {}

                                                                property data

                                                                data: string;

                                                                  property mode

                                                                  mode: 'kanji';

                                                                    interface QRCodeNumericSegment

                                                                    interface QRCodeNumericSegment {}

                                                                      property data

                                                                      data: string | number;

                                                                        property mode

                                                                        mode: 'numeric';

                                                                          interface QRCodeOptions

                                                                          interface QRCodeOptions {}

                                                                            property errorCorrectionLevel

                                                                            errorCorrectionLevel?: QRCodeErrorCorrectionLevel | undefined;
                                                                            • Error correction level. 'M'

                                                                            property maskPattern

                                                                            maskPattern?: QRCodeMaskPattern | undefined;
                                                                            • Mask pattern used to mask the symbol.

                                                                              If not specified the more suitable value will be calculated.

                                                                            property toSJISFunc

                                                                            toSJISFunc?: QRCodeToSJISFunc | undefined;
                                                                            • Helper function used internally to convert a kanji to its Shift JIS value. Provide this function if you need support for Kanji mode.

                                                                            property version

                                                                            version?: number | undefined;
                                                                            • QR Code version. If not specified the more suitable value will be calculated.

                                                                            interface QRCodeRenderersOptions

                                                                            interface QRCodeRenderersOptions extends QRCodeOptions {}

                                                                              property color

                                                                              color?:
                                                                              | {
                                                                              /**
                                                                              * Color of dark module. Value must be in hex format (RGBA).
                                                                              * Note: dark color should always be darker than `color.light`.
                                                                              * @default '#000000ff'
                                                                              */
                                                                              dark?: string | undefined;
                                                                              /**
                                                                              * Color of light module. Value must be in hex format (RGBA).
                                                                              * @default '#ffffffff'
                                                                              */
                                                                              light?: string | undefined;
                                                                              }
                                                                              | undefined;

                                                                                property margin

                                                                                margin?: number | undefined;
                                                                                • Define how much wide the quiet zone should be. 4

                                                                                property scale

                                                                                scale?: number | undefined;
                                                                                • Scale factor. A value of 1 means 1px per modules (black dots). 4

                                                                                property width

                                                                                width?: number | undefined;
                                                                                • Forces a specific width for the output image. If width is too small to contain the qr symbol, this option will be ignored. Takes precedence over scale.

                                                                                interface QRCodeToBufferOptions

                                                                                interface QRCodeToBufferOptions extends QRCodeRenderersOptions {}

                                                                                  property rendererOpts

                                                                                  rendererOpts?:
                                                                                  | {
                                                                                  /**
                                                                                  * Compression level for deflate.
                                                                                  * @default 9
                                                                                  */
                                                                                  deflateLevel?: number | undefined;
                                                                                  /**
                                                                                  * Compression strategy for deflate.
                                                                                  * @default 3
                                                                                  */
                                                                                  deflateStrategy?: number | undefined;
                                                                                  }
                                                                                  | undefined;

                                                                                    property type

                                                                                    type?: QRCodeBufferType | undefined;
                                                                                    • Output format. Only png supported for Buffer.

                                                                                    interface QRCodeToDataURLOptionsJpegWebp

                                                                                    interface QRCodeToDataURLOptionsJpegWebp extends QRCodeRenderersOptions {}

                                                                                      property rendererOpts

                                                                                      rendererOpts?:
                                                                                      | {
                                                                                      /**
                                                                                      * A number between `0` and `1` indicating image quality.
                                                                                      * @default 0.92
                                                                                      */
                                                                                      quality?: number | undefined;
                                                                                      }
                                                                                      | undefined;

                                                                                        property type

                                                                                        type: 'image/jpeg' | 'image/webp';
                                                                                        • Data URI format. 'image/png'

                                                                                        interface QRCodeToDataURLOptionsOther

                                                                                        interface QRCodeToDataURLOptionsOther extends QRCodeRenderersOptions {}

                                                                                          property type

                                                                                          type?: Exclude<QRCodeDataURLType, 'image/jpeg' | 'image/webp'> | undefined;
                                                                                          • Data URI format. 'image/png'

                                                                                          interface QRCodeToFileOptionsOther

                                                                                          interface QRCodeToFileOptionsOther extends QRCodeRenderersOptions {}

                                                                                            property type

                                                                                            type: Exclude<QRCodeFileType, 'png'> | undefined;
                                                                                            • Output format. 'png'

                                                                                            interface QRCodeToFileOptionsPng

                                                                                            interface QRCodeToFileOptionsPng extends QRCodeRenderersOptions {}

                                                                                              property rendererOpts

                                                                                              rendererOpts?:
                                                                                              | {
                                                                                              /**
                                                                                              * Compression level for deflate.
                                                                                              * @default 9
                                                                                              */
                                                                                              deflateLevel?: number | undefined;
                                                                                              /**
                                                                                              * Compression strategy for deflate.
                                                                                              * @default 3
                                                                                              */
                                                                                              deflateStrategy?: number | undefined;
                                                                                              }
                                                                                              | undefined;

                                                                                                property type

                                                                                                type?: 'png' | undefined;
                                                                                                • Output format. 'png'

                                                                                                interface QRCodeToFileStreamOptions

                                                                                                interface QRCodeToFileStreamOptions extends QRCodeRenderersOptions {}

                                                                                                  property rendererOpts

                                                                                                  rendererOpts?:
                                                                                                  | {
                                                                                                  /**
                                                                                                  * Compression level for deflate.
                                                                                                  * @default 9
                                                                                                  */
                                                                                                  deflateLevel?: number | undefined;
                                                                                                  /**
                                                                                                  * Compression strategy for deflate.
                                                                                                  * @default 3
                                                                                                  */
                                                                                                  deflateStrategy?: number | undefined;
                                                                                                  }
                                                                                                  | undefined;

                                                                                                    property type

                                                                                                    type?: QRCodeFileStreamType | undefined;
                                                                                                    • Output format. Only png supported for file stream.

                                                                                                    interface QRCodeToStringOptionsOther

                                                                                                    interface QRCodeToStringOptionsOther extends QRCodeRenderersOptions {}

                                                                                                      property type

                                                                                                      type?: Exclude<QRCodeStringType, 'terminal'> | undefined;
                                                                                                      • Output format. 'utf8'

                                                                                                      interface QRCodeToStringOptionsTerminal

                                                                                                      interface QRCodeToStringOptionsTerminal extends QRCodeRenderersOptions {}

                                                                                                        property small

                                                                                                        small?: boolean | undefined;
                                                                                                        • Outputs smaller QR code. false

                                                                                                        property type

                                                                                                        type: 'terminal';
                                                                                                        • Output format. 'utf8'

                                                                                                        Type Aliases

                                                                                                        type GeneratedQRCodeSegment

                                                                                                        type GeneratedQRCodeSegment = NumericData | AlphanumericData | ByteData | KanjiData;

                                                                                                          type ModeId

                                                                                                          type ModeId = 'Numeric' | 'Alphanumeric' | 'Byte' | 'Kanji';

                                                                                                            type QRCodeBufferType

                                                                                                            type QRCodeBufferType = 'png';

                                                                                                              type QRCodeDataURLType

                                                                                                              type QRCodeDataURLType = 'image/png' | 'image/jpeg' | 'image/webp';

                                                                                                                type QRCodeErrorCorrectionLevel

                                                                                                                type QRCodeErrorCorrectionLevel =
                                                                                                                | 'low'
                                                                                                                | 'medium'
                                                                                                                | 'quartile'
                                                                                                                | 'high'
                                                                                                                | 'L'
                                                                                                                | 'M'
                                                                                                                | 'Q'
                                                                                                                | 'H';

                                                                                                                  type QRCodeFileStreamType

                                                                                                                  type QRCodeFileStreamType = 'png';

                                                                                                                    type QRCodeFileType

                                                                                                                    type QRCodeFileType = 'png' | 'svg' | 'utf8';

                                                                                                                      type QRCodeMaskPattern

                                                                                                                      type QRCodeMaskPattern = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;

                                                                                                                        type QRCodeSegment

                                                                                                                        type QRCodeSegment =
                                                                                                                        | QRCodeNumericSegment
                                                                                                                        | QRCodeAlphanumericSegment
                                                                                                                        | QRCodeByteSegment
                                                                                                                        | QRCodeKanjiSegment
                                                                                                                        | {
                                                                                                                        mode?: never;
                                                                                                                        data: string | Buffer | Uint8ClampedArray | Uint8Array;
                                                                                                                        };

                                                                                                                          type QRCodeSegmentMode

                                                                                                                          type QRCodeSegmentMode = 'alphanumeric' | 'numeric' | 'byte' | 'kanji';

                                                                                                                            type QRCodeStringType

                                                                                                                            type QRCodeStringType = 'utf8' | 'svg' | 'terminal';

                                                                                                                              type QRCodeToDataURLOptions

                                                                                                                              type QRCodeToDataURLOptions =
                                                                                                                              | QRCodeToDataURLOptionsJpegWebp
                                                                                                                              | QRCodeToDataURLOptionsOther;

                                                                                                                                type QRCodeToFileOptions

                                                                                                                                type QRCodeToFileOptions = QRCodeToFileOptionsPng | QRCodeToFileOptionsOther;

                                                                                                                                  type QRCodeToSJISFunc

                                                                                                                                  type QRCodeToSJISFunc = (codePoint: string) => number;

                                                                                                                                    type QRCodeToStringOptions

                                                                                                                                    type QRCodeToStringOptions =
                                                                                                                                    | QRCodeToStringOptionsTerminal
                                                                                                                                    | QRCodeToStringOptionsOther;

                                                                                                                                      Package Files (1)

                                                                                                                                      Dependencies (1)

                                                                                                                                      Dev Dependencies (0)

                                                                                                                                      No dev dependencies.

                                                                                                                                      Peer Dependencies (0)

                                                                                                                                      No peer dependencies.

                                                                                                                                      Badge

                                                                                                                                      To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                      You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/qrcode.

                                                                                                                                      • Markdown
                                                                                                                                        [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/qrcode)
                                                                                                                                      • HTML
                                                                                                                                        <a href="https://www.jsdocs.io/package/@types/qrcode"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>