UNPKG

ts-prime

Version:

A utility library for JavaScript and Typescript.

22 lines (21 loc) 562 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var base64_1 = require("./base64"); /** * Non cryptographic quality hashing function * @param data - Hash content * @example * P.hash("THIS IS AWESOME") //=> LTU1MjU4ODc4NQ * @category Utility */ function hash(data) { // tslint:disable return base64_1.base64encode((data || '') .split('') .reduce(function (a, b) { a = (a << 5) - a + b.charCodeAt(0); return a & a; }, 0) .toString()).replace(/=/gm, ''); } exports.hash = hash;