Skip to content

@avatune/vanilla

Source: packages/vanilla/README.md

Vanilla JavaScript function for rendering avatars from themes.

Terminal window
npm install @avatune/vanilla
import { avatar } from '@avatune/vanilla'
import theme from '@avatune/micah-theme/vanilla'
const svgString = avatar({
theme,
seed: 'user@example.com',
size: 200
})
document.getElementById('avatar-container').innerHTML = svgString
function avatar(args: AvatarArgs): string

Parameters:

{
theme: VanillaTheme // Theme to use for rendering (required)
seed?: string // Random seed for avatar generation
size?: number // Avatar size in pixels (default: theme size)
// Part selection (string identifier)
body?: string
ears?: string
eyebrows?: string
eyes?: string
hair?: string
head?: string
mouth?: string
noses?: string
// Part colors (CSS color values)
bodyColor?: string
earsColor?: string
eyebrowsColor?: string
eyesColor?: string
hairColor?: string
headColor?: string
mouthColor?: string
nosesColor?: string
}

Returns: SVG string ready for insertion into DOM

Random avatar with seed:

const svg = avatar({
theme: nevmstasTheme,
seed: '521411f1-fab6-4ed5-90bf-2863028bcae6'
})

Specific parts with custom colors:

const svg = avatar({
theme: nevmstasTheme,
hair: 'long',
hairColor: '#ff6b6b',
eyes: 'happy',
eyesColor: '#4ecdc4'
})