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

@shreyaadhikari/qr-code-generator

v1.0.17

Published

A utility package to generate QR codes

Downloads

71

Readme

QR Code Generator

Description

QR Code Generator is a simple Node.js package for generating QR codes and saving them as image files. Ideal for adding QR code functionality to your Node.js applications effortlessly.

Build Status

Version

Table of Contents

Features

  • Generate QR Codes: Easily generate QR codes from text.
  • Save as Image: Save the generated QR codes directly to image files (PNG format).

Installation

You can install this package using npm:

npm install @shreyaadhikari/qr-code-generator

Usage

Here’s a quick guide on how to use the QR Code Generator in your Node.js project.

Import the package

const generateQRCode = require('@shreyaadhikari/qr-code-generator');

Generate and Save a QR Code

const text = 'Hello World';
const outputPath = 'qrcode.png';

generateQRCode(text, outputPath, (err, message) => {
    if (err) {
        console.error('Error generating QR code:', err);
    } else {
        console.log(message); // Output: 'QR Code saved to qrcode.png'
    }
});
  • text: The text you want to encode into a QR code.
  • outputPath: The path where the QR code image will be saved.
  • callback: A function that handles the success or error response.

Example Usage

Here is a complete example using a file named test.js:

const generateQRCode = require('@shreyaadhikari/qr-code-generator');

const text = 'Hello World';
const outputPath = 'qrcode.png';

generateQRCode(text, outputPath, (err, message) => {
    if (err) {
        console.error('Error generating QR code:', err);
    } else {
        console.log(message); // Output: 'QR Code saved to qrcode.png'
    }
});

Usage in Different Environments

Node.js

This package is designed for use with Node.js. See the Usage section for examples.

Browser

To use this package in a browser, include the script tag as follows:

<script src="https://cdn.jsdelivr.net/npm/@yourusername/qr-code-generator"></script>

Example Usage in a browser

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>QR Code Generator</title>
</head>
<body>
    <input type="text" id="textInput" placeholder="Enter text for QR Code">
    <button id="generateButton">Generate QR Code</button>
    <img id="qrCodeImage" alt="QR Code">

    <script src="https://cdn.jsdelivr.net/npm/@shreyaadhikari/qr-code-generator"></script>
    <script>
        document.getElementById('generateButton').addEventListener('click', () => {
            const text = document.getElementById('textInput').value;
            const outputPath = 'data:image/png;base64,'; // QR code will be displayed as a base64-encoded PNG

            generateQRCode(text, outputPath, (err, imageSrc) => {
                if (err) {
                    console.error('Error generating QR code:', err);
                } else {
                    document.getElementById('qrCodeImage').src = imageSrc;
                }
            });
        });
    </script>
</body>
</html>

Dependencies

This package requires the following dependencies:

Credits

  • Special thanks to the QRCode library for providing QR code generation functionality.

FAQ

Q: What if I encounter an error generating the QR code?

A: Make sure the text input is a valid string and check the file path permissions.

Contributing

Contributions are welcome! If you want to improve this package, follow these steps:

  • Fork the repository.
  • Create a new branch (git checkout -feature-branch).
  • Make your changes.
  • Commit your changes (git commit -am 'Add new feature').
  • Push to the branch (git push origin feature-branch).
  • Create a pull request.

License

This package is licensed under the ISC License. See the LICENSE file for details.

Contact

For questions or suggestions, feel free to open an issue on the GitHub repository or contact me at [email protected].