emvco-qr-sdk
Version:
A robust TypeScript SDK for decoding, validating, and processing EMVCo-compliant QR codes used in digital payment systems.
41 lines (40 loc) • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TlvEntity = void 0;
/**
* Represents a single TLV (Tag-Length-Value) structure used in QR codes or similar encoding formats.
*
* This entity encapsulates the fundamental components of a TLV:
* - A tag (identifier)
* - A value
* - Its corresponding length (in characters)
*
* Optionally, a TLV may contain nested sub-tags (subTags), allowing for hierarchical data structures.
*/
class TlvEntity {
/**
* Creates a new TLV entity.
*
* @param tag - The tag that identifies the data field.
* @param value - The raw value associated with the tag.
* @param subTags - (Optional) Nested TLV entities parsed from the value.
*/
constructor(tag, value, subTags) {
this.tag = tag;
this.value = value;
this.length = value.length;
if (subTags && subTags.length > 0) {
this.subTags = subTags;
}
}
/**
* Serializes the TLV entity back into its string representation.
*
* @returns A string in the format: TAG + LENGTH (2 digits) + VALUE.
*/
toString() {
const lenString = this.length.toString().padStart(2, '0');
return `${this.tag}${lenString}${this.value}`;
}
}
exports.TlvEntity = TlvEntity;