Comprehensive Cyclic Redundancy Check (CRC) calculation library supporting 13 different CRC algorithms for Node.js and browser environments.
npx @tessl/cli install tessl/npm-crc@4.3.0Comprehensive Cyclic Redundancy Check (CRC) calculation library supporting 13 different CRC algorithms for Node.js and browser environments.
The CRC package provides a comprehensive set of CRC calculation functions with full TypeScript support, pure JavaScript implementation (no native dependencies), and support for both ESM and CommonJS module systems. It implements 13 different CRC algorithms including CRC1, CRC8 variants, CRC16 variants, CRC24, CRC32 variants, and CRCJAM.
Key features:
npm install crcimport { crc32, crc16, crc8, type CRCModule } from "crc";
import crc32 from "crc/crc32";
import crc32Calculator from "crc/calculators/crc32";const { crc32, crc16, crc8 } = require("crc");
const crc32 = require("crc/crc32");
const crc32Calculator = require("crc/calculators/crc32");/**
* Input types accepted by CRC functions
*/
type BufferInput = string | ArrayBuffer | Buffer;
/**
* Generic CRC calculator function interface
*/
interface CRCCalculator<T = BufferInput | Uint8Array> {
(value: T, previous?: number): number;
}
/**
* Main CRC function interface with additional properties
*/
interface CRCModule extends CRCCalculator<BufferInput> {
/** Returns signed CRC value */
signed: CRCCalculator<BufferInput>;
/** Returns unsigned CRC value (same as main function) */
unsigned: CRCCalculator<BufferInput>;
/** CRC model identifier string */
model: string;
}import crc32 from "crc/crc32";
// Calculate CRC32 of a string
const result = crc32("hello");
console.log(result.toString(16)); // "3610a686"
// Calculate CRC32 of a buffer
import fs from "fs";
const fileBuffer = fs.readFileSync("data.txt");
const fileCrc = crc32(fileBuffer);import crc32 from "crc/crc32";
// Calculate CRC incrementally for large data
let crcValue = crc32("chunk1");
crcValue = crc32("chunk2", crcValue);
crcValue = crc32("chunk3", crcValue);
console.log(crcValue.toString(16));import { crc32, crc16, crc8 } from "crc";
const data = "test data";
const crc32Result = crc32(data);
const crc16Result = crc16(data);
const crc8Result = crc8(data);The CRC package provides 13 different CRC algorithms organized by bit width:
The package supports multiple import strategies for different use cases:
import crc from "crc";
const result = crc.crc32("data");import { crc32, crc16ccitt } from "crc";import crc32 from "crc/crc32";
import crc16ccitt from "crc/crc16ccitt";import crc32Calculator from "crc/calculators/crc32";
const buffer = new Uint8Array([104, 101, 108, 108, 111]);
const result = crc32Calculator(buffer);Use direct imports for minimal bundle size:
// Only imports CRC32 algorithm
import crc32 from "crc/crc32";
// Even smaller - only the raw calculator
import crc32Calculator from "crc/calculators/crc32";Use raw calculators when working with Uint8Array data:
import crc32Calculator from "crc/calculators/crc32";
// Convert string to Uint8Array manually for better performance
const encoder = new TextEncoder();
const data = encoder.encode("hello");
const result = crc32Calculator(data);CRC functions are designed to be robust and handle various input types. Common considerations:
buffer polyfill for browser compatibility