@codegouvfr/react-dsfr
Version:
French State Design System React integration library
9 lines (8 loc) • 345 B
text/typescript
export function fnv1aHashToHex(str: string) {
let hash = 2166136261;
for (let i = 0; i < str.length; i++) {
hash ^= str.charCodeAt(i);
hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
}
return (hash >>> 0).toString(16); // Convert to unsigned 32-bit integer and then to hexadecimal
}