Skip to content

Instantly share code, notes, and snippets.

@jahilldev
Created May 30, 2022 15:47
Show Gist options
  • Save jahilldev/9e5a0553ae57d3548f192d53a254204c to your computer and use it in GitHub Desktop.
Save jahilldev/9e5a0553ae57d3548f192d53a254204c to your computer and use it in GitHub Desktop.
Generate a non-secure reproducible hash from an input seed value (not suitable for passwords, or sensitive data)
function getHash(value, length = 16) {
let hash = 0;
for (let index = 0; index < value.length; index++) {
hash = (hash << 5) - hash + value.charCodeAt(index);
hash = hash & hash;
}
hash = Math.abs(hash);
return `${hash}`.padStart(length, '0').substring(-1, length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment