Github style deterministic avatar generator using unique identifier for React application . SVG format, SSR-safe, zero runtime deps.
import { Identiface } from "react-identiface";
<Identiface identifier="user_name" />;| Prop | Type | Default |
|---|---|---|
identifier |
string (required) |
- |
size |
number |
100 |
background |
string (any CSS color) |
"#ffffff" |
shape |
"square" | "circle" | "triangle" | "diamond" |
"square" |
className |
string |
- |
style |
React.CSSProperties |
- |
ariaLabel |
string (accessible label override) |
identifier |
Instead, this package ships a small (~100 line) pure-JS MD5 implementation
(src/md5.ts) with no dependency on Web Crypto or Node's crypto module.
It's synchronous, so:
- The component computes its hash and full SVG markup in a single render
pass - no loading state, no
useEffect. - Server-rendered HTML and client-rendered HTML are byte-identical, so there's no hydration mismatch.
- It works the same in Node SSR, edge runtimes, static export, and the browser, since it doesn't touch any runtime-specific crypto API.
md5(identifier)-> 16 bytes (0-255 each).- The first 3 bytes become the foreground color:
rgb(r, g, b). - The 16 bytes are chunked into non-overlapping groups of 3, discarding any leftover (5 chunks of 3 = 15 bytes used, 1 discarded).
- Each 3-byte chunk
[a, b, c]is mirrored into a 5-wide row[a, b, c, b, a], then all 5 rows are flattened into a 25-cell grid. (replacesmirror_row/1+build_grid/1) - A cell is "filled" (painted with the foreground color) when its byte value is even.
- Each filled cell's grid position (
row,col) maps directly onto an SVG<rect>inside a0 0 100 100viewBox, sosizeis purely a presentational scale-factor (width/heighton the outer<svg>) and never affects the underlying pattern math.
.
square- the full grid, no clippingcircle- grid clipped to an inscribed circle.triangle/diamond- grid clipped to the respective polygon.
All shapes clip the same underlying background + grid, so the same identifier still produces a recognizably-related avatar across shapes.
npm install
npm run build