Package Exports
- ts-md5
- ts-md5/dist/cjs/index.js
- ts-md5/dist/esm/index.js
- ts-md5/dist/md5
- ts-md5/dist/md5.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ts-md5) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Introduction
A MD5 implementation for TypeScript
- Can handle Unicode strings
- Supports incremental hashing
- Works with Files and Blobs
This library also includes tools for:
- Hashing a file or blob
- A webworker for performing hashing
- A webworker handler for requesting files or blobs to be hashed
- promise based
- files or blobs are queued for processing on the webworker
Based on work by
- Joseph Myers: http://www.myersdaily.org/joseph/javascript/md5-text.html
- André Cruz: https://github.com/satazor/SparkMD5
- Raymond Hill: https://github.com/gorhill/yamd5.js
Usage
Install
Install the node module with npm install ts-md5
Basic Hashing
- Import the class
import {Md5} from 'ts-md5';
- Hash some things
Md5.hashStr('blah blah blah')
=> hex:stringMd5.hashStr('blah blah blah', true)
=> raw:Int32Array(4)Md5.hashAsciiStr('blah blah blah')
=> hex:stringMd5.hashAsciiStr('blah blah blah', true)
=> raw:Int32Array(4)
For more complex uses:
md5 = new Md5();
// Append incrementally your file or other input
// Methods are chainable
md5.appendStr('somestring')
.appendAsciiStr('a different string')
.appendByteArray(blob);
// Generate the MD5 hex string
md5.end();
Hashing a File
NOTE:: You have to make sure ts-md5/dist/md5_worker.js
is made available in your build so it can be accessed directly by a browser
It should always remain as a seperate file.
import {ParallelHasher} from 'ts-md5';
let hasher = new ParallelHasher('/path/to/ts-md5/dist/md5_worker.js');
hasher.hash(fileBlob).then(function(result) {
console.log('md5 of fileBlob is', result);
});
Building from src
The project is written in typescript and transpiled into ES5.
- Install TypeScript:
npm install -g typescript
(if you haven't already) - Configure compile options in
tsconfig.json
- Perform build using:
tsc
You can find more information here: https://github.com/Microsoft/TypeScript/wiki/tsconfig.json
Scripts
- Build Script:
npm run build
- Test Script:
npm run test
Publishing
- Sign up to https://www.npmjs.com/
- Configure
package.json
https://docs.npmjs.com/files/package.json - run
npm publish
https://docs.npmjs.com/cli/publish
License
MIT