All files / core/src/utilities fnv1aHash.ts

100% Statements 6/6
100% Branches 0/0
100% Functions 1/1
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15            174x 174x 6264x 6264x     174x    
/**
 * Generates a hash for a string using FNV-1a algorithm
 * @param str - string to hash
 * @returns the hashed string in base 36
 */
export default function fnv1aHash(str: string): string {
  let hash = 0x811c9dc5;
  for (let i = 0; i < str.length; i++) {
    hash ^= str.charCodeAt(i);
    hash +=
      (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
  }
  return (hash >>> 0).toString(36);
}