Skip to content

Instantly share code, notes, and snippets.

@iMoses
Created February 17, 2022 16:28
Show Gist options
  • Save iMoses/516245b9f9571f5731993e864ed79795 to your computer and use it in GitHub Desktop.
Save iMoses/516245b9f9571f5731993e864ed79795 to your computer and use it in GitHub Desktop.
function stringToHsl(
str,
{ saturation = 50, lightness = 50, range: [minHue, maxHue] = [0, 360] } = {}
) {
const hash = str.split('').reduce((hash, char) => char.charCodeAt(0) + ((hash << 5) - hash), 0);
return `hsl(${(Math.abs(hash) % (maxHue - minHue)) + minHue}, ${saturation}%, ${lightness}%)`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment