nelsonic/hits

View on GitHub
lib/hash.js

Summary

Maintainability
A
0 mins
Test Coverage
var crypto = require('crypto');

// generate a hash of a specific length
module.exports = function hash (str, length) {
  return crypto.createHash('sha512') // crypto.stackexchange.com/questions/26336
  .update(str.toString()).digest('base64')
  .replace('/','').replace(/[Il0oO=\/\+]/g,'') // remove ambiguous chars
  .substring(0, length || 12);
}