How to use the qrcode.toString function in qrcode

To help you get started, we’ve selected a few qrcode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dtinth / promptpay-qr / cli.js View on Github external
#!/usr/bin/env node
const qr = require('qrcode')
const argv = require('minimist')(process.argv.slice(2), { string: '_' })
const generatePayload = require('./')
const target = String(argv._[0]).replace(/-/g, '')

if (!/^(0|66)\d{9}|\d{13}$/.test(target)) {
  console.error('Invalid recipient given: expected tax id or phone number')
  process.exit(1)
}

const payload = generatePayload(target, { amount: +argv.amount || +argv._[1] })
console.log(payload)

qr.toString(payload, { type: 'terminal', errorCorrectionLevel: 'L' }, (e, s) => {
  if (e) throw e
  console.log(s)
})
github dtinth / promptpay-qr / webapp / src / QRCode.js View on Github external
update (payload) {
    this.payload = payload
    qr.toString(payload, { type: 'svg', errorCorrectionLevel: 'L' }, (err, svg) => {
      if (err) {
        window.alert('Cannot generate QR code: ' + String(err))
        return
      }
      if (this.payload === payload) {
        const sizeMatch = /width="(\d+)" height="(\d+)"/.exec(svg)
        if (!sizeMatch) {
          window.alert('Failed to parse SVG...')
          return
        }
        const width = sizeMatch[1] / 4
        const height = sizeMatch[2] / 4
        const regexp = /x="(\d+)" y="(\d+)"/g
        const pixels = [ ]
        for (;;) {
          const m = regexp.exec(svg)
github BrightID / BrightID / BrightID-rn / src / components / WebrtcScreens / MyCodeScreen.js View on Github external
genQrCode = (data) => {
    qrcode.toString(data, (err, qr) => {
      if (err) throw err;
      this.parseSVG(qr);
    });
  };
github olymp / olymp / _ / _deprecated / auth / server / auth-engine.es6 View on Github external
new Promise((yay, nay) => {
      qrcode.toString(
        `otpauth://totp/${field}?secret=${x}&issuer=${issuer || 'Olymp'}`,
        { type: 'svg' },
        (err, data) => (err ? nay(err) : yay(data)),
      );
    });
  const cleanUser = ({ salt, hash, confirmed, _id, ...rest }) => rest;
github olymp / olymp / packages / auth / server / auth.js View on Github external
const qr = (email, x, issuer) => new Promise((yay, nay) => {
  require('qrcode').toString(`otpauth://totp/${email}?secret=${x}&issuer=${issuer || 'Olymp'}`, { type: 'svg' }, (err, data) => err ? nay(err) : yay(data));
});
const cleanUser = (user) => {
github BrightID / BrightID / webrtc-app / src / DisplayQR.js View on Github external
genQrCode = () => {
    const { rtcId } = this.props;
    if (rtcId) {
      qrcode.toString(rtcId, (err, data) => {
        if (err) throw err;
        this.setState({
          qrcode: data,
        });
      });
    }
  };
github egodigital / ego-cli / src / commands / qr / index.ts View on Github external
await withSpinnerAsync(`Creating QR code with '${TEXT}' ...`, async (spinner) => {
            await fs.writeFile(
                outputFile,
                await qrcode.toString(TEXT, QRCODE_OPTIONS),
                'utf8'
            );

            spinner.text = `Saved QR code with '${TEXT}' to '${outputFile}'`;
        });
    }
github scotow / sendrop / lib / utils.js View on Github external
function displayFiles(req, res, data, statusCode = 200) {
    res.status(statusCode);
    if(isPretty(req) && !hasFlag(req, 'drop-upload')) {
        res.render('links', data.files ? data : { files: [data] });
    } else if(isShort(req)) {
        const files = data.files ? data.files : [data];
        if(data.archive) files.push(data.archive);
        res.send(files.map(file => file.status === 'success' ? file.link.short : file.message).join('\n'));
    } else if(hasFlag(req, 'qr')) {
        const file = data.archive ? data.archive : (data.files ? data.files[0] : data);
        if(file.status === 'success') {
            QRCode.toString(file.link.short, { type: hasFlag(req, 'utf8') ? 'utf' : 'terminal' })
            .then((qrCode) => { res.send(qrCode); })
            .catch(error => res.send('Error while generating QR code.'));
        } else {
            res.send(file.message);
        }
    } else {
        res.json(data);
    }
}