@se-oss/md5
v1.0.0
Published
A simple, zero-dependency MD5 hashing library for Node.js and browsers. Automatically uses native crypto in Node.js for performance.
Maintainers
Readme
@se-oss/md5
@se-oss/md5 is a MD5 hashing library for JavaScript that works seamlessly in both Node.js and browser environments. It automatically detects the environment and uses the fastest available implementation, it's up to 50x faster than other popular libraries.
📦 Installation
pnpm install @se-oss/md5npm
npm install @se-oss/md5yarn
yarn add @se-oss/md5📖 Usage
@se-oss/md5 provides a simple and flexible API for creating MD5 hashes. It automatically selects the best implementation for your environment.
import { md5 } from '@se-oss/md5';
// Hash a string
const hash = md5('message');
console.log(hash); // Uint8Array [120, 231, 49, 2, 125, 143, 213, 14, 214, 66, 52, 11, 124, 154, 99, 179]
// Hash a Uint8Array
const uint8Array = new TextEncoder().encode('hello world');
const bufferHash = md5(uint8Array);
console.log(bufferHash); // Uint8Array [94, 182, 59, 187, 224, 30, 238, 208, 147, 203, 34, 187, 143, 90, 205, 195]🌐 Environments
This library is designed to be universal:
- Node.js: It automatically uses the built-in
node:cryptomodule for optimal performance. - Browsers and other environments: It falls back to a reliable pure JavaScript implementation.
You don't need to configure anything; the library handles the environment detection for you.
📚 Documentation
For all configuration options, please see the API docs.
🚀 Performance
When running in Node.js, @se-oss/md5 automatically uses the native node:crypto module, making it significantly faster than pure JavaScript implementations.
| Library | Short String Hashing | Long String (1MB) | Short Buffer Hashing | Long Buffer (1MB) | | ------------------------ | -------------------- | ----------------- | -------------------- | ----------------- | | @se-oss/md5 (Native) | 919,060 ops/sec | 682 ops/sec | 622,662 ops/sec | 849 ops/sec | | @se-oss/md5 | 874,791 ops/sec | 117 ops/sec | 685,003 ops/sec | 71 ops/sec | | md5 | 747,229 ops/sec | 56 ops/sec | 516,042 ops/sec | 16 ops/sec |
These benchmarks were run on a standard development machine. Your results may vary.
Benchmark script: src/index.bench.ts
🤝 Contributing
Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub.
Thanks again for your support, it is much appreciated! 🙏
License
MIT © Shahrad Elahi and contributors.
