13 lines
369 B
TypeScript
13 lines
369 B
TypeScript
/**
|
|
* Hash a phone number for analytics purposes
|
|
* Uses a consistent hashing algorithm to create a deterministic hash
|
|
*/
|
|
export function hashPhoneNumber(phoneNumber: string): string {
|
|
let hash = 0;
|
|
for (let i = 0; i < phoneNumber.length; i++) {
|
|
hash = ((hash << 5) - hash) + phoneNumber.charCodeAt(i);
|
|
hash |= 0;
|
|
}
|
|
return `hash_${Math.abs(hash)}`;
|
|
}
|