1 | /* @flow */
|
2 |
|
3 | // a simple djb2 hash based on hash-string:
|
4 | // https://github.com/MatthewBarker/hash-string/blob/master/source/hash-string.js
|
5 | // returns a hex-encoded hash
|
6 | export default function hash(text: string): string {
|
7 | if (!text) {
|
8 | return '';
|
9 | }
|
10 |
|
11 | let hashValue = 5381;
|
12 | let index = text.length - 1;
|
13 |
|
14 | while (index) {
|
15 | hashValue = hashValue * 33 ^ text.charCodeAt(index);
|
16 | index -= 1;
|
17 | }
|
18 |
|
19 | return (hashValue >>> 0).toString(16);
|
20 | }
|