Git Product home page Git Product logo

qrcode's Introduction

๐Ÿ“‡ QR Code

Generate QR codes in Deno, as base64-encoded images, completely dependency-free and requires no binary.

This is a port of zenozeng/node-yaqrcode, which itself is a port of the QR code generator in the d-project.

Deno CI GitHub Contributors Deno Starter Made by Denorg TypeScript semantic-release

โญ Getting started

import { qrcode } from "https://deno.land/x/qrcode/mod.ts";
const base64Image = qrcode("bitcoin:ADDRESS?amount=0.5&label=ORDER"); // data:image/gif;base64,...

QR code

You can also add a custom size by specifying size in the second parameter:

const fixedSizeImage = await qrcode("bitcoin:ADDRESS?amount=0.5&label=ORDER", { size: 500 });

CLI with DPX

After installing DPX, you can directly use the CLI using the dpx command:

dpx qrcode <text>

CLI

Alternatively, you can use it directly from the CLI by using deno run:

deno run https://deno.land/x/qrcode/cli.ts <text>

You can also install it globally using the following:

deno install https://deno.land/x/qrcode/cli.ts

Then, the package is available to run:

qrcode <text>

๐Ÿ‘ฉโ€๐Ÿ’ป Development

Run tests:

deno test

Notes

โญ Related Work

๐Ÿ“„ License

A project by Denorg, the world's first Deno-focused community
organization and consulting company. Work with us โ†’

qrcode's People

Contributors

adaamz avatar anandchowdhary avatar jj avatar moncefplastin07 avatar oplik0 avatar zenozeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qrcode's Issues

A bit of more documentation would help

For instance, document the fact that qrcode is asynchronous, or that it returns a QRCode class which seems to be a string, or at least can be converted to string.

Audit underlying JS code

For starters, it's 15-year old code. Refactoring it to common practices today
would probably make it easier to understand, and work on it. But, more
importantly, it would allow exposition of the functionality that's there and
which is so far not being tapped.

Deno.serve QRCode Server Example for All

The following code snippet serves a QRCode using Deno.

URL Params Example:

http://localhost:4000/?d=Hello+World!&v=5&e=L&s=250&m=Byte

import { qrcode } from "https://deno.land/x/qrcode/mod.ts";
import { decodeBase64 } from "https://deno.land/[email protected]/encoding/base64.ts";

// Deno.serve() handler
async function handler(request: Request, connInfo: Deno.ServeHandlerInfo): Promise<Response> {

  // Information for a HTTP request.
  const remoteAddr = connInfo.remoteAddr;

  const url = new URL(request.url);
  // Data to encode...
  const d = url.searchParams.get("d") || "Hello World!";
  // Version of barcode 0 (Automatic type number) - 40
  // https://www.qrcode.com/en/about/version.html
  const v = Math.min(40, Math.max(0, Number(url.searchParams.get("v")) || 0));
  // Error Correction L = 7% | M = 15% | Q = 25% | H = 30%
  const e = ["L", "M", "Q", "H"].includes(url.searchParams.get("e")) ? url.searchParams.get("e") : "M";
  // Size of barcode 250 - 500
  const s = Math.min(500, Math.max(250, Number(url.searchParams.get("s")) || 250));
  // Mode = 'Numeric' | 'Alphanumeric' | 'Byte' | 'Kanji'
  const m = ['Numeric', 'Alphanumeric', 'Byte', 'Kanji'].includes(url.searchParams.get("m")) ? url.searchParams.get("m") : "Byte";

  const base64Image = await qrcode(d, { typeNumber: v, errorCorrectLevel: e, size: s, mode: m }); // data:image/gif;base64,...
  const binaryImage = new Uint8Array(decodeBase64(base64Image.split(",")[1]));

  return new Response(binaryImage, {
    status: 200,
    headers: {
      "Server": `Deno v${Deno.version.deno}`,
      "Allow": "HEAD, GET, OPTIONS",
      "Cache-Control": "no-store",
      "Content-Language": "en-US",
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Methods": "HEAD, GET, OPTIONS",
      "Access-Control-Allow-Headers": "Content-Type",
      "Access-Control-Allow-Credentials": "false",
      "Content-Type": "image/gif",
    },
  })

}

// Start the QRCode server of Port 4000
Deno.serve({
  port: 4000,
  hostname: "0.0.0.0",
  onListen({ port, hostname }) {
    console.log(`Application..... QR Code - Model 2 - A QR Code Model 2 Server
Deno v${Deno.version.deno} : Typescript v${Deno.version.typescript} : V8 v${Deno.version.v8}
Permissions..... --allow-net
Gateway URL..... http://${hostname}:${port}\n\n`);
  },
  onError(error: unknown) {
    console.error(error);
    return new Response("HTTP 500: Internal Server Error", {
      status: 500,
      headers: { "Content-Type": "text/plain" },
    });
  },
}, handler);

// deno run --allow-net qrServe.ts

Hello World!

sample

Upgrade infra a bit

Check workflows, bring them up to latest version of actions, check if there's
any deprecated workflow or step
Captura de pantalla de 2023-10-07 20-36-48

Enhance test coverage

First, actually try and measure coverage; second, try at least to test different
options for error-correction, which is not being tested right now.

Addittionally, try to test round-trip. Since right now it's not possible to do
it with the code itself (it does not decode), it might help to use some external
utility... Or actually address #6 in order to test

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.