emvco-qr-sdk
Version:
A robust TypeScript SDK for decoding, validating, and processing EMVCo-compliant QR codes used in digital payment systems.
27 lines (26 loc) • 1.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateQRString = validateQRString;
const qr_errors_constant_1 = require("../../constants/qr-errors.constant");
const validate_tlv_format_util_1 = require("./validate-tlv-format.util");
/**
* Validates that a QR string is non-empty and follows the TLV format.
*
* This function checks two things:
* 1. The string must not be empty or whitespace.
* 2. It must follow a pattern consistent with EMVCo TLV encoding
* (e.g., `ID + LENGTH + VALUE`).
*
* Throws meaningful errors if the input fails these validations.
*
* @param rawQRString - The QR string to validate.
* @throws {Error} If the QR string is empty or not TLV-compliant.
*/
function validateQRString(rawQRString) {
if (!rawQRString || rawQRString.trim().length === 0) {
throw new Error(qr_errors_constant_1.PARSE_ERRORS.EMPTY_QR);
}
if (!(0, validate_tlv_format_util_1.isValidTLVFormat)(rawQRString)) {
throw new Error(qr_errors_constant_1.PARSE_ERRORS.INVALID_TLV_FORMAT(rawQRString));
}
}