UNPKG

shelving

Version:

Toolkit for using data in JavaScript.

13 lines (12 loc) 417 B
import { wrapNumber } from "./number.js"; /** Hash a string into an idempotent number. */ export function hashString(str) { let hash = 0; for (let i = 0; i < str.length; i++) hash += str.charCodeAt(i); return hash; } /** Hash a string into an idempotent number between two values. */ export function hashStringBetween(str, min = 0, max = 256) { return wrapNumber(hashString(str), min, max); }