Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

murmurhash mirror PR #127

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/ui/components/ui/identicon/generate.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Inspired by: https://github.com/vercel/avatar

import djb2a from 'djb2a';
import color from 'tinycolor2';
import Murmur from 'murmurhash3js';

// Deterministically getting a gradient from a string for use as an identicon
export const generateGradient = (str: string) => {
// Get first color
const hash = djb2a(str);
const hash = Murmur.x86.hash32(str);
const c = color({ h: hash % 360, s: 0.95, l: 0.5 });

const tetrad = c.tetrad(); // 4 colors spaced around the color wheel, the first being the input
Expand All @@ -22,11 +22,10 @@ export const generateGradient = (str: string) => {

export const generateSolidColor = (str: string) => {
// Get color
const hash = djb2a(str);
const hash = Murmur.x86.hash32(str);
const c = color({ h: hash % 360, s: 0.95, l: 0.5 })
.saturate(0)
.darken(20);

return {
bg: c.toHexString(),
// get readable text color
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"framer-motion": "^11.2.4",
"humanize-duration": "^3.32.0",
"lucide-react": "^0.378.0",
"murmurhash3js": "^3.0.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-loader-spinner": "^6.1.6",
Expand All @@ -83,6 +84,7 @@
"@testing-library/dom": "^10.1.0",
"@testing-library/react": "^15.0.7",
"@types/humanize-duration": "^3.27.4",
"@types/murmurhash3js": "^3.0.7",
"@types/react": "^18.3.2",
"@types/react-dom": "^18.3.0",
"@types/tinycolor2": "^1.4.6",
Expand Down
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.