node-bcc
Version:
A simple Block Check Character library.
25 lines • 645 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Bcc = void 0;
const helper_1 = require("../helper");
/**
* This class provides methods for calculating the Block Check Character of a
* message.
*
* @export
* @class Bcc
*/
class Bcc {
static calculate(message) {
let bcc = 0x00;
if (!Buffer.isBuffer(message) && !helper_1.Helper.checkArray(message)) {
return -1;
}
for (const byte of message) {
bcc ^= typeof byte === 'string' ? parseInt(byte, 16) : byte;
}
return bcc;
}
}
exports.Bcc = Bcc;
//# sourceMappingURL=bcc.js.map