UNPKG

emvco-qr-sdk

Version:

A robust TypeScript SDK for decoding, validating, and processing EMVCo-compliant QR codes used in digital payment systems.

42 lines (41 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Tag = void 0; /** * Represents a Tag value object in a TlvEntity structure. * * This class encapsulates the tag identifier ensuring that it complies with the expected format. * According to the EMVCo specifications, a valid Tag is typically a two-character string. */ class Tag { /** * Constructs a Tag value object. * * @param value - The tag string. It must be exactly two characters. * @throws {Error} If the tag is not exactly two characters. */ constructor(value) { if (!Tag.isValid(value)) { throw new Error(`Invalid Tag: ${value}. A valid tag must be exactly 2 characters.`); } this._value = value; } /** * Returns the tag value as a string. * * @returns The tag as a string. */ toString() { return this._value; } /** * Validates the provided tag value. * * @param value - The tag value to validate. * @returns True if the tag is exactly two characters, false otherwise. */ static isValid(value) { return typeof value === 'string' && value.length === 2; } } exports.Tag = Tag;