• Stars
    star
    197
  • Rank 197,313 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 10 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A pure JavaScript QRCode encode and decode library.

QRCode

A pure JavaScript QRCode encode and decode library.

NPM Version Download Status Tree Shakeable Side Effect Snyk Vulnerabilities License

QRCode guide and demo

QRCode guide

QRCode example

Modify from kazuhikoarase/qrcode-generator and cozmo/jsQR

Usage

Encoder

import { Byte, Encoder, Hanzi, Kanji } from '@nuintun/qrcode';

const encoder = new Encoder({
  level: 'H'
});

const qrcode = encoder.encode(
  // Hanzi
  new Hanzi('你好世界'),
  // Byte
  new Byte('\nhello world\n'),
  // Kanji
  new Kanji('こんにちは世界')
);

console.log(qrcode.toDataURL());

Interface

declare type Level = 'L' | 'M' | 'Q' | 'H';

declare type RGB = [R: number, G: number, B: number];

declare type FNC1 = [mode: 'GS1'] | [mode: 'AIM', indicator: number];

declare class Charset {
  public static readonly CP437: Charset;
  public static readonly ISO_8859_1: Charset;
  public static readonly ISO_8859_2: Charset;
  public static readonly ISO_8859_3: Charset;
  public static readonly ISO_8859_4: Charset;
  public static readonly ISO_8859_5: Charset;
  public static readonly ISO_8859_6: Charset;
  public static readonly ISO_8859_7: Charset;
  public static readonly ISO_8859_8: Charset;
  public static readonly ISO_8859_9: Charset;
  public static readonly ISO_8859_10: Charset;
  public static readonly ISO_8859_11: Charset;
  public static readonly ISO_8859_13: Charset;
  public static readonly ISO_8859_14: Charset;
  public static readonly ISO_8859_15: Charset;
  public static readonly ISO_8859_16: Charset;
  public static readonly SJIS: Charset;
  public static readonly CP1250: Charset;
  public static readonly CP1251: Charset;
  public static readonly CP1252: Charset;
  public static readonly CP1256: Charset;
  public static readonly UTF_16BE: Charset;
  public static readonly UTF_8: Charset;
  public static readonly ASCII: Charset;
  public static readonly BIG5: Charset;
  public static readonly GB18030: Charset;
  public static readonly EUC_KR: Charset;
  public constructor(label: string, ...values: number[]);
}

declare class Matrix {
  public size: number;
  public get(x: number, y: number): number;
}

declare interface DataURLOptions {
  margin?: number;
  foreground?: RGB;
  background?: RGB;
}

declare class QRCode {
  public level: Level;
  public mask: number;
  public matrix: Matrix;
  public version: number;
  public toDataURL(moduleSize: number, options?: DataURLOptions): string;
}

declare class Alphanumeric {
  public constructor(content: string);
}

declare class Byte {
  public constructor(content: string, charset?: Charset);
}

declare class Hanzi {
  public constructor(content: string);
}

declare class Kanji {
  public constructor(content: string);
}

declare class Numeric {
  public constructor(content: string);
}

declare interface Options {
  level?: Level;
  hints?: { fnc1?: FNC1 };
  version?: 'Auto' | number;
  encode?: (content: string, charset: Charset) => Uint8Array;
}

declare class Encoder {
  public constructor(options?: Options);
  public encode(...segments: (Alphanumeric | Byte | Hanzi | Kanji | Numeric)[]): QRCode;
}

Decoder

import { Decoder } from '@nuintun/qrcode';

const qrcode = new Decoder();

qrcode
  .scan('https://nuintun.github.io/qrcode/examples/qrcode.jpg')
  .then(result => {
    console.log(result.data);
  })
  .catch(error => {
    console.error(error);
  });
Constructor
  • new Decoder(options?: Options): Decoder

    • canOverwriteImage?: boolean
    • inversionAttempts?: 'dontInvert' | 'onlyInvert' | 'attemptBoth' | 'invertFirst'
    • greyScaleWeights?: { red: number, green: number, blue: number, useIntegerApproximation?: boolean }
Methods
  • setOptions(options: Options): Decoder

    • Set decode options.
      • canOverwriteImage?: boolean
      • inversionAttempts?: 'dontInvert' | 'onlyInvert' | 'attemptBoth' | 'invertFirst'
      • greyScaleWeights?: { red: number, green: number, blue: number, useIntegerApproximation?: boolean }
  • scan(src: string): Promise<DecoderResult>

    • Decode a qrcode from image src.
    • Notice: support browser environment only.
  • decode(data: Uint8ClampedArray, width: number, height: number): DecoderResult

    • Decode a qrcode from image data.

More Repositories

1

node-adodb

A node.js javascript client implementing the ADODB protocol on windows.
JavaScript
184
star
2

mailtip

A jquery email autocomplete plugin
JavaScript
17
star
3

command-manager

A command manager app
JavaScript
15
star
4

x-qrcode

A powerfull chrome extension for qrcode encoding and decoding.
JavaScript
9
star
5

koa-files

A static files serving middleware for koa.
TypeScript
8
star
6

grunt-cmd

A tools for cmd transport and deploy
JavaScript
5
star
7

webpack-dev-service

A koa 2 middleware for webpack development and hot reloading.
TypeScript
5
star
8

webpack-entry-manifest-plugin

Webpack plugin for generating an asset manifest with grouped entry chunks.
JavaScript
5
star
9

webpack-antd-builder

A webpack antd build configure tools.
TypeScript
4
star
10

payday2

payday2 mods
Lua
3
star
11

gulp-sample

The gulp-cmd and gulp-css sample
JavaScript
3
star
12

gulp-cmd

A gulp plugin for cmd transport and concat
JavaScript
3
star
13

react-nest-router

Declarative routing for React.
TypeScript
3
star
14

fetch

A pure JavaScript window.fetch polyfill.
JavaScript
2
star
15

inquirer-datepicker

Datepicker prompt for inquirer.js
JavaScript
2
star
16

URI

A simple WHATWG URI parser.
TypeScript
2
star
17

file-send

A http/https file send
JavaScript
2
star
18

webpack-glob-entries-plugin

Provides a way to glob for entry files in Webpack watch and non-watch modes.
JavaScript
2
star
19

swc-plugin-import

Modularly import plugin for swc.
JavaScript
2
star
20

bundler

An async file dependency bundle parser
TypeScript
1
star
21

antd-site

Antd site
TypeScript
1
star
22

react-nest-router-examples

React nest router examples.
JavaScript
1
star
23

vguilocalizationtool

Valve Source Engine game language resource file localization tool
C#
1
star
24

svgc-loader

SVGO jsx loader
TypeScript
1
star
25

html-webpack-bom-plugin

Add utf8 BOM for the html file.
JavaScript
1
star
26

switch-stream

A stream condition for switch/case
JavaScript
1
star
27

css-modules-types-loader

A webpack loader that dynamically generates TypeScript typings for CSS modules from css-loader.
TypeScript
1
star
28

svgo-loader

svgo loader for webpack.
TypeScript
1
star
29

Buffer

A buffer tool for javascript.
JavaScript
1
star
30

taro-bugs

Taro bugs reproduce.
TypeScript
1
star
31

gulp-css

A gulp plugin for css transport and concat
JavaScript
1
star
32

babel-issues

Babel issues.
JavaScript
1
star
33

taro-cases

Taro case
JavaScript
1
star
34

web-shell

A web shell tools.
TypeScript
1
star
35

wxwork-api

WXWork API for the node.js
JavaScript
1
star
36

LinkedList

A typescript array-like doubly linked list.
TypeScript
1
star
37

useVirtual

😎 ♻️ A tiny React hook for rendering large datasets like a breeze.
TypeScript
1
star
38

cmd-deps

Transform cmd and get cmd dependences
JavaScript
1
star
39

AssemblyBuffer

A buffer tool using WebAssembly.
TypeScript
1
star
40

impsorter-vscode

A vscode extension to sort selected import statements.
TypeScript
1
star
41

style-tokens

A tools can parse css text to css tokens
JavaScript
1
star
42

microtask

A pure JavaScript cross browser microtask
JavaScript
1
star
43

files-extractor

Extract files that have changed between the specified date
JavaScript
1
star
44

koa-interceptors

An Interceptors middleware for koa2
JavaScript
1
star