JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q44388F
  • License MIT

Package Exports

  • qrcoder

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (qrcoder) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

QRCoder

QRCoder is a pure browser qrcode generation which is standalone. It is based on a library which build qrcode in various language.

install

npm install qrcoder --save

Example

default

import QRCoder from 'qrcoder'

const qr = new QRCoder({
  data: 'Hi!'
});

// data:image/gif;base64,R0lGODdhUgBS...WQBADs=
const dataURL = qr.getDataURL()

// <img src="data:image/gif;base64,R0lGODdhUgBS...WQBADs=" width="82" height="82"/>
const imgTag = qr.createImgTag()

document.getElementById('placeHolder').innerHTML = imgTag;

more options

import QRCoder from 'qrcoder'

const qr = new QRCoder({
  typeNumber: 4,
  errorCorrectionLevel: 'L',
  mode: 'Byte',
  cellSize: 2,
  margin: 8,
  data: 'Hi!'
});

// data:image/gif;base64,R0lGODdhUgBS...WQBADs=
const dataURL = qr.getDataURL()

// <img src="data:image/gif;base64,R0lGODdhUgBS...WQBADs=" width="82" height="82"/>
const imgTag = qr.createImgTag()

document.getElementById('placeHolder').innerHTML = imgTag;

native

import QRCoder from 'qrcoder'

const typeNumber = 4;
const errorCorrectionLevel = 'L';
const qr = new QRCoder(typeNumber, errorCorrectionLevel);
qr.addData('Hi!');
qr.make();
document.getElementById('placeHolder').innerHTML = qr.createImgTag();

API Documentation

QRCoder Class

QRCoder(options) => QRCoder

Create a QRCoder Object.

Param Type Description
options object options Object

Default options

Param Type Description
options.typeNumber number default: 4
options.errorCorrectionLevel string default: 'L'
options.mode string default: 'Byte'
options.cellSize number default: 2
options.margin number default: 8
options.data string default: undefined

QRCoder(typeNumber, errorCorrectionLevel) => QRCoder

Create a QRCoder Object.

Param Type Description
typeNumber number Type number (1 ~ 40)
errorCorrectionLevel string Error correction level ('L', 'M', 'Q', 'H')

QRCoder.stringToBytes(s) : number[]

Encodes a string into an array of number(byte) using any charset. This function is used by internal. Overwrite this function to encode using a multibyte charset.

Param Type Description
s string string to encode

QRCoder

addData(data, mode) => void

Add a data to encode.

Param Type Description
data string string to encode
mode string Mode ('Numeric', 'Alphanumeric', 'Byte'(default), 'Kanji')

make() => void

Make a QR Code.

getModuleCount() => number

The number of modules(cells) for each orientation. [Note] call make() before this function.

isDark(row, col) => boolean

The module at row and col is dark or not. [Note] call make() before this function.

Param Type Description
row number 0 ~ moduleCount - 1
col number 0 ~ moduleCount - 1

getDataURL(cellSize, margin) => string

createImgTag(cellSize, margin) => string

createSvgTag(cellSize, margin) => string

createTableTag(cellSize, margin) => string

Helper functions for HTML. [Note] call make() before these functions.

Param Type Description
cellSize number default: 2
margin number default: cellSize * 4

License

MIT