1.1.6 • Published 4 months ago

qrcode-generator-sabai v1.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

qrcode-generator-sabai

npm version npm License

āš ļø Important: This package is designed for server-side (Node.js) applications only and will not work in a browser environment.


Sample QR code

Overview

qrcode-generator-sabai is a server-side Node.js package for generating QR codes in PNG, SVG, or Base64 formats with customization options such as size, error correction levels, and embedded logos.

šŸ“Œ Server-Side Only

This package does NOT work in the browser because:

  • It uses Node.js file system (fs) to save QR codes as images.
  • It depends on server-side modules that are not available in browser environments.
  • If you need a frontend QR code generator, consider browser-compatible libraries like qrcode.

āœ… Use This Package For:

  • Backend APIs (e.g., Express.js, NestJS, Fastify)
  • Generating QR codes on the server and sending them to clients
  • Saving QR code images or Base64 data in databases or cloud storage

🚫 Do NOT Use This Package For:

  • Frontend/Browser apps (it will fail due to missing Node.js dependencies)

šŸ“Œ Quick Start (Server-Side Usage)

const { QR } = require('qrcode-generator-sabai');

async function generateQRCode() {
    await QR.generate('https://github.com/iamlex01/qrcode-generator-sabai', {
        filePath: './public/images',
        fileName: 'qr-code.png'
    });
    console.log('QR Code saved successfully!');
}

generateQRCode().catch(console.error);

šŸ“– Detailed Usage

1ļøāƒ£ Generate a PNG QR Code

const { QR } = require('qrcode-generator-sabai');

async function generateQRCode() {
    await QR.generate('https://example.com', {
        size: 300,
        errorCorrection: 'Q',
        format: 'png',
        filePath: './public/images',
        fileName: 'qr-code.png'
    });
    console.log('QR Code saved successfully!');
}

generateQRCode().catch(console.error);

2ļøāƒ£ Generate an SVG QR Code as a String

const { QR } = require('qrcode-generator-sabai');

async function generateQRCode() {
    const svgString = await QR.generate('https://example.com', {
        size: 400,
        errorCorrection: 'H',
        format: 'svg'
    });
    console.log('QR Code SVG:', svgString);
}

generateQRCode().catch(console.error);

3ļøāƒ£ Generate an SVG QR Code and Save as a File

const { QR } = require('qrcode-generator-sabai');

async function generateQRCode() {
    await QR.generate('https://example.com', {
        size: 400,
        errorCorrection: 'H',
        format: 'svg',
        filePath: './public/images',
        fileName: 'qr-code.svg'
    });
    console.log('QR Code SVG file saved successfully!');
}

generateQRCode().catch(console.error);

4ļøāƒ£ Generate a Base64 QR Code

const { QR } = require('qrcode-generator-sabai');

async function generateQRCode() {
    const base64 = await QR.generate('https://example.com', {
        size: 500,
        errorCorrection: 'M',
        format: 'base64'
    });
    console.log('QR Code Base64:', base64);
}

generateQRCode().catch(console.error);

5ļøāƒ£ Generate a PNG QR Code with a Logo

const { QR } = require('qrcode-generator-sabai');

async function generateQRCode() {
    await QR.generate('https://example.com', {
        size: 400,
        logoPath: './logo.png', 
        format: 'png',
        filePath: './public/images',
        fileName: 'qr-code-logo.png'
    });
    console.log('PNG QR Code with logo generated!');
}

generateQRCode().catch(console.error);

6ļøāƒ£ Generate an SVG QR Code with a Logo

const { QR } = require('qrcode-generator-sabai');

async function generateQRCode() {
    await QR.generate('https://example.com', {
        size: 400,
        logoPath: './logo.svg', 
        format: 'svg',
        filePath: './public/images',
        fileName: 'qr-code-logo.svg'
    });
    console.log('SVG QR Code with logo generated!');
}

generateQRCode().catch(console.error);

šŸŽÆ QR Code Options

OptionTypeDefaultDescription
sizenumber200QR code size in pixels (applies to PNG, SVG, and Base64).
errorCorrection'L' \| 'M' \| 'Q' \| 'H''M'Set the error correction level (applies to PNG, SVG, and Base64).
format'png' \| 'svg' \| 'base64''png'Choose output format.
filePathstringnullDirectory path to save the QR code file (only for png and svg).
fileNamestringnullFile name for the saved QR code (only for png and svg).
logoPathstringnullPath to an image file (PNG or SVG) to embed in the QR code (applies to png and svg).

šŸ”„ Error Correction Levels

LevelError Resistance
L (Low)~7%
M (Medium)~15%
Q (Quartile)~25%
H (High)~30%

šŸ“œ License

qrcode-generator-sabai is licensed under the MIT License.

1.1.0

4 months ago

1.1.6

4 months ago

1.1.5

4 months ago

1.1.4

4 months ago

1.1.3

4 months ago

1.1.2

4 months ago

1.0.1

9 months ago

1.0.0

1 year ago