crc16 xmodem derived from pycrc16 for node.js / browser
npm install crc16-xmodemDerived from pycrc16 library implementation (Link)
For using in Node.js and Browser
No dependency needed
Tested and worked in Node 12, Chrome 83
__(Not tested in JS import yet).__
---
Step 1: Load script via Require / Browser script tag
``javascript`
// For node.js
const crc16xmodem = require('crc16-xmodem'); `html`
Step 2: Methods
`javascript`
// Calculate checksum with 4 digit hex output
const originalStr = '00020101021129370016A000000677010111011300660000000005802TH53037646304';
console.log(crc16xmodem.calculateChecksum(originalStr));
// Result: 8956`javascript
// Validate from last 4 digit hex checksum
const fullStr = '00020101021129370016A000000677010111011300660000000005802TH530376463048956';
console.log(crc16xmodem.validateChecksum(fullStr));
// Result: true
``javascript``
// or just crc16 input string with custom initial value like 0
crc16xmodem.crc16(str, initialValue);