papnkukn / qrcode-svg

A simple QR Code generator in pure JavaScript / node.js library
MIT License
451 stars 92 forks source link

Support Numeric and Alphanumeric encoding modes #13

Open glumb opened 4 years ago

glumb commented 4 years ago

QR codes can also be encoded with numeric or alphanumeric encoding for optimal data density. Quoting https://en.wikipedia.org/wiki/QR_code

Input mode Bits/char. Possible characters, default encoding
Numeric only 3⅓ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Alphanumeric 0–9, A–Z (upper-case only), space, $, %, *, +, -, ., /, :
Binary/byte 8 ISO 8859-1
Kanji/kana 13 Shift JIS X 0208

Is this done automatically in this library? How can I configure what encoding should be used?

ghost commented 3 years ago

Based on a quick test, it looks like alphanumeric encoding is not automatic.

ghost commented 3 years ago

This library worked well for me: https://github.com/soldair/node-qrcode

const QRCode = require('qrcode')
QRCode.toString(
  'TEXT',
  { type: 'svg', errorCorrectionLevel: 'M', margin: 0 },
  function (error, string) {
    if (error) console.error(error)
    console.log(string)
  }
)