index.js 416 B

123456789101112
  1. var createHash = require('crypto').createHash
  2. var stringify = require('fast-safe-stringify')
  3. module.exports = function shasum (input, hash, digest) {
  4. if (!hash) hash = 'sha1'
  5. if (!digest) digest = 'hex'
  6. if (typeof input !== 'string' && !Buffer.isBuffer(input)) input = stringify.stable(input)
  7. return createHash(hash)
  8. .update(input, typeof input === 'string' ? 'utf8' : undefined)
  9. .digest(digest)
  10. }