File: browser.js

package info (click to toggle)
node-shasum 1.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 104 kB
  • sloc: sh: 13; makefile: 11
file content (13 lines) | stat: -rw-r--r-- 385 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13

var createHash = require('sha.js')
var Buffer = require('buffer').Buffer
var stringify = require('json-stable-stringify')

module.exports = function hash (str, alg, format) {
  str = 'string' === typeof str ? str
    : Buffer.isBuffer(str) ? str
    : stringify(str)
  return createHash(alg || 'sha1')
    .update(str, Buffer.isBuffer(str) ? null : 'utf8').digest(format || 'hex')
}