Git Product home page Git Product logo

ts-md5's Introduction

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

Usage

Basic Hashing

  1. Import the class
    • import {Md5} from 'ts-md5/dist/md5';
  2. Hash some things
    • Md5.hashStr('blah blah blah') => hex:string
    • Md5.hashStr('blah blah blah', true) => raw:Int32Array(4)
    • Md5.hashAsciiStr('blah blah blah') => hex:string
    • Md5.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/dist/parallel_hasher';

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.

  1. Install TypeScript: npm install -g typescript (if you haven't already)
  2. Configure compile options in tsconfig.json
  3. Perform build using: tsc

You can find more information here: https://github.com/Microsoft/TypeScript/wiki/tsconfig.json

Type Definitions

These allow projects like jasmine to work with .ts files. This is here as a guide more than anything else. See: https://github.com/typings/typings

  1. Install typings: npm install typings --global (if you haven't already)
  2. Download definitions: typings install jasmine --ambient --save
  3. Reference the typings using /// <reference path="../typings/main.d.ts" /> from tests

To update typings:

  • From command line run: typings install

Scripts

  1. Build Script: npm run build
  2. Test Script: npm run test

Publishing

  1. Sign up to https://www.npmjs.com/
  2. Configure package.json https://docs.npmjs.com/files/package.json
  3. run npm publish https://docs.npmjs.com/cli/publish

License

MIT

ts-md5's People

Contributors

mryuion avatar stakach avatar itsmontoya avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.