Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80522 views
1
2
var createHash = require('sha.js')
3
var Buffer = require('buffer').Buffer
4
var stringify = require('json-stable-stringify')
5
6
module.exports = function hash (str, alg, format) {
7
str = 'string' === typeof str ? str
8
: Buffer.isBuffer(str) ? str
9
: stringify(str)
10
return createHash(alg || 'sha1')
11
.update(str, Buffer.isBuffer(str) ? null : 'utf8').digest(format || 'hex')
12
}
13
14
15