lib/Hash.js
function hash(input, algo, type){
    // string or buffer input ? => keep it
    if (typeof input !== 'string' && !(input instanceof Buffer)){
        input = JSON.stringify(input);
    }

    // create hash algo
    var sum = _crypto.createHash(algo);

    // set content
    sum.update(input);

    // binary output ?
    if (type && type.toLowerCase().trim() == 'binary'){
        // calculate hashsum
        return sum.digest();

    // base 64 urlsafe ?
    }else if (type==='base64-urlsafe'){
        return base64urlsafe(sum.digest('base64'));

    // string output
    }else{
        // calculate hashsum
        return sum.digest(type);
    }
}
function hash(input, algo, type){
    // string or buffer input ? => keep it
    if (typeof input !== 'string' && !(input instanceof Buffer)){
        input = JSON.stringify(input);
    }

    // create hash algo
    var sum = _crypto.createHash(algo);

    // set content
    sum.update(input);

    // binary output ?
    if (type && type.toLowerCase().trim() == 'binary'){
        // calculate hashsum
        return sum.digest();

    // base 64 urlsafe ?
    }else if (type==='base64-urlsafe'){
        return base64urlsafe(sum.digest('base64'));

    // string output
    }else{
        // calculate hashsum
        return sum.digest(type);
    }
}
function hash ( input , algo , type ) { // string or buffer input ? => keep it if ( typeof input !== 'string' && ! ( input instanceof Buffer ) ) { input = JSON . stringify ( input ) ; } // create hash algo var sum = _crypto . createHash ( algo ) ; // set content sum . update ( input ) ; // binary output ? if ( type && type . toLowerCase ( ) . trim ( ) == 'binary' ) { // calculate hashsum return sum . digest ( ) ; // base 64 urlsafe ? } else if ( type === 'base64-urlsafe' ) { return base64urlsafe ( sum . digest ( 'base64' ) ) ; // string output } else { // calculate hashsum return sum . digest ( type ) ; } }
generic string hashing
generic string hashing