ts-md5 is a TypeScript-first implementation of the MD5 hashing algorithm, designed for both Node.js (>=18) and browser environments. It provides functionalities for hashing Unicode and ASCII strings, supporting incremental hashing, and directly processing Files and Blobs. The library also includes advanced features like a `ParallelHasher` that leverages web workers for asynchronous file/blob hashing, improving performance in browser contexts. Its current stable version is 2.0.1, with releases showing active maintenance, including a recent major update to v2.0.0 in July 2025 that shifted to Vite for bundling. Key differentiators include its strong TypeScript typing, robust handling of various input types (strings, byte arrays, files), and built-in web worker support for computationally intensive tasks, making it a versatile choice for applications requiring MD5 checksums. It builds upon established MD5 implementations by Joseph Myers, André Cruz (SparkMD5), and Raymond Hill (yamd5.js).
npm install ts-md5Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic synchronous string hashing, incremental hashing with the Md5 class, and asynchronous blob hashing using ParallelHasher with a mocked Blob and worker path.
Migrate your project to use ECMAScript Modules (ESM) `import` syntax. If using Node.js, ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`) or use a bundler that transpiles ESM for CJS consumption.
Configure your build tool (e.g., Webpack, Rollup, Vite) to copy `node_modules/ts-md5/dist/md5_worker.js` to your public directory (e.g., `dist/public/ts-md5/md5_worker.js`) and pass the corresponding public URL (e.g., `/public/ts-md5/md5_worker.js`) to the `ParallelHasher` constructor.
For security-critical hashing, use modern and robust cryptographic hash functions like SHA-256, SHA-3, or Argon2 (for password hashing).
Always check the return type when using the second argument. If you consistently need a hexadecimal string, omit the second argument or explicitly convert the raw array to your desired format.
Update your import statements to use ESM `import { Md5 } from 'ts-md5';`. If your project is CommonJS, consider setting `"type": "module"` in your `package.json` or configuring your bundler to transpile ESM for CJS consumption.Ensure `md5_worker.js` (from `node_modules/ts-md5/dist/`) is copied to your public assets directory by your build system. Then, provide the correct, publicly accessible URL to the `ParallelHasher` constructor (e.g., `new ParallelHasher('/assets/md5_worker.js')`).Verify that you are importing `Md5` as a named export: `import { Md5 } from 'ts-md5';`. Then, call `Md5.hashStr()` directly on the class name, as it is a static method.No dependency data recorded yet.