npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

easygenqr

v1.3.0

Published

This is a library for generating QR codes.

Downloads

60

Readme

easygenqr

This is a library for generating QR codes. Use encodeData to implement data parsing for qrcode, and then use generateSVGQRCode to generate svg for qrcode

  • generate svg for qrcode

  • custom styles

  • add brand logo

Installation

$ npm install easygenqr
or
$ yarn add easygenqr
or
$ pnpm add easygenqr

Usage

Vanilla js demo

 const qr = encodeData({
    text: "Hello World!",
    errorCorrectionLevel: 3
 });

 const svg = generateSVGQRCode(qr,{
     bgColor: "#ffffff",
     dotColor: "#000000",
     dotMode: 0,
     markerColor: "#000000",
     markerMode: 0
 });

 // add to html
 const div = document.createElement("div");
 div.style.width = "300px";
 div.style.height = "300px";
 div.innerHTML = svg;

Vue.js demo

<script setup lang="ts">
import {
  encodeData,
  ErrorCorrectLevel,
  generateSVGQRCode,
  MarkerModes,
} from "easygenqr";

interface Props {
  text: string;
  width?: number;
  height?: number;
  ecc?: ErrorCorrectLevel;
  bgColor?: string;
  dotColor?: string;
  dotMode?: number;
  markerMode?: MarkerModes;
  markerColor?: string;
}

const props = defineProps<Props>();
const qrSVGString = ref<string>();
const qrData = ref<any>();

function render() {
  const qr = encodeData({
    text: props.text,
    errorCorrectionLevel: props.ecc || 1,
  });
  qrData.value = qr;
  qrSVGString.value = generateSVGQRCode(qr, {
    bgColor: props.bgColor || "#ffffff",
    dotColor: props.dotColor || "#000000",
    dotMode: props.dotMode || 0,
    markerMode: props.markerMode || 0,
    markerColor: props.markerColor || "#000000",
  });
}

watch(
  props,
  () => {
    render();
  },
  { immediate: true }
);
</script>

<template>
  <div
    :style="{
      width: props.width ? props.width + 'px' : '150px',
      height: props.height ? props.height + 'px' : '150px',
    }"
    v-html="qrSVGString"
  ></div>
</template>

React.js demo

import { encodeData, generateSVGQRCode } from 'easygenqr'

export default function QRCode(){
  const qr = encodeData({
    text: "Hello easygenqr!",
    errorCorrectionLevel: 1,
  });

  const svgString = generateSVGQRCode(qr, {
    bgColor: "#ffffff",
    dotColor: "#000000",
    dotMode: 0,
    markerMode: 0,
    markerColor: "#000000",
  })

  return <div dangerouslySetInnerHTML={{ __html: svgString }} />;
}

API

encodeData

| Parameters | Type | Default | Description | | -------------------- | ----------------- | ------- | ------------------------------------------------------------ | | text | string | | qr code text | | errorCorrectionLevel | ErrorCorrectLevel | 3 | error correction level: 0=>LOW 1=>MEDIUM 2=>QUARTILE 3=>HIGH |

generateSVGQRCode

| Parameters | Type | Default | Description | | ---------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | | qr | qrcodegen.QrCode | | The data returned by encodeData()refrenceQR Code generator library | | options | QRCodeOptions | { bgColor: "#ffffff", dotColor: "#000000", markerColor: "#000000", dotMode: 0, markerMode: 0,withLogo:true } | qr code options for render svg |

QRCodeOptions:

QRCodeOptions {
    bgColor?: string; // qr code background color
    dotColor?: string; // qr code dot color
    markerColor?: string; // marker color
    dotMode?: DotModes; // dot style 0=>SQUARE 1=>CIRCLE
    markerMode?: MarkerModes; // marker style
    logo?: string; // logo url
    withLogoBg?: boolean; // logo background is transparent or not
}

DotModes

| Value | Description | | ----- | ----------- | | 0 | Square | | 1 | Circle | | 2 | Rounded | | 3 | LineCircle |

MarkerModes

| Value | Description | | ----- | ----------------------------------------------- | | 0 | Base: border square and center square | | 1 | border rounded corner and center rounded corner | | 2 | border circle and center circle | | 3 | border square and center circle | | 4 | border circle and center square |

logo

Support Base64 or picture url.

withLogoBg

| Value | Description | | -------------- | ------------------------------- | | true (default) | logo background is white. | | false | logo background is transparent. |

Developer

Using tsup to build easygenqr.

Generating data for qrcode based on https://www.nayuki.io/page/qr-code-generator-library

run locally

npm run dev

open example

open example/index.html in browser

debug in index.html file

 

Reference

QR Code generator: https://www.nayuki.io/page/qr-code-generator-library