36 lines
794 B
JavaScript
36 lines
794 B
JavaScript
// http://www.cse.yorku.ca/~oz/hash.html
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
0 && (module.exports = {
|
|
djb2Hash: null,
|
|
hexHash: null
|
|
});
|
|
function _export(target, all) {
|
|
for(var name in all)Object.defineProperty(target, name, {
|
|
enumerable: true,
|
|
get: all[name]
|
|
});
|
|
}
|
|
_export(exports, {
|
|
djb2Hash: function() {
|
|
return djb2Hash;
|
|
},
|
|
hexHash: function() {
|
|
return hexHash;
|
|
}
|
|
});
|
|
function djb2Hash(str) {
|
|
let hash = 5381;
|
|
for(let i = 0; i < str.length; i++){
|
|
const char = str.charCodeAt(i);
|
|
hash = (hash << 5) + hash + char;
|
|
}
|
|
return Math.abs(hash);
|
|
}
|
|
function hexHash(str) {
|
|
return djb2Hash(str).toString(36).slice(0, 5);
|
|
}
|
|
|
|
//# sourceMappingURL=hash.js.map
|