Skip to content

Instantly share code, notes, and snippets.

@joscha
Created September 25, 2024 19:54
Show Gist options
  • Save joscha/b2f96866e4fb29c9dfadec7472ef0eb6 to your computer and use it in GitHub Desktop.
Save joscha/b2f96866e4fb29c9dfadec7472ef0eb6 to your computer and use it in GitHub Desktop.
"use strict";
var crypto_1 = require("crypto");
var util_1 = require("util");
/**
* Compute a string's hash.
*
* @param str The string to hash.
* @param algorithm The algorithm used.
*/
function getHash(str, algorithm) {
if (algorithm === void 0) { algorithm = 'md5'; }
var hash = (0, crypto_1.createHash)(algorithm);
hash.end(str);
var buf = hash.read();
return new Uint8Array(buf.buffer, buf.byteOffset, buf.length);
}
module.exports = {
getHash: getHash,
debuglog: util_1.debuglog,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment