9 lines
275 B
TypeScript
9 lines
275 B
TypeScript
/** Non-cryptographic hash for cache keys and display purposes — do not use for security. */
|
|
export function strToHash(str: string): number {
|
|
let hash = 0;
|
|
for (let i = 0; i < str.length; i++) {
|
|
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
}
|
|
return hash;
|
|
}
|