16 lines
431 B
JavaScript
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,
|
|
);
|
|
}
|