Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

easy-crc

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-crc - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

3

dist/src/lib/crc16.d.ts

@@ -6,5 +6,6 @@ /// <reference types="node" />

* @param {String|Buffer} data A string or an array of bytes
* @param {Number=} seed A number
* @returns {Number} CRC16 checksum
*/
declare function crc16(algorithm: keyof Crc16Algorithms, data: string | Buffer): number;
declare function crc16(algorithm: keyof Crc16Algorithms, data: string | Buffer, seed?: number): number;
export { crc16 };

@@ -56,5 +56,6 @@ "use strict";

* @param {String|Buffer} data A string or an array of bytes
* @param {Number=} seed A number
* @returns {Number} CRC16 checksum
*/
function crc16(algorithm, data) {
function crc16(algorithm, data, seed) {
const availables = Object.keys(crc16Algorithms);

@@ -66,3 +67,3 @@ if (!availables.includes(algorithm))

const { init, invertedInit, xorOut, refOut, refIn, table } = crc16Algorithms[algorithm];
let crc = refIn ? invertedInit || 0 : init;
let crc = seed ? seed ^ xorOut : (refIn ? invertedInit || 0 : init);
if (refOut) {

@@ -69,0 +70,0 @@ for (const b of data)

@@ -6,5 +6,6 @@ /// <reference types="node" />

* @param {String|Buffer} data A string or an array of bytes
* @param {Number=} seed A number
* @returns {Number} CRC32 checksum
*/
declare function crc32(algorithm: keyof Crc32Algorithms, data: string | Buffer): number;
declare function crc32(algorithm: keyof Crc32Algorithms, data: string | Buffer, seed?: number): number;
export { crc32 };

@@ -28,5 +28,6 @@ "use strict";

* @param {String|Buffer} data A string or an array of bytes
* @param {Number=} seed A number
* @returns {Number} CRC32 checksum
*/
function crc32(algorithm, data) {
function crc32(algorithm, data, seed) {
const availables = Object.keys(crc32Algorithms);

@@ -38,3 +39,3 @@ if (!availables.includes(algorithm))

const { init, xorOut, refOut, table } = crc32Algorithms[algorithm];
let crc = init;
let crc = seed ? (seed ^ xorOut) : init;
if (refOut) {

@@ -41,0 +42,0 @@ for (const b of data)

@@ -6,5 +6,6 @@ /// <reference types="node" />

* @param {String|Buffer} data A string or an array of bytes
* @param {Number=} seed A number
* @returns {Number} CRC8 checksum
*/
declare function crc8(algorithm: keyof Crc8Algorithms, data: string | Buffer): number;
declare function crc8(algorithm: keyof Crc8Algorithms, data: string | Buffer, seed?: number): number;
export { crc8 };

@@ -30,5 +30,6 @@ "use strict";

* @param {String|Buffer} data A string or an array of bytes
* @param {Number=} seed A number
* @returns {Number} CRC8 checksum
*/
function crc8(algorithm, data) {
function crc8(algorithm, data, seed) {
const availables = Object.keys(crc8Algorithms);

@@ -40,3 +41,3 @@ if (!availables.includes(algorithm))

const { init, xorOut, table } = crc8Algorithms[algorithm];
let crc = init;
let crc = seed ? seed ^ xorOut : init;
for (const b of data)

@@ -43,0 +44,0 @@ crc = table[crc ^ b];

@@ -13,14 +13,28 @@ "use strict";

describe('CCITT-FALSE', function () {
it('should return 0x7D61', function (done) {
const crcCheck = (0, index_1.crc16)('CCITT-FALSE', check);
crcCheck.should.equal(0x7D61);
const algorithm = 'CCITT-FALSE';
const expected = 0x7D61;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('ARC', function () {
it('should return 0x443D', function (done) {
const crcCheck = (0, index_1.crc16)('ARC', check);
crcCheck.should.equal(0x443D);
const algorithm = 'ARC';
const expected = 0x443D;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});

@@ -35,119 +49,238 @@ // describe('AUG-CCITT', function () {

describe('CDMA2000', function () {
it('should return 0xD89D', function (done) {
const crcCheck = (0, index_1.crc16)('CDMA2000', check);
crcCheck.should.equal(0xD89D);
const algorithm = 'CDMA2000';
const expected = 0xD89D;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('BUYPASS', function () {
it('should return 0xFD14', function (done) {
const crcCheck = (0, index_1.crc16)('BUYPASS', check);
crcCheck.should.equal(0xFD14);
const algorithm = 'BUYPASS';
const expected = 0xFD14;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('DDS-110', function () {
it('should return 0xDB54', function (done) {
const crcCheck = (0, index_1.crc16)('DDS-110', check);
crcCheck.should.equal(0xDB54);
const algorithm = 'DDS-110';
const expected = 0xDB54;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('DECT-R', function () {
it('should return 0x422B', function (done) {
const crcCheck = (0, index_1.crc16)('DECT-R', check);
crcCheck.should.equal(0x422B);
const algorithm = 'DECT-R';
const expected = 0x422B;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('DECT-X', function () {
it('should return 0x422A', function (done) {
const crcCheck = (0, index_1.crc16)('DECT-X', check);
crcCheck.should.equal(0x422A);
const algorithm = 'DECT-X';
const expected = 0x422A;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('DNP', function () {
it('should return 0x6772', function (done) {
const crcCheck = (0, index_1.crc16)('DNP', check);
crcCheck.should.equal(0x6772);
const algorithm = 'DNP';
const expected = 0x6772;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('EN-13757', function () {
it('should return 0xFC73', function (done) {
const crcCheck = (0, index_1.crc16)('EN-13757', check);
crcCheck.should.equal(0xFC73);
const algorithm = 'EN-13757';
const expected = 0xFC73;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('GENIBUS', function () {
it('should return 0x829E', function (done) {
const crcCheck = (0, index_1.crc16)('GENIBUS', check);
crcCheck.should.equal(0x829E);
const algorithm = 'GENIBUS';
const expected = 0x829E;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('MAXIM', function () {
it('should return 0xBBC2', function (done) {
const crcCheck = (0, index_1.crc16)('MAXIM', check);
crcCheck.should.equal(0xBBC2);
const algorithm = 'MAXIM';
const expected = 0xBBC2;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('KERMIT', function () {
it('should return 0x5F6E', function (done) {
const crcCheck = (0, index_1.crc16)('KERMIT', check);
crcCheck.should.equal(0x5F6E);
const algorithm = 'KERMIT';
const expected = 0x5F6E;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('MCRF4XX', function () {
it('should return 0xC3E9', function (done) {
const crcCheck = (0, index_1.crc16)('MCRF4XX', check);
crcCheck.should.equal(0xC3E9);
const algorithm = 'MCRF4XX';
const expected = 0xC3E9;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('MODBUS', function () {
it('should return 0x434D', function (done) {
const crcCheck = (0, index_1.crc16)('MODBUS', check);
crcCheck.should.equal(0x434D);
const algorithm = 'MODBUS';
const expected = 0x434D;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('RIELLO', function () {
it('should return 0x9068', function (done) {
const crcCheck = (0, index_1.crc16)('RIELLO', check);
crcCheck.should.equal(0x9068);
const algorithm = 'RIELLO';
const expected = 0x9068;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('T10-DIF', function () {
it('should return 0xDE40', function (done) {
const crcCheck = (0, index_1.crc16)('T10-DIF', check);
crcCheck.should.equal(0xDE40);
const algorithm = 'T10-DIF';
const expected = 0xDE40;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('TELEDISK', function () {
it('should return 0x1BBF', function (done) {
const crcCheck = (0, index_1.crc16)('TELEDISK', check);
crcCheck.should.equal(0x1BBF);
const algorithm = 'TELEDISK';
const expected = 0x1BBF;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('TMS37157', function () {
it('should return 0xE2A2', function (done) {
const crcCheck = (0, index_1.crc16)('TMS37157', check);
crcCheck.should.equal(0xE2A2);
const algorithm = 'TMS37157';
const expected = 0xE2A2;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('USB', function () {
it('should return 0xBCB2', function (done) {
const crcCheck = (0, index_1.crc16)('USB', check);
crcCheck.should.equal(0xBCB2);
const algorithm = 'USB';
const expected = 0xBCB2;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});

@@ -160,17 +293,43 @@ describe('X-25', function () {

});
const algorithm = 'X-25';
const expected = 0x3C16;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('XMODEM', function () {
it('should return 0x9C58', function (done) {
const crcCheck = (0, index_1.crc16)('XMODEM', check);
crcCheck.should.equal(0x9C58);
const algorithm = 'XMODEM';
const expected = 0x9C58;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('CRC-A', function () {
it('should return 0x1194', function (done) {
const crcCheck = (0, index_1.crc16)('CRC-A', check);
crcCheck.should.equal(0x1194);
const algorithm = 'CRC-A';
const expected = 0x1194;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc16)(algorithm, check.slice(5), (0, index_1.crc16)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
});

@@ -13,64 +13,127 @@ "use strict";

describe('CRC-32', function () {
it('should return 0xA684C7C6', function (done) {
const crcCheck = (0, index_1.crc32)('CRC-32', check);
crcCheck.should.equal(0xA684C7C6);
const algorithm = 'CRC-32';
const expected = 0xA684C7C6;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc32)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc32)(algorithm, check.slice(5), (0, index_1.crc32)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('CRC-32C', function () {
it('should return 0x280C069E', function (done) {
const crcCheck = (0, index_1.crc32)('CRC-32C', check);
crcCheck.should.equal(0x280C069E);
const algorithm = 'CRC-32C';
const expected = 0x280C069E;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc32)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc32)(algorithm, check.slice(5), (0, index_1.crc32)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('CRC-32D', function () {
it('should return 0x95ED974E', function (done) {
const crcCheck = (0, index_1.crc32)('CRC-32D', check);
crcCheck.should.equal(0x95ED974E);
const algorithm = 'CRC-32D';
const expected = 0x95ED974E;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc32)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc32)(algorithm, check.slice(5), (0, index_1.crc32)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('CRC-32Q', function () {
it('should return 0xB1FF798E', function (done) {
const crcCheck = (0, index_1.crc32)('CRC-32Q', check);
crcCheck.should.equal(0xB1FF798E);
const algorithm = 'CRC-32Q';
const expected = 0xB1FF798E;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc32)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc32)(algorithm, check.slice(5), (0, index_1.crc32)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('BZIP2', function () {
it('should return 0x96B0E4E0', function (done) {
const crcCheck = (0, index_1.crc32)('BZIP2', check);
crcCheck.should.equal(0x96B0E4E0);
const algorithm = 'BZIP2';
const expected = 0x96B0E4E0;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc32)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc32)(algorithm, check.slice(5), (0, index_1.crc32)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('JAMCRC', function () {
it('should return 0x597B3839', function (done) {
const crcCheck = (0, index_1.crc32)('JAMCRC', check);
crcCheck.should.equal(0x597B3839);
const algorithm = 'JAMCRC';
const expected = 0x597B3839;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc32)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc32)(algorithm, check.slice(5), (0, index_1.crc32)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('MPEG-2', function () {
it('should return 0x694F1B1F', function (done) {
const crcCheck = (0, index_1.crc32)('MPEG-2', check);
crcCheck.should.equal(0x694F1B1F);
const algorithm = 'MPEG-2';
const expected = 0x694F1B1F;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc32)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc32)(algorithm, check.slice(5), (0, index_1.crc32)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('POSIX', function () {
it('should return 0x07594AD8', function (done) {
const crcCheck = (0, index_1.crc32)('POSIX', check);
crcCheck.should.equal(0x07594AD8);
const algorithm = 'POSIX';
const expected = 0x07594AD8;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc32)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc32)(algorithm, check.slice(5), (0, index_1.crc32)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('XFER', function () {
it('should return 0x031DB075', function (done) {
const crcCheck = (0, index_1.crc32)('XFER', check);
crcCheck.should.equal(0x031DB075);
const algorithm = 'XFER';
const expected = 0x031DB075;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc32)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc32)(algorithm, check.slice(5), (0, index_1.crc32)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
});

@@ -13,71 +13,141 @@ "use strict";

describe('CRC-8', function () {
it('should return 0x45', function (done) {
const crcCheck = (0, index_1.crc8)('CRC-8', check);
crcCheck.should.equal(0x45);
const algorithm = 'CRC-8';
const expected = 0x45;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check.slice(5), (0, index_1.crc8)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('CDMA2000', function () {
it('should return 0xAB', function (done) {
const crcCheck = (0, index_1.crc8)('CDMA2000', check);
crcCheck.should.equal(0xAB);
const algorithm = 'CDMA2000';
const expected = 0xAB;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check.slice(5), (0, index_1.crc8)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('DARC', function () {
it('should return 0x83', function (done) {
const crcCheck = (0, index_1.crc8)('DARC', check);
crcCheck.should.equal(0x83);
const algorithm = 'DARC';
const expected = 0x83;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check.slice(5), (0, index_1.crc8)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('DVB-S2', function () {
it('should return 0x26', function (done) {
const crcCheck = (0, index_1.crc8)('DVB-S2', check);
crcCheck.should.equal(0x26);
const algorithm = 'DVB-S2';
const expected = 0x26;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check.slice(5), (0, index_1.crc8)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('EBU', function () {
it('should return 0xC0', function (done) {
const crcCheck = (0, index_1.crc8)('EBU', check);
crcCheck.should.equal(0xC0);
const algorithm = 'EBU';
const expected = 0xC0;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check.slice(5), (0, index_1.crc8)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('I-CODE', function () {
it('should return 0x6C', function (done) {
const crcCheck = (0, index_1.crc8)('I-CODE', check);
crcCheck.should.equal(0x6C);
const algorithm = 'I-CODE';
const expected = 0x6C;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check.slice(5), (0, index_1.crc8)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('ITU', function () {
it('should return 0x10', function (done) {
const crcCheck = (0, index_1.crc8)('ITU', check);
crcCheck.should.equal(0x10);
const algorithm = 'ITU';
const expected = 0x10;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check.slice(5), (0, index_1.crc8)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('MAXIM', function () {
it('should return 0x75', function (done) {
const crcCheck = (0, index_1.crc8)('MAXIM', check);
crcCheck.should.equal(0x75);
const algorithm = 'MAXIM';
const expected = 0x75;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check.slice(5), (0, index_1.crc8)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('ROHC', function () {
it('should return 0xE3', function (done) {
const crcCheck = (0, index_1.crc8)('ROHC', check);
crcCheck.should.equal(0xE3);
const algorithm = 'ROHC';
const expected = 0xE3;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check.slice(5), (0, index_1.crc8)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('WCDMA', function () {
it('should return 0xE3', function (done) {
const crcCheck = (0, index_1.crc8)('WCDMA', check);
crcCheck.should.equal(0xE3);
const algorithm = 'WCDMA';
const expected = 0xE3;
it(`should return ${expected}`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = (0, index_1.crc8)(algorithm, check.slice(5), (0, index_1.crc8)(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
});
{
"name": "easy-crc",
"version": "1.0.0",
"version": "1.1.0",
"description": "A pure JavaScript and zero dependencies CRC node module.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -16,4 +16,5 @@ # EASY-CRC

There are three functions available respectively named `crc8()`, `crc16()` and `crc32()`. These functions take two arguments.
The first argument is a string with the name of the desired algorithm (below the list), and the second is the data on which you want to calculate crc. Data can be a string or a buffer.
There are three functions available respectively named `crc8()`, `crc16()` and `crc32()`. These functions take three arguments.
The first argument is a string with the name of the desired algorithm (below the list), and the second is the data on which you want to calculate crc. Data can be a string or a buffer.
The third parameter is the **CRC seed** and is optional.

@@ -20,0 +21,0 @@ ```js

@@ -57,5 +57,6 @@ import { Crc16Algorithms } from "../common/interfaces";

* @param {String|Buffer} data A string or an array of bytes
* @param {Number=} seed A number
* @returns {Number} CRC16 checksum
*/
function crc16 (algorithm: keyof Crc16Algorithms, data: string | Buffer) {
function crc16 (algorithm: keyof Crc16Algorithms, data: string | Buffer, seed?: number) {
const availables = Object.keys(crc16Algorithms);

@@ -76,3 +77,3 @@ if (!availables.includes(algorithm))

let crc = refIn ? invertedInit || 0 : init;
let crc = seed ? seed ^ xorOut : (refIn ? invertedInit || 0 : init);

@@ -79,0 +80,0 @@ if (refOut) {

@@ -29,5 +29,6 @@ import { Crc32Algorithms } from "../common/interfaces";

* @param {String|Buffer} data A string or an array of bytes
* @param {Number=} seed A number
* @returns {Number} CRC32 checksum
*/
function crc32 (algorithm: keyof Crc32Algorithms, data: string | Buffer) {
function crc32 (algorithm: keyof Crc32Algorithms, data: string | Buffer, seed?: number) {
const availables = Object.keys(crc32Algorithms);

@@ -46,3 +47,3 @@ if (!availables.includes(algorithm))

let crc = init;
let crc = seed ? (seed ^ xorOut) : init;

@@ -49,0 +50,0 @@ if (refOut) {

@@ -31,5 +31,6 @@ import { Crc8Algorithms } from "../common/interfaces";

* @param {String|Buffer} data A string or an array of bytes
* @param {Number=} seed A number
* @returns {Number} CRC8 checksum
*/
function crc8 (algorithm: keyof Crc8Algorithms, data: string | Buffer) {
function crc8 (algorithm: keyof Crc8Algorithms, data: string | Buffer, seed?: number) {
const availables = Object.keys(crc8Algorithms);

@@ -47,3 +48,3 @@ if (!availables.includes(algorithm))

let crc = init;
let crc = seed ? seed ^ xorOut : init;

@@ -50,0 +51,0 @@ for (const b of data)

@@ -10,14 +10,30 @@ // Return values gotten from https://crccalc.com/

describe('CCITT-FALSE', function () {
it('should return 0x7D61', function (done) {
const crcCheck = crc16('CCITT-FALSE', check);
crcCheck.should.equal(0x7D61);
const algorithm = 'CCITT-FALSE';
const expected = 0x7D61;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('ARC', function () {
it('should return 0x443D', function (done) {
const crcCheck = crc16('ARC', check);
crcCheck.should.equal(0x443D);
const algorithm = 'ARC';
const expected = 0x443D;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});

@@ -32,119 +48,255 @@ // describe('AUG-CCITT', function () {

describe('CDMA2000', function () {
it('should return 0xD89D', function (done) {
const crcCheck = crc16('CDMA2000', check);
crcCheck.should.equal(0xD89D);
const algorithm = 'CDMA2000';
const expected = 0xD89D;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('BUYPASS', function () {
it('should return 0xFD14', function (done) {
const crcCheck = crc16('BUYPASS', check);
crcCheck.should.equal(0xFD14);
const algorithm = 'BUYPASS';
const expected = 0xFD14;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('DDS-110', function () {
it('should return 0xDB54', function (done) {
const crcCheck = crc16('DDS-110', check);
crcCheck.should.equal(0xDB54);
const algorithm = 'DDS-110';
const expected = 0xDB54;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('DECT-R', function () {
it('should return 0x422B', function (done) {
const crcCheck = crc16('DECT-R', check);
crcCheck.should.equal(0x422B);
const algorithm = 'DECT-R';
const expected = 0x422B;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('DECT-X', function () {
it('should return 0x422A', function (done) {
const crcCheck = crc16('DECT-X', check);
crcCheck.should.equal(0x422A);
const algorithm = 'DECT-X';
const expected = 0x422A;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('DNP', function () {
it('should return 0x6772', function (done) {
const crcCheck = crc16('DNP', check);
crcCheck.should.equal(0x6772);
const algorithm = 'DNP';
const expected = 0x6772;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('EN-13757', function () {
it('should return 0xFC73', function (done) {
const crcCheck = crc16('EN-13757', check);
crcCheck.should.equal(0xFC73);
const algorithm = 'EN-13757';
const expected = 0xFC73;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('GENIBUS', function () {
it('should return 0x829E', function (done) {
const crcCheck = crc16('GENIBUS', check);
crcCheck.should.equal(0x829E);
const algorithm = 'GENIBUS';
const expected = 0x829E;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('MAXIM', function () {
it('should return 0xBBC2', function (done) {
const crcCheck = crc16('MAXIM', check);
crcCheck.should.equal(0xBBC2);
const algorithm = 'MAXIM';
const expected = 0xBBC2;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('KERMIT', function () {
it('should return 0x5F6E', function (done) {
const crcCheck = crc16('KERMIT', check);
crcCheck.should.equal(0x5F6E);
const algorithm = 'KERMIT';
const expected = 0x5F6E;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('MCRF4XX', function () {
it('should return 0xC3E9', function (done) {
const crcCheck = crc16('MCRF4XX', check);
crcCheck.should.equal(0xC3E9);
const algorithm = 'MCRF4XX';
const expected = 0xC3E9;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('MODBUS', function () {
it('should return 0x434D', function (done) {
const crcCheck = crc16('MODBUS', check);
crcCheck.should.equal(0x434D);
const algorithm = 'MODBUS';
const expected = 0x434D;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('RIELLO', function () {
it('should return 0x9068', function (done) {
const crcCheck = crc16('RIELLO', check);
crcCheck.should.equal(0x9068);
const algorithm = 'RIELLO';
const expected = 0x9068;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('T10-DIF', function () {
it('should return 0xDE40', function (done) {
const crcCheck = crc16('T10-DIF', check);
crcCheck.should.equal(0xDE40);
const algorithm = 'T10-DIF';
const expected = 0xDE40;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('TELEDISK', function () {
it('should return 0x1BBF', function (done) {
const crcCheck = crc16('TELEDISK', check);
crcCheck.should.equal(0x1BBF);
const algorithm = 'TELEDISK';
const expected = 0x1BBF;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('TMS37157', function () {
it('should return 0xE2A2', function (done) {
const crcCheck = crc16('TMS37157', check);
crcCheck.should.equal(0xE2A2);
const algorithm = 'TMS37157';
const expected = 0xE2A2;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('USB', function () {
it('should return 0xBCB2', function (done) {
const crcCheck = crc16('USB', check);
crcCheck.should.equal(0xBCB2);
const algorithm = 'USB';
const expected = 0xBCB2;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});

@@ -157,17 +309,46 @@ describe('X-25', function () {

});
const algorithm = 'X-25';
const expected = 0x3C16;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('XMODEM', function () {
it('should return 0x9C58', function (done) {
const crcCheck = crc16('XMODEM', check);
crcCheck.should.equal(0x9C58);
const algorithm = 'XMODEM';
const expected = 0x9C58;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('CRC-A', function () {
it('should return 0x1194', function (done) {
const crcCheck = crc16('CRC-A', check);
crcCheck.should.equal(0x1194);
const algorithm = 'CRC-A';
const expected = 0x1194;
it(`should return ${expected}`, function (done) {
const crcCheck = crc16(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc16(algorithm, check.slice(5), crc16(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
});
// Return values gotten from https://crccalc.com/
import { doesNotMatch } from 'assert';
import chai from 'chai';

@@ -10,64 +11,136 @@ import { crc32 } from '../index'

describe('CRC-32', function () {
it('should return 0xA684C7C6', function (done) {
const crcCheck = crc32('CRC-32', check);
crcCheck.should.equal(0xA684C7C6);
const algorithm = 'CRC-32';
const expected = 0xA684C7C6;
it(`should return ${expected}`, function (done) {
const crcCheck = crc32(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc32(algorithm, check.slice(5), crc32(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('CRC-32C', function () {
it('should return 0x280C069E', function (done) {
const crcCheck = crc32('CRC-32C', check);
crcCheck.should.equal(0x280C069E);
const algorithm = 'CRC-32C';
const expected = 0x280C069E;
it(`should return ${expected}`, function (done) {
const crcCheck = crc32(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc32(algorithm, check.slice(5), crc32(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('CRC-32D', function () {
it('should return 0x95ED974E', function (done) {
const crcCheck = crc32('CRC-32D', check);
crcCheck.should.equal(0x95ED974E);
const algorithm = 'CRC-32D';
const expected = 0x95ED974E;
it(`should return ${expected}`, function (done) {
const crcCheck = crc32(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc32(algorithm, check.slice(5), crc32(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('CRC-32Q', function () {
it('should return 0xB1FF798E', function (done) {
const crcCheck = crc32('CRC-32Q', check);
crcCheck.should.equal(0xB1FF798E);
const algorithm = 'CRC-32Q';
const expected = 0xB1FF798E;
it(`should return ${expected}`, function (done) {
const crcCheck = crc32(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc32(algorithm, check.slice(5), crc32(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('BZIP2', function () {
it('should return 0x96B0E4E0', function (done) {
const crcCheck = crc32('BZIP2', check);
crcCheck.should.equal(0x96B0E4E0);
const algorithm = 'BZIP2';
const expected = 0x96B0E4E0;
it(`should return ${expected}`, function (done) {
const crcCheck = crc32(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc32(algorithm, check.slice(5), crc32(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('JAMCRC', function () {
it('should return 0x597B3839', function (done) {
const crcCheck = crc32('JAMCRC', check);
crcCheck.should.equal(0x597B3839);
const algorithm = 'JAMCRC';
const expected = 0x597B3839;
it(`should return ${expected}`, function (done) {
const crcCheck = crc32(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc32(algorithm, check.slice(5), crc32(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('MPEG-2', function () {
it('should return 0x694F1B1F', function (done) {
const crcCheck = crc32('MPEG-2', check);
crcCheck.should.equal(0x694F1B1F);
const algorithm = 'MPEG-2';
const expected = 0x694F1B1F;
it(`should return ${expected}`, function (done) {
const crcCheck = crc32(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc32(algorithm, check.slice(5), crc32(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('POSIX', function () {
it('should return 0x07594AD8', function (done) {
const crcCheck = crc32('POSIX', check);
crcCheck.should.equal(0x07594AD8);
const algorithm = 'POSIX';
const expected = 0x07594AD8;
it(`should return ${expected}`, function (done) {
const crcCheck = crc32(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc32(algorithm, check.slice(5), crc32(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('XFER', function () {
it('should return 0x031DB075', function (done) {
const crcCheck = crc32('XFER', check);
crcCheck.should.equal(0x031DB075);
const algorithm = 'XFER';
const expected = 0x031DB075;
it(`should return ${expected}`, function (done) {
const crcCheck = crc32(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc32(algorithm, check.slice(5), crc32(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
});

@@ -10,71 +10,151 @@ // Return values got from https://crccalc.com/

describe('CRC-8', function () {
it('should return 0x45', function (done) {
const crcCheck = crc8('CRC-8', check);
crcCheck.should.equal(0x45);
const algorithm = 'CRC-8';
const expected = 0x45;
it(`should return ${expected}`, function (done) {
const crcCheck = crc8(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc8(algorithm, check.slice(5), crc8(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('CDMA2000', function () {
it('should return 0xAB', function (done) {
const crcCheck = crc8('CDMA2000', check);
crcCheck.should.equal(0xAB);
const algorithm = 'CDMA2000';
const expected = 0xAB;
it(`should return ${expected}`, function (done) {
const crcCheck = crc8(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc8(algorithm, check.slice(5), crc8(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('DARC', function () {
it('should return 0x83', function (done) {
const crcCheck = crc8('DARC', check);
crcCheck.should.equal(0x83);
const algorithm = 'DARC';
const expected = 0x83;
it(`should return ${expected}`, function (done) {
const crcCheck = crc8(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc8(algorithm, check.slice(5), crc8(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('DVB-S2', function () {
it('should return 0x26', function (done) {
const crcCheck = crc8('DVB-S2', check);
crcCheck.should.equal(0x26);
const algorithm = 'DVB-S2';
const expected = 0x26;
it(`should return ${expected}`, function (done) {
const crcCheck = crc8(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc8(algorithm, check.slice(5), crc8(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('EBU', function () {
it('should return 0xC0', function (done) {
const crcCheck = crc8('EBU', check);
crcCheck.should.equal(0xC0);
const algorithm = 'EBU';
const expected = 0xC0;
it(`should return ${expected}`, function (done) {
const crcCheck = crc8(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc8(algorithm, check.slice(5), crc8(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('I-CODE', function () {
it('should return 0x6C', function (done) {
const crcCheck = crc8('I-CODE', check);
crcCheck.should.equal(0x6C);
const algorithm = 'I-CODE';
const expected = 0x6C;
it(`should return ${expected}`, function (done) {
const crcCheck = crc8(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc8(algorithm, check.slice(5), crc8(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('ITU', function () {
it('should return 0x10', function (done) {
const crcCheck = crc8('ITU', check);
crcCheck.should.equal(0x10);
const algorithm = 'ITU';
const expected = 0x10;
it(`should return ${expected}`, function (done) {
const crcCheck = crc8(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc8(algorithm, check.slice(5), crc8(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('MAXIM', function () {
it('should return 0x75', function (done) {
const crcCheck = crc8('MAXIM', check);
crcCheck.should.equal(0x75);
const algorithm = 'MAXIM';
const expected = 0x75;
it(`should return ${expected}`, function (done) {
const crcCheck = crc8(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc8(algorithm, check.slice(5), crc8(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('ROHC', function () {
it('should return 0xE3', function (done) {
const crcCheck = crc8('ROHC', check);
crcCheck.should.equal(0xE3);
const algorithm = 'ROHC';
const expected = 0xE3;
it(`should return ${expected}`, function (done) {
const crcCheck = crc8(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc8(algorithm, check.slice(5), crc8(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
describe('WCDMA', function () {
it('should return 0xE3', function (done) {
const crcCheck = crc8('WCDMA', check);
crcCheck.should.equal(0xE3);
const algorithm = 'WCDMA';
const expected = 0xE3;
it(`should return ${expected}`, function (done) {
const crcCheck = crc8(algorithm, check);
crcCheck.should.equal(expected);
done();
});
it(`should return ${expected} when seeded`, function (done) {
const crcCheck = crc8(algorithm, check.slice(5), crc8(algorithm, check.slice(0, 5)));
crcCheck.should.equal(expected);
done();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc