Skip to content

Instantly share code, notes, and snippets.

@lionello
Last active November 10, 2018 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lionello/b430c15d4b91b50e9d17badfc6ebba73 to your computer and use it in GitHub Desktop.
Save lionello/b430c15d4b91b50e9d17badfc6ebba73 to your computer and use it in GitHub Desktop.
Tiny QR code generator for showing text/urls in the terminal
#!/usr/bin/env node
const QR = require("qr-image");
const arrayOf = (len, filler) => new Array(len).fill(filler);
const text = process.argv[2];
const matrix = QR.matrix(text, "L");
const topBottomPad = arrayOf(4, arrayOf(matrix[0].length, 0));
const rowPad = arrayOf(4, 0);
const qr = topBottomPad
.concat(matrix, topBottomPad)
.map(row =>
rowPad
.concat(row, rowPad)
.map(i => (i ? " " : "██"))
.join("")
)
.join("\n");
console.log(qr);
console.log(text);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment