All files hash.ts

100% Statements 5/5
50% Branches 1/2
100% Functions 2/2
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 16 17 18 19 20 21 229x                 9x   107x       1338x 1338x          
import { base64encode } from './base64';
 
/**
 * Non cryptographic quality hashing function
 * @param data - Hash content
 * @example
 * P.hash("THIS IS AWESOME") //=> LTU1MjU4ODc4NQ
 * @category Utility
 */
export function hash(data: string | undefined): string {
  // tslint:disable
  return base64encode(
    (data || '')
      .split('')
      .reduce((a, b) => {
        a = (a << 5) - a + b.charCodeAt(0);
        return a & a;
      }, 0)
      .toString()
  ).replace(/=/gm, '');
}