client/packages/shared/src/code.ts
Alois f4088691c5
All checks were successful
/ build-web (push) Successful in 1m20s
/ build-desktop (linux) (push) Successful in 6m18s
/ build-mobile (push) Successful in 12m28s
/ release (push) Successful in 29s
(feat): improve profile popup in the navbar, add shared code to that popup
2026-06-03 16:14:39 +02:00

20 lines
772 B
TypeScript

export function toLossySixDigitCode(input: string): string {
let firstHash = 0xdeadbeef;
let secondHash = 0x41c6ce57;
for (let index = 0; index < input.length; index += 1) {
const character = input.charCodeAt(index);
firstHash = Math.imul(firstHash ^ character, 2654435761);
secondHash = Math.imul(secondHash ^ character, 1597334677);
}
firstHash = Math.imul(firstHash ^ (firstHash >>> 16), 2246822507);
firstHash ^= Math.imul(secondHash ^ (secondHash >>> 13), 3266489909);
secondHash = Math.imul(secondHash ^ (secondHash >>> 16), 2246822507);
secondHash ^= Math.imul(firstHash ^ (firstHash >>> 13), 3266489909);
const hash = 4294967296 * (2097151 & secondHash) + (firstHash >>> 0);
return String(hash % 1_000_000).padStart(6, "0");
}