lion/packages-node/providence-analytics/src/program/utils/get-hash.js
2023-11-08 19:02:51 +01:00

16 lines
431 B
JavaScript

/**
* @param {string|object} inputValue
* @returns {number}
*/
export function getHash(inputValue) {
if (typeof inputValue === 'object') {
// eslint-disable-next-line no-param-reassign
inputValue = JSON.stringify(inputValue);
}
return inputValue.split('').reduce(
(prevHash, currVal) =>
// eslint-disable-next-line no-bitwise
((prevHash << 5) - prevHash + currVal.charCodeAt(0)) | 0,
0,
);
}