modify-qris
Version:
Modify QRIS Generator is a javascript based libraries that enabling flexible payments with customizable amounts for improved efficiency and user experience
29 lines (28 loc) • 907 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CRC16CCITT = void 0;
/**
* CRC16CCITT implementation for generating CRC codes
*/
class CRC16CCITT {
/**
* Generate CRC16-CCITT input from input string
* @param input Input string to generate CRC from
* @returns Uppercase hexadecimal representation of the CRC
*/
static generateCode(input) {
function charCodeAt(input, i) {
return input.charCodeAt(i);
}
let crc = 0xFFFF;
for (let i = 0; i < input.length; i++) {
crc ^= charCodeAt(input, i) << 8;
for (let j = 0; j < 8; j++) {
crc = (crc & 0x8000) ? (crc << 1) ^ 0x1021 : crc << 1;
}
}
let hex = (crc & 0xFFFF).toString(16).toUpperCase();
return hex.length === 3 ? "0" + hex : hex;
}
}
exports.CRC16CCITT = CRC16CCITT;