kazuhikoarase / qrcode-generator

QR Code Generator implementation in JavaScript, Java and more.
https://kazuhikoarase.github.io/qrcode-generator/js/demo/
MIT License
2.1k stars 677 forks source link

Importing the Kanji support file in Node.js #47

Closed no23reason closed 6 years ago

no23reason commented 6 years ago

Hello, I am confused as on how to import the Kanji qrcode_SJIS file in Node.js. When I tried:

const qrcode = require("qrcode-generator")
require("qrcode-generator/qrcode_SJIS")
const qr = qrcode(0, "L");
qr.addData(`敦煌天空的沙礫帶著我們的記憶`, `Kanji`);
qr.make();
console.log(qr.createSvgTag());

it died on an reference error in the qrcode_SJIS saying that qrcode is not defined 😕 Can you please provide an example on how to do this?

kazuhikoarase commented 6 years ago

Hi,

There are two problems.

  1. qrcode_SJIS.js is not ready for nodejs
  2. Chinese characters are similar with Japanese but not SJIS and so you should use Bytes/UTF-8 instead of Kanji/SJIS.

Try this. https://runkit.com/embed/xl2ig6ti9z7e

const qrcode = require("qrcode-generator")
//require("qrcode-generator/qrcode_SJIS")
qrcode.stringToBytes = qrcode.stringToBytesFuncs['UTF-8'];
const qr = qrcode(0, "L");
//qr.addData(`敦煌天空的沙礫帶著我們的記憶`, `Kanji`);
qr.addData(`敦煌天空的沙礫帶著我們的記憶`);
qr.make();
qr.createSvgTag();
no23reason commented 6 years ago

Thank you for your reply, this works for me. Closing.