Skip to content

Instantly share code, notes, and snippets.

@dskvr
Created May 6, 2025 19:03
Show Gist options
  • Save dskvr/b9e3bbd6ad2d4150b1d31e14d00a51b7 to your computer and use it in GitHub Desktop.
Save dskvr/b9e3bbd6ad2d4150b1d31e14d00a51b7 to your computer and use it in GitHub Desktop.
for usage with @libs/qrcode
function _renderQrArrayWithQuietZone(
qrArray: boolean[][] | undefined,
borderSize: number,
lightCharPair = "\u2588\u2588",
darkCharPair = " "
): void {
if (!qrArray || qrArray.length === 0) {
log.warn("QR array is empty, cannot render.");
return;
}
const qrWidth = qrArray[0].length;
const totalWidthModules = qrWidth + 2 * borderSize;
for (let i = 0; i < borderSize; i++) {
console.log(lightCharPair.repeat(totalWidthModules));
}
for (const row of qrArray) {
let line = "";
line += lightCharPair.repeat(borderSize);
for (const cell of row) {
line += cell ? darkCharPair : lightCharPair;
}
line += lightCharPair.repeat(borderSize);
console.log(line);
}
for (let i = 0; i < borderSize; i++) {
console.log(lightCharPair.repeat(totalWidthModules));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment