UNPKG

promptparse

Version:

All-in-one JS library for PromptPay & EMVCo QR Codes

110 lines (104 loc) 3.27 kB
export { i as generate } from './index-CdYOtGd6.js'; export { i as validate } from './index-BhcWWZJq.js'; interface TLVTag { /** Tag ID */ id: string; /** Tag Value */ value: string; /** Sub Tags */ subTags?: TLVTag[]; /** Tag Length */ length: number; } /** * Decode TLV string into array of TLV Tags * * @param payload - TLV string * @returns Array of TLV Tags */ declare function decode(payload: string): TLVTag[]; /** * Encode TLV Tags array into TLV string * * @param tags - Array of TLV Tags * @returns TLV string */ declare function encode(tags: TLVTag[]): string; /** * Generate CRC Checksum for provided string * * @param payload - Any string * @param upperCase - Return CRC Checksum as uppercase string * @returns CRC Checksum */ declare function checksum(payload: string, upperCase?: boolean): string; /** * Get TLV string combined with CRC Tag * * @param payload - TLV string (without CRC Tag) * @param crcTagId - CRC Tag ID * @param upperCase - Return CRC Checksum as uppercase string * @returns TLV string + CRC Tag ID + CRC Length + CRC Checksum */ declare function withCrcTag(payload: string, crcTagId: string, upperCase?: boolean): string; /** * Get Tag or Sub-tag by Tag ID in array of TLV Tags * * @param tlvTags - Array of TLV Tags * @param tagId - Target Tag ID * @param subTagId - Target Sub-tag ID * @returns Instance of Target Tag/Sub-tag */ declare function get(tlvTags: TLVTag[], tagId: string, subTagId?: string): TLVTag | undefined; /** * Create new TLV Tag * * @param tagId - Tag ID * @param value - Tag Value * @returns TLV Tag */ declare function tag(tagId: string, value: string): TLVTag; declare class EMVCoQR { private payload; private tags; constructor(payload: string, tags: TLVTag[]); getTag(tagId: string, subTagId?: string): TLVTag | undefined; getTagValue(tagId: string, subTagId?: string): string | undefined; getTags(): TLVTag[]; getPayload(): string; validate(crcTagId: string): boolean; } declare class BOTBarcode { billerId: string; ref1: string; ref2: string | null; amount: number | null; constructor(billerId: string, ref1: string, ref2?: string | null, amount?: number | null); static fromString(payload: string): BOTBarcode | null; toString(): string; /** * Converts BOT Barcode to PromptPay QR Tag 30 (Bill Payment) * * This method works for some biller, depends on destination bank * * @returns QR Code payload */ toQrTag30(): string; } /** * Parse any EMVCo-compatible QR Code data string * * @param payload - QR Code data string from the scanner * @param strict - Validate CRC checksum before parsing the entire string * @param subTags - Parse TLV Sub-tags (If exists) * @returns QR Instance with TLV Tags */ declare function parse(payload: string, strict?: boolean, subTags?: boolean): EMVCoQR | null; /** * Parse barcode data string (BOT Barcode Standard) * * @param payload - Barcode data string from the scanner * @returns BOT Barcode Instance */ declare function parseBarcode(payload: string): BOTBarcode | null; export { BOTBarcode, EMVCoQR, type TLVTag, checksum, decode, encode, get, parse, parseBarcode, tag, withCrcTag };