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

mnb-qr-v3

v1.0.2

Published

`MNBQrV3` is a JavaScript class designed to handle payment-related data according to the MNB QR v3 specification. It ensures that the data fields adhere to specific validation rules and formats. This class can generate JSON data for further processing.

Downloads

7

Readme

MNBQrV3

MNBQrV3 is a JavaScript class designed to handle payment-related data according to the MNB QR v3 specification. It ensures that the data fields adhere to specific validation rules and formats. This class can generate JSON data for further processing.

Features

  • Field validation: All fields have associated validation rules (e.g., required fields, pattern matching).
  • JSON generation: Generates a JSON string based on the provided data.
  • Encapsulation: Internal data is stored in private fields and can only be accessed or modified through getter and setter methods.

Installation

Include the MNBQrV3 class in your project:

NPM:

npm i mnb-qr-v3

CDN:

<script type="text/javascript" src="https://unpkg.com/mnb-qr-v3@latest/dist/MNBQrV3-min.js"></script>

Usage

Creating an Instance

You can initialize an instance of MNBQrV3 by passing an optional configuration object. This object should match the schema described below:

const MNBQrV3 = require('path/to/MNBQrV3');

const qrData = new MNBQrV3({
    BIC: 'GIBAHUHB',
    name: 'Example Name',
    IBAN: 'HU12345678901234567890123456',
    value: 1000,
    currency: 'HUF',
    expiry: '2024-12-31T23:59',
    identification: 1,
    // ... other optional fields
});

Methods

  • get(field): Retrieve the value of a specific field.
  • set(field, value): Set the value of a specific field after validation.
  • generateObject(): Generate a JS object based on the field values.
  • generateJSON(): Generate a JSON string based on the field values.

Example

const qr = new MNBQrV3();

qr.setBIC("GIBAHUHB");
qr.setIBAN("HU12345678901234567890123456");
qr.setIdentification(MNBQrV3.HCT);
qr.setName("John Doe");
qr.setValue(10000);
qr.setCurrency("HUF");
qr.setRepeatability(MNBQrV3.REPETABLE);
qr.setExpiry(
    Date.parse("2024-12-31T23:59")
);

const json = qr.generateJSON();
console.log(json);

Generating the QR Code

Once you've prepared the necessary data and structure, you can generate the QR code using any QR code generation library. One widely-used and easy-to-integrate option is qrcodejs.

const json = qr.generateJSON();

new QRCode( document.getElementById('qr-code'), {
        text: json,
        width: 250,
        height: 250,
        colorDark : "#000000",
        colorLight : "#ffffff",
        correctLevel : QRCode.CorrectLevel.H
    });

Fields

  • The MNBQrV3 class supports the following fields:
  • BIC (required): Bank Identifier Code, validated by pattern /^[a-zA-Z]{8,11}$/.
  • name (required): Name of the beneficiary, validated by pattern /^.{1,70}$/.
  • IBAN (required): International Bank Account Number, validated by pattern /^[a-zA-Z0-9]{28}$/.
  • value (required): Amount, validated as a number with a pattern /^(10{7}|[1-9]\d{0,6}|0)$/.
  • currency (required): Currency code, validated by pattern /^[a-zA-Z]{3}$/.
  • expiry (required): Expiry date in ISO 8601 format.
  • identification (required): Numeric identification.
  • text: Optional text field.
  • positionId: Optional position ID.
  • shopId: Optional shop ID.
  • machineId: Optional machine ID.
  • billId: Optional bill ID.
  • costumerId: Optional customer ID.
  • transactionId: Optional transaction ID.
  • discountId: Optional discount ID.
  • NAVCode: Optional NAV code.

Validation

Each field is validated based on its defined pattern and type. Required fields must be provided; otherwise, an error will be thrown during validation.

JSON Structure

The generated JSON object has the following structure:

{
    "M": {
        "I": 1,
        "V": 3,
        "C": 1,
        "E": 1735689599000,
        "R": 0
    },
    "R": {
        "B": "GIBAHUHB",
        "N": "John Doe",
        "I": "HU12345678901234567890123456"
    },
    "a": {
        "V": 10000,
        "C": "HUF"
    },
    "t": "Optional text",
    "i": {
        "p": "Optional Position ID",
        "s": "Optional Shop ID",
        "m": "Optional Machine ID",
        "b": "Optional Bill ID",
        "c": "Optional Customer ID",
        "t": "Optional Transaction ID",
        "d": "Optional Discount ID",
        "n": "Optional NAV Code"
    }
}