hashString()function
Hash a string into an idempotent number.
hashString(str: string): number
Lightweight, deterministic string-to-number hashing. Useful for consistently mapping a string to a bucket — for example picking a stable colour, avatar, or index for a user or entity name without storing anything.
Things to know:
hashStringBetween() wraps the result into [min, max) using modular arithmetic, so the same string always produces the same number within the range.import { hashString, hashStringBetween } from "shelving/util";
hashString("alice"); // 527 (stable across calls)
hashString("bob"); // 313
// Map a username to one of 10 avatar colours.
const colorIndex = hashStringBetween("alice", 0, 10); // 0–9Hash a string into an idempotent number.
hashString(str: string): number
Hash a string into an idempotent number wrapped between two values.
hashStringBetween(str: string, min = 0, max = 256): number